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
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 retrieve(OSCommandLine *oscommandline, OSnl2OS *nl2OS) { FileUtil *fileUtil = NULL; fileUtil = new FileUtil(); std::string osrl = ""; OSSolverAgent* osagent = NULL; try { if (oscommandline->serviceLocation != "") { if (!nl2OS->readNl(oscommandline->nlFile)) throw ErrorClass("Error reading .nl file."); 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; } osrl = osagent->retrieve(oscommandline->osol); reportResults(oscommandline, osrl, nl2OS); 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 retrieve
int main(int argC, char* argV[]) { WindowsErrorPopupBlocker(); FileUtil *fileUtil = NULL; const char dirsep = CoinFindDirSeparator(); std::string osilFileNameWithPath; std::string osilFileName; std::string osil; std::string uploadResult; std::string actualServer; /* Replace this URL as needed */ std::string defaultServer = "http://128.135.130.17:8080/os/servlet/OSFileUpload"; try{ if( argC == 1 || argC > 3 || argV[1] == "-?") throw ErrorClass( "usage: OSFileUpload <filename> [<serverURL>]"); fileUtil = new FileUtil(); time_t start, finish, tmp; osilFileNameWithPath = argV[ 1]; std::cout << "FILE NAME = " << argV[1] << std::endl; std::cout << "Read the file into a string" << std::endl; osil = fileUtil->getFileAsString( osilFileNameWithPath.c_str() ); OSSolverAgent* osagent = NULL; if (argC == 2) actualServer = defaultServer; else actualServer = argV[2]; osagent = new OSSolverAgent(actualServer); // strip off just the file name // modify to into a file C:filename int index = osilFileNameWithPath.find_last_of( dirsep); int slength = osilFileNameWithPath.size(); osilFileName = osilFileNameWithPath.substr( index + 1, slength) ; std::cout << std::endl << std::endl; std::cout << "Place remote synchronous call" << std::endl; start = time( &tmp); uploadResult = osagent->fileUpload(osilFileName, osil); finish = time( &tmp); std::cout << "File Upload took (seconds): "<< difftime(finish, start) << std::endl; std::cout << uploadResult << std::endl; if(fileUtil != NULL) delete fileUtil; return 0; } catch( const ErrorClass& eclass){ std::cout << eclass.errormsg << std::endl; if(fileUtil != NULL) delete fileUtil; return 0; } }
void solve(OSCommandLine *oscommandline, OSnl2OS *nl2OS) { std::string osrl = ""; OSSolverAgent* osagent = NULL; FileUtil *fileUtil = NULL; fileUtil = new FileUtil(); try { // place a remote call osagent = new OSSolverAgent(oscommandline->serviceLocation); //no need to worry about jobID, but make sure we have strings oscommandline->jobID = ""; makeStrings(oscommandline); osrl = osagent->solve(oscommandline->osil, oscommandline->osol); delete osagent; osagent = NULL; reportResults(oscommandline, osrl, nl2OS); //garbage collection delete fileUtil; fileUtil = NULL; }//end try catch (const ErrorClass& eclass) { reportErrors(oscommandline, eclass.errormsg, nl2OS); //garbage collection delete fileUtil; fileUtil = NULL; }//end local catch }//end solve
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
void knock(OSCommandLine *oscommandline, OSnl2OS* nl2OS) { std::string osplOutput = ""; OSSolverAgent* osagent = NULL; FileUtil *fileUtil = NULL; fileUtil = new FileUtil(); try { if (oscommandline->serviceLocation != "") { osagent = new OSSolverAgent(oscommandline->serviceLocation); // if no OSpL file was given, make a default one if (oscommandline->osplInput == "") { std::ostringstream temp; temp << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" << "<ospl xmlns=\"os.optimizationservices.org\"\n" << " xmlns:xs=\"http://www.w3.org/2001/XMLSchema\"\n" << " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n" << " xsi:schemaLocation=\"os.optimizationservices.org\n" << " http://www.optimizationservices.org/schemas/OSpL.xsd\">\n"<< " <processHeader>\n" << " <request action=\"getAll\"/>\n" << " </processHeader>\n" << " <processData/>\n" << "</ospl>\n"; oscommandline->osplInput = temp.str(); } // if a jobID was given on the command line, use it if(oscommandline->jobID != "") { OSOption *osOption = NULL; if (oscommandline->osol == "") { osOption = new OSOption(); } else { OSoLReader *osolReader = new OSoLReader(); try { osOption = osolReader->readOSoL(oscommandline->osol); delete osolReader; osolReader = NULL; } catch (const ErrorClass& eclass) { if (osolReader != NULL) delete osolReader; osolReader = NULL; throw ErrorClass(eclass.errormsg); } } osOption->setJobID( oscommandline->jobID); OSoLWriter *osolWriter = new OSoLWriter(); oscommandline->osol = osolWriter->writeOSoL( osOption); delete osOption; osOption = NULL; delete osolWriter; osolWriter = NULL; } osplOutput = osagent->knock(oscommandline->osplInput, oscommandline->osol); if (oscommandline->osplOutputFile != "") fileUtil->writeFileFromString(oscommandline->osplOutputFile, osplOutput); else osoutput->OSPrint(ENUM_OUTPUT_AREA_main, ENUM_OUTPUT_LEVEL_error, osplOutput); delete osagent; } else { delete osagent; 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 knock
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