void kill(OSCommandLine *oscommandline, OSnl2OS* nl2OS) { FileUtil *fileUtil = NULL; fileUtil = new FileUtil(); std::string osplOutput = ""; OSSolverAgent* osagent = NULL; try { if (oscommandline->serviceLocation != "") { osagent = new OSSolverAgent(oscommandline->serviceLocation); if (oscommandline->osol == "") { // we need to construct the OSoL OSOption *osOption = NULL; osOption = new OSOption(); // get a jobId if necessary if (oscommandline->jobID == "") throw ErrorClass("there is no JobID"); //set the jobID osOption->setJobID( oscommandline->jobID); // now read the osOption object into a string OSoLWriter *osolWriter = NULL; osolWriter = new OSoLWriter(); oscommandline->osol = osolWriter->writeOSoL( osOption); delete osOption; osOption = NULL; delete osolWriter; osolWriter = NULL; } osplOutput = osagent->kill(oscommandline->osol); if (oscommandline->osplOutputFile != "") fileUtil->writeFileFromString(oscommandline->osplOutputFile, osplOutput); else osoutput->OSPrint(ENUM_OUTPUT_AREA_main, ENUM_OUTPUT_LEVEL_summary, osplOutput); delete osagent; osagent = NULL; } else { delete osagent; osagent = NULL; throw ErrorClass("please specify service location (url)"); } delete fileUtil; fileUtil = NULL; } catch (const ErrorClass& eclass) { reportErrors(oscommandline, eclass.errormsg, nl2OS); if (osagent != NULL) delete osagent; osagent = NULL; delete fileUtil; fileUtil = NULL; } }//end kill
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