/** * @brief Update transfer information when the transfer were initiated from the client side * @param profile The profile information * @return 0 on success, non-zero on erro */ int solveUpdateClientSideTransfer(diet_profile_t* profile) { std::string sessionKey = ""; std::string transferSerialized = ""; diet_string_get(profile,0, sessionKey); diet_string_get(profile,1, transferSerialized); try { FMS_Data::FileTransfer_ptr transfer; if (! vishnu::parseEmfObject(transferSerialized, transfer)) { SystemException(ERRCODE_INVDATA, "solveUpdateClientSideTransfer: invalid transfer object"); } FileTransferServer transferServer(SessionServer(sessionKey), ServerXMS::getInstance()->getVishnuId()); transferServer.setFileTransfer(*transfer); transferServer.updateDatabaseRecord(); delete transfer; // reset the profile to handle result diet_profile_reset(profile, 2); // set success result diet_string_set(profile, 0, "success"); diet_string_set(profile, 1, ""); } catch (VishnuException& err) { diet_string_set(profile, 0, "error"); diet_string_set(profile, 1, err.what()); } return 0; }
int solveGenerique(diet_profile_t* pb) { std::string authKey; std::string machineId; std::string optionValueSerialized; std::string listSerialized = ""; //IN Parameters diet_string_get(pb,0, authKey); diet_string_get(pb,1, machineId); diet_string_get(pb,2, optionValueSerialized); // reset profile to handle result diet_profile_reset(pb, 2); QueryParameters* options = NULL; List* list = NULL; try { //To parse the object serialized if (! vishnu::parseEmfObject(optionValueSerialized, options)) { throw TMSVishnuException(ERRCODE_INVALID_PARAM); } QueryType query(authKey); //MAPPER CREATION Mapper *mapper = MapperRegistry::getInstance()->getMapper(vishnu::TMSMAPPERNAME); int mapperkey = mapper->code(query.getCommandName()); mapper->code(optionValueSerialized, mapperkey); std::string cmd = mapper->finalize(mapperkey); list = query.list(options); ::ecorecpp::serializer::serializer _ser; listSerialized = _ser.serialize_str(list); //OUT Parameter diet_string_set(pb,0, "success"); diet_string_set(pb,1, listSerialized); FINISH_COMMAND(authKey, cmd, vishnu::TMS, vishnu::CMDSUCCESS, ""); } catch (VishnuException& ex) { try { FINISH_COMMAND(authKey, "", vishnu::TMS, vishnu::CMDFAILED, ""); } catch (VishnuException& fe) { ex.appendMsgComp(fe.what()); } diet_string_set(pb,0, "error"); diet_string_set(pb,1, ex.what()); } delete options; delete list; return 0; }
/** * \brief Function to solve the jobSubmit service * \param pb is a structure which corresponds to the descriptor of a profile * \return raises an exception on error */ int solveSubmitJob(diet_profile_t* pb) { std::string scriptContent; std::string machineId; std::string jsonEncodedOptions; std::string authKey; // get profile parameters diet_string_get(pb,0, authKey); diet_string_get(pb,1, machineId); diet_string_get(pb,2, scriptContent); diet_string_get(pb,3, jsonEncodedOptions); // reset the profile to send back result diet_profile_reset(pb, 2); try { JsonObject options(jsonEncodedOptions); std::string scriptPath = options.getStringProperty("scriptpath"); //MAPPER CREATION Mapper *mapper = MapperRegistry::getInstance()->getMapper(vishnu::TMSMAPPERNAME); int mapperkey = mapper->code("vishnu_submit_job"); mapper->code(scriptPath, mapperkey); mapper->code(jsonEncodedOptions, mapperkey); std::string cmd = mapper->finalize(mapperkey); //FIXME: decode job and options ServerXMS* server = ServerXMS::getInstance(); JobServer jobServer(authKey, machineId, server->getSedConfig()); jobServer.setDebugLevel(server->getDebugLevel()); // Set the debug level std::string jobId = jobServer.submitJob(scriptContent, & options, server->getDefaultBatchOption()); diet_string_set(pb,0, "success"); diet_string_set(pb,1, JsonObject::serialize(jobServer.getJobInfo(jobId))); FINISH_COMMAND(authKey, cmd, vishnu::TMS, vishnu::CMDSUCCESS, jobId); } catch (VishnuException& ex) { try { FINISH_COMMAND(authKey, "", vishnu::TMS, vishnu::CMDFAILED, ""); } catch (VishnuException& fe) { ex.appendMsgComp(fe.what()); } diet_string_set(pb,0, "error"); diet_string_set(pb,1, ex.what()); } return 0; }
/** * \brief Function to solve the jobOutPutGetResult service * \param pb is a structure which corresponds to the descriptor of a profile * \return raises an exception on error */ int solveJobOutPutGetResult(diet_profile_t* pb) { std::string authKey; std::string machineId; std::string optionsSerialized; std::string jobid; //IN Parameters diet_string_get(pb,0, authKey); diet_string_get(pb,1, machineId); diet_string_get(pb,2, optionsSerialized); diet_string_get(pb,3, jobid); // reset profile to handle result diet_profile_reset(pb, 2); try { //MAPPER CREATION Mapper *mapper = MapperRegistry::getInstance()->getMapper(vishnu::TMSMAPPERNAME); int mapperkey = mapper->code("vishnu_get_job_output"); mapper->code(machineId, mapperkey); mapper->code(optionsSerialized, mapperkey); mapper->code(jobid, mapperkey); std::string cmd = mapper->finalize(mapperkey); //Start dealing with output JobOutputServer jobOutputServer(authKey, machineId); JsonObject options(optionsSerialized); TMS_Data::JobResult result = jobOutputServer.getJobOutput(&options, jobid); std::string jobFiles = vishnu::getResultFiles(result, false) ; std::string outputInfo = bfs::unique_path(boost::str(boost::format("%1%/vishnu-%2%-outdescr%3%") % boost::filesystem::temp_directory_path().string() % jobid % "%%%%%%%")).string(); vishnu::saveInFile(outputInfo, jobFiles); diet_string_set(pb,0, "success"); diet_string_set(pb,1, outputInfo); FINISH_COMMAND(authKey, cmd, vishnu::TMS, vishnu::CMDSUCCESS, ""); } catch (VishnuException& e) { try { FINISH_COMMAND(authKey, "", vishnu::TMS, vishnu::CMDFAILED, ""); } catch (VishnuException& fe) { e.appendMsgComp(fe.what()); } diet_string_set(pb,0, "error"); diet_string_set(pb,1, e.what()); } return 0; }
/** * \brief Function to solve the getListOfQueues service * \param pb is a structure which corresponds to the descriptor of a profile * \return raises an exception on error */ int solveListOfQueues(diet_profile_t* pb) { std::string authKey; std::string machineId; std::string optionSerialized; std::string listQueuesSerialized; diet_string_get(pb,0, authKey); diet_string_get(pb,1, machineId); diet_string_get(pb,2, optionSerialized); // reset profile to handle result diet_profile_reset(pb, 2); TMS_Data::ListQueues_ptr listQueues = NULL; ListQueuesServer queryQueues(authKey, ServerXMS::getInstance()->getBatchType(), ServerXMS::getInstance()->getBatchVersion(), optionSerialized); try { //MAPPER CREATION Mapper *mapper = MapperRegistry::getInstance()->getMapper(vishnu::TMSMAPPERNAME); int mapperkey = mapper->code("vishnu_list_queues"); mapper->code(machineId, mapperkey); mapper->code(optionSerialized, mapperkey); std::string cmd = mapper->finalize(mapperkey); listQueues = queryQueues.list(); ::ecorecpp::serializer::serializer _ser; listQueuesSerialized = _ser.serialize_str(listQueues); diet_string_set(pb,0, "success"); diet_string_set(pb,1, listQueuesSerialized); FINISH_COMMAND(authKey, cmd, vishnu::TMS, vishnu::CMDSUCCESS, ""); } catch (VishnuException& ex) { try { FINISH_COMMAND(authKey, "", vishnu::TMS, vishnu::CMDFAILED, ""); } catch (VishnuException& fe) { ex.appendMsgComp(fe.what()); } diet_string_set(pb,0, "error"); diet_string_set(pb,1, ex.what()); } return 0; }
/** * \brief Function to solve the File transfer stop service * \param profile is a structure which corresponds to the descriptor of a profile * \return raises an exception on error */ int solveFileTransferStop(diet_profile_t* profile) { std::string sessionKey = ""; std::string optionsSerialized = ""; std::string cmd = ""; diet_string_get(profile,0, sessionKey); diet_string_get(profile,1, optionsSerialized); // reset the profile to handle result diet_profile_reset(profile, 2); SessionServer sessionServer = SessionServer(sessionKey); try { //MAPPER CREATION int mapperkey; Mapper *mapper = MapperRegistry::getInstance()->getMapper(vishnu::FMSMAPPERNAME); mapperkey = mapper->code("vishnu_stop_file_transfer"); mapper->code(optionsSerialized, mapperkey); cmd = mapper->finalize(mapperkey); FMS_Data::StopTransferOptions_ptr options_ptr = NULL; if(! vishnu::parseEmfObject(optionsSerialized, options_ptr)) { SystemException(ERRCODE_INVDATA, "solveFileTransferStop: options object is not well built"); } FileTransferServer fileTransferServer(sessionServer, ServerXMS::getInstance()->getVishnuId()); fileTransferServer.stopThread(*options_ptr); delete options_ptr; // set success result diet_string_set(profile, 0, "success"); diet_string_set(profile, 1, ""); sessionServer.finish(cmd, vishnu::FMS, vishnu::CMDSUCCESS); } catch (VishnuException& err) { try { sessionServer.finish(cmd, vishnu::FMS, vishnu::CMDFAILED); } catch (VishnuException& fe) { err.appendMsgComp(fe.what()); } // set error result diet_string_set(profile, 0, "error"); diet_string_set(profile, 1, err.what()); } return 0; }
int heartbeat(diet_profile_t* pb){ std::string serviceName = std::string(pb->name); std::string batch; if (serviceName.find("tms") != std::string::npos){ batch = (boost::format("\n With batch scheduler %1% %2%") % VISHNU_BATCH_SCHEDULER % VISHNU_BATCH_SCHEDULER_VERSION).str(); } std::string msg = (boost::format("%1% %2%") % VISHNU_VERSION % batch).str(); // reset the profile to handle result diet_profile_reset(pb, 2); diet_string_set(pb, 1, msg); diet_string_set(pb, 0, "success"); return 0; }
/** * \brief Function to solve the jobInfo service * \param pb is a structure which corresponds to the descriptor of a profile * \return raises an exception on error */ int solveJobInfo(diet_profile_t* pb) { std::string authKey; std::string machineId; std::string jobId; //IN Parameters diet_string_get(pb, 0, authKey); diet_string_get(pb, 1, machineId); diet_string_get(pb, 2, jobId); // reset the profile to send back result diet_profile_reset(pb, 2); try{ //MAPPER CREATION Mapper *mapper = MapperRegistry::getInstance()->getMapper(vishnu::TMSMAPPERNAME); int mapperkey = mapper->code("vishnu_get_job_info"); mapper->code(machineId, mapperkey); mapper->code(jobId, mapperkey); std::string cmd = mapper->finalize(mapperkey); JobServer jobServer(authKey, machineId, ServerXMS::getInstance()->getSedConfig()); std::string jobSerialized = JsonObject::serialize(jobServer.getJobInfo(jobId)); diet_string_set(pb,1, jobSerialized); diet_string_set(pb,0, "success"); FINISH_COMMAND(authKey, cmd, vishnu::TMS, vishnu::CMDSUCCESS, ""); } catch (VishnuException& e) { try { FINISH_COMMAND(authKey, "", vishnu::TMS, vishnu::CMDFAILED, ""); } catch (VishnuException& fe) { e.appendMsgComp(fe.what()); } diet_string_set(pb,0, "error"); diet_string_set(pb,1, e.what()); } return 0; }
/** * \brief Function to solve the jobCancel service * \param pb is a structure which corresponds to the descriptor of a profile * \return raises an exception on error */ int solveCancelJob(diet_profile_t* pb) { std::string authKey; std::string machineId; std::string optionSerialized; diet_string_get(pb,0, authKey); diet_string_get(pb,1, machineId); diet_string_get(pb,2, optionSerialized); // reset the profile to send back result diet_profile_reset(pb, 2); try { //MAPPER CREATION Mapper *mapper = MapperRegistry::getInstance()->getMapper(vishnu::TMSMAPPERNAME); int mapperkey = mapper->code("vishnu_cancel_job"); mapper->code(optionSerialized, mapperkey); std::string cmd = mapper->finalize(mapperkey); ServerXMS* server = ServerXMS::getInstance(); JobServer jobServer(authKey, machineId, server->getSedConfig()); JsonObject options(optionSerialized); jobServer.cancelJob(&options); diet_string_set(pb,0, "success"); diet_string_set(pb,1, ""); FINISH_COMMAND(authKey, cmd, vishnu::TMS, vishnu::CMDSUCCESS, ""); } catch (VishnuException& ex) { try { FINISH_COMMAND(authKey, "", vishnu::TMS, vishnu::CMDFAILED, ""); } catch (VishnuException& fe) { ex.appendMsgComp(fe.what()); } diet_string_set(pb,0, "error"); diet_string_set(pb,1, ex.what()); } return 0; }
/* Returns the n first line of the file to the client application. */ int solveChangeGroup (diet_profile_t* profile) { std::string localPath, userKey="", acLogin, machineName; std::string path = ""; std::string host = ""; std::string sessionKey = ""; std::string group = ""; std::string cmd = ""; diet_string_get(profile, 0, sessionKey); diet_string_get(profile, 1, path); diet_string_get(profile, 2, host); diet_string_get(profile, 3, group); // reset the profile to handle result diet_profile_reset(profile, 2); localPath = path; SessionServer sessionServer (sessionKey); try { int mapperkey; //MAPPER CREATION Mapper *mapper = MapperRegistry::getInstance()->getMapper(vishnu::FMSMAPPERNAME); mapperkey = mapper->code("vishnu_chgrp"); mapper->code(group, mapperkey); mapper->code(host + ":" + path, mapperkey); cmd = mapper->finalize(mapperkey); sessionServer.check(); UMS_Data::Machine_ptr machine = new UMS_Data::Machine(); machine->setMachineId(host); MachineServer machineServer(machine); // check the machine machineServer.checkMachine(); machineName = machineServer.getMachineName(); delete machine; // get the acLogin acLogin = UserServer(sessionServer).getUserAccountLogin(host); FileFactory fileFactory; fileFactory.setSSHServer(machineName); boost::scoped_ptr<File> file (fileFactory.getFileServer(sessionServer,localPath, acLogin, userKey)); file->chgrp(group); // set success result diet_string_set(profile, 0, "success"); diet_string_set(profile, 1, ""); //To register the command sessionServer.finish(cmd, vishnu::FMS, vishnu::CMDSUCCESS); } catch (VishnuException& err) { try { sessionServer.finish(cmd, vishnu::FMS, vishnu::CMDFAILED); } catch (VishnuException& fe) { err.appendMsgComp(fe.what()); } // set error result diet_string_set(profile, 0, "error"); diet_string_set(profile, 1, err.what()); } return 0; }
/* Returns the n last lines of a file to the client application. */ int solveTailFile(diet_profile_t* profile) { std::string localPath; std::string userKey; std::string acLogin; std::string machineName; std::string path = ""; std::string host = ""; std::string sessionKey = ""; std::string optionsSerialized = ""; std::string cmd = ""; diet_string_get(profile, 0, sessionKey); diet_string_get(profile, 1, path); diet_string_get(profile, 2, host); diet_string_get(profile, 3, optionsSerialized); // reset the profile to handle result diet_profile_reset(profile, 2); localPath = path; SessionServer sessionServer (sessionKey); try { sessionServer.check(); //MAPPER CREATION int mapperkey; Mapper *mapper = MapperRegistry::getInstance()->getMapper(vishnu::FMSMAPPERNAME); mapperkey = mapper->code("vishnu_tail_of_file"); mapper->code(host + ":" + path, mapperkey); mapper->code(optionsSerialized, mapperkey); cmd = mapper->finalize(mapperkey); // Check machine UMS_Data::Machine_ptr machine = new UMS_Data::Machine(); machine->setMachineId(host); MachineServer machineServer(machine); machineServer.checkMachine(); machineName = machineServer.getMachineName(); delete machine; // get the acLogin acLogin = UserServer(sessionServer).getUserAccountLogin(host); FileFactory ff; ff.setSSHServer(machineName); boost::scoped_ptr<File> file (ff.getFileServer(sessionServer,localPath, acLogin, userKey)); FMS_Data::TailOfFileOptions_ptr options_ptr= NULL; if(!vishnu::parseEmfObject(optionsSerialized, options_ptr )) { throw SystemException(ERRCODE_INVDATA, "solve_Tail: TailOfFileOptions object is not well built"); } // set success result diet_string_set(profile, 1, file->tail(*options_ptr)); diet_string_set(profile, 0, "success"); delete options_ptr; //To register the command sessionServer.finish(cmd, vishnu::FMS, vishnu::CMDSUCCESS); } catch (VishnuException& err) { try { sessionServer.finish(cmd, vishnu::FMS, vishnu::CMDFAILED); } catch (VishnuException& fe) { err.appendMsgComp(fe.what()); } // set error result diet_string_set(profile, 0, "error"); diet_string_set(profile, 1, err.what()); } return 0; }
/* The function returns all the information about a file: * - The local owner * - The local group * - The local uid & gid * - The creation, modification and acces time. * - The file type. */ int solveGetInfos(diet_profile_t* profile) { std::string path = ""; std::string host = ""; std::string sessionKey = ""; std::string localPath, userKey, machineName; std::string cmd = ""; std::string fileStatSerialized = ""; diet_string_get(profile, 0, sessionKey); diet_string_get(profile, 1, path); diet_string_get(profile, 2, host); // reset the profile to handle result diet_profile_reset(profile, 2); localPath = path; SessionServer sessionServer (sessionKey); try { int mapperkey; //MAPPER CREATION Mapper *mapper = MapperRegistry::getInstance()->getMapper(vishnu::FMSMAPPERNAME); mapperkey = mapper->code("vishnu_stat"); mapper->code(host + ":" + path, mapperkey); cmd = mapper->finalize(mapperkey); // check the sessionKey sessionServer.check(); UMS_Data::Machine_ptr machine = new UMS_Data::Machine(); machine->setMachineId(host); MachineServer machineServer(machine); // check the machine machineServer.checkMachine(); // get the machineName machineName = machineServer.getMachineName(); delete machine; std::string acLogin = UserServer(sessionServer).getUserAccountLogin(host); FileFactory ff; ff.setSSHServer(machineName); boost::scoped_ptr<File> file (ff.getFileServer(sessionServer,localPath, acLogin, userKey)); boost::scoped_ptr<FMS_Data::FileStat> fileStat_ptr (new FMS_Data::FileStat()); if ( file->exists()) { *fileStat_ptr=file->getFileStat(); ::ecorecpp::serializer::serializer _ser; fileStatSerialized = _ser.serialize_str(const_cast<FMS_Data::FileStat_ptr>(fileStat_ptr.get())); } else { throw FMSVishnuException(ERRCODE_RUNTIME_ERROR, static_cast<SSHFile*>(file.get())->getErrorMsg()); } // set success result diet_string_set(profile, 1, fileStatSerialized); diet_string_set(profile, 0, "success"); //To register the command sessionServer.finish(cmd, vishnu::FMS, vishnu::CMDSUCCESS); } catch (VishnuException& err) { try { sessionServer.finish(cmd, vishnu::FMS, vishnu::CMDFAILED); } catch (VishnuException& fe) { err.appendMsgComp(fe.what()); } // set error result diet_string_set(profile, 0, "error"); diet_string_set(profile, 1, err.what()); } return 0; }
int solveGenerique(diet_profile_t* profile) { std::string sessionKey = ""; std::string optionValueSerialized = ""; std::string listSerialized = ""; std::string errorInfo; std::string cmd; std::string finishError =""; //IN Parameters diet_string_get(profile,0, sessionKey); diet_string_get(profile,1, optionValueSerialized); // reset profile to handle result diet_profile_reset(profile, 2); SessionServer sessionServer = SessionServer(sessionKey); QueryParameters* options = NULL; List* list = NULL; try { int mapperkey; //To parse the object serialized if (!vishnu::parseEmfObject(optionValueSerialized, options)) { throw UMSVishnuException(ERRCODE_INVALID_PARAM); } QueryType query(sessionKey); //MAPPER CREATION Mapper *mapper = MapperRegistry::getInstance()->getMapper(vishnu::FMSMAPPERNAME); mapperkey = mapper->code(query.getCommandName()); mapper->code(optionValueSerialized, mapperkey); cmd = mapper->finalize(mapperkey); // perform the query list = query.list(options); ::ecorecpp::serializer::serializer _ser; listSerialized = _ser.serialize_str(const_cast<List*>(list)); //OUT Parameter diet_string_set(profile, 0, "success"); diet_string_set(profile, 1, listSerialized.c_str()); sessionServer.finish(cmd, vishnu::FMS, vishnu::CMDSUCCESS); } catch (VishnuException& e) { try { sessionServer.finish(cmd, vishnu::FMS, vishnu::CMDFAILED); } catch (VishnuException& fe) { finishError = fe.what(); finishError +="\n"; } e.appendMsgComp(finishError); errorInfo = e.buildExceptionString(); //OUT Parameter // set error result diet_string_set(profile, 0, "error"); diet_string_set(profile, 1, errorInfo); } delete options; delete list; return 0; }
/** * \brief Function to solve the service solveAddWork * \param pb is a structure which corresponds to the descriptor of a profile * \return raises an exception on error */ int solveAddWork(diet_profile_t* pb) { std::string authKey; std::string workSerialized; std::string opSerialized; //IN Parameters diet_string_get(pb,0, authKey); diet_string_get(pb,1, workSerialized); diet_string_get(pb,2, opSerialized); // reset profile to handle result diet_profile_reset(pb, 2); //FIXME: SessionServer sessionServer = SessionServer(authKey); TMS_Data::AddWorkOptions_ptr workop = NULL; TMS_Data::Work_ptr work = NULL; try { std::string msgComp = ""; //MAPPER CREATION Mapper *mapper = MapperRegistry::getInstance()->getMapper(vishnu::TMSMAPPERNAME); int mapperkey = mapper->code("vishnu_add_work"); mapper->code(opSerialized, mapperkey); std::string cmd = mapper->finalize(mapperkey); //To parse the object serialized if (! vishnu::parseEmfObject(workSerialized, work)) { throw TMSVishnuException(ERRCODE_INVALID_PARAM, msgComp); } //To parse the object serialized if (! vishnu::parseEmfObject(opSerialized, workop)) { throw TMSVishnuException(ERRCODE_INVALID_PARAM, msgComp); } WorkServer workServer = WorkServer(authKey, workop->getMachineId(), work); workServer.add(workop); //To serialize the user object ::ecorecpp::serializer::serializer _ser; std::string workSerializedUpdate = _ser.serialize_str(work); // set result diet_string_set(pb,0, "success"); diet_string_set(pb,1, workSerializedUpdate); FINISH_COMMAND(authKey, cmd, vishnu::TMS, vishnu::CMDFAILED, work->getWorkId()); } catch (VishnuException& e) { try { FINISH_COMMAND(authKey, "", vishnu::TMS, vishnu::CMDFAILED, ""); } catch (VishnuException& fe) { e.appendMsgComp(fe.what()); } // set result diet_string_set(pb,0, "error"); diet_string_set(pb,1, e.what()); } delete work; return 0; }
/** * \brief Function to solve the jobOutputGetCompletedJobs service * \param pb is a structure which corresponds to the descriptor of a profile * \return raises an exception on error */ int solveJobOutPutGetCompletedJobs(diet_profile_t* pb) { std::string authKey; std::string machineId; std::string serializedOptions; std::string jobListsSerialized; int mapperkey; std::string cmd; diet_string_get(pb, 0, authKey); diet_string_get(pb, 1, machineId); diet_string_get(pb, 2, serializedOptions); // reset profile to handle result diet_profile_reset(pb, 2); try { //MAPPER CREATION Mapper *mapper = MapperRegistry::getInstance()->getMapper(vishnu::TMSMAPPERNAME); mapperkey = mapper->code("vishnu_get_completed_jobs_output"); mapper->code(machineId, mapperkey); mapper->code(serializedOptions, mapperkey); cmd = mapper->finalize(mapperkey); JsonObject options(serializedOptions); JobOutputServer jobOutputServer(authKey, machineId); TMS_Data::ListJobResults_ptr jobResults = jobOutputServer.getCompletedJobsOutput(&options); ::ecorecpp::serializer::serializer _ser; jobListsSerialized = _ser.serialize_str(jobResults); std::ostringstream ossFileName ; size_t nbResult = jobResults->getResults().size() ; for(size_t i = 0; i < nbResult; ++i) { std::ostringstream missingFiles; missingFiles.clear() ; ossFileName << vishnu::getResultFiles(*jobResults->getResults().get(i), true); } std::string outputInfo = bfs::unique_path(boost::filesystem::temp_directory_path().string()+"/vishnu-outdescr%%%%%%%").string(); vishnu::saveInFile(outputInfo, ossFileName.str()); JsonObject data; data.setProperty("infofile", outputInfo); data.setProperty("joblist", jobListsSerialized); // set result diet_string_set(pb, 0, "success"); diet_string_set(pb, 1, data.encode()); FINISH_COMMAND(authKey, cmd, vishnu::TMS, vishnu::CMDSUCCESS, ""); } catch (VishnuException& e) { try { FINISH_COMMAND(authKey, cmd, vishnu::TMS, vishnu::CMDFAILED, ""); } catch (VishnuException& fe) { e.appendMsgComp(fe.what()); } // set result diet_string_set(pb, 0, "error"); diet_string_set(pb, 1, e.what()); } return 0; }
int solveTransferRemoteFile(diet_profile_t* profile){ std::string srcPath = ""; std::string destUser = ""; std::string srcHost = ""; std::string sessionKey = ""; std::string destHost = ""; std::string destPath = ""; std::string optionsSerialized = ""; std::string srcUserKey = ""; std::string srcUserLogin = ""; std::string srcMachineName = ""; std::string errMsg = ""; std::string finishError = ""; std::string fileTransferSerialized = ""; std::string cmd = ""; diet_string_get(profile, 0, sessionKey); diet_string_get(profile, 1, srcHost); diet_string_get(profile, 2, srcPath); diet_string_get(profile, 3, destHost); diet_string_get(profile, 4, destPath); diet_string_get(profile, 5, optionsSerialized); // reset profile to handle result diet_profile_reset(profile, 2); SessionServer sessionServer (sessionKey); try { int mapperkey; std::string destUserLogin(destUser); std::string destMachineName(destHost); SessionServer sessionServer (sessionKey); // check the source machine // and get the source machine if applied if (destHost != "localhost"){ UMS_Data::Machine_ptr machine = new UMS_Data::Machine(); machine->setMachineId(destHost); MachineServer destMachineServer(machine); destMachineServer.checkMachine(); destMachineName = destMachineServer.getMachineName(); delete machine; } else { destMachineName = destHost; } // get the source machine user login if (destHost != "localhost"){ destUserLogin = UserServer(sessionServer).getUserAccountLogin(destHost); } else { destUserLogin = destUser; } //MAPPER CREATION std::string destCpltPath = destPath; if (destUser.empty()) { destCpltPath = destHost + ":" + destPath; } Mapper *mapper = MapperRegistry::getInstance()->getMapper(vishnu::FMSMAPPERNAME); if (transferMode == File::sync) { if(transferType == File::copy) { mapperkey = mapper->code("vishnu_cp"); } if(transferType == File::move) { mapperkey = mapper->code("vishnu_mv"); } } else{ if (transferType == File::copy) { mapperkey = mapper->code("vishnu_acp"); } if (transferType == File::move) { mapperkey = mapper->code("vishnu_amv"); } } mapper->code(srcHost + ":" + srcPath, mapperkey); mapper->code(destCpltPath, mapperkey); mapper->code(optionsSerialized, mapperkey); cmd = mapper->finalize(mapperkey); // check the sessionKey sessionServer.check(); // get the source Vishnu machine UMS_Data::Machine_ptr machine = new UMS_Data::Machine(); machine->setMachineId(srcHost); MachineServer srcMachineServer(machine); // check the source machine if (srcHost != "localhost"){ srcMachineServer.checkMachine(); srcMachineName = srcMachineServer.getMachineName(); } else { srcMachineName = srcHost; } delete machine; // get the source machine user login if (srcHost != "localhost"){ srcUserLogin = UserServer(sessionServer).getUserAccountLogin(srcHost); } else { srcUserLogin = destUser; } if (destUser.empty()) { // get the destination Vishnu machine machine = new UMS_Data::Machine(); machine->setMachineId(destHost); // check the destination machine if (destHost != "localhost"){ MachineServer destMachineServer(machine); destMachineServer.checkMachine(); // get the destination machineName destMachineName = destMachineServer.getMachineName(); delete machine; } // get the destination machine user login if (destHost != "localhost"){ destUserLogin = UserServer(sessionServer).getUserAccountLogin(destHost); } else { destUserLogin = destUser; } } FMS_Data::CpFileOptions_ptr options_ptr= NULL; if (! vishnu::parseEmfObject(optionsSerialized, options_ptr) ) { throw SystemException(ERRCODE_INVDATA, "solve_Copy: CpFileOptions object is not well built"); } boost::shared_ptr<FileTransferServer> fileTransferServer = \ boost::make_shared<FileTransferServer>(sessionServer, srcHost, destHost, srcPath, destPath); // Perfor the transfer now if (transferMode==File::sync) { if (transferType == File::copy) { fileTransferServer->addCpThread(srcUserLogin, srcMachineName, srcUserKey, destUserLogin, destMachineName, *options_ptr); } if (transferType == File::move) { fileTransferServer->addMvThread(srcUserLogin, srcMachineName, srcUserKey, destUserLogin, destMachineName, *options_ptr); } } else { if (transferType == File::copy) { fileTransferServer->addCpAsyncThread(srcUserLogin, srcMachineName, srcUserKey, destUserLogin, destMachineName, *options_ptr); } if (transferType == File::move) { fileTransferServer->addMvAsyncThread(srcUserLogin, srcMachineName, srcUserKey, destUserLogin, destMachineName, *options_ptr); } } FMS_Data::FMS_DataFactory_ptr ecoreFactory = FMS_Data::FMS_DataFactory::_instance(); boost::scoped_ptr<FMS_Data::FileTransfer> fileTransfer(ecoreFactory->createFileTransfer()); *(fileTransfer.get()) = fileTransferServer->getFileTransfer(); ::ecorecpp::serializer::serializer _ser; fileTransferSerialized = _ser.serialize_str(const_cast<FMS_Data::FileTransfer_ptr>(fileTransfer.get())); //To register the command sessionServer.finish(cmd, vishnu::FMS, vishnu::CMDSUCCESS); } catch (VishnuException& err) { try { sessionServer.finish(cmd, vishnu::FMS, vishnu::CMDFAILED); } catch (VishnuException& fe) { finishError = fe.what(); finishError +="\n"; } err.appendMsgComp(finishError); errMsg = err.buildExceptionString().c_str(); } if (errMsg.empty()){ diet_string_set(profile, 0, "success"); diet_string_set(profile, 1, fileTransferSerialized.c_str()); } else { diet_string_set(profile, 0, "error"); diet_string_set(profile, 1, errMsg); } return 0; }