Beispiel #1
0
/**
* \brief Function to get a certain user account property
* \param machineId The machine identifier of machine on which the user have a account
* \param property The property name
* \return the user account login
*/
std::string
UserServer::getUserAccountProperty(const std::string& machineId, const std::string& property) {

  init();

  std::string userId = getData().getUserId();
  UMS_Data::LocalAccount_ptr account = new UMS_Data::LocalAccount();
  account->setMachineId(machineId);
  account->setUserId(userId);
  LocalAccountServer localAccount(account, *msessionServer);

  UMS_Data::Machine_ptr machine = new UMS_Data::Machine();
  machine->setMachineId(machineId);
  MachineServer machineServer(machine);

  //To get the database number id of the machine
  std::string numMachine = machineServer.getAttribut("where machineid='"+localAccount.getData()->getMachineId()+"'");
  //To get the database number id of the user
  std::string numUser = getAttribut("where userid='"+localAccount.getData()->getUserId()+"'");

  std::string value;
  if ((numMachine.size() > 0) && (numUser.size() > 0)) {
	  value = localAccount.getAttribut("where machine_nummachineid="+numMachine+" and users_numuserid="+numUser, property);
  }

  if(value.size()==0) {
    delete account;
    delete machine;
    throw UMSVishnuException(ERRCODE_UNKNOWN_LOCAL_ACCOUNT, "You have not a local account on this machine");
  }

  delete account;
  delete machine;
  return value;
}
Beispiel #2
0
/**
 * \brief getJobProgress: function gets the progression status of jobs
 * \param sessionKey: The session key
 * \param listOfProgress: The object containing jobs progression information
 * \param options: The object containing the available options jobs for progression .
 * \return int: an error code
 */
int
vishnu::getJobProgress(const std::string& sessionKey,
                       TMS_Data::ListProgression& listOfProgress,
                       const TMS_Data::ProgressOptions& options)
throw (UMSVishnuException, TMSVishnuException, UserException, SystemException) {

  checkEmptyString(sessionKey, "The session key");

  std::string machineId = options.getMachineId();
  UMS_Data::ListMachines machines;
  if (! machineId.empty() && machineId != ALL_KEYWORD) {
    // Use the specified machine
    UMS_Data::Machine_ptr machine = new UMS_Data::Machine();
    machine->setMachineId(machineId);
    machines.getMachines().push_back(machine);
  } else {
    listMachinesWithUserLocalAccount(sessionKey, machines);
  }

  // Now perform the request
  listOfProgress.setNbJobs(0);
  for(int i=0; i< machines.getMachines().size(); i++) {

    UMS_Data::Machine_ptr machine = machines.getMachines().get(i);
    std::string serviceName = (boost::format("%1%@%2%") % SERVICES_TMS[GETJOBSPROGRESSION] % machine->getMachineId()).str();

    SessionProxy sessionProxy(sessionKey);
    QueryProxy<TMS_Data::ProgressOptions, TMS_Data::ListProgression>
        query(options, sessionProxy, serviceName, machine->getMachineId());

    TMS_Data::ListProgression* listProgression_ptr = NULL ;
    try {
      listProgression_ptr = query.list();
    } catch(...) {
      // Means that the machine is not active or the user doesn't have a local account on it
      if(machineId != ALL_KEYWORD) {
        throw ;
      } else {
        continue ;
      }
    }

    if (listProgression_ptr != NULL) {
      TMS_Data::TMS_DataFactory_ptr ecoreFactory = TMS_Data::TMS_DataFactory::_instance();
      for(unsigned int i = 0; i < listProgression_ptr->getProgress().size(); i++) {
        TMS_Data::Progression_ptr progression = ecoreFactory->createProgression();
        //To copy the content and not the pointer
        *progression = *listProgression_ptr->getProgress().get(i);
        listOfProgress.getProgress().push_back(progression);
      }
      listOfProgress.setNbJobs(listOfProgress.getNbJobs()+listProgression_ptr->getProgress().size());
      delete listProgression_ptr;
    }
  }

  return 0;
}
Beispiel #3
0
/**
 * \brief The listJobs function gets a list of all submitted jobs
 * \param sessionKey : The session key
 * \param listOfJobs : The constructed object list of jobs
 * \param options : Additional options for jobs listing
 * \return int : an error code
 */
int
vishnu::listJobs(const std::string& sessionKey,
                 TMS_Data::ListJobs& listOfJobs,
                 const TMS_Data::ListJobsOptions& options)
throw (UMSVishnuException, TMSVishnuException, UserException, SystemException) {

  checkEmptyString(sessionKey, "The session key");

  UMS_Data::Machine_ptr machine = new UMS_Data::Machine();
  const std::string machineId = ALL_KEYWORD;

  // Here the list of machine should contain only a single machine
  machine->setMachineId(machineId);

  listOfJobs.setNbJobs(0);
  listOfJobs.setNbRunningJobs(0);
  listOfJobs.setNbWaitingJobs(0);


  std::string serviceName = (boost::format("%1%") % SERVICES_TMS[GETLISTOFJOBS_ALL]).str();
  SessionProxy sessionProxy(sessionKey);

  checkJobStatus(options.getStatus()); // check the job status options
  checkJobPriority(options.getPriority()); //check the job priority options

  QueryProxy<TMS_Data::ListJobsOptions, TMS_Data::ListJobs>
      query(options, sessionProxy, serviceName, machine->getMachineId());
  TMS_Data::ListJobs* listJobs_ptr = NULL;
  try {
    listJobs_ptr = query.list();
  } catch(...) {
    throw ;
  }
  if (listJobs_ptr != NULL) {

    TMS_Data::TMS_DataFactory_ptr ecoreFactory = TMS_Data::TMS_DataFactory::_instance();
    for (unsigned int j = 0; j < listJobs_ptr->getJobs().size(); j++) {
      TMS_Data::Job_ptr job = ecoreFactory->createJob();
      //copy the content and not the pointer
      *job = *listJobs_ptr->getJobs().get(j);
      listOfJobs.getJobs().push_back(job);
    }
    listOfJobs.setNbJobs(listOfJobs.getNbJobs()+listJobs_ptr->getJobs().size());
    listOfJobs.setNbRunningJobs(listOfJobs.getNbRunningJobs()+listJobs_ptr->getNbRunningJobs());
    listOfJobs.setNbWaitingJobs(listOfJobs.getNbWaitingJobs()+listJobs_ptr->getNbWaitingJobs());
    delete listJobs_ptr;
  }
  return 0;
}
Beispiel #4
0
/**
 * \brief Gets standard output files of all completed jobs (applies only once for each job)
 * \param sessionKey : The session key
 * \param options: object containing options
 * \param listOfResults : Is the list of jobs results
   * \param options: Object containing options
 * \return int : an error code
 */
int
vishnu::getCompletedJobsOutput(const std::string& sessionKey,
                               TMS_Data::ListJobResults& listOfResults,
                               const TMS_Data::JobOutputOptions& options)
throw (UMSVishnuException, TMSVishnuException, UserException, SystemException) {

  checkEmptyString(sessionKey, "The session key");

  std::string outputDir = options.getOutputDir();
  if (! outputDir.empty() && ! boost::filesystem::exists(outputDir)) {
    throw UMSVishnuException(ERRCODE_INVALID_PARAM, "The ouput directory does not exist: "+outputDir);
  }

  UMS_Data::ListMachines machines;
  if (options.getMachineId().empty()) {
    vishnu::listMachinesWithUserLocalAccount(sessionKey, machines);
  } else {
    UMS_Data::Machine_ptr machine = new UMS_Data::Machine(); // delete by EMF
    machine->setMachineId(options.getMachineId());
    machines.getMachines().push_back(machine);
  }

  int machineCount = machines.getMachines().size();
  for (int index = 0; index < machineCount; ++index) {
    SessionProxy sessionProxy(sessionKey);
    JobOutputProxy jobOutputProxy(sessionProxy, machines.getMachines().get(index)->getMachineId());

    TMS_Data::ListJobResults_ptr listJobResults_ptr = jobOutputProxy.getCompletedJobsOutput(options);

    if (listJobResults_ptr != NULL) {
      TMS_Data::TMS_DataFactory_ptr ecoreFactory = TMS_Data::TMS_DataFactory::_instance();
      for(unsigned int i = 0; i < listJobResults_ptr->getResults().size(); i++) {
        TMS_Data::JobResult_ptr jobResult = ecoreFactory->createJobResult();
        //To copy the content and not the pointer
        *jobResult = *listJobResults_ptr->getResults().get(i);
        listOfResults.getResults().push_back(jobResult);
      }
      listOfResults.setNbJobs(listJobResults_ptr->getNbJobs());
      delete listJobResults_ptr;
    }
  }
  return 0;
}
Beispiel #5
0
  /**
  * \brief Function to list machines information
  * \return The pointer to the UMS_Data::ListMachines containing machines information
  * \return raises an exception on error
  */
  UMS_Data::ListMachines* list(UMS_Data::ListMachineOptions_ptr option) {
    std::string sqlListofMachines = boost::str(boost::format("SELECT machineid, address, status, description"
                                                             " FROM machine"
                                                             " WHERE machine.status != %1%") % vishnu::STATUS_DELETED);
    std::vector<std::string>::iterator dbResultIter;
    std::vector<std::string> dbResults;
    UMS_Data::UMS_DataFactory_ptr ecoreFactory = UMS_Data::UMS_DataFactory::_instance();
    mlistObject = ecoreFactory->createListMachines();

    //Creation of the object user
    UserServer userServer = UserServer(msessionServer);
    userServer.init();
    //if the user exists
    if (userServer.exist()) {

      //To process options
      processOptions(userServer, option, sqlListofMachines);

      boost::scoped_ptr<DatabaseResult> ListofMachines (mdatabase->getResult(sqlListofMachines.c_str()));
      if (ListofMachines->getNbTuples() != 0){
        for (size_t i = 0; i < ListofMachines->getNbTuples(); ++i) {
          dbResults.clear();
          dbResults = ListofMachines->get(i);
          dbResultIter = dbResults.begin();
          UMS_Data::Machine_ptr machine = ecoreFactory->createMachine();
          machine->setMachineId(*dbResultIter);
          machine->setAddress(*(++dbResultIter));
          machine->setStatus(vishnu::convertToInt(*(++dbResultIter)));
          machine->setDescription(*(++dbResultIter));

          mlistObject->getMachines().push_back(machine);
        }
      }

    } else {
      UMSVishnuException e (ERRCODE_UNKNOWN_USER);
      throw e;
    }
    return mlistObject;
  }
Beispiel #6
0
/**
 * \brief The cancelJob function cancels a job from its id
 * \param session : The session information
 * \param options : An object containing user-provided options
 * \param infoMsg : The information message
 * \return int : an error code
 */
int
vishnu::cancelJob(const std::string& sessionKey,
                  const TMS_Data::CancelOptions& options)
throw (UMSVishnuException, TMSVishnuException, UserException, SystemException) {

  checkEmptyString(sessionKey, "The session key");

  if (options.getJobId().empty() && options.getMachineId().empty() && options.getUser().empty()) {
    throw UserException(ERRCODE_INVALID_PARAM, "Neither job, machine, nor user target was specified");
  }
  int retCode = 0;
  if (! options.getJobId().empty()) { // cancel a specific job
    TMS_Data::Job job;
    if (options.getMachineId().empty()) {
      vishnu::getJobInfo(sessionKey, options.getJobId(), "", job);
    } else {
      job.setMachine(options.getMachineId());
    }
    retCode = JobProxy(sessionKey, job.getMachine()).cancelJob(options);
  } else {
    std::string machineId = options.getMachineId();
    UMS_Data::ListMachines machines;
    if (! machineId.empty() && machineId != ALL_KEYWORD) { // cancel job on the specified machine
      UMS_Data::Machine_ptr machine = new UMS_Data::Machine();
      machine->setMachineId(machineId);
      machines.getMachines().push_back(machine);
    } else {                                              // cancel job on all machines
      listMachinesWithUserLocalAccount(sessionKey, machines);
    }

    // now perform the request
    for (int i=0; i< machines.getMachines().size(); ++i) {
      retCode += JobProxy(sessionKey, machines.getMachines().get(i)->getMachineId()).cancelJob(options);
    }
  }
  return retCode;
}
Beispiel #7
0
 /**
  * \brief Function to list machines information
  * \fn UMS_Data::ListMachines* list()
  * \return The pointer to the UMS_Data::ListMachines containing machines information
  * \return raises an exception on error
  */
 UMS_Data::ListMachines* list() {
    std::string sqlListofMachines = "SELECT machineid, name, site, status, lang, description from machine, description "
    "where machine.nummachineid = description.machine_nummachineid";

    std::vector<std::string>::iterator ii;
    std::vector<std::string> results;
    UMS_Data::UMS_DataFactory_ptr ecoreFactory = UMS_Data::UMS_DataFactory::_instance();
    mlistObject = ecoreFactory->createListMachines();

    //Creation of the object user
    UserServer userServer = UserServer(msessionServer);
    userServer.init();
    //if the user exists
    if (userServer.exist()) {

      //To process options
      processOptions(userServer, mparameters, sqlListofMachines);

      boost::scoped_ptr<DatabaseResult> ListofMachines (mdatabaseVishnu->getResult(sqlListofMachines.c_str()));
      if (ListofMachines->getNbTuples() != 0){
        for (size_t i = 0; i < ListofMachines->getNbTuples(); ++i) {
          results.clear();
          results = ListofMachines->get(i);
          ii = results.begin();
          UMS_Data::Machine_ptr machine = ecoreFactory->createMachine();
          machine->setMachineId(*ii);
          machine->setName(*(++ii));
          machine->setSite(*(++ii));
          machine->setStatus(convertToInt(*(++ii)));
          machine->setLanguage(*(++ii));
          machine->setMachineDescription(*(++ii));

          mlistObject->getMachines().push_back(machine);
        }
      }

    } else {
      UMSVishnuException e (ERRCODE_UNKNOWN_USER);
      throw e;
    }
    return mlistObject;
  }
Beispiel #8
0
/* 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;
}
Beispiel #9
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;
}
Beispiel #10
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;
}
Beispiel #11
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;
}
Beispiel #12
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;
}
Beispiel #13
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;
}