hce-node application  1.4.3
HCE Hierarchical Cluster Engine node application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
ResourceUsageLimitsChecker.cpp
Go to the documentation of this file.
1 /*
2  * ResourceUsageLimitsChecker.cpp
3  *
4  * Created on: Mar 17, 2015
5  * Author: alexander
6  */
7 
9 #include "JsonSerializable.hpp"
10 
11 namespace HCE
12 {
13 namespace handlers
14 {
15 //-----------------------------------------------------------------------------
17 : limitsData(limitsData_)
18 {
19 }
20 //-----------------------------------------------------------------------------
21 void ResourceUsageLimitsChecker::executeCheck(const CalculatorNodeResourceData& resourceData) throw (Poco::Exception)
22 {
24  for (ResourceUsageLimitsData::ConstIterator iter=limitsData.begin();iter!=limitsData.end();++iter)
25  {
26  const double resourceUsage = resourceData.getItem((*iter).first);
27  if ((*iter).second && (*iter).second < resourceUsage)
28  {
29  std::stringstream errMsg;
30  errMsg << "Node '" << resourceData.getIdentity() << "' has exceeded max allowed "
31  << resourcesUsageMessage[(*iter).first] << " resource usage. Limits: " << trim((*iter).second) << " %. Current usage: " << trim(resourceUsage) << " %.";
32  throw Poco::Exception(errMsg.str());
33  }
34  }
35 }
36 //-----------------------------------------------------------------------------
38 {
39  bool result = false;
40  errorMsg.clear();
41  try
42  {
43  executeCheck(resourceData);
44  result = true;
45  }
46  catch(Poco::Exception& e)
47  {
48  errorMsg = e.message();
49  }
50  return result;
51 }
52 //-----------------------------------------------------------------------------
53 //-----------------------------------------------------------------------------
54 }// end namespace handlers
55 } // end namespace HCE