ListObject* QueryProxy<QueryParameters, ListObject>::list() { //If the query uses the machineId (machineId not null) diet_profile_t* profile =NULL; if (! mmachineId.empty()) { profile = diet_profile_alloc(mserviceName, 3); } else { profile = diet_profile_alloc(mserviceName, 2); } std::string queryParmetersToString = SerializeAdaptor<QueryParameters>::serialize(mparameters); // Set parameters diet_string_set(profile, 0, msessionProxy.getSessionKey()); if (! mmachineId.empty()) { diet_string_set(profile, 1, mmachineId); diet_string_set(profile, 2, queryParmetersToString); } else { diet_string_set(profile, 1, queryParmetersToString); } if (diet_call(profile)) { raiseCommunicationMsgException("RPC call failed"); } raiseExceptionOnErrorResult(profile); std::string listObjectInString; diet_string_get(profile,1, listObjectInString); parseEmfObject(listObjectInString, mlistObject, "Error by receiving List object serialized"); return mlistObject; }
/** * \brief Main loop. receives data and deal with it if it isn't empty * Uses protected method doCall to provide implementation specific * behavior when recieving data. */ void operator()() { Socket socket(*ctx_, ZMQ_REP); socket.connect(uriInproc_.c_str()); std::string data; while (true) { //vishnu::exitProcessIfAnyZombieChild(-1); data.clear(); try { data = socket.get(); } catch (zmq::error_t &error) { LOG(boost::str(boost::format("[ERROR] %1%\n") % error.what()), LogErr); continue; } // Deserialize and call Method if (! data.empty()) { try { std::string resultSerialized = doCall(data); socket.send(resultSerialized); } catch (const VishnuException& ex) { diet_profile_t* profile = diet_profile_alloc("docall", 2); diet_string_set(profile, 0, "error"); diet_string_set(profile, 1, ex.what()); socket.send(JsonObject::serialize(profile)); diet_profile_free(profile); LOG(boost::str(boost::format("[ERROR] %1%\n")%ex.what()), LogErr); } } } }
/** * @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; }
/** * \brief Function to change user password * \fn int changePassword(const std::string& password, const std::string& newPassword) * \param oldPassword the old password of the user * \param newPassword the new password of the user * \return raises an exception on error */ int UserProxy::changePassword(const std::string& password, const std::string& newPassword) { diet_profile_t* profile = NULL; char* errorInfo; std::string msg = "call of function diet_string_set is rejected "; std::string versionToString; UMS_Data::Version_ptr versionObj = vishnu::parseVersion(VISHNU_VERSION); if (versionObj == NULL) { throw UMSVishnuException(ERRCODE_INVALID_PARAM, "The format of the VISHNU VERSION is incorrect"); } else { // SERIALIZE DATA MODEL ::ecorecpp::serializer::serializer _ser; //To serialize the version object in to versionToString versionToString = _ser.serialize_str(versionObj); } profile = diet_profile_alloc("userPasswordChange", 3, 3, 4); //IN Parameters if(diet_string_set(diet_parameter(profile,0), strdup((muser.getUserId()).c_str()), DIET_VOLATILE)) { msg += "with sessionKey parameter "+msessionProxy->getSessionKey(); raiseDietMsgException(msg); } if(diet_string_set(diet_parameter(profile,1), strdup(password.c_str()), DIET_VOLATILE)) { msg += "with password parameter "+password; raiseDietMsgException(msg); } if(diet_string_set(diet_parameter(profile,2), strdup(newPassword.c_str()), DIET_VOLATILE)) { msg += "with newPassword parameter "+newPassword; raiseDietMsgException(msg); } if(diet_string_set(diet_parameter(profile,3), strdup(versionToString.c_str()), DIET_VOLATILE)) { msg += "with version parameter "+versionToString; raiseDietMsgException(msg); } //OUT Parameters diet_string_set(diet_parameter(profile,4), NULL, DIET_VOLATILE); if(!diet_call(profile)) { if(diet_string_get(diet_parameter(profile,4), &errorInfo, NULL)){ msg += "by receiving errorInfo message"; raiseDietMsgException(msg); } } else { raiseDietMsgException("DIET call failure"); } /*To raise a vishnu exception if the receiving message is not empty*/ raiseExceptionIfNotEmptyMsg(errorInfo); diet_profile_free(profile); delete versionObj; return 0; }
/** * \brief Function to add new user * \param user The object which encapsulates the user information * \return raises an exception on error */ int UserProxy::add(UMS_Data::User& user) { std::string sessionKey; std::string userInString; diet_profile_t* profile = diet_profile_alloc(SERVICES_UMS[USERCREATE], 2); sessionKey = msessionProxy->getSessionKey(); ::ecorecpp::serializer::serializer _ser; //To serialize the user object in to userToString std::string userToString = _ser.serialize_str(const_cast<UMS_Data::User_ptr>(&user)); //IN Parameters diet_string_set(profile, 0, msessionProxy->getSessionKey()); diet_string_set(profile, 1, userToString); if (diet_call(profile)) { raiseCommunicationMsgException("RPC call failed"); } raiseExceptionOnErrorResult(profile); diet_string_get(profile,1, userInString); //To parse User object serialized UMS_Data::User_ptr user_ptr; parseEmfObject(userInString, user_ptr, "Error by receiving User object serialized"); user = *user_ptr; muser = user; delete user_ptr; diet_profile_free(profile); return 0; }
/** * \brief Function to change user password * \param oldPassword the old password of the user * \param newPassword the new password of the user * \return raises an exception on error */ int UserProxy::changePassword(const std::string& password, const std::string& newPassword) { std::string errorInfo; std::string msg = "call of function diet_string_set is rejected "; std::string versionToString; UMS_Data::Version_ptr versionObj = vishnu::parseVersion(VISHNU_VERSION); if (versionObj == NULL) { throw UMSVishnuException(ERRCODE_INVALID_PARAM, "The format of the VISHNU VERSION is incorrect"); } else { // SERIALIZE DATA MODEL ::ecorecpp::serializer::serializer _ser; //To serialize the version object in to versionToString versionToString = _ser.serialize_str(versionObj); } diet_profile_t* profile = diet_profile_alloc(SERVICES_UMS[USERPASSWORDCHANGE], 4); diet_string_set(profile,0, muser.getUserId()); diet_string_set(profile,1, password); diet_string_set(profile,2, newPassword); diet_string_set(profile,3, versionToString); if (diet_call(profile)) { raiseCommunicationMsgException("RPC call failed"); } raiseExceptionOnErrorResult(profile); diet_profile_free(profile); delete versionObj; return 0; }
/** * \brief Function to add new user * \fn int add(UMS_Data::User& user) * \param user The object which encapsulates the user information * \return raises an exception on error */ int UserProxy::add(UMS_Data::User& user) { diet_profile_t* profile = NULL; std::string sessionKey; char* userToString; char* errorInfo; char* userInString; std::string msg = "call of function diet_string_set is rejected "; profile = diet_profile_alloc("userCreate", 1, 1, 3); sessionKey = msessionProxy->getSessionKey(); ::ecorecpp::serializer::serializer _ser; //To serialize the user object in to userToString userToString = strdup(_ser.serialize_str(const_cast<UMS_Data::User_ptr>(&user)).c_str()); //IN Parameters if(diet_string_set(diet_parameter(profile,0), strdup(sessionKey.c_str()), DIET_VOLATILE)) { msg += "with sessionKey parameter "+sessionKey; raiseDietMsgException(msg); } if(diet_string_set(diet_parameter(profile,1), userToString, DIET_VOLATILE)) { msg += "with userToString parameter "+std::string(userToString); raiseDietMsgException(msg); } //OUT Parameters diet_string_set(diet_parameter(profile,2), NULL, DIET_VOLATILE); diet_string_set(diet_parameter(profile,3), NULL, DIET_VOLATILE); if(!diet_call(profile)) { if(diet_string_get(diet_parameter(profile,2), &userInString, NULL)){ msg += " by receiving User serialized message"; raiseDietMsgException(msg); } if(diet_string_get(diet_parameter(profile,3), &errorInfo, NULL)){ msg += " by receiving errorInfo message"; raiseDietMsgException(msg); } } else { raiseDietMsgException("DIET call failure"); } /*To raise a vishnu exception if the receiving message is not empty*/ raiseExceptionIfNotEmptyMsg(errorInfo); UMS_Data::User_ptr user_ptr; //To parse User object serialized parseEmfObject(std::string(userInString), user_ptr, "Error by receiving User object serialized"); user = *user_ptr; muser = user; delete user_ptr; diet_profile_free(profile); 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 update machine description * \fn int update() * \return raises an exception on error */ int MachineProxy::update() { diet_profile_t* updateProfile = NULL; std::string sessionKey; std::string machineToString; char* errorInfo; std::string msg = "call of function diet_string_set is rejected "; updateProfile = diet_profile_alloc("machineUpdate", 1, 1, 2); sessionKey = msessionProxy.getSessionKey(); ::ecorecpp::serializer::serializer _ser; //To serialize the mmachine object in to machineToString machineToString = _ser.serialize_str(const_cast<UMS_Data::Machine_ptr>(&mmachine)); std::string sshKeyFilePath = mmachine.getSshPublicKey(); if(sshKeyFilePath.find("\"")!=std::string::npos) { throw UMSVishnuException(ERRCODE_INVALID_PARAM, " The machine SshPublicKey contains special character double quote \""); } //IN Parameters if(diet_string_set(diet_parameter(updateProfile,0), strdup(sessionKey.c_str()), DIET_VOLATILE)) { msg += "with sessionKey parameter "+sessionKey; raiseDietMsgException(msg); } if(diet_string_set(diet_parameter(updateProfile,1), strdup(machineToString.c_str()), DIET_VOLATILE)) { msg += "with machineToString parameter "+machineToString; raiseDietMsgException(msg); } //OUT Parameters diet_string_set(diet_parameter(updateProfile,2), NULL, DIET_VOLATILE); if(!diet_call(updateProfile)) { if(diet_string_get(diet_parameter(updateProfile,2), &errorInfo, NULL)){ msg += "by receiving errorInfo message"; raiseDietMsgException(msg); } } else { raiseDietMsgException("DIET call failure"); } /*To raise a vishnu exception if the receiving message is not empty*/ raiseExceptionIfNotEmptyMsg(errorInfo); diet_profile_free(updateProfile); return 0; }
/** * \brief Function to reset user password * \fn int resetPassword(UMS_Data::User& user) * \param user The object which encapsulates the user information * \return raises an exception on error */ int UserProxy::resetPassword(UMS_Data::User& user) { diet_profile_t* profile = NULL; char* tmpPassword; char* errorInfo; std::string msg = "call of function diet_string_set is rejected "; profile = diet_profile_alloc("userPasswordReset", 1, 1, 3); //IN Parameters if(diet_string_set(diet_parameter(profile,0), strdup((msessionProxy->getSessionKey()).c_str()), DIET_VOLATILE)) { msg += "with sessionKey parameter "+msessionProxy->getSessionKey(); raiseDietMsgException(msg); } if(diet_string_set(diet_parameter(profile,1), strdup((user.getUserId()).c_str()), DIET_VOLATILE)) { msg += "with userId parameter "+user.getUserId(); raiseDietMsgException(msg); } //OUT Parameters diet_string_set(diet_parameter(profile,2), NULL, DIET_VOLATILE); diet_string_set(diet_parameter(profile,3), NULL, DIET_VOLATILE); if(!diet_call(profile)) { if(diet_string_get(diet_parameter(profile,2), &tmpPassword, NULL)){ msg += "by receiving tmpPassWord message"; raiseDietMsgException(msg); } if(diet_string_get(diet_parameter(profile,3), &errorInfo, NULL)){ msg += "by receiving errorInfo message"; raiseDietMsgException(msg); } } else { raiseDietMsgException("DIET call failure"); } /*To raise a vishnu exception if the receiving message is not empty*/ raiseExceptionIfNotEmptyMsg(errorInfo); /*To set the temporary password*/ muser.setUserId(user.getUserId()); muser.setPassword(std::string(tmpPassword)); diet_profile_free(profile); 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; }
/** * \brief Function to update an authentication system * \return raises an exception on error */ int AuthSystemProxy::update() { diet_profile_t* profile = NULL; std::string sessionKey; std::string authSystemToString; char* errorInfo; std::string msg = "call of function diet_string_set is rejected "; profile = diet_profile_alloc("authSystemUpdate", 1, 1, 2); sessionKey = msessionProxy.getSessionKey(); ::ecorecpp::serializer::serializer _ser; //To serialize the mauthSystem object in to authSystemToString authSystemToString = _ser.serialize_str(const_cast<UMS_Data::AuthSystem_ptr>(&mauthSystem)); //IN Parameters if(diet_string_set(diet_parameter(profile,0), strdup(sessionKey.c_str()), DIET_VOLATILE)) { msg += "with sessionKey parameter "+sessionKey; raiseDietMsgException(msg); } if(diet_string_set(diet_parameter(profile,1), strdup(authSystemToString.c_str()), DIET_VOLATILE)) { msg += "with authSystemToString parameter "+authSystemToString; raiseDietMsgException(msg); } //OUT Parameters diet_string_set(diet_parameter(profile,2), NULL, DIET_VOLATILE); if(!diet_call(profile)) { if(diet_string_get(diet_parameter(profile,2), &errorInfo, NULL)){ msg += "by receiving errorInfo message"; raiseDietMsgException(msg); } } else { raiseDietMsgException("DIET call failure"); } /*To raise a vishnu exception if the receiving message is not empty*/ raiseExceptionIfNotEmptyMsg(errorInfo); diet_profile_free(profile); return 0; }
/** * \brief Function to remove user information * \param user The object which encapsulates the user information * \return raises an exception on error */ int UserProxy::deleteUser(const UMS_Data::User& user) { diet_profile_t* profile = diet_profile_alloc(SERVICES_UMS[USERDELETE], 2); //IN Parameters diet_string_set(profile, 0, msessionProxy->getSessionKey()); diet_string_set(profile, 1, user.getUserId()); if (diet_call(profile)) { raiseCommunicationMsgException("RPC call failed"); } raiseExceptionOnErrorResult(profile); diet_profile_free(profile); 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 removes an authentication system * \return raises an exception on error */ int AuthSystemProxy::deleteAuthSystem() { diet_profile_t* profile = NULL; std::string sessionKey; std::string sysId; char* errorInfo; std::string msg = "call of function diet_string_set is rejected "; profile = diet_profile_alloc("authSystemDelete", 1, 1, 2); sessionKey = msessionProxy.getSessionKey(); sysId = mauthSystem.getAuthSystemId(); //IN Parameters if(diet_string_set(diet_parameter(profile,0), strdup(sessionKey.c_str()), DIET_VOLATILE)) { msg += "with sessionKey parameter "+sessionKey; raiseDietMsgException(msg); } if(diet_string_set(diet_parameter(profile,1), strdup(sysId.c_str()), DIET_VOLATILE)) { msg += "with systemId parameter "+sysId; raiseDietMsgException(msg); } //OUT Parameters diet_string_set(diet_parameter(profile,2), NULL, DIET_VOLATILE); if(!diet_call(profile)) { if(diet_string_get(diet_parameter(profile,2), &errorInfo, NULL)){ msg += "by receiving errorInfo message"; raiseDietMsgException(msg); } } else { raiseDietMsgException("DIET call failure"); } /*To raise a vishnu exception if the receiving message is not empty*/ raiseExceptionIfNotEmptyMsg(errorInfo); diet_profile_free(profile); 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; }
/** * \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 update user information * \param user The object which encapsulates the user information * \return raises an exception on error */ int UserProxy::update(const UMS_Data::User& user) { diet_profile_t* profile = diet_profile_alloc(SERVICES_UMS[USERUPDATE], 2); //To serialize the user object in to userToString ::ecorecpp::serializer::serializer _ser; std::string userToString = _ser.serialize_str(const_cast<UMS_Data::User_ptr>(&user)); //IN Parameters diet_string_set(profile, 0, msessionProxy->getSessionKey()); diet_string_set(profile, 1, userToString); if (diet_call(profile)) { raiseCommunicationMsgException("RPC call failed"); } raiseExceptionOnErrorResult(profile); diet_profile_free(profile); return 0; }
/** * \brief Function to reset user password * \param user The object which encapsulates the user information * \return raises an exception on error */ int UserProxy::resetPassword(UMS_Data::User& user) { diet_profile_t* profile = diet_profile_alloc(SERVICES_UMS[USERPASSWORDRESET], 2); diet_string_set(profile, 0, msessionProxy->getSessionKey()); diet_string_set(profile, 1, user.getUserId()); if (diet_call(profile)) { raiseCommunicationMsgException("RPC call failed"); } raiseExceptionOnErrorResult(profile); std::string tmpPassword; diet_string_get(profile, 1, tmpPassword); /*To set the temporary password*/ muser.setUserId(user.getUserId()); muser.setPassword(tmpPassword); diet_profile_free(profile); 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; }
/* 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 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; }
/** * \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; }