/* Returns the n last lines of a file to the client application. */ int tailFile(diet_profile_t* profile) { string localPath, localUser, userKey, tail, acLogin, machineName; char* path, *user, *host,*sessionKey, *errMsg = NULL, *result = NULL, *optionsSerialized= NULL; std::string finishError =""; int mapperkey; std::string cmd = ""; diet_string_get(diet_parameter(profile, 0), &sessionKey, NULL); diet_string_get(diet_parameter(profile, 1), &path, NULL); diet_string_get(diet_parameter(profile, 2), &user, NULL); diet_paramstring_get(diet_parameter(profile, 3), &host, NULL); diet_string_get(diet_parameter(profile, 4),&optionsSerialized, NULL); localUser = user; localPath = path; SessionServer sessionServer (sessionKey); try { //MAPPER CREATION Mapper *mapper = MapperRegistry::getInstance()->getMapper(FMSMAPPERNAME); mapperkey = mapper->code("vishnu_tail"); mapper->code(std::string(host)+":"+std::string(path), mapperkey); mapper->code(optionsSerialized, 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; // get the acLogin acLogin = UserServer(sessionServer).getUserAccountLogin(host); FileFactory::setSSHServer(machineName); boost::scoped_ptr<File> file (FileFactory::getFileServer(sessionServer,localPath, acLogin, userKey)); TailOfFileOptions_ptr options_ptr= NULL; if(!vishnu::parseEmfObject(std::string(optionsSerialized), options_ptr )) { throw SystemException(ERRCODE_INVDATA, "solve_Tail: TailOfFileOptions object is not well built"); } tail = file->tail(*options_ptr); result = strdup(tail.c_str()); //To register the command sessionServer.finish(cmd, FMS, vishnu::CMDSUCCESS); } catch (VishnuException& err) { try { sessionServer.finish(cmd, FMS, vishnu::CMDFAILED); } catch (VishnuException& fe) { finishError = fe.what(); finishError +="\n"; } err.appendMsgComp(finishError); result = strdup(""); errMsg = strdup(err.buildExceptionString().c_str()); } if (errMsg==NULL){ errMsg = strdup(""); } else { result = strdup(""); } diet_string_set(diet_parameter(profile, 5), result, DIET_VOLATILE); diet_string_set(diet_parameter(profile, 6), errMsg, DIET_VOLATILE); return 0; }
/* Returns the n first line of the file to the client application. */ int solveChangeGroup (diet_profile_t* profile) { string localPath, localUser,userKey="", acLogin, machineName; char* path, *user, *host,*sessionKey, *group, *errMsg = NULL; std::string finishError =""; int mapperkey; std::string cmd = ""; diet_string_get(diet_parameter(profile, 0), &sessionKey, NULL); diet_string_get(diet_parameter(profile, 1), &path, NULL); diet_string_get(diet_parameter(profile, 2), &user, NULL); diet_paramstring_get(diet_parameter(profile, 3), &host, NULL); diet_string_get(diet_parameter(profile, 4), &group, NULL); localUser = user; localPath = path; SessionServer sessionServer (sessionKey); try { //MAPPER CREATION Mapper *mapper = MapperRegistry::getInstance()->getMapper(FMSMAPPERNAME); mapperkey = mapper->code("vishnu_chgrp"); mapper->code(group, mapperkey); mapper->code(std::string(host)+":"+std::string(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; // get the acLogin acLogin = UserServer(sessionServer).getUserAccountLogin(host); FileFactory::setSSHServer(machineName); boost::scoped_ptr<File> file (FileFactory::getFileServer(sessionServer,localPath, acLogin, userKey)); file->chgrp(group); //To register the command sessionServer.finish(cmd, FMS, vishnu::CMDSUCCESS); } catch (VishnuException& err) { try { sessionServer.finish(cmd, FMS, vishnu::CMDFAILED); } catch (VishnuException& fe) { finishError = fe.what(); finishError +="\n"; } err.appendMsgComp(finishError); errMsg = strdup(err.buildExceptionString().c_str()); } if (errMsg==NULL) { errMsg = strdup(""); } diet_string_set(diet_parameter(profile, 5), errMsg, DIET_VOLATILE); 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 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; }