hce-node application  1.4.3
HCE Hierarchical Cluster Engine node application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
DataServerProxy.hpp
Go to the documentation of this file.
1 
16 #ifndef __HCE_DATASERVER_PROXY_INCLUDED__
17 #define __HCE_DATASERVER_PROXY_INCLUDED__
18 
19 #include <sstream>
20 #include <map>
21 
22 #include "Handler.hpp"
23 #include "DataNodeOptions.hpp"
24 
25 //Node ini
26 #include <Poco/Util/IniFileConfiguration.h>
27 #include "Poco/String.h"
28 //Message cover object
29 #include "JsonMessageCover.hpp"
30 //Calculator balancing nodes for execution
32 //Checker of resource usage limits
34 
35 namespace HCE {
36  namespace handlers {
37 
39  public:
40  DataServerProxy(std::string name, zmq::context_t& ctx, const std::string& clientIdentity, std::string connectionString,
41  unsigned char nodeMode, int64_t startedAt, unsigned char logPriority, const std::string& iniFile="");
43 
44  protected:
45  int initialize(void);
46  void deinitialize(void);
47  void* process(void);
48 
49  void handleInternalMessage(void);
50  void handleExternalMessage(void);
51 
52  std::string processAdminCommands(std::string& command, std::string& parameters);
53 
54  void logPeriodicStatistics(void);
55  void heartbit(void);
56  void sendHeartbeat(const std::string& identity);
57  void registerClient(const std::string& identity);
58 
59  void processControlMessage(zmsg& msg);
60  void processDataMessage(zmsg& msg);
61 
63  std::string getPropertyInformation(void);
64 
65  enum class EmptyResponseType : std::int8_t
66  {
67  ertNoClients=0,
68  ertBadNodeMode=1,
69  ertNotEnoughResourceLimits=2
70  };
72  std::string makeEmptyResponseMessage(const std::string& messageBody,
73  EmptyResponseType responseType,
74  const std::string& messageRoute,
75  const std::string& errorMsg="");
76 
79  const std::string& coverMessageBody,
80  EmptyResponseType responseType,
81  const std::string& messageId,
82  const std::string& messageRoute,
83  const std::string& errorMsg="");
84 
86  void sendResponseMessage(const std::string& identity,
87  const std::string& messageId,
88  const std::string& messageBody,
89  const std::string& messageRoute);
90 
92  void nodeInit(const std::string& iniFile);
93 
95  void checkInit(void);
96 
101 
103  size_t _previousClientNumber;
104 
106  size_t getRandomNodeNumber(size_t maxNumber);
108  std::string getIdentityRandom(std::vector<ClientWorkerItem>& clients,
109  size_t& previousClientNumber);
111  std::string getIdentityResourceUsage(std::vector<ClientWorkerItem>& clients,
112  size_t& previousClientNumber,
113  CalculatorAlgorithm::Types typeAlgorithm,
114  const CalculatorAlgorithmData& algorithmData);
115 
122 
125 
127  std::vector<ClientWorkerItem> _clientsQueue;
129 
131  int64_t _heartbeatAt;
132 
134  void setNodeMode(unsigned char nodeMode);
135  unsigned char getNodeMode(void);
136 
138  void setResourcesUsageAlg(unsigned int resourcesUsageAlg);
139  unsigned int getResourcesUsageAlg(void);
140 
142  void setResourcesUsageAlg0Weights(const std::string& resourcesUsageAlg0Weights);
143  std::string getResourcesUsageAlg0Weights(void);
144 
146  void setResourcesUsageOrder(unsigned int resourcesUsageOrder);
147  unsigned int getResourcesUsageOrder(void);
148 
150  void setResourcesUsageLimits(const std::string& resourcesUsageLimits);
151  std::string getResourcesUsageLimits(void);
152 
154  void setResourcesUsageCollectedSize(unsigned int resourcesUsageCollectedSize);
155  unsigned int getResourcesUsageCollectedSize(void);
156 
158  void setResourcesUsageMaxAllowedRange(double resourcesUsageMaxAllowedRange);
160 
162  void setResourcesExtractorMaxThreads(unsigned int resourcesExtractorMaxThreads);
163  unsigned int getResourcesExtractorMaxThreads(void);
164 
166  void setResourcesExtractorMaxProcesses(unsigned int resourcesExtractorMaxProcesses);
167  unsigned int getResourcesExtractorMaxProcesses(void);
168 
170  void setResourcesExtractorMaxDiskSize(unsigned int resourcesExtractorMaxDiskSize);
171  unsigned int getResourcesExtractorMaxDiskSize(void);
172 
174  void setResourcesExtractorMaxVramSize(unsigned int resourcesExtractorMaxVramSize);
175  unsigned int getResourcesExtractorMaxVramSize(void);
176 
178  void setResourcesExtractorMaxRramSize(unsigned int resourcesExtractorMaxRramSize);
179  unsigned int getResourcesExtractorMaxRramSize(void);
180 
182  void setStatClientRequests(unsigned int statClientRequests);
183  unsigned int getStatClientRequests(void);
184 
185  void setStatClientResponses(unsigned int statClientResponses);
186  unsigned int getStatClientResponses(void);
187 
188  void setStatRequests(unsigned int statRequests);
189  unsigned int getStatRequests(void);
190 
191  void setStatClientRequestsSize(unsigned int statRequestsSize);
192  unsigned int getStatClientRequestsSize(void);
193 
194  void setStatClientResponsesSize(unsigned int statResponsesSize);
195  unsigned int getStatClientResponsesSize(void);
196 
197  void setStatRequestsSize(unsigned int statRequestsSize);
198  unsigned int getStatRequestsSize(void);
199 
200  void setPeriodicStatClientRequests(unsigned int periodicStatClientRequests);
201  unsigned int getPeriodicStatClientRequests(void);
202 
203  void setPeriodicStatClientResponses(unsigned int periodicStatClientResponses);
204  unsigned int getPeriodicStatClientResponses(void);
205 
206  void setStatRequestsProcessed(unsigned int statRequestsProcessed);
207  unsigned int getStatRequestsProcessed(void);
208 
209  void setStatRequestsProcessedSize(unsigned int statRequestsProcessedSize);
210  unsigned int getStatRequestsProcessedSize(void);
211 
212  void setPeriodicStatClientRequestsSize(unsigned int periodicStatClientRequestsSize);
213  unsigned int getPeriodicStatClientRequestsSize(void);
214 
215  void setPeriodicStatClientResponsesSize(unsigned int periodicStatClientResponsesSize);
216  unsigned int getPeriodicStatClientResponsesSize(void);
217 
218  void setStatQPSClient(float statQPSClient);
219  float getStatQPSClient(void);
220 
221  void setStatQPSServer(float statQPSServer);
222  float getStatQPSServer(void);
223 
224  void setStatRPSClient(float statRPSClient);
225  float getStatRPSClient(void);
226 
227  void setStatRPSServer(float statRPSServer);
228  float getStatRPSServer(void);
229 
230  void setStatRequestsBandwidthClient(float statRequestsBandwidthClient);
231  float getStatRequestsBandwidthClient(void);
232 
233  void setStatRequestsBandwidthServer(float statRequestsBandwidthServer);
234  float getStatRequestsBandwidthServer(void);
235 
236  void setStatResponsesBandwidthClient(float statResponsesBandwidthClient);
238 
239  void setStatResponsesBandwidthServer(float statResponsesBandwidthServer);
241 
243  int64_t _pstatsAt = s_clock() + HEARTBEAT_DELAY;
244  };
245  }
246 }
247 
248 #endif /* __HCE_DATASERVER_PROXY_INCLUDED__ */