hce-node application  1.4.3
HCE Hierarchical Cluster Engine node application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
DRCEFunctionalObjectBase.cpp
Go to the documentation of this file.
1 #include <Poco/JSON/Object.h>
2 #include <Poco/JSON/Array.h>
3 #include <Poco/JSON/JSON.h>
4 #include <Poco/JSON/Stringifier.h>
5 #include <Poco/JSON/Parser.h>
6 #include <Poco/JSON/JSONException.h>
7 #include <Poco/Dynamic/Var.h>
8 #include <algorithm>
9 #include <ctype.h>
10 
12 #include "DRCEMessageConst.hpp"
13 #include "DRCEError.hpp"
15 
16 namespace HCE
17 {
18 namespace drce
19 {
20 //-----------------------------------------------------------------------------
22 :errorMsg(""), errorCode(NO_ERROR), _isError(false), logger(drce_const::moduleName), environments()
23 {
24 }
25 //-----------------------------------------------------------------------------
27 {
29 }
30 //-----------------------------------------------------------------------------
32 {
33  logger.setLogStream(os);
34 }
35 //-----------------------------------------------------------------------------
36 std::string DRCEFunctionalObjectBase::logMsg(bool isReset)
37 {
38  return logger.logMsg(isReset);
39 }
40 //-----------------------------------------------------------------------------
42 {
43  return logger.log(logPriority);
44 }
45 //-----------------------------------------------------------------------------
47 {
48  logger.setLoggable(loggable);
49 }
50 //-----------------------------------------------------------------------------
52 {
54 }
55 //-----------------------------------------------------------------------------
56 //-----------------------------------------------------------------------------
57 // cppcheck-suppress unusedFunction
58 bool DRCEFunctionalObjectBase::insensitiveCompare(const std::string& lhs, const std::string& rhs)
59 {
60  std::string lhsCpy(lhs);
61  std::string rhsCpy(rhs);
62  std::transform(lhsCpy.begin(), lhsCpy.end(), lhsCpy.begin(), tolower);
63  std::transform(rhsCpy.begin(), rhsCpy.end(), rhsCpy.begin(), tolower);
64  return (lhsCpy == rhsCpy);
65 }
66 //-------------------------------------------------------------------
67 size_t DRCEFunctionalObjectBase::getElapsedTimeMsec(const Poco::Timestamp& tsStart)
68 {
69  Poco::Timestamp tsStop;
70  Poco::Timestamp::TimeDiff diff = tsStop-tsStart;
71  return static_cast<size_t>(diff/1000);
72 }
73 //-----------------------------------------------------------------------------
75 {
76  environments.clear();
77  if (!env.empty())
78  {
79  try
80  {
81  Poco::JSON::Parser parser;
82  Poco::Dynamic::Var res = parser.parse(env);
83  Poco::JSON::Object::Ptr pObj = res.extract<Poco::JSON::Object::Ptr>();
84 
85  if (!pObj.isNull())
86  {
87  Poco::Dynamic::Var tmp;
88  std::vector<std::string> names;
89  pObj->getNames(names);
90  for (size_t k=0;k<names.size();++k)
91  {
92  tmp = pObj->get(names[k]);
93  if (tmp.isString())
94  environments.push_back(std::make_pair(names[k], tmp.convert<std::string>()));
95  }
96  }
97  _isError = false;
98  }
99  catch(Poco::JSON::JSONException& e)
100  {
101  _isError = true;
102  errorMsg = std::string(message_const::setEnvironmentError)+": "+e.message();
104  }
105  catch(Poco::Exception& e)
106  {
107  _isError = true;
108  errorMsg = std::string(message_const::setEnvironmentError)+": "+e.message();
110  }
111  }
112 }
113 //-----------------------------------------------------------------------------
115 {
116  DRCETaskRequestSetExecute* pTaskRequestSetExecute = dynamic_cast<DRCETaskRequestSetExecute*>(pTaskRequest);
117  if (pTaskRequestSetExecute && !environments.empty())
118  {
119  SessionOptions sessionOptions = pTaskRequestSetExecute->getSessionOptions();
120  for (size_t i=0;i<environments.size();++i)
121  {
122  sessionOptions.environments.push_back(environments[i]);
123  }
124  pTaskRequestSetExecute->setSessionOptions(std::forward<SessionOptions>(sessionOptions));
125  }
126 }
127 //-----------------------------------------------------------------------------
128 //-----------------------------------------------------------------------------
129 } // namespace drce
130 } // namespace HCE