From 36bb910c8e4ad26ab0b2c9618abc02c255b24e58 Mon Sep 17 00:00:00 2001 From: Eduardo Ramos Testillano Date: Fri, 17 Apr 2015 11:45:51 +0200 Subject: [PATCH] traces to trace extension. Implements clear and dump in answers programming interface --- example/diameter/launcher/DEPLOY.sh | 2 +- .../launcher/deployments/advanced/README | 2 +- example/diameter/launcher/main.cpp | 83 ++++++++++++++----- 3 files changed, 62 insertions(+), 25 deletions(-) diff --git a/example/diameter/launcher/DEPLOY.sh b/example/diameter/launcher/DEPLOY.sh index 80c9f96..034ccf9 100755 --- a/example/diameter/launcher/DEPLOY.sh +++ b/example/diameter/launcher/DEPLOY.sh @@ -55,7 +55,7 @@ EXE=$exe STARTED=\`pgrep \$EXE 2>/dev/null\` [ \$? -eq 0 ] && { echo "Already started!"; echo "\$STARTED" ; exit 1 ; } ./pre-start.sh -0> launcher.traces +0> launcher.trace rm -f counters/* # Execution line: ./\$EXE -cntDir counters $(for i in `cat args.txt | grep -v "^#"`; do echo -n "$i "; done)& diff --git a/example/diameter/launcher/deployments/advanced/README b/example/diameter/launcher/deployments/advanced/README index 9e0b3b6..aa5c3d3 100644 --- a/example/diameter/launcher/deployments/advanced/README +++ b/example/diameter/launcher/deployments/advanced/README @@ -13,7 +13,7 @@ Additional helpers/scripts could be found at './resources' directory. STARTING THE PROCESS -------------------- Start with 'run.sh'. You could manually edit such script adding parameters as '-trace debug' to -get complete 'launcher.traces'. Execute 'ADL-launcher' without arguments to see a complete +get complete 'launcher.trace'. Execute 'ADL-launcher' without arguments to see a complete command-line help. DEPLOYED SCRIPTS diff --git a/example/diameter/launcher/main.cpp b/example/diameter/launcher/main.cpp index 38a6b1d..7baab28 100644 --- a/example/diameter/launcher/main.cpp +++ b/example/diameter/launcher/main.cpp @@ -116,12 +116,34 @@ typedef std::map < int /* message code */, codec_messages_deque* >::const_iterat public: ProgrammedAnswers() {}; - ~ProgrammedAnswers() { + ~ProgrammedAnswers() { clear(); } + + void clear () throw() { for (reacting_answers_const_iterator it = a_deques.begin(); it != a_deques.end(); it++) { anna::diameter::codec::Engine *engine = anna::functions::component (ANNA_FILE_LOCATION); engine->releaseMessage(*(it->second->begin())); delete(it->second); } + a_deques.clear(); + } + + void dump () throw() { + std::string outfilename, xmlString; + for(reacting_answers_const_iterator it = a_deques.begin(); it != a_deques.end(); it++) { + int sequence = 1; + for(codec_messages_deque_const_iterator itm = it->second->begin(); itm != it->second->end(); itm++) { + // programmed_answer.. + outfilename = "programmed_answer."; + outfilename += anna::functions::asString(it->first); + outfilename += "."; + outfilename += anna::functions::asString(sequence++); + outfilename += ".xml"; + std::ofstream outfile(outfilename.c_str(), std::ifstream::out); + xmlString = (*itm)->asXMLString(); + outfile.write(xmlString.c_str(), xmlString.size()); + outfile.close(); + } + } } void addMessage(int code, anna::diameter::codec::Message *message) throw() { @@ -731,7 +753,7 @@ std::string Launcher::help() const throw() { result += "\n establish as minimum), separate statistics analyzer per each resource, automatic CER/CEA and DWR/DWA"; result += "\n generation, expiration control and many more features."; result += "\n"; - result += "\nProcess traces are dump on \"launcher.traces\" and could have any trace level (POSIX levels), usually"; + result += "\nProcess traces are dump on \"launcher.trace\" and could have any trace level (POSIX levels), usually"; result += "\n 'debug' or 'warning'. See ANNA documentation for more details."; result += "\n"; result += "\nAs any other ANNA process, context dump could be retrieved sending SIGUSR1 signal:"; @@ -819,10 +841,17 @@ std::string Launcher::help() const throw() { result += "\nsendxml2e| Sends xml source file (pathfile) through configured entity."; result += "\nsendxml2c| Sends xml source file (pathfile) to client."; result += "\nsendxml| Same as 'sendxml2e'."; - result += "\nanswerxml2e|[source_file] Answer xml source file (pathfile) for corresponding request from entity."; - result += "\nanswerxml2c|[source_file] Answer xml source file (pathfile) for corresponding request from client."; + result += "\nanswerxml2e|[source_file] Answer xml source file (pathfile) for incoming request with same code from entity."; + result += "\n The answer is stored in a FIFO queue for a specific message code, then there are"; + result += "\n as many queues as different message codes have been received."; + result += "\nanswerxml2c|[source_file] Answer xml source file (pathfile) for incoming request with same code from client."; + result += "\n The answer is stored in a FIFO queue for a specific message code, then there are"; + result += "\n as many queues as different message codes have been received."; result += "\nanswerxml|[source_file] Same as 'answerxml2c'."; - result += "\n List programmed answers if no parameter provided."; + result += "\nanswerxml(2e/2c) List programmed answers (to entity/client) if no parameter provided."; + result += "\nanswerxml(2e/2c)|dump Write programmed answers (to entity/client) to file 'programmed_answer..',"; + result += "\n where 'sequence' is the order of the answer in each FIFO code-queue of programmed answers."; + result += "\nanswerxml(2e/2c)|clear Clear programmed answers (to entity/client)."; result += "\n"; result += "\nSend operations are available using hexadecimal content (hex formatted files) which also allow to test"; result += "\nspecial scenarios (protocol errors):"; @@ -998,7 +1027,7 @@ using namespace anna::diameter; int main(int argc, const char** argv) { anna::Logger::setLevel(anna::Logger::Warning); - anna::Logger::initialize("launcher", new TraceWriter("launcher.traces", 2048000)); + anna::Logger::initialize("launcher", new TraceWriter("launcher.trace", 2048000)); anna::time::functions::initialize(); // before application instantiation (it have a anna::time object) anna::time::functions::setControlPoint(); // start control point (application lifetime) Launcher app; @@ -1729,7 +1758,7 @@ void Launcher::eventOperation(const std::string &operation, std::string &respons std::string s_help = help(); std::cout << s_help << std::endl; LOGINFORMATION(anna::Logger::information(s_help, ANNA_FILE_LOCATION)); - response_content = "Help dumped on stdout and information-level traces (launcher.traces file)\n"; + response_content = "Help dumped on stdout and information-level traces (launcher.trace file)\n"; return; } @@ -2019,7 +2048,17 @@ void Launcher::eventOperation(const std::string &operation, std::string &respons if(!localServer) throw anna::RuntimeException("Operation not applicable (no own diameter server has been configured)", ANNA_FILE_LOCATION); - if(param1 != "") { + if(param1 == "") { // programmed answers FIFO's to stdout + std::cout << std::endl << std::endl; + std::cout << " ------------- CURRENT PROGRAMMED ANSWERS TO CLIENT -------------\n\n"; + std::cout << G_reactingAnswers2C.asString() << std::endl; + response_content = "Programmed answers dumped on stdout\n"; + return; + } else if (param1 == "clear") { + G_reactingAnswers2C.clear(); + } else if (param1 == "dump") { + G_reactingAnswers2C.dump(); + } else { anna::diameter::codec::Engine *engine = anna::functions::component (ANNA_FILE_LOCATION); anna::diameter::codec::Message *message = engine->createMessage(param1); LOGDEBUG @@ -2031,14 +2070,8 @@ void Launcher::eventOperation(const std::string &operation, std::string &respons throw anna::RuntimeException("Cannot program diameter requests. Answer type must be provided", ANNA_FILE_LOCATION); int code = message->getId().first; - LOGDEBUG(anna::Logger::debug("Adding a new programed 'answer to client' to the deque...", ANNA_FILE_LOCATION)); + LOGDEBUG(anna::Logger::debug("Adding a new programed 'answer to client' to the FIFO queue corresponding to its message code ...", ANNA_FILE_LOCATION)); G_reactingAnswers2C.addMessage(code, message); - } else { // answers query on stdout - std::cout << std::endl << std::endl; - std::cout << " ------------- CURRENT PROGRAMMED ANSWERS TO CLIENT -------------\n\n"; - std::cout << G_reactingAnswers2C.asString() << std::endl; - response_content = "Programmed answers dumped on stdout\n"; - return; } } else if(opType == "answerxml2e") { anna::diameter::comm::Entity *entity = getEntity(); @@ -2046,7 +2079,17 @@ void Launcher::eventOperation(const std::string &operation, std::string &respons if(!entity) throw anna::RuntimeException("Operation not applicable (no diameter entity has been configured)", ANNA_FILE_LOCATION); - if(param1 != "") { + if(param1 == "") { // programmed answers FIFO's to stdout + std::cout << std::endl << std::endl; + std::cout << " ------------- CURRENT PROGRAMMED ANSWERS TO ENTITY -------------\n\n"; + std::cout << G_reactingAnswers2E.asString() << std::endl; + response_content = "Programmed answers dumped on stdout\n"; + return; + } else if (param1 == "clear") { + G_reactingAnswers2E.clear(); + } else if (param1 == "dump") { + G_reactingAnswers2E.dump(); + } else { anna::diameter::codec::Engine *engine = anna::functions::component (ANNA_FILE_LOCATION); anna::diameter::codec::Message *message = engine->createMessage(param1); LOGDEBUG @@ -2058,14 +2101,8 @@ void Launcher::eventOperation(const std::string &operation, std::string &respons throw anna::RuntimeException("Cannot program diameter requests. Answer type must be provided", ANNA_FILE_LOCATION); int code = message->getId().first; - LOGDEBUG(anna::Logger::debug("Adding a new programed 'answer to entity' to the deque...", ANNA_FILE_LOCATION)); + LOGDEBUG(anna::Logger::debug("Adding a new programed 'answer to entity' to the FIFO queue corresponding to its message code ...", ANNA_FILE_LOCATION)); G_reactingAnswers2E.addMessage(code, message); - } else { // answers query on stdout - std::cout << std::endl << std::endl; - std::cout << " ------------- CURRENT PROGRAMMED ANSWERS TO ENTITY -------------\n\n"; - std::cout << G_reactingAnswers2E.asString() << std::endl; - response_content = "Programmed answers dumped on stdout\n"; - return; } } else { LOGWARNING(anna::Logger::warning(help(), ANNA_FILE_LOCATION)); -- 2.20.1