hce-node application  1.4.3
HCE Hierarchical Cluster Engine node application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
DRCEFunctionalObjectTest.cpp
Go to the documentation of this file.
1 #include <gtest/gtest.h>
2 #include <fstream>
3 #include <sstream>
4 #include <iomanip>
5 #include <utility>
6 
7 #include "DRCEError.hpp"
8 #include "DRCESessionOptions.hpp"
12 #include "DRCEFunctionalObject.hpp"
14 #include "DRCEResultData.hpp"
16 
17 #include "DRCEProtocolsTest.hpp"
18 #include "DRCEPrintStatus.hpp"
21 
22 namespace HCE
23 {
24 namespace drce
25 {
26 namespace tests
27 {
28 //-----------------------------------------------------------------------------
30 {
31  std::vector<std::pair<std::string, std::string> > testEnv={{"env1", "val1"}, {"env2", "val2"}, {"env3", "val3"}};
32 
34  DRCEFunctionalObject fObj(nodeOptions.getNodeName(), nodeOptions.getHomeDir(), nodeOptions.getTasksDataDir(), nodeOptions.getTasksStatusDir());
35 
36  std::stringstream sourceJson;
37  DRCETaskRequestSetExecute sourceMessage;
38  sourceMessage.setCommandLine("env | grep PATH");
39 
40  SessionOptions sessionOption;
41  sessionOption.shellName = "bash -c";
42  sessionOption.environments = testEnv;
43  sourceMessage.setSessionOptions(sessionOption);
44 
45  sourceJson << sourceMessage;
46 
47 // std::cout << "sourceJson = " << sourceJson.str() << std::endl;
48 
49  ASSERT_FALSE(sourceMessage.isError()) << printError(sourceMessage);
50  ASSERT_EQ(sourceMessage.getErrorCode(), NO_ERROR);
51  ASSERT_TRUE(sourceMessage.getErrorMsg().empty());
52  printSuccess("DRCETaskRequestSetExecute serialize");
53 
54  DRCEInputJsonMessage inputJsonMessage;
55  inputJsonMessage.setRequestType(DRCETaskRequest::RequestType::rtSetTaskExecute);
56  inputJsonMessage.setRequestData(sourceJson.str());
57  inputJsonMessage.setRequestId(2345);
58 
59  sourceJson.str("");
60  sourceJson << inputJsonMessage;
61 
62  ASSERT_FALSE(inputJsonMessage.isError()) << printError(inputJsonMessage);
63  ASSERT_EQ(inputJsonMessage.getErrorCode(), NO_ERROR);
64  ASSERT_TRUE(inputJsonMessage.getErrorMsg().empty());
65  printSuccess("DRCEInputJsonMessage serialize");
66 
67  std::string resultJson = fObj.Process(sourceJson.str());
68 
69 // std::cout << "resultJson = " << resultJson << std::endl;
70 
71  ASSERT_FALSE(fObj.isError()) << printError(fObj);
72  ASSERT_EQ(fObj.getErrorCode(), NO_ERROR);
73  ASSERT_TRUE(fObj.getErrorMsg().empty());
74  printSuccess("DRCEFunctionalObject Process use Enviroments");
75 }
76 //-----------------------------------------------------------------------------
77 //-----------------------------------------------------------------------------
79 {
80  const std::string json = "{\"session\":{\"type\":0,\"port\":0,\"user\":\"\",\"tmode\":1,\"time_max\":0,\"password\":\"\",\"shell\":\"\",\"environment\":[{\"LINES\":\"80\",\"HOSTNAME\":\"node22\"}]},\"command\":\"sort\",\"input\":\"def\\nabc\\n123\\n\",\"files\":[{\"name\":\"file1\",\"data\":\"test content of file1\\n\",\"action\":13},{\"name\":\"file2\",\"data\":\"test content of file2\\n\",\"action\":1}]}";
81 
83  DRCEFunctionalObject fObj(nodeOptions.getNodeName(), nodeOptions.getHomeDir(), nodeOptions.getTasksDataDir(), nodeOptions.getTasksStatusDir());
84 
85  DRCETaskRequestSetExecute inputJsonMessage(json);
86 
87  ASSERT_FALSE(inputJsonMessage.isError()) << printError(inputJsonMessage);
88  ASSERT_EQ(inputJsonMessage.getErrorCode(), NO_ERROR);
89  ASSERT_TRUE(inputJsonMessage.getErrorMsg().empty());
90  printSuccess("DRCETaskRequestSetExecute unserialize");
91 
92  ASSERT_EQ(inputJsonMessage.getSessionOptions().sessionType, static_cast<SessionOptions::SessionType>(0));
93  ASSERT_TRUE(inputJsonMessage.getSessionOptions().userName.empty());
94  ASSERT_TRUE(inputJsonMessage.getSessionOptions().userPassword.empty());
95  ASSERT_TRUE(inputJsonMessage.getSessionOptions().shellName.empty());
96  ASSERT_EQ(inputJsonMessage.getSessionOptions().port, 0);
97  ASSERT_EQ(inputJsonMessage.getSessionOptions().environments.size(), 2);
98  for (size_t i=0;i<inputJsonMessage.getSessionOptions().environments.size();++i)
99  {
100  if (inputJsonMessage.getSessionOptions().environments[i].first=="LINES")
101  ASSERT_EQ(inputJsonMessage.getSessionOptions().environments[i].second, "80");
102  if (inputJsonMessage.getSessionOptions().environments[i].first=="HOSTNAME")
103  ASSERT_EQ(inputJsonMessage.getSessionOptions().environments[i].second, "node22");
104  }
105  printSuccess("DRCESessionOptions checking members");
106 
107  ASSERT_EQ(inputJsonMessage.getFilesCount(), 2);
108  for (size_t i=0;i<inputJsonMessage.getFilesCount();++i)
109  {
110  if (inputJsonMessage.getFileItem(i).name=="file1")
111  {
112  ASSERT_EQ(inputJsonMessage.getFileItem(i).data, "test content of file1\n");
113  ASSERT_EQ(inputJsonMessage.getFileItem(i).actionType, 13);
114  }
115  if (inputJsonMessage.getFileItem(i).name=="file2")
116  {
117  ASSERT_EQ(inputJsonMessage.getFileItem(i).data, "test content of file2\n");
118  ASSERT_EQ(inputJsonMessage.getFileItem(i).actionType, 1);
119  }
120  }
121  printSuccess("DRCEFilesItemArray checking members");
122 
123  ASSERT_EQ(inputJsonMessage.getCommandLine(), "sort");
124  ASSERT_EQ(inputJsonMessage.getInputStream(), "def\nabc\n123\n");
125  printSuccess("Test Request for local Shell Input");
126 }
127 //-----------------------------------------------------------------------------
129 {
130  const std::string json = "[{\"error_code\": 0,\"error_message\": \"Success\",\"exit_status\": 5,\"fields\": [],\"files\":[{\"action\":13,\"data\":\"test content of file1\\n\",\"name\":\"file1\"}],\"host\":\"\",\"id\":2345,\"node\":\"TEST_NODE\",\"pid\":2595,\"port\":\"\",\"state\":42,\"stderror\":\"\",\"stdout\":\"MTIzCmFiYwpkZWYK\",\"time\":5,\"type\":0}]";
131 
132  DRCEOutputJsonMessage outputJsonMessage(json);
133 
134  ASSERT_FALSE(outputJsonMessage.isError()) << printError(outputJsonMessage);
135  ASSERT_EQ(outputJsonMessage.getErrorCode(), NO_ERROR);
136  ASSERT_TRUE(outputJsonMessage.getErrorMsg().empty());
137  printSuccess("DRCEOutputJsonMessage unserialize");
138 
139  ASSERT_EQ(outputJsonMessage.getResultData().getItemsCount(), 1);
140  ASSERT_EQ(outputJsonMessage.getResultData().getDataItem(0).getStdoutStream(), "123\nabc\ndef\n");
141  ASSERT_EQ(outputJsonMessage.getResultData().getDataItem(0).getStderrStream(), "");
142  ASSERT_EQ(outputJsonMessage.getResultData().getDataItem(0).getErrorCode(), 0);
143  ASSERT_EQ(outputJsonMessage.getResultData().getDataItem(0).getErrorMessage(), "Success");
144  ASSERT_EQ(outputJsonMessage.getResultData().getDataItem(0).getExitStatus(), 5);
145  ASSERT_EQ(outputJsonMessage.getResultData().getDataItem(0).getNodeHost(), "");
146  ASSERT_EQ(outputJsonMessage.getResultData().getDataItem(0).getNodeName(), "TEST_NODE");
147  ASSERT_EQ(outputJsonMessage.getResultData().getDataItem(0).getNodePort(), "");
148  ASSERT_EQ(outputJsonMessage.getResultData().getDataItem(0).getRequestId(), 2345);
149  ASSERT_EQ(outputJsonMessage.getResultData().getDataItem(0).getRequestType(), DRCETaskRequest::RequestType::rtSetTaskExecute);
150  ASSERT_EQ(outputJsonMessage.getResultData().getDataItem(0).getTime(), 5);
151  ASSERT_EQ(outputJsonMessage.getResultData().getDataItem(0).getState(), 42);
152  ASSERT_EQ(outputJsonMessage.getResultData().getDataItem(0).getFilesCount(), 1);
153  ASSERT_EQ(outputJsonMessage.getResultData().getDataItem(0).getFileItem(0).name, "file1");
154  ASSERT_EQ(outputJsonMessage.getResultData().getDataItem(0).getFileItem(0).data, "test content of file1\n");
155  ASSERT_EQ(outputJsonMessage.getResultData().getDataItem(0).getFileItem(0).actionType, 13);
156  printSuccess("Test Request for local Shell Output");
157 }
158 //-----------------------------------------------------------------------------
160 {
161  const std::string requestJson = "{\"session\":{\"type\":0,\"port\":0,\"user\":\"\",\"time_max\":0,\"tmode\":1,\"time_max\":0,\"password\":\"\",\"shell\":\"\",\"environment\":[{\"LINES\":\"80\",\"HOSTNAME\":\"node22\"}]},\"command\":\"sort\",\"input\":\"def\\nabc\\n123\\n\",\"files\":[{\"name\":\"file1\",\"data\":\"test content of file1\\n\",\"action\":13},{\"name\":\"file2\",\"data\":\"test content of file2\\n\",\"action\":1}]}";
162 
164  DRCEFunctionalObject fObj(nodeOptions.getNodeName(), nodeOptions.getHomeDir(), nodeOptions.getTasksDataDir(), nodeOptions.getTasksStatusDir());
165  fObj.setNodeHost("NODE_HOST");
166  fObj.setNodePort("NODE_PORT");
167  fObj.setNodeName("NODE_NAME");
168 
169 // std::cout << "json: " << requestJson << std::endl;
170 
171  DRCEInputJsonMessage inputJsonMessage;
172  inputJsonMessage.setRequestType(DRCETaskRequest::RequestType::rtSetTaskExecute);
173  inputJsonMessage.setRequestData(requestJson);
174  inputJsonMessage.setRequestId(2345);
175 
176  std::stringstream sourceJson;
177  sourceJson << inputJsonMessage;
178 
179  ASSERT_FALSE(inputJsonMessage.isError()) << printError(inputJsonMessage);
180  ASSERT_EQ(inputJsonMessage.getErrorCode(), NO_ERROR);
181  ASSERT_TRUE(inputJsonMessage.getErrorMsg().empty());
182  printSuccess("DRCEInputJsonMessage serialize");
183 
184 // std::cout << "IN JSON: " << sourceJson.str() << std::endl;
185 
186  std::string resultJson = fObj.Process(sourceJson.str());
187 
188  ASSERT_FALSE(fObj.isError()) << printError(fObj);
189  ASSERT_EQ(fObj.getErrorCode(), NO_ERROR);
190  ASSERT_TRUE(fObj.getErrorMsg().empty());
191  printSuccess("DRCEFunctionalObject Process");
192 
193 // std::cout << "OUT JSON: " << resultJson << std::endl;
194 
195  DRCEOutputJsonMessage resultJsonMessage(resultJson);
196 
197  ASSERT_FALSE(resultJsonMessage.isError()) << printError(resultJsonMessage);
198  ASSERT_EQ(resultJsonMessage.getErrorCode(), NO_ERROR);
199  ASSERT_TRUE(resultJsonMessage.getErrorMsg().empty());
200  printSuccess("DRCEOutputJsonMessage unserialize");
201 
202  ASSERT_EQ(resultJsonMessage.getResultData().getItemsCount(), 1);
203  ASSERT_EQ(resultJsonMessage.getResultData().getDataItem(0).getStdoutStream(), "123\nabc\ndef\n");
204  ASSERT_EQ(resultJsonMessage.getResultData().getDataItem(0).getStderrStream(), "");
205  ASSERT_EQ(resultJsonMessage.getResultData().getDataItem(0).getErrorCode(), 0);
206  ASSERT_EQ(resultJsonMessage.getResultData().getDataItem(0).getErrorMessage(), "");
207  ASSERT_EQ(resultJsonMessage.getResultData().getDataItem(0).getExitStatus(), 0);
208  ASSERT_EQ(resultJsonMessage.getResultData().getDataItem(0).getNodeHost(), "NODE_HOST");
209  ASSERT_EQ(resultJsonMessage.getResultData().getDataItem(0).getNodeName(), "NODE_NAME");
210  ASSERT_EQ(resultJsonMessage.getResultData().getDataItem(0).getNodePort(), "NODE_PORT");
211  ASSERT_EQ(resultJsonMessage.getResultData().getDataItem(0).getRequestId(), 2345);
212  ASSERT_EQ(resultJsonMessage.getResultData().getDataItem(0).getRequestType(), DRCETaskRequest::RequestType::rtSetTaskExecute);
213  ASSERT_EQ(resultJsonMessage.getResultData().getDataItem(0).getFilesCount(), 1);
214  ASSERT_EQ(resultJsonMessage.getResultData().getDataItem(0).getFileItem(0).name, "file1");
215  ASSERT_EQ(resultJsonMessage.getResultData().getDataItem(0).getFileItem(0).data, "test content of file1\n");
216  ASSERT_EQ(resultJsonMessage.getResultData().getDataItem(0).getFileItem(0).actionType, 13);
217  printSuccess("Test Request for local Shell (sort)");
218 }
219 //-----------------------------------------------------------------------------
220 //-----------------------------------------------------------------------------
222 {
223  const std::string json = "{\"session\":{\"type\":0,\"port\":0,\"user\":\"\",\"password\":\"\",\"time_max\":0,\"tmode\":1,\"shell\":\"\",\"environment\":[{\"LINES\":\"80\",\"HOSTNAME\":\"node22\"}]},\"command\":\"ps > _ps_results.txt\",\"input\":\"\",\"files\":[{\"name\":\"_ps_results.txt\",\"data\":\"\",\"action\":12}]}";
224 
226  DRCEFunctionalObject fObj(nodeOptions.getNodeName(), nodeOptions.getHomeDir(), nodeOptions.getTasksDataDir(), nodeOptions.getTasksStatusDir());
227 
228  DRCETaskRequestSetExecute taskRequestExecute(json);
229 
230  ASSERT_FALSE(taskRequestExecute.isError()) << printError(taskRequestExecute);
231  ASSERT_EQ(taskRequestExecute.getErrorCode(), NO_ERROR);
232  ASSERT_TRUE(taskRequestExecute.getErrorMsg().empty());
233  printSuccess("DRCETaskRequestSetExecute unserialize");
234 
235  ASSERT_EQ(taskRequestExecute.getSessionOptions().sessionType, static_cast<SessionOptions::SessionType>(0));
236  ASSERT_TRUE(taskRequestExecute.getSessionOptions().userName.empty());
237  ASSERT_TRUE(taskRequestExecute.getSessionOptions().userPassword.empty());
238  ASSERT_TRUE(taskRequestExecute.getSessionOptions().shellName.empty());
239  ASSERT_EQ(taskRequestExecute.getSessionOptions().port, 0);
240  ASSERT_EQ(taskRequestExecute.getSessionOptions().environments.size(), 2);
241 
242  for (size_t i=0;i<taskRequestExecute.getSessionOptions().environments.size();++i)
243  {
244  if (taskRequestExecute.getSessionOptions().environments[i].first=="LINES")
245  ASSERT_EQ(taskRequestExecute.getSessionOptions().environments[i].second, "80");
246  if (taskRequestExecute.getSessionOptions().environments[i].first=="HOSTNAME")
247  ASSERT_EQ(taskRequestExecute.getSessionOptions().environments[i].second, "node22");
248  }
249  printSuccess("SessionOptions checking members");
250 
251  ASSERT_EQ(taskRequestExecute.getFilesCount(), 1);
252  ASSERT_EQ(taskRequestExecute.getFileItem(0).name, "_ps_results.txt");
253  ASSERT_TRUE(taskRequestExecute.getFileItem(0).data.empty());
254  ASSERT_EQ(taskRequestExecute.getFileItem(0).actionType, 12);
255  printSuccess("DRCEFilesItemList checking members");
256 
257  ASSERT_EQ(taskRequestExecute.getCommandLine(), "ps > _ps_results.txt");
258  ASSERT_TRUE(taskRequestExecute.getInputStream().empty());
259  printSuccess("Test Request for local Shell Input");
260 }
261 //-----------------------------------------------------------------------------
263 {
264  const std::string json = "[{\"error_code\":1,\"error_message\":\"none\",\"exit_status\":127,\"fields\":[],\"files\":[{\"action\":12,\"data\":\"File content\",\"name\":\"_ps_results.txt\"}],\"host\":\"NODE_HOST\",\"id\":2345,\"node\":\"NODE_NAME\",\"pid\":4208,\"port\":\"NODE_PORT\",\"state\":42,\"stderror\":\"stderr_content\",\"stdout\":\"stdout_content\",\"time\":13,\"type\":1}]";
265 
266  DRCEOutputJsonMessage outputJsonMessage(json);
267 
268  ASSERT_FALSE(outputJsonMessage.isError()) << printError(outputJsonMessage);
269  ASSERT_EQ(outputJsonMessage.getErrorCode(), NO_ERROR);
270  ASSERT_TRUE(outputJsonMessage.getErrorMsg().empty());
271  printSuccess("DRCEOutputJsonMessage unserialize");
272 
273  ASSERT_EQ(outputJsonMessage.getResultData().getItemsCount(), 1);
274  ASSERT_EQ(outputJsonMessage.getResultData().getDataItem(0).getStdoutStream(), "");
275  ASSERT_EQ(outputJsonMessage.getResultData().getDataItem(0).getStderrStream(), "");
276  ASSERT_EQ(outputJsonMessage.getResultData().getDataItem(0).getErrorCode(), 1);
277  ASSERT_EQ(outputJsonMessage.getResultData().getDataItem(0).getErrorMessage(), "none");
278  ASSERT_EQ(outputJsonMessage.getResultData().getDataItem(0).getExitStatus(), 127);
279  ASSERT_EQ(outputJsonMessage.getResultData().getDataItem(0).getNodeHost(), "NODE_HOST");
280  ASSERT_EQ(outputJsonMessage.getResultData().getDataItem(0).getNodeName(), "NODE_NAME");
281  ASSERT_EQ(outputJsonMessage.getResultData().getDataItem(0).getNodePort(), "NODE_PORT");
282  ASSERT_EQ(outputJsonMessage.getResultData().getDataItem(0).getRequestId(), 2345);
283  ASSERT_EQ(outputJsonMessage.getResultData().getDataItem(0).getRequestType(), DRCETaskRequest::RequestType::rtCheckTaskState);
284  ASSERT_EQ(outputJsonMessage.getResultData().getDataItem(0).getTime(), 13);
285  ASSERT_EQ(outputJsonMessage.getResultData().getDataItem(0).getState(), 42);
286  ASSERT_EQ(outputJsonMessage.getResultData().getDataItem(0).getFilesCount(), 1);
287  ASSERT_EQ(outputJsonMessage.getResultData().getDataItem(0).getFileItem(0).name, "_ps_results.txt");
288  ASSERT_EQ(outputJsonMessage.getResultData().getDataItem(0).getFileItem(0).data, "File content");
289  ASSERT_EQ(outputJsonMessage.getResultData().getDataItem(0).getFileItem(0).actionType, 12);
290  printSuccess("Test Request for local Shell Output");
291 }
292 //-----------------------------------------------------------------------------
294 {
295  const std::string requestJson = "{\"session\":{\"type\":0,\"port\":0,\"user\":\"\",\"time_max\":0,\"tmode\":1,\"password\":\"\",\"shell\":\"\",\"environment\":[{\"LINES\":\"80\",\"HOSTNAME\":\"node22\"}]},\"command\":\"ps > _ps_results.txt\",\"input\":\"\",\"files\":[{\"name\":\"_ps_results.txt\",\"data\":\"\",\"action\":12}]}";
296 
298  DRCEFunctionalObject fObj(nodeOptions.getNodeName(), nodeOptions.getHomeDir(), nodeOptions.getTasksDataDir(), nodeOptions.getTasksStatusDir());
299  fObj.setNodeHost("NODE_HOST");
300  fObj.setNodePort("NODE_PORT");
301  fObj.setNodeName("NODE_NAME");
302 
303 // std::cout << "json: " << requestJson << std::endl;
304 
305  DRCEInputJsonMessage inputJsonMessage;
306  inputJsonMessage.setRequestType(DRCETaskRequest::RequestType::rtSetTaskExecute);
307  inputJsonMessage.setRequestData(requestJson);
308  inputJsonMessage.setRequestId(2345);
309 
310  std::stringstream sourceJson;
311  sourceJson << inputJsonMessage;
312 
313  ASSERT_FALSE(inputJsonMessage.isError()) << printError(inputJsonMessage);
314  ASSERT_EQ(inputJsonMessage.getErrorCode(), NO_ERROR);
315  ASSERT_TRUE(inputJsonMessage.getErrorMsg().empty());
316  printSuccess("DRCEInputJsonMessage serialize");
317 
318 // std::cout << "IN JSON: " << sourceJson.str() << std::endl;
319 
320  std::string resultJson = fObj.Process(sourceJson.str());
321 
322  ASSERT_FALSE(fObj.isError()) << printError(fObj);
323  ASSERT_EQ(fObj.getErrorCode(), NO_ERROR);
324  ASSERT_TRUE(fObj.getErrorMsg().empty());
325  printSuccess("DRCEFunctionalObject Process");
326 
327 // std::cout << "OUT JSON: " << resultJson << std::endl;
328 
329  DRCEOutputJsonMessage resultJsonMessage(resultJson);
330 
331  ASSERT_FALSE(resultJsonMessage.isError()) << printError(resultJsonMessage);
332  ASSERT_EQ(resultJsonMessage.getErrorCode(), NO_ERROR);
333  ASSERT_TRUE(resultJsonMessage.getErrorMsg().empty());
334  printSuccess("DRCEOutputJsonMessage unserialize");
335 
336  ASSERT_EQ(resultJsonMessage.getResultData().getItemsCount(), 1);
337  ASSERT_EQ(resultJsonMessage.getResultData().getDataItem(0).getStdoutStream(), "");
338  ASSERT_EQ(resultJsonMessage.getResultData().getDataItem(0).getStderrStream(), "");
339  ASSERT_EQ(resultJsonMessage.getResultData().getDataItem(0).getErrorCode(), 0);
340  ASSERT_EQ(resultJsonMessage.getResultData().getDataItem(0).getErrorMessage(), "");
341  ASSERT_EQ(resultJsonMessage.getResultData().getDataItem(0).getExitStatus(), 0);
342  ASSERT_EQ(resultJsonMessage.getResultData().getDataItem(0).getNodeHost(), "NODE_HOST");
343  ASSERT_EQ(resultJsonMessage.getResultData().getDataItem(0).getNodeName(), "NODE_NAME");
344  ASSERT_EQ(resultJsonMessage.getResultData().getDataItem(0).getNodePort(), "NODE_PORT");
345  ASSERT_EQ(resultJsonMessage.getResultData().getDataItem(0).getRequestId(), 2345);
346  ASSERT_EQ(resultJsonMessage.getResultData().getDataItem(0).getRequestType(), DRCETaskRequest::RequestType::rtSetTaskExecute);
347  ASSERT_EQ(resultJsonMessage.getResultData().getDataItem(0).getFilesCount(), 1);
348  ASSERT_EQ(resultJsonMessage.getResultData().getDataItem(0).getFileItem(0).name, "_ps_results.txt");
349  ASSERT_FALSE(resultJsonMessage.getResultData().getDataItem(0).getFileItem(0).data.empty());
350  ASSERT_EQ(resultJsonMessage.getResultData().getDataItem(0).getFileItem(0).actionType, 12);
351  printSuccess("Test Request for local Shell (ps)"); // ps -e
352 }
353 //-----------------------------------------------------------------------------
354 //-----------------------------------------------------------------------------
356 {
357  const std::string requestJson = "{\"session\":{\"type\":0,\"port\":0,\"user\":\"\",\"time_max\":0,\"tmode\":1,\"password\":\"\",\"shell\":\"\",\"environment\":[{\"LINES\":\"80\",\"HOSTNAME\":\"node22\"}]},\"command\":\"php -v > php_version.txt\",\"input\":\"\",\"files\":[{\"name\":\"php_version.txt\",\"data\":\"\",\"action\":12}]}";
358 
360  DRCEFunctionalObject fObj(nodeOptions.getNodeName(), nodeOptions.getHomeDir(), nodeOptions.getTasksDataDir(), nodeOptions.getTasksStatusDir());
361  fObj.setNodeHost("NODE_HOST");
362  fObj.setNodePort("NODE_PORT");
363  fObj.setNodeName("NODE_NAME");
364 
365  DRCEInputJsonMessage inputJsonMessage;
366  inputJsonMessage.setRequestType(DRCETaskRequest::RequestType::rtSetTaskExecute);
367  inputJsonMessage.setRequestData(requestJson);
368  inputJsonMessage.setRequestId(2345);
369 
370  std::stringstream sourceJson;
371  sourceJson << inputJsonMessage;
372 
373  ASSERT_FALSE(inputJsonMessage.isError()) << printError(inputJsonMessage);
374  ASSERT_EQ(inputJsonMessage.getErrorCode(), NO_ERROR);
375  ASSERT_TRUE(inputJsonMessage.getErrorMsg().empty());
376  printSuccess("DRCEInputJsonMessage serialize");
377 
378  std::string resultJson = fObj.Process(sourceJson.str());
379 
380  ASSERT_FALSE(fObj.isError()) << printError(fObj);
381  ASSERT_EQ(fObj.getErrorCode(), NO_ERROR);
382  ASSERT_TRUE(fObj.getErrorMsg().empty());
383  printSuccess("DRCEFunctionalObject Process");
384 
385 // std::cout << "JSON: " << resultJson << std::endl;
386 // std::cout << "JSON: " << responseJson << std::endl;
387 
388  // check right result (unserialize and compare two objects)
389  DRCEOutputJsonMessage resultJsonMessage(resultJson);
390 
391  ASSERT_FALSE(resultJsonMessage.isError()) << printError(resultJsonMessage);
392  ASSERT_EQ(resultJsonMessage.getErrorCode(), NO_ERROR);
393  ASSERT_TRUE(resultJsonMessage.getErrorMsg().empty());
394  printSuccess("DRCEOutputJsonMessage unserialize");
395 
396  ASSERT_EQ(resultJsonMessage.getResultData().getItemsCount(), 1);
397  ASSERT_EQ(resultJsonMessage.getResultData().getDataItem(0).getNodeName(), "NODE_NAME");
398  ASSERT_EQ(resultJsonMessage.getResultData().getDataItem(0).getNodePort(), "NODE_PORT");
399  ASSERT_EQ(resultJsonMessage.getResultData().getDataItem(0).getNodeHost(), "NODE_HOST");
400  ASSERT_TRUE(resultJsonMessage.getResultData().getDataItem(0).getStdoutStream().empty());
401  ASSERT_TRUE(resultJsonMessage.getResultData().getDataItem(0).getStderrStream().empty());
402  ASSERT_EQ(resultJsonMessage.getResultData().getDataItem(0).getFilesCount(), 1);
403 
404  ASSERT_EQ(resultJsonMessage.getResultData().getDataItem(0).getFileItem(0).actionType, 12);
405  ASSERT_EQ(resultJsonMessage.getResultData().getDataItem(0).getFileItem(0).name, "php_version.txt");
406 // std::cout << "DATA: " << resultData.getDataItem(0).getFileItem(0).data << std::endl;
407 
408  printSuccess("Test Request for local Shell (php -v)");
409 }
410 //-----------------------------------------------------------------------------
412 {
413  const std::string requestJson = "{\"session\":{\"type\":0,\"port\":0,\"user\":\"\",\"time_max\":0,\"tmode\":1,\"password\":\"\",\"shell\":\"\",\"environment\":[{\"LINES\":\"80\",\"HOSTNAME\":\"node22\"}]},\"command\":\"php test.php > result.txt\",\"input\":\"\",\"files\":[{\"name\":\"test.php\",\"data\":\"<?php\\necho 'Hello, world!';\\n?>\\n\",\"action\":9}, {\"name\":\"result.txt\",\"data\":\"\",\"action\":12}]}";
414 
416  DRCEFunctionalObject fObj(nodeOptions.getNodeName(), nodeOptions.getHomeDir(), nodeOptions.getTasksDataDir(), nodeOptions.getTasksStatusDir());
417  fObj.setNodeHost("NODE_HOST");
418  fObj.setNodePort("NODE_PORT");
419  fObj.setNodeName("NODE_NAME");
420 // std::cout << "json: " << requestJson << std::endl;
421 
422  DRCEInputJsonMessage inputJsonMessage;
423  inputJsonMessage.setRequestType(DRCETaskRequest::RequestType::rtSetTaskExecute);
424  inputJsonMessage.setRequestData(requestJson);
425  inputJsonMessage.setRequestId(2345);
426 
427  std::stringstream sourceJson;
428  sourceJson << inputJsonMessage;
429 
430  ASSERT_FALSE(inputJsonMessage.isError()) << printError(inputJsonMessage);
431  ASSERT_EQ(inputJsonMessage.getErrorCode(), NO_ERROR);
432  ASSERT_TRUE(inputJsonMessage.getErrorMsg().empty());
433  printSuccess("DRCEInputJsonMessage serialize");
434 
435 // std::cout << "IN JSON: " << sourceJson.str() << std::endl;
436 
437  std::string resultJson = fObj.Process(sourceJson.str());
438 
439  ASSERT_FALSE(fObj.isError()) << printError(fObj);
440  ASSERT_EQ(fObj.getErrorCode(), NO_ERROR);
441  ASSERT_TRUE(fObj.getErrorMsg().empty());
442  printSuccess("DRCEFunctionalObject Process");
443 
444 // std::cout << "OUT JSON: " << resultJson << std::endl;
445 
446  // check right result (unserialize and compare two objects)
447  DRCEOutputJsonMessage resultJsonMessage(resultJson);
448 
449  ASSERT_FALSE(resultJsonMessage.isError()) << printError(resultJsonMessage);
450  ASSERT_EQ(resultJsonMessage.getErrorCode(), NO_ERROR);
451  ASSERT_TRUE(resultJsonMessage.getErrorMsg().empty());
452  printSuccess("DRCEOutputJsonMessage unserialize");
453 
454  ASSERT_EQ(resultJsonMessage.getResultData().getItemsCount(), 1);
455  ASSERT_EQ(resultJsonMessage.getResultData().getDataItem(0).getNodeName(), "NODE_NAME");
456  ASSERT_EQ(resultJsonMessage.getResultData().getDataItem(0).getNodePort(), "NODE_PORT");
457  ASSERT_EQ(resultJsonMessage.getResultData().getDataItem(0).getNodeHost(), "NODE_HOST");
458  ASSERT_TRUE(resultJsonMessage.getResultData().getDataItem(0).getStdoutStream().empty());
459  ASSERT_TRUE(resultJsonMessage.getResultData().getDataItem(0).getStderrStream().empty());
460  ASSERT_EQ(resultJsonMessage.getResultData().getDataItem(0).getFilesCount(), 1);
461 
462  ASSERT_EQ(resultJsonMessage.getResultData().getDataItem(0).getFileItem(0).actionType, 12);
463  ASSERT_EQ(resultJsonMessage.getResultData().getDataItem(0).getFileItem(0).name, "result.txt");
464  ASSERT_EQ(resultJsonMessage.getResultData().getDataItem(0).getFileItem(0).data, "Hello, world!");
465 
466  printSuccess("Test Request for local Shell (php test.php > result.txt)");
467 }
468 //-----------------------------------------------------------------------------
470 {
471  const std::string requestJson = "{\"session\":{\"type\":0,\"port\":0,\"user\":\"\",\"time_max\":0,\"tmode\":1,\"password\":\"\",\"shell\":\"\",\"environment\":[]},\"command\":\"perl -v > php_version.txt\",\"input\":\"\",\"files\":[{\"name\":\"php_version.txt\",\"data\":\"\",\"action\":12}]}";
472 
474  DRCEFunctionalObject fObj(nodeOptions.getNodeName(), nodeOptions.getHomeDir(), nodeOptions.getTasksDataDir(), nodeOptions.getTasksStatusDir());
475  fObj.setNodeHost("NODE_HOST");
476  fObj.setNodePort("NODE_PORT");
477  fObj.setNodeName("NODE_NAME");
478 
479  DRCEInputJsonMessage inputJsonMessage;
480  inputJsonMessage.setRequestType(DRCETaskRequest::RequestType::rtSetTaskExecute);
481  inputJsonMessage.setRequestData(requestJson);
482  inputJsonMessage.setRequestId(2345);
483 
484  std::stringstream sourceJson;
485  sourceJson << inputJsonMessage;
486 
487  ASSERT_FALSE(inputJsonMessage.isError()) << printError(inputJsonMessage);
488  ASSERT_EQ(inputJsonMessage.getErrorCode(), NO_ERROR);
489  ASSERT_TRUE(inputJsonMessage.getErrorMsg().empty());
490  printSuccess("DRCEInputJsonMessage serialize");
491 
492  std::string resultJson = fObj.Process(sourceJson.str());
493 
494  ASSERT_FALSE(fObj.isError()) << printError(fObj);
495  ASSERT_EQ(fObj.getErrorCode(), NO_ERROR);
496  ASSERT_TRUE(fObj.getErrorMsg().empty());
497  printSuccess("DRCEFunctionalObject Process");
498 
499 // std::cout << "JSON: " << resultJson << std::endl;
500 // std::cout << "JSON: " << responseJson << std::endl;
501 
502  // check right result (unserialize and compare two objects)
503  DRCEOutputJsonMessage resultJsonMessage(resultJson);
504 
505  ASSERT_FALSE(resultJsonMessage.isError()) << printError(resultJsonMessage);
506  ASSERT_EQ(resultJsonMessage.getErrorCode(), NO_ERROR);
507  ASSERT_TRUE(resultJsonMessage.getErrorMsg().empty());
508  printSuccess("DRCEOutputJsonMessage unserialize");
509 
510  ASSERT_EQ(resultJsonMessage.getResultData().getItemsCount(), 1);
511  ASSERT_EQ(resultJsonMessage.getResultData().getDataItem(0).getNodeName(), "NODE_NAME");
512  ASSERT_EQ(resultJsonMessage.getResultData().getDataItem(0).getNodePort(), "NODE_PORT");
513  ASSERT_EQ(resultJsonMessage.getResultData().getDataItem(0).getNodeHost(), "NODE_HOST");
514  ASSERT_TRUE(resultJsonMessage.getResultData().getDataItem(0).getStdoutStream().empty());
515  ASSERT_TRUE(resultJsonMessage.getResultData().getDataItem(0).getStderrStream().empty());
516  ASSERT_EQ(resultJsonMessage.getResultData().getDataItem(0).getFilesCount(), 1);
517 
518  ASSERT_EQ(resultJsonMessage.getResultData().getDataItem(0).getFileItem(0).actionType, 12);
519  ASSERT_EQ(resultJsonMessage.getResultData().getDataItem(0).getFileItem(0).name, "php_version.txt");
520  ASSERT_FALSE(resultJsonMessage.getResultData().getDataItem(0).getFileItem(0).data.empty());
521 
522  printSuccess("Test Request for local Shell (perl -v > php_version.txt)");
523 }
524 //-----------------------------------------------------------------------------
526 {
527  const std::string requestJson = "{\"session\":{\"type\":0,\"port\":0,\"user\":\"\",\"time_max\":0,\"tmode\":1,\"password\":\"\",\"shell\":\"\",\"environment\":[]},\"command\":\"perl test.pl > result.txt\",\"input\":\"\",\"files\":[{\"name\":\"test.pl\",\"data\":\"#!/usr/bin/perl\\nprint \\\"Hello, world!\\\";\",\"action\":9}, {\"name\":\"result.txt\",\"data\":\"\",\"action\":12}]}";
528 
530  DRCEFunctionalObject fObj(nodeOptions.getNodeName(), nodeOptions.getHomeDir(), nodeOptions.getTasksDataDir(), nodeOptions.getTasksStatusDir());
531  fObj.setNodeHost("NODE_HOST");
532  fObj.setNodePort("NODE_PORT");
533  fObj.setNodeName("NODE_NAME");
534 
535  DRCEInputJsonMessage inputJsonMessage;
536  inputJsonMessage.setRequestType(DRCETaskRequest::RequestType::rtSetTaskExecute);
537  inputJsonMessage.setRequestData(requestJson);
538  inputJsonMessage.setRequestId(2345);
539 
540  std::stringstream sourceJson;
541  sourceJson << inputJsonMessage;
542 
543  ASSERT_FALSE(inputJsonMessage.isError()) << printError(inputJsonMessage);
544  ASSERT_EQ(inputJsonMessage.getErrorCode(), NO_ERROR);
545  ASSERT_TRUE(inputJsonMessage.getErrorMsg().empty());
546  printSuccess("DRCEInputJsonMessage serialize");
547 
548  std::string resultJson = fObj.Process(sourceJson.str());
549 
550  ASSERT_FALSE(fObj.isError()) << printError(fObj);
551  ASSERT_EQ(fObj.getErrorCode(), NO_ERROR);
552  ASSERT_TRUE(fObj.getErrorMsg().empty());
553  printSuccess("DRCEFunctionalObject Process");
554 
555 // std::cout << "JSON: " << resultJson << std::endl;
556 
557  // check right result (unserialize and compare two objects)
558  DRCEOutputJsonMessage resultJsonMessage(resultJson);
559 
560  ASSERT_FALSE(resultJsonMessage.isError()) << printError(resultJsonMessage);
561  ASSERT_EQ(resultJsonMessage.getErrorCode(), NO_ERROR);
562  ASSERT_TRUE(resultJsonMessage.getErrorMsg().empty());
563  printSuccess("DRCEOutputJsonMessage unserialize");
564 
565  ASSERT_EQ(resultJsonMessage.getResultData().getItemsCount(), 1);
566  ASSERT_EQ(resultJsonMessage.getResultData().getDataItem(0).getNodeName(), "NODE_NAME");
567  ASSERT_EQ(resultJsonMessage.getResultData().getDataItem(0).getNodePort(), "NODE_PORT");
568  ASSERT_EQ(resultJsonMessage.getResultData().getDataItem(0).getNodeHost(), "NODE_HOST");
569  ASSERT_TRUE(resultJsonMessage.getResultData().getDataItem(0).getStdoutStream().empty());
570  ASSERT_TRUE(resultJsonMessage.getResultData().getDataItem(0).getStderrStream().empty());
571  ASSERT_EQ(resultJsonMessage.getResultData().getDataItem(0).getFilesCount(), 1);
572 
573  ASSERT_EQ(resultJsonMessage.getResultData().getDataItem(0).getFileItem(0).actionType, 12);
574  ASSERT_EQ(resultJsonMessage.getResultData().getDataItem(0).getFileItem(0).name, "result.txt");
575  ASSERT_EQ(resultJsonMessage.getResultData().getDataItem(0).getFileItem(0).data, "Hello, world!");
576 
577  printSuccess("Test Request for local Shell (perl test.pl > result.txt)");
578 }
579 //-----------------------------------------------------------------------------
580 //-----------------------------------------------------------------------------
581 } // end namespace tests
582 } // end namespace drce
583 } // end namespace HCE