00001
00016 #include "OSSolverAgent.h"
00017 #include "OSWSUtil.h"
00018 #include "CoinTime.hpp"
00019 #include "OSParameters.h"
00020 #include "OSOutput.h"
00021
00022 #include <cstdlib>
00023
00024 #ifdef HAVE_CTIME
00025 # include <ctime>
00026 #else
00027 # ifdef HAVE_TIME_H
00028 # include <time.h>
00029 # else
00030 # error "don't have header file for time"
00031 # endif
00032 #endif
00033
00034 using std::string;
00035 using std::ostringstream;
00036 using std::cout;
00037 using std::endl;
00038
00039 extern const OSSmartPtr<OSOutput> osoutput;
00040
00041 OSSolverAgent::OSSolverAgent(string solverURI) : OShL()
00042 {
00043 string::size_type nstart = 0;
00044 string::size_type posSlash;
00045
00046
00047 if (solverURI.find("http://") != string::npos) solverURI = solverURI.substr(7);
00048
00049 posSlash = solverURI.find("/", nstart);
00050 if(posSlash != std::string::npos) nstart = posSlash;
00051 postURI = solverURI.substr(nstart, solverURI.size() - 1);
00052
00053 string::size_type colonlocation = solverURI.find(":");
00054 if(colonlocation == string::npos)
00055 {
00056 solverAddress = solverURI.substr(0, nstart);
00057 solverPortNumber = 80;
00058 }
00059 else
00060 {
00061 solverPortNumber = (unsigned short) atoi( &solverURI.substr(colonlocation + 1, nstart - colonlocation - 1)[0] ) ;
00062 solverAddress = solverURI.substr(0, colonlocation);
00063 }
00064 }
00065
00066 OSSolverAgent::~OSSolverAgent()
00067 {
00068 }
00069
00070 string OSSolverAgent::solve(string osil, string osol)
00071 {
00072 string sOSrL ;
00073 string theSOAP;
00074 string solveResult;
00075
00076 #ifndef NDEBUG
00077 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSAgent, ENUM_OUTPUT_LEVEL_trace, "Inside SolverAgent solve() method \n");
00078 #endif
00079
00080 bool useCDATA = true;
00081
00082 int numInputs = 2;
00083 string smethod = "solve";
00084 string msInputs[2];
00085
00086
00087
00088 #ifndef NDEBUG
00089 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSAgent, ENUM_OUTPUT_LEVEL_trace, "SOAPify OSiL \n");
00090 #endif
00091 msInputs[0] = WSUtil::SOAPify( osil, useCDATA) ;
00092
00093 #ifndef NDEBUG
00094 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSAgent, ENUM_OUTPUT_LEVEL_detailed_trace, msInputs[0]);
00095 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSAgent, ENUM_OUTPUT_LEVEL_trace, "SOAPify OSoL \n");
00096 #endif
00097 msInputs[1] = WSUtil::SOAPify( osol, useCDATA) ;
00098 #ifndef NDEBUG
00099 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSAgent, ENUM_OUTPUT_LEVEL_detailed_trace, msInputs[1]);
00100 #endif
00101 string msInputNames[2] = {"osil", "osol"};
00102 string sSoapAction = "OSSolverService#solve";
00103
00104 double cpuTime;
00105 double startTime = 0;
00106 startTime = CoinCpuTime();
00107 theSOAP = WSUtil::createSOAPMessage(numInputs, solverAddress, postURI,
00108 smethod, msInputs, msInputNames, sSoapAction);
00109
00110 cpuTime = CoinCpuTime() - startTime;
00111 startTime = CoinWallclockTime();
00112 #ifndef NDEBUG
00113 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSAgent, ENUM_OUTPUT_LEVEL_trace, "SEND THE SOAP\n");
00114 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSAgent, ENUM_OUTPUT_LEVEL_detailed_trace, theSOAP);
00115 #endif
00116 solveResult = WSUtil::sendSOAPMessage( theSOAP, solverAddress, solverPortNumber);
00117 #ifndef NDEBUG
00118 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSAgent, ENUM_OUTPUT_LEVEL_trace, "Response received\n");
00119 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSAgent, ENUM_OUTPUT_LEVEL_detailed_trace, solveResult);
00120 #endif
00121 cpuTime = CoinWallclockTime() - startTime;
00122
00123
00124
00125 solveResult = WSUtil::getOSxL(solveResult, "solve");
00126 #ifndef NDEBUG
00127 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSAgent, ENUM_OUTPUT_LEVEL_trace, "Result received\n");
00128 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSAgent, ENUM_OUTPUT_LEVEL_detailed_trace, solveResult);
00129 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSAgent, ENUM_OUTPUT_LEVEL_trace, "DeSOAPify result\n");
00130 #endif
00131
00132 useCDATA = false;
00133 sOSrL = WSUtil::deSOAPify( solveResult, useCDATA);
00134 #ifndef NDEBUG
00135 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSAgent, ENUM_OUTPUT_LEVEL_detailed_trace, sOSrL);
00136 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSAgent, ENUM_OUTPUT_LEVEL_trace, "RETURN THE OSRL\n");
00137 #endif
00138
00139 return sOSrL;
00140 }
00141
00142 string OSSolverAgent::fileUpload( string osilFileName, string theOSiLFile)
00143 {
00144 string theHTTPPOST="";
00145 string uploadResult="";
00146 string boundaryName = "AaB03x";
00147 theHTTPPOST = WSUtil::createFormDataUpload(solverAddress, postURI,
00148 osilFileName, theOSiLFile, boundaryName);
00149
00150
00151 #ifndef NDEBUG
00152 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSAgent, ENUM_OUTPUT_LEVEL_trace, "Upload file in SolverAgent\n");
00153 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSAgent, ENUM_OUTPUT_LEVEL_detailed_trace, theHTTPPOST);
00154 #endif
00155 uploadResult = WSUtil::sendSOAPMessage( theHTTPPOST, solverAddress, solverPortNumber);
00156 return uploadResult;
00157 }
00158
00159
00160 bool OSSolverAgent::send(string osil, string osol)
00161 {
00162 string theSOAP;
00163 string sendResult;
00164 bool useCDATA = true;
00165
00166 #ifndef NDEBUG
00167 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSAgent, ENUM_OUTPUT_LEVEL_trace, "Inside SolverAgent send() method \n");
00168 #endif
00169
00170
00171 int numInputs = 2;
00172 string smethod = "send";
00173 string msInputs[2];
00174
00175
00176 #ifndef NDEBUG
00177 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSAgent, ENUM_OUTPUT_LEVEL_trace, "SOAPIFY OSIL\n");
00178 #endif
00179 msInputs[0] = WSUtil::SOAPify( osil, useCDATA);
00180 #ifndef NDEBUG
00181
00182 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSAgent, ENUM_OUTPUT_LEVEL_detailed_trace, msInputs[0]);
00183 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSAgent, ENUM_OUTPUT_LEVEL_trace, "SOAPIFY OSOL\n");
00184 #endif
00185 msInputs[1] = WSUtil::SOAPify( osol, useCDATA) ;
00186 #ifndef NDEBUG
00187 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSAgent, ENUM_OUTPUT_LEVEL_detailed_trace, msInputs[1]);
00188 #endif
00189
00190 string msInputNames[2] = {"osil", "osol"};
00191 string sSoapAction = "OSSolverService#send";
00192
00193 theSOAP = WSUtil::createSOAPMessage(numInputs, solverAddress, postURI,
00194 smethod, msInputs, msInputNames, sSoapAction);
00195 #ifndef NDEBUG
00196 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSAgent, ENUM_OUTPUT_LEVEL_trace, "Send the SOAP\n");
00197 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSAgent, ENUM_OUTPUT_LEVEL_detailed_trace, theSOAP);
00198 #endif
00199
00200
00201 sendResult = WSUtil::sendSOAPMessage( theSOAP, solverAddress, solverPortNumber);
00202 #ifndef NDEBUG
00203 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSAgent, ENUM_OUTPUT_LEVEL_trace, "Message returned\n");
00204 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSAgent, ENUM_OUTPUT_LEVEL_detailed_trace, sendResult);
00205 #endif
00206
00207
00208 #ifndef NDEBUG
00209 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSAgent, ENUM_OUTPUT_LEVEL_detailed_trace, "Strip out OSxL string\n");
00210 #endif
00211 sendResult = WSUtil::getOSxL(sendResult, "send");
00212 #ifndef NDEBUG
00213 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSAgent, ENUM_OUTPUT_LEVEL_detailed_trace, sendResult);
00214 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSAgent, ENUM_OUTPUT_LEVEL_trace, "DeSOAPify\n");
00215 #endif
00216
00217 useCDATA = false;
00218 sendResult = WSUtil::deSOAPify( sendResult, useCDATA);
00219 #ifndef NDEBUG
00220 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSAgent, ENUM_OUTPUT_LEVEL_detailed_trace, sendResult);
00221 #endif
00222 if( sendResult.find("true") != string::npos ) return true;
00223 else return false;
00224 }
00225
00226 string OSSolverAgent::getJobID(string osol)
00227 {
00228 string sjobID = "";
00229 string getJobIDResult;
00230 string theSOAP;
00231 bool useCDATA = true;
00232
00233 #ifndef NDEBUG
00234 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSAgent, ENUM_OUTPUT_LEVEL_trace, "Inside SolverAgent getJobID() method \n");
00235 #endif
00236
00237
00238 int numInputs = 1;
00239 string smethod = "getJobID";
00240 string msInputs[1];
00241
00242
00243
00244 #ifndef NDEBUG
00245 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSAgent, ENUM_OUTPUT_LEVEL_trace, "SOAPIFY OSOL\n");
00246 #endif
00247 msInputs[0] = WSUtil::SOAPify( osol, useCDATA) ;
00248 #ifndef NDEBUG
00249 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSAgent, ENUM_OUTPUT_LEVEL_detailed_trace, msInputs[0]);
00250 #endif
00251 string msInputNames[1] = {"osol"};
00252 string sSoapAction = "OSSolverService#getJobID";
00253
00254 theSOAP = WSUtil::createSOAPMessage(numInputs, solverAddress, postURI,
00255 smethod, msInputs, msInputNames, sSoapAction);
00256 #ifndef NDEBUG
00257 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSAgent, ENUM_OUTPUT_LEVEL_trace, "Send the SOAP\n");
00258 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSAgent, ENUM_OUTPUT_LEVEL_detailed_trace, theSOAP);
00259 #endif
00260
00261 getJobIDResult = WSUtil::sendSOAPMessage( theSOAP, solverAddress, solverPortNumber);
00262 #ifndef NDEBUG
00263 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSAgent, ENUM_OUTPUT_LEVEL_trace, "Message returned\n");
00264 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSAgent, ENUM_OUTPUT_LEVEL_detailed_trace, getJobIDResult);
00265 #endif
00266
00267 getJobIDResult = WSUtil::getOSxL(getJobIDResult, "getJobID");
00268 #ifndef NDEBUG
00269 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSAgent, ENUM_OUTPUT_LEVEL_detailed_trace, "Strip out job ID\n");
00270 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSAgent, ENUM_OUTPUT_LEVEL_detailed_trace, getJobIDResult);
00271 #endif
00272
00273 useCDATA = false;
00274 sjobID = WSUtil::deSOAPify( getJobIDResult, useCDATA);
00275 #ifndef NDEBUG
00276 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSAgent, ENUM_OUTPUT_LEVEL_trace, "DeSOAPify\n");
00277 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSAgent, ENUM_OUTPUT_LEVEL_detailed_trace, sjobID);
00278 #endif
00279
00280 return sjobID;
00281 }
00282
00283
00284 string OSSolverAgent::retrieve(string osol)
00285 {
00286 string sOSrL;
00287 string retrieveResult;
00288 string theSOAP;
00289 bool useCDATA = true;
00290
00291 #ifndef NDEBUG
00292 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSAgent, ENUM_OUTPUT_LEVEL_trace, "Inside SolverAgent retrieve() method \n");
00293 #endif
00294
00295
00296 int numInputs = 1;
00297 string smethod = "retrieve";
00298 string msInputs[1];
00299
00300
00301 #ifndef NDEBUG
00302 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSAgent, ENUM_OUTPUT_LEVEL_trace, "SOAPIFY OSoL\n");
00303 #endif
00304 msInputs[0] = WSUtil::SOAPify( osol, useCDATA) ;
00305 #ifndef NDEBUG
00306 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSAgent, ENUM_OUTPUT_LEVEL_detailed_trace, msInputs[0]);
00307 #endif
00308 string msInputNames[1] = {"osol"};
00309 string sSoapAction = "OSSolverService#retrieve";
00310
00311 theSOAP = WSUtil::createSOAPMessage(numInputs, solverAddress, postURI,
00312 smethod, msInputs, msInputNames, sSoapAction);
00313 #ifndef NDEBUG
00314 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSAgent, ENUM_OUTPUT_LEVEL_trace, "Send the SOAP\n");
00315 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSAgent, ENUM_OUTPUT_LEVEL_detailed_trace, theSOAP);
00316 #endif
00317
00318
00319 retrieveResult = WSUtil::sendSOAPMessage( theSOAP, solverAddress, solverPortNumber);
00320 #ifndef NDEBUG
00321 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSAgent, ENUM_OUTPUT_LEVEL_trace, "Message returned\n");
00322 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSAgent, ENUM_OUTPUT_LEVEL_detailed_trace, retrieveResult);
00323 #endif
00324
00325
00326 #ifndef NDEBUG
00327 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSAgent, ENUM_OUTPUT_LEVEL_detailed_trace, "Strip out OSxL string\n");
00328 #endif
00329 retrieveResult = WSUtil::getOSxL(retrieveResult, "retrieve");
00330
00331
00332 #ifndef NDEBUG
00333 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSAgent, ENUM_OUTPUT_LEVEL_detailed_trace, retrieveResult);
00334 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSAgent, ENUM_OUTPUT_LEVEL_trace, "DeSOAPify\n");
00335 #endif
00336 useCDATA = false;
00337 sOSrL = WSUtil::deSOAPify( retrieveResult, useCDATA);
00338 #ifndef NDEBUG
00339 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSAgent, ENUM_OUTPUT_LEVEL_detailed_trace, sOSrL);
00340 #endif
00341
00342 return sOSrL;
00343 }
00344
00345
00346 string OSSolverAgent::kill(string osol)
00347 {
00348 string sOSpL;
00349 string killResult;
00350 string theSOAP;
00351 bool useCDATA = true;
00352
00353 #ifndef NDEBUG
00354 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSAgent, ENUM_OUTPUT_LEVEL_trace, "Inside SolverAgent kill() method \n");
00355 #endif
00356
00357
00358 int numInputs = 1;
00359 string smethod = "kill";
00360 string msInputs[1];
00361
00362
00363 #ifndef NDEBUG
00364 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSAgent, ENUM_OUTPUT_LEVEL_trace, "SOAPify OSoL \n");
00365 #endif
00366 msInputs[0] = WSUtil::SOAPify( osol, useCDATA) ;
00367 #ifndef NDEBUG
00368 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSAgent, ENUM_OUTPUT_LEVEL_detailed_trace, msInputs[0]);
00369 #endif
00370 string msInputNames[1] = {"osol"};
00371 string sSoapAction = "OSSolverService#kill";
00372
00373 theSOAP = WSUtil::createSOAPMessage(numInputs, solverAddress, postURI,
00374 smethod, msInputs, msInputNames, sSoapAction);
00375
00376 #ifndef NDEBUG
00377 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSAgent, ENUM_OUTPUT_LEVEL_trace, "SEND THE SOAP\n");
00378 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSAgent, ENUM_OUTPUT_LEVEL_detailed_trace, theSOAP);
00379 #endif
00380 killResult = WSUtil::sendSOAPMessage( theSOAP, solverAddress, solverPortNumber);
00381 #ifndef NDEBUG
00382 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSAgent, ENUM_OUTPUT_LEVEL_trace, "Response received\n");
00383 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSAgent, ENUM_OUTPUT_LEVEL_detailed_trace, killResult);
00384 #endif
00385
00386 killResult = WSUtil::getOSxL( killResult, "kill");
00387
00388
00389 useCDATA = false;
00390 #ifndef NDEBUG
00391 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSAgent, ENUM_OUTPUT_LEVEL_trace, "DeSOAPify result\n");
00392 #endif
00393 sOSpL = WSUtil::deSOAPify( killResult, useCDATA);
00394 #ifndef NDEBUG
00395 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSAgent, ENUM_OUTPUT_LEVEL_detailed_trace, sOSpL);
00396 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSAgent, ENUM_OUTPUT_LEVEL_trace, "RETURN THE OSpL\n");
00397 #endif
00398
00399 return sOSpL;
00400 }
00401
00402 string OSSolverAgent::knock(string ospl, string osol)
00403 {
00404 string sOSpL;
00405 string theSOAP;
00406 string knockResult;
00407 bool useCDATA = true;
00408 #ifndef NDEBUG
00409 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSAgent, ENUM_OUTPUT_LEVEL_trace, "Inside SolverAgent knock() method \n");
00410 #endif
00411
00412
00413 int numInputs = 2;
00414 string smethod = "knock";
00415 string msInputs[2];
00416
00417
00418 #ifndef NDEBUG
00419 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSAgent, ENUM_OUTPUT_LEVEL_trace, "SOAPify OSpL \n");
00420 #endif
00421 msInputs[0] = WSUtil::SOAPify( ospl, useCDATA) ;
00422 #ifndef NDEBUG
00423 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSAgent, ENUM_OUTPUT_LEVEL_detailed_trace, msInputs[0]);
00424 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSAgent, ENUM_OUTPUT_LEVEL_trace, "SOAPify OSoL \n");
00425 #endif
00426 msInputs[1] = WSUtil::SOAPify( osol, useCDATA) ;
00427 #ifndef NDEBUG
00428 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSAgent, ENUM_OUTPUT_LEVEL_detailed_trace, msInputs[1]);
00429 #endif
00430
00431 string msInputNames[2] = {"ospl", "osol"};
00432 string sSoapAction = "OSSolverService#knock";
00433
00434 theSOAP = WSUtil::createSOAPMessage(numInputs, solverAddress, postURI,
00435 smethod, msInputs, msInputNames, sSoapAction);
00436
00437 #ifndef NDEBUG
00438 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSAgent, ENUM_OUTPUT_LEVEL_trace, "SEND THE SOAP\n");
00439 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSAgent, ENUM_OUTPUT_LEVEL_detailed_trace, theSOAP);
00440 #endif
00441 knockResult = WSUtil::sendSOAPMessage( theSOAP, solverAddress, solverPortNumber);
00442 #ifndef NDEBUG
00443 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSAgent, ENUM_OUTPUT_LEVEL_trace, "Response received\n");
00444 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSAgent, ENUM_OUTPUT_LEVEL_detailed_trace, knockResult);
00445 #endif
00446
00447
00448 knockResult = WSUtil::getOSxL( knockResult, "knock");
00449
00450 useCDATA = false;
00451 #ifndef NDEBUG
00452 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSAgent, ENUM_OUTPUT_LEVEL_trace, "DeSOAPify result\n");
00453 #endif
00454 sOSpL = WSUtil::deSOAPify( knockResult, useCDATA);
00455 #ifndef NDEBUG
00456 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSAgent, ENUM_OUTPUT_LEVEL_detailed_trace, sOSpL);
00457 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSAgent, ENUM_OUTPUT_LEVEL_trace, "RETURN THE OSpL\n");
00458 #endif
00459
00460 return sOSpL;
00461 }