Optimize clone procedure
[anna.git] / example / diameter / launcher / Launcher.cpp
index 4ec6ea0..45f51a9 100644 (file)
@@ -174,6 +174,11 @@ void Launcher::servicesFromXML(const anna::xml::Node* servicesNode, bool eventOp
       dictionary = (*it)->getAttribute("dictionary");
       id_value = id->getIntegerValue();
 
+      if (stackEngine.getDictionary(id_value)) { // Ignore (but don't fail) dictionary load with same stack id already registered
+        LOGWARNING(anna::Logger::warning(anna::functions::asString("Ignore dictionary load for stack id already registered: %llu", id_value), ANNA_FILE_LOCATION));
+        continue;
+      }
+
       try {
         d = stackEngine.createDictionary(id_value, dictionary->getValue());
         LOGDEBUG(anna::Logger::debug(anna::functions::asString("Created dictionary (%p) for stack id %llu", d, id_value), ANNA_FILE_LOCATION));
@@ -797,7 +802,7 @@ void Launcher::resetCounters() throw() {
 
 void Launcher::signalUSR2() throw(anna::RuntimeException) {
   LOGNOTICE(
-      std::string msg = "Captured signal SIGUSR2. Reading tasks at '";
+  std::string msg = "Captured signal SIGUSR2. Reading tasks at '";
   msg += SIGUSR2_TASKS_INPUT_FILENAME;
   msg += "' (results will be written at '";
   msg += SIGUSR2_TASKS_OUTPUT_FILENAME;
@@ -812,7 +817,6 @@ void Launcher::signalUSR2() throw(anna::RuntimeException) {
   std::ofstream out_file(SIGUSR2_TASKS_OUTPUT_FILENAME);
 
   if(!in_file.is_open()) throw RuntimeException("Unable to read tasks", ANNA_FILE_LOCATION);
-
   if(!out_file.is_open()) throw RuntimeException("Unable to write tasks", ANNA_FILE_LOCATION);
 
   while(getline(in_file, line)) {
@@ -832,6 +836,7 @@ void Launcher::signalUSR2() throw(anna::RuntimeException) {
   }
 
   in_file.close();
+  out_file << "EOF\n";
   out_file.close();
 }
 
@@ -1158,6 +1163,7 @@ std::string Launcher::help() const throw() {
   result += "\n";
   result += "\n                              delay|<msecs>              Blocking step until the time lapse expires. Useful to give ";
   result += "\n                                                          some cadence control and time schedule for a specific case.";
+  result += "\n                                                         A value of 0 could be used as a dummy step.";
   result += "\n                              wait<fe/fc>|<condition>    Blocking step until condition is fulfilled. The message could";
   result += "\n                                                          received from entity (waitfe) or from client (waitfc).";
   result += "\n";
@@ -1310,13 +1316,18 @@ std::string Launcher::help() const throw() {
   result += "\n";
   result += "\n                                 Provide 0 in order to stop the timer triggering.";
   result += "\n";
-  result += "\n                                 There timer manager resolution currently harcoded allows a maximum  of ";
+  result += "\n                                 The timer manager resolution currently harcoded allows a maximum  of ";
   result += anna::functions::asString(1000/a_admlMinResolution); result += " events";
   result += "\n                                 per second. To reach greater rates ADML will join synchronously the needed number of";
   result += "\n                                 new time-triggered test cases per a single event, writting a warning-level trace to";
   result += "\n                                 advice about the risk of burst sendings and recommend launching multiple instances";
   result += "\n                                 to achieve such load with a lower rate per instance.";
   result += "\n";
+  result += "\n   test|next[|<sync-amount>]     Forces the execution of the next test case(s) without waiting for test manager tick.";
+  result += "\n                                 Provide an integer value for 'sync-amount' to send a burst synchronous amount of the";
+  result += "\n                                 next programmed test cases (1 by default). This event works regardless the timer tick";
+  result += "\n                                 function, but it is normally used with the test manager tick stopped.";
+  result += "\n";
   result += "\n   test|ip-limit[|amount]        In-progress limit of test cases. No new test cases will be launched over this value";
   result += "\n                                 (test Manager tick work will be ignored). Zero-value is equivalent to stop the clock.";
   result += "\n                                 tick, -1 is used to specify 'no limit' which is the default. If missing amount, the";
@@ -1392,6 +1403,8 @@ std::string Launcher::help() const throw() {
   result += "\n    and then see the results:";
   result += "\n   cat "; result += SIGUSR2_TASKS_OUTPUT_FILENAME;
   result += "\n";
+  result += "\n   (this file is ended with EOF final line, useful managing huge batch files to ensure the job completion)";
+  result += "\n";
   result += "\nYou could place more than one line (task) in the input file. Output reports will be appended in that";
   result += "\n case over the output file. Take into account that all the content of the task file will be executed";
   result += "\n sinchronously by the process. If you are planning traffic load, better use the asynchronous http";
@@ -1757,6 +1770,7 @@ void Launcher::eventOperation(const std::string &operation, std::string &respons
   } else if((opType == "test")) {
     // test|<id>|<command>[|parameters]   Add a new step to the test case ...
     // test|ttps|<amount>                 Starts/resume the provided number of time ticks per second (ttps). The ADML starts ...
+    // test|next[|<sync-amount>]          Forces the execution of the next test case(s) without waiting for test manager tick ...
     // test|ip-limit[|amount]             In-progress limit of test cases. No new test cases will be launched over this value ...
     // test|repeats|<amount>              Restarts the whole programmed test list when finished the amount number of times ...
     // test|report[|[yes]|no]             Every time a test case is finished a report file in xml format will be created under ...
@@ -1783,6 +1797,22 @@ void Launcher::eventOperation(const std::string &operation, std::string &respons
         opt_response_content += "unable to configure the test rate provided";
       }
     }
+    else if (param1 == "next") {
+      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 sync_amount = ((param2 != "") ? atoi(param2.c_str()) : 1);
+
+      if (sync_amount < 1)
+        throw anna::RuntimeException("The parameter 'sync-amount' must be a positive integer value", ANNA_FILE_LOCATION);
+
+      bool success = testManager.execTestCases(sync_amount);
+
+      opt_response_content = (success ? "" : "not completely " /* completed cycle and no repeats, rare case */);
+      opt_response_content += "processed ";
+      opt_response_content += anna::functions::asString(sync_amount);
+      opt_response_content += ((sync_amount > 1) ? " test cases synchronously" : " test case");
+    }
     else if(param1 == "ip-limit") {
       if (numParams > 2)
         throw anna::RuntimeException("Wrong body content format on HTTP Request. Use 'help' management command to see more information.", ANNA_FILE_LOCATION);
@@ -1989,7 +2019,7 @@ void Launcher::eventOperation(const std::string &operation, std::string &respons
         if (numParams > 3)
           throw anna::RuntimeException("Wrong body content format on HTTP Request. Use 'help' management command to see more information.", ANNA_FILE_LOCATION);
         if(param3 == "") throw anna::RuntimeException("Missing milliseconds for 'delay' command in test id operation", ANNA_FILE_LOCATION);
-        anna::Millisecond delay = checkTimeMeasure("Test case delay step", param3);
+        anna::Millisecond delay = ((param3 == "0" /* special case */) ? (anna::Millisecond)0 : checkTimeMeasure("Test case delay step", param3));
         testManager.getTestCase(id)->addDelay(delay); // creates / reuses
       }
       else if ((param2 == "waitfe")||(param2 == "waitfc")) {