void getJobID(OSCommandLine *oscommandline, OSnl2OS* nl2OS) { OSSolverAgent* osagent = NULL; try { if (oscommandline->serviceLocation != "") { osagent = new OSSolverAgent(oscommandline->serviceLocation); oscommandline->jobID = osagent->getJobID(oscommandline->osol); osoutput->OSPrint(ENUM_OUTPUT_AREA_main, ENUM_OUTPUT_LEVEL_error, oscommandline->jobID); delete osagent; osagent = NULL; } else { delete osagent; osagent = NULL; throw ErrorClass("please specify service location (url)"); } } catch (const ErrorClass& eclass) { reportErrors(oscommandline, eclass.errormsg, nl2OS); if (osagent != NULL) delete osagent; osagent = NULL; } }//end getJobID
void send(OSCommandLine *oscommandline, OSnl2OS *nl2OS) { bool bSend = false; bool always_print = false; OSSolverAgent* osagent = NULL; ostringstream outStr; try { osagent = new OSSolverAgent(oscommandline->serviceLocation); // get a job ID if necessary if (oscommandline->jobID == "NEW") { always_print = true; oscommandline->jobID = osagent->getJobID(""); if (oscommandline->osoption != NULL) oscommandline->osoption->setJobID(oscommandline->jobID); } makeStrings(oscommandline); outStr.str(""); outStr.clear(); outStr << "Submitting Job " << oscommandline->jobID << std::endl; osoutput->OSPrint(ENUM_OUTPUT_AREA_main, ENUM_OUTPUT_LEVEL_info, outStr.str()); bSend = osagent->send(oscommandline->osil, oscommandline->osol); outStr.str(""); outStr.clear(); outStr << "Job " << oscommandline->jobID; if (bSend == true) { outStr << " successfully submitted." << std::endl; if (always_print) osoutput->OSPrint(ENUM_OUTPUT_AREA_main, ENUM_OUTPUT_LEVEL_always, outStr.str()); else osoutput->OSPrint(ENUM_OUTPUT_AREA_main, ENUM_OUTPUT_LEVEL_info, outStr.str()); } else { outStr << ": send failed." << std::endl; outStr << "Check to make sure you sent a jobID not on the system." << std::endl; osoutput->OSPrint(ENUM_OUTPUT_AREA_main, ENUM_OUTPUT_LEVEL_error, outStr.str()); } delete osagent; osagent = NULL; } catch (const ErrorClass& eclass) { reportErrors(oscommandline, eclass.errormsg, nl2OS); if (osagent != NULL) delete osagent; osagent = NULL; } }//end send
bool OSServiceMethods::executeServiceMethod(OSCommandLine *oscommandline) { OSSolverAgent* osagent = NULL; /** * The required file conversions are all assumed * to have been taken care of in the nonstandard constructor, * so this wrapper merely directs traffic */ try { /** the only local service method is solve() */ if (oscommandline->serviceLocation == "") if (oscommandline->serviceMethod == "solve") //resultString = runSolver(oscommandline->solverName, oscommandline->osoption, oscommandline->osinstance); int junk; else throw ErrorClass("No service location (URL) specified. Only \"solve\" is available locally"); /** Here we have a remote call --- reuse as much code as possible */ else { osagent = new OSSolverAgent(oscommandline->serviceLocation); //solve if (oscommandline->serviceMethod == "solve") resultString = osagent->solve(oscommandline->osil, oscommandline->osol); //send --- first check that there is a jobID. If not, get one else if (oscommandline->serviceMethod == "send") { if (oscommandline->osol.find( "<jobID") == std::string::npos) { OSoLReader *osolreader = NULL; osolreader = new OSoLReader(); OSoLWriter *osolwriter = NULL; osolwriter = new OSoLWriter(); try { if (oscommandline->osol != "") oscommandline->osoption = osolreader->readOSoL(oscommandline->osol); oscommandline->osoption->setJobID(osagent->getJobID("")); // now write the osOption object into a string oscommandline->osol = osolwriter->writeOSoL(oscommandline->osoption); delete osolreader; osolreader = NULL; delete osolwriter; osolwriter = NULL; } catch (const ErrorClass& eclass) { delete osolreader; osolreader = NULL; delete osolwriter; osolwriter = NULL; throw ErrorClass(eclass.errormsg); } } bool sendResult; sendResult = osagent->send(oscommandline->osil, oscommandline->osol); if (sendResult == false) throw ErrorClass("send() method failed"); } //retrieve else if (oscommandline->serviceMethod == "retrieve") { if (oscommandline->osol.find( "<jobID") == std::string::npos) throw ErrorClass("there is no JobID to retrieve"); resultString = osagent->retrieve(oscommandline->osol); } //getJobID else if (oscommandline->serviceMethod == "getJobID") resultString = osagent->getJobID(oscommandline->osol); //knock else if (oscommandline->serviceMethod == "knock") resultString = osagent->knock(oscommandline->osplInput, oscommandline->osol); //kill else if (oscommandline->serviceMethod == "kill") { if (oscommandline->osol.find( "<jobID") == std::string::npos) throw ErrorClass("there is no JobID to kill"); resultString = osagent->kill(oscommandline->osol); } else throw ErrorClass("serviceMethod not recognized"); delete osagent; osagent = NULL; } return true; } catch (const ErrorClass& eclass) { OSResult *osresult = NULL; OSrLWriter *osrlwriter = NULL; osrlwriter = new OSrLWriter(); osresult = new OSResult(); osresult->setGeneralMessage(eclass.errormsg); osresult->setGeneralStatusType("error"); resultString = osrlwriter->writeOSrL(osresult); //catch garbage collection delete osresult; osresult = NULL; delete osrlwriter; osrlwriter = NULL; if (osagent != NULL) delete osagent; osagent = NULL; return false; } }//executeServiceMethod