Add deployment for ADML agent with http interface
[anna.git] / example / diameter / launcher / Launcher.cpp
index 2175263..420a498 100644 (file)
@@ -330,7 +330,7 @@ void Launcher::servicesFromXML(const anna::xml::Node* servicesNode, bool eventOp
 
       // Checking command line parameters
       std::string sessionBasedModelsType;
-      anna::diameter::comm::Entity::SessionBasedModelsType::_v sessionBasedModelsTypeEnum;
+      anna::diameter::comm::Entity::SessionBasedModelsType::_v sessionBasedModelsTypeEnum = anna::diameter::comm::Entity::SessionBasedModelsType::SessionIdLowPart;
       if(sessionBasedModelsClientSocketSelection) {
         sessionBasedModelsType = sessionBasedModelsClientSocketSelection->getValue();
        if (sessionBasedModelsType == "RoundRobin") {
@@ -1463,6 +1463,8 @@ std::string Launcher::help() const throw() {
   result += "\n                                 Test cases reports are not dumped on process context (too many information in general).";
   result += "\n                                 The report contains context information in every moment: this operation acts as a snapshot.";
   result += "\n";
+  result += "\n   test|state[|id]               Get test case state for id provided, current 'in-process' test case when missing.";
+  result += "\n";
   result += "\n   test|interact|amount[|id]     Makes interactive a specific test case id. The amount is the margin of execution steps";
   result += "\n                                 to be done. Normally, we will execute 'test|interact|0[|<test case id>]', which means that";
   result += "\n                                 the test case is selected to be interactive, but no step is executed. Then you have to";
@@ -1567,7 +1569,7 @@ std::string Launcher::help() const throw() {
   result += "\n";
   result += "\nThe alternative using SIGUSR2 signal requires the creation of the task(s) file which will be read at";
   result += "\n signal event:";
-  result += "\n   echo \"<<operation>\" > "; result += getSignalUSR2InputFile();
+  result += "\n   echo \"<operation>\" > "; result += getSignalUSR2InputFile();
   result += "\n    then";
   result += "\n   kill -12 <pid>";
   result += "\n    or";
@@ -1619,9 +1621,12 @@ void Launcher::logStatisticsSamples(const std::string &conceptsList) throw() {
 }
 
 
-void Launcher::eventOperation(const std::string &operation, std::string &response_content) throw(anna::RuntimeException) {
+bool Launcher::eventOperation(const std::string &operation, std::string &response_content) throw(anna::RuntimeException) {
+
+  bool result = true;
+
   LOGMETHOD(anna::TraceMethod tm("Launcher", "eventOperation", ANNA_FILE_LOCATION));
-  if (operation == "") return; // ignore
+  if (operation == "") return result; // ignore
   LOGDEBUG(anna::Logger::debug(anna::functions::asString("Operation: %s", operation.c_str()), ANNA_FILE_LOCATION));
 
   // Default response:
@@ -1651,15 +1656,15 @@ void Launcher::eventOperation(const std::string &operation, std::string &respons
     catch(anna::RuntimeException &ex) {
       ex.trace();
       response_content = ex.asString();
-      return;
+      return false;
     }
-    return;
+    return true; // OK
   }
 
   // Help:
   if(operation == "help") {
     response_content = help();
-    return;
+    return true; // OK
   }
 
   // Reset performance data:
@@ -1667,26 +1672,26 @@ void Launcher::eventOperation(const std::string &operation, std::string &respons
     resetCounters();
     resetStatistics();
     response_content = "All process counters & statistic information have been reset";
-    return;
+    return true; // OK
   }
 
   // Counters dump on demand:
   if(operation == "forceCountersRecord") {
     forceCountersRecord();
     response_content = "Current counters have been dump to disk";
-    return;
+    return true; // OK
   }
 
   // OAM & statistics:
   if(operation == "show-oam") {
     anna::xml::Node root("root");
     response_content = anna::xml::Compiler().apply(oamAsXML(&root));
-    return;
+    return true; // OK
   }
   if(operation == "show-stats") {
     anna::xml::Node root("root");
     response_content = anna::xml::Compiler().apply(statsAsXML(&root));
-    return;
+    return true; // OK
   }
 
   ///////////////////////////////////////////////////////////////////
@@ -1761,25 +1766,27 @@ void Launcher::eventOperation(const std::string &operation, std::string &respons
     std::string contextFile = ((numParams == 1) ? param1 : anna::functions::asString("/var/tmp/anna.context.%05d", getPid()));
     writeContext(contextFile);
     response_content = anna::functions::asString("Context dumped on file '%s'", contextFile.c_str());
-    return;
+    return true; // OK
   }
 
   if(opType == "log-statistics-samples") {
     logStatisticsSamples(param1);
     response_content = anna::functions::asString("Log statistics samples for '%s' concepts", param1.c_str());
-    return;
+    return true; // OK
   }
 
   // Change execution directory:
   if(opType == "change-dir") {
     if (param1 == "") param1 = a_initialWorkingDirectory;
-    if (chdir(param1.c_str()) == 0)
+    result = (chdir(param1.c_str()) == 0);
+
+    if (result)
       response_content = "New execution directory configured: ";
     else
       response_content = "Cannot assign provided execution directory: ";
 
     response_content += param1;
-    return;
+    return result;
   }
 
   if(opType == "services") {
@@ -1790,10 +1797,10 @@ void Launcher::eventOperation(const std::string &operation, std::string &respons
     catch(anna::RuntimeException &ex) {
       ex.trace();
       response_content = anna::functions::asString("Loaded services from file '%s' with errors", servicesFile.c_str());
-      return;
+      return false;
     }
     response_content = anna::functions::asString("Loaded services from file '%s'", servicesFile.c_str());
-    return;
+    return true; // OK
   }
 
   // Host switch:
@@ -1810,12 +1817,12 @@ void Launcher::eventOperation(const std::string &operation, std::string &respons
         response_content = "Working node is automatic";
       }
     }
-    return;
+    return true; // OK
   }
   if(opType == "node_auto") {
     a_workingNode = NULL;
     response_content = "Working node has been set to automatic";
-    return;
+    return true; // OK
   }
 
   // Operated host from possible forced-working node:
@@ -2159,9 +2166,33 @@ void Launcher::eventOperation(const std::string &operation, std::string &respons
 
       if (testCase) {
         response_content = testCase->asXMLString();
-        return;
+        return true; // OK
+      }
+      else {
+        result = false;
+        if (id == -1) {
+          opt_response_content = "no current test case detected (testing started ?)";
+        }
+        else {
+          opt_response_content = "cannot found test id (";
+          opt_response_content += anna::functions::asString(id);
+          opt_response_content += ")";
+        }
+      }
+    }
+    else if(param1 == "state") {
+      if (numParams > 2)
+        throw anna::RuntimeException("Wrong body content format on HTTP Request. Use 'help' management command to see more information.", ANNA_FILE_LOCATION);
+
+      int id = ((param2 != "") ? atoi(param2.c_str()) : -1);
+      anna::testing::TestCase *testCase = testManager.findTestCase(id);
+
+      if (testCase) {
+        response_content = anna::testing::TestCase::asText(testCase->getState());
+        return testCase->isSuccess();
       }
       else {
+        result = false;
         if (id == -1) {
           opt_response_content = "no current test case detected (testing started ?)";
         }
@@ -2198,6 +2229,7 @@ void Launcher::eventOperation(const std::string &operation, std::string &respons
         opt_response_content += anna::functions::asString(id);
       }
       else {
+        result = false;
         opt_response_content = "cannot found test id (";
         opt_response_content += anna::functions::asString(id);
         opt_response_content += ")";
@@ -2228,6 +2260,7 @@ void Launcher::eventOperation(const std::string &operation, std::string &respons
           opt_response_content = param2; opt_response_content += " reset have been sent to all programmed tests: "; opt_response_content += anyReset ? "some/all have been reset" : "nothing was reset";
         }
         else {
+          result = false;
           opt_response_content = "cannot found test id (";
           opt_response_content += anna::functions::asString(id);
           opt_response_content += ")";
@@ -2269,19 +2302,19 @@ void Launcher::eventOperation(const std::string &operation, std::string &respons
     }
     else if(param1 == "junit") {
       response_content = testManager.junitAsXMLString();
-      return;
+      return true; // OK
     }
     else if(param1 == "summary-counts") {
       response_content = testManager.summaryCounts();
-      return;
+      return true; // OK
     }
     else if(param1 == "summary-states") {
       response_content = testManager.summaryStates();
-      return;
+      return true; // OK
     }
     else if(param1 == "summary") {
       response_content = testManager.asXMLString();
-      return;
+      return true; // OK
     }
     else {
       int id = atoi(param1.c_str());
@@ -2488,7 +2521,7 @@ void Launcher::eventOperation(const std::string &operation, std::string &respons
   } else if(opType == "loadxml") {
     codecMsg.loadXML(param1);
     response_content = codecMsg.asXMLString();
-    return;
+    return true; // OK
   } else if(opType == "diameterServerSessions") {
     int diameterServerSessions = atoi(param1.c_str());
     getOperatedServer()->setMaxConnections(diameterServerSessions);
@@ -2496,7 +2529,7 @@ void Launcher::eventOperation(const std::string &operation, std::string &respons
   } else if(opType == "answerxml2c") {
     if(param1 == "") { // programmed answers FIFO's to stdout
       response_content = getOperatedServer()->getReactingAnswers()->asString("ANSWERS TO CLIENT");
-      return;
+      return true; // OK
     } else if (param1 == "rotate") {
       getOperatedServer()->getReactingAnswers()->rotate(true);
     } else if (param1 == "exhaust") {
@@ -2522,7 +2555,7 @@ void Launcher::eventOperation(const std::string &operation, std::string &respons
 
     if(param1 == "") { // programmed answers FIFO's to stdout
       response_content = getOperatedEntity()->getReactingAnswers()->asString("ANSWERS TO ENTITY");
-      return;
+      return true; // OK
     } else if (param1 == "rotate") {
       getOperatedEntity()->getReactingAnswers()->rotate(true);
     } else if (param1 == "exhaust") {
@@ -2554,6 +2587,8 @@ void Launcher::eventOperation(const std::string &operation, std::string &respons
     response_content += " => ";
     response_content += opt_response_content;
   }
+
+  return result;
 }
 
 anna::xml::Node* Launcher::asXML(anna::xml::Node* parent) const