Exemplo n.º 1
0
/**
* \brief Function to update a VISHNU machine
* \return raises an exception on error
*/
int
MachineServer::update() {

  std::string sqlCommand = "";

  UserServer userServer = UserServer(msessionServer);
  userServer.init();

  //if the user exists
  if (! userServer.exist()) {
    throw UMSVishnuException (ERRCODE_UNKNOWN_USER);
  }
  if (! userServer.isAdmin()) {
    throw UMSVishnuException (ERRCODE_NO_ADMIN);
  }

  //if the machine to update exists
  std::string numMachineId = getEntryAttribute(mmachine->getMachineId(), "nummachineid");
  if (numMachineId.empty()) {
    throw UMSVishnuException (ERRCODE_UNKNOWN_MACHINE);
  }

  if (! mmachine->getAddress().empty()) {
    std::string query = boost::str(boost::format("UPDATE machine SET address='%1%'"
                                                 " WHERE nummachineid='%2%';")
                                   % mdatabase->escapeData(mmachine->getAddress())
                                   % numMachineId);
    sqlCommand.append(query);
  }

  if (mmachine->getStatus() != vishnu::STATUS_UNDEFINED) {
    std::string query = boost::str(
                          boost::format("UPDATE machine SET status='%1%'"
                                        " WHERE nummachineid='%2%';")
                          % mmachine->getStatus()
                          % numMachineId);
    sqlCommand.append(query);
  }

  if (! mmachine->getDescription().empty()) {
    std::string query = boost::str(
                          boost::format("UPDATE machine SET description='%1%'"
                                        " WHERE machine_nummachineid='%2%';")
                          % mdatabase->escapeData(mmachine->getDescription())
                          % numMachineId);

    sqlCommand.append(query);
  }

  if (! sqlCommand.empty()) {
    mdatabase->process(sqlCommand);
  }

  return 0;
}
Exemplo n.º 2
0
  /**
   * \brief Function to list sessions information
   * \return The pointer to the UMS_Data::ListSessions containing sessions information
   * \return raises an exception on error
   */
  UMS_Data::ListSessions*
  list(UMS_Data::ListSessionOptions_ptr option)
  {
    std::string query = (boost::format("SELECT DISTINCT vsessionid, userid, sessionkey, state, closepolicy, "
                                       "                timeout, lastconnect, creation, closure, authid "
                                       " FROM vsession, users, clmachine"
                                       " WHERE vsession.state            = %1%"
                                       "    AND users.status             = %1%"
                                       "    AND vsession.users_numuserid = users.numuserid"
                                       "    AND vsession.clmachine_numclmachineid=clmachine.numclmachineid")
                         % vishnu::STATUS_ACTIVE).str();

    std::vector<std::string>::iterator dbResultIter;
    std::vector<std::string> dbResults;
    UMS_Data::UMS_DataFactory_ptr ecoreFactory = UMS_Data::UMS_DataFactory::_instance();
    mlistObject = ecoreFactory->createListSessions();

    //Creation of the object user
    UserServer userServer = UserServer(msessionServer);
    userServer.init();

    if (! userServer.exist()) {
      throw UMSVishnuException (ERRCODE_UNKNOWN_USER);
    }

    processOptions(userServer, option, query);
    query.append(" order by creation");
    //To get the list of sessions from the database
    boost::scoped_ptr<DatabaseResult> ListOfSessions (mdatabase->getResult(query));

    if (ListOfSessions->getNbTuples() != 0){
      for (size_t i = 0; i < ListOfSessions->getNbTuples(); ++i) {
        dbResults.clear();
        dbResults = ListOfSessions->get(i);
        dbResultIter = dbResults.begin();

        UMS_Data::Session_ptr session = ecoreFactory->createSession();
        session->setSessionId(*(dbResultIter));
        session->setUserId(*(++dbResultIter));
        session->setSessionKey(*(++dbResultIter));
        session->setStatus(vishnu::convertToInt(*(++dbResultIter)));
        session->setClosePolicy(vishnu::convertToInt(*(++dbResultIter)));
        session->setTimeout(vishnu::convertToInt(*(++dbResultIter)));
        session->setDateLastConnect(convertToTimeType(*(++dbResultIter)));
        session->setDateCreation(convertToTimeType(*(++dbResultIter)));
        session->setDateClosure(convertToTimeType(*(++dbResultIter)));
        session->setAuthenId(*(++dbResultIter));
        mlistObject->getSessions().push_back(session);
      }
    }

    return mlistObject;
  }
Exemplo n.º 3
0
  /**
   * \brief Function to list commands information
   * \return The pointer to the UMS_Data::ListCommands containing commands information
   * \return raises an exception on error
   */
  UMS_Data::ListCommands* list(UMS_Data::ListCmdOptions_ptr option)
  {
    std::string query;
    std::vector<std::string>::iterator ii;
    std::vector<std::string> results;
    std::string description;

    query = "SELECT DISTINCT ctype, vsessionid, name, description, starttime, endtime, command.status"
            " FROM vsession, clmachine, command, users"
            " WHERE vsession.numsessionid=command.vsession_numsessionid"
            "  AND vsession.clmachine_numclmachineid=clmachine.numclmachineid"
            "  AND vsession.users_numuserid=users.numuserid";


    UMS_Data::UMS_DataFactory_ptr ecoreFactory = UMS_Data::UMS_DataFactory::_instance();
    mlistObject = ecoreFactory->createListCommands();

    //Creation of the object user
    UserServer userServer = UserServer(msessionServer);
    userServer.init();
    //if the user exists
    if (!userServer.exist()) {
      UMSVishnuException e (ERRCODE_UNKNOWN_USER);
      throw e;
    }

    processOptions(userServer, option, query);
    query.append(" order by starttime");
    //To get the list of commands from the database
    boost::scoped_ptr<DatabaseResult> ListOfCommands (mdatabase->getResult(query.c_str()));
    for (size_t i = 0; i < ListOfCommands->getNbTuples(); ++i) {

      results.clear();
      results = ListOfCommands->get(i);
      ii = results.begin();

      UMS_Data::Command_ptr command = ecoreFactory->createCommand();
      vishnu::CmdType currentCmdType = static_cast<vishnu::CmdType>(vishnu::convertToInt(*ii));
      command->setCommandId(convertCmdType(static_cast<vishnu::CmdType>(currentCmdType)));
      command->setSessionId(*(++ii));
      command->setMachineId(*(++ii));
      //MAPPER CREATION
      Mapper* mapper = MapperRegistry::getInstance()->getMapper(convertypetoMapperName(currentCmdType));
      description = mapper->decode(*(++ii));
      command->setCmdDescription(description);
      command->setCmdStartTime(convertToTimeType(*(++ii)));
      command->setCmdEndTime(convertToTimeType(*(++ii)));
      command->setStatus(vishnu::convertToInt(*(++ii)));

      mlistObject->getCommands().push_back(command);
    }
    return mlistObject;
  }
Exemplo n.º 4
0
  /**
   * \brief Function to list sessions information
   * \return The pointer to the UMS_Data::ListSessions containing sessions information
   * \return raises an exception on error
   */
  UMS_Data::ListSessions*
  list(UMS_Data::ListSessionOptions_ptr option)
  {
    std::string sqlListOfSessions = "SELECT vsessionid, userid, sessionkey, state, closepolicy, timeout, lastconnect, "
                                    "creation, closure, authid from vsession, users where vsession.users_numuserid=users.numuserid";

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

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

      processOptions(userServer, option, sqlListOfSessions);
      sqlListOfSessions.append(" order by creation");
      //To get the list of sessions from the database
      boost::scoped_ptr<DatabaseResult> ListOfSessions (mdatabaseInstance->getResult(sqlListOfSessions.c_str()));

      if (ListOfSessions->getNbTuples() != 0){
        for (size_t i = 0; i < ListOfSessions->getNbTuples(); ++i) {
          results.clear();
          results = ListOfSessions->get(i);
          ii = results.begin();

          UMS_Data::Session_ptr session = ecoreFactory->createSession();
          session->setSessionId(*(ii));
          session->setUserId(*(++ii));
          session->setSessionKey(*(++ii));
          session->setStatus(vishnu::convertToInt(*(++ii)));
          session->setClosePolicy(vishnu::convertToInt(*(++ii)));
          session->setTimeout(vishnu::convertToInt(*(++ii)));
          session->setDateLastConnect(convertToTimeType(*(++ii)));
          session->setDateCreation(convertToTimeType(*(++ii)));
          session->setDateClosure(convertToTimeType(*(++ii)));
          session->setAuthenId(*(++ii));

          mlistObject->getSessions().push_back(session);
        }
      }
    }
    else {
      UMSVishnuException e (ERRCODE_UNKNOWN_USER);
      throw e;
    }
    return mlistObject;
  }
Exemplo n.º 5
0
/**
 * \brief Function to treat the Stop file transfer options
 * \param options the object which contains the Stop file transfers options values
 * \param sqlRequest the sql data base request
 * \return raises an exception on error
 */
void
FileTransferServer::processOptions(const FMS_Data::StopTransferOptions& options,
                                   std::string& sqlRequest) {

  std::string transferId(options.getTransferId()),machineName(options.getFromMachineId()),userId(options.getUserId());

  //To check if the transferId is defined
  if (transferId.size() != 0) {

    if (transferId.compare("all")!=0 && transferId.compare("ALL")!=0){
      //To check the transfer Id
      FileTransferServer::checkTransferId(options.getTransferId());
      //To add the transferId on the request
      FileTransferServer::addOptionRequest("transferId", options.getTransferId(), sqlRequest);

    }

  }

  //To check if the fromMachineId is defined
  if (machineName.size() != 0) {

    sqlRequest.append(" and (sourceMachineId='"+FileTransferServer::getDatabaseInstance()->escapeData(machineName)+"'"+" or destinationMachineId='"+FileTransferServer::getDatabaseInstance()->escapeData(machineName)+"')");
  }

  //Creation of the object user
  UserServer userServer = UserServer(msessionServer);

  userServer.init();

  //To check if the userId is defined
  if (userId.size() != 0) {

    if (!userServer.isAdmin()) {
      UMSVishnuException e (ERRCODE_NO_ADMIN);
      throw e;
    }

    if (userId.compare("all")!=0 && userId.compare("ALL")!=0){
      //To check the user Id
      FileTransferServer::checkUserId(options.getUserId());

      //To add the userId on the request
      FileTransferServer::addOptionRequest("userId", userId, sqlRequest);
    }
  } else {
    FileTransferServer::addOptionRequest("userId", userServer.getData().getUserId(), sqlRequest);
  }
}
Exemplo n.º 6
0
  /**
   * \brief Function to list locoal accounts information
   * \return The pointer to the UMS_Data::ListLocalAccounts containing local accounts information
   * \return raises an exception on error
   */
  UMS_Data::ListLocalAccounts* list(UMS_Data::ListLocalAccOptions_ptr option)
  {
    std::string query = boost::str(boost::format("SELECT DISTINCT machineid, userid, aclogin, home"
                                                 " FROM account, machine, users"
                                                 " WHERE account.status               = %1%"
                                                 "   AND machine.status               = %1%"
                                                 "   AND users.status                 = %1%"
                                                 "   AND account.machine_nummachineid = machine.nummachineid"
                                                 "   AND account.users_numuserid      = users.numuserid"
                                                 ) % vishnu::STATUS_ACTIVE);


    std::vector<std::string>::iterator dbResultIter;
    std::vector<std::string> dbResults;
    UMS_Data::UMS_DataFactory_ptr ecoreFactory = UMS_Data::UMS_DataFactory::_instance();
    mlistObject = ecoreFactory->createListLocalAccounts();

    //Creation of the object user
    UserServer userServer = UserServer(msessionServer);
    userServer.init();
    if (! userServer.exist()) {
      throw UMSVishnuException (ERRCODE_UNKNOWN_USER);
    }

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

    boost::scoped_ptr<DatabaseResult> resultAccount(mdatabase->getResult(query));
    if (resultAccount->getNbTuples() != 0){
      for (size_t i = 0; i < resultAccount->getNbTuples(); ++i) {
        dbResults.clear();
        dbResults = resultAccount->get(i);
        dbResultIter = dbResults.begin();

        UMS_Data::LocalAccount_ptr localAccount = ecoreFactory->createLocalAccount();
        localAccount->setMachineId(*dbResultIter);
        localAccount->setUserId(*(++dbResultIter));
        localAccount->setAcLogin(*(++dbResultIter));
        localAccount->setHomeDirectory(*(++dbResultIter));

        mlistObject->getAccounts().push_back(localAccount);
      }
    }

    return mlistObject;
  }
Exemplo n.º 7
0
/**
* \brief Function to add a new VISHNU machine
* \return raises an exception on error
*/
int
MachineServer::add(void) {

  UserServer userServer = UserServer(msessionServer);
  userServer.init();

  if (! userServer.exist()) {
    throw UMSVishnuException (ERRCODE_UNKNOWN_USER);
  }

  if (! userServer.isAdmin()) {
    throw UMSVishnuException (ERRCODE_NO_ADMIN);
  }

  dbSave();

  return 0;
}
Exemplo n.º 8
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;
  }
Exemplo n.º 9
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;
  }
Exemplo n.º 10
0
  /**
  * \brief Function to list users information
  * \return The pointer to the UMS_Data::ListUsers containing users information
  * \return raises an exception on error
  */
  UMS_Data::ListUsers* list(UMS_Data::ListUsersOptions_ptr option) {

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

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

      std::string sqlQuery = "";
      if ( userServer.isAdmin()) {
        // query all users
        sqlQuery = boost::str(boost::format(
                                "SELECT userid, pwd, firstname, lastname, privilege, email, status"
                                " FROM users"
                                " WHERE users.status<>%1%") % vishnu::STATUS_DELETED);
      } else {
        // dont query admin users
        sqlQuery = boost::str(boost::format(
                                "SELECT userid, pwd, firstname, lastname, privilege, email, status"
                                " FROM users"
                                " WHERE userid<>'%1%'"
                                " AND users.status<>%2%") % vishnu::ROOTUSERNAME % vishnu::STATUS_DELETED);
      }

      processOptions(userServer, option, sqlQuery);

      sqlQuery.append(" ORDER BY userid");

      //To get the list of users from the database
      boost::scoped_ptr<DatabaseResult> ListofUsers (mdatabaseInstance->getResult(sqlQuery));

      if (ListofUsers->getNbTuples() != 0){
        for (size_t resultIndex = 0; resultIndex < ListofUsers->getNbTuples(); ++resultIndex) {
          results.clear();
          results = ListofUsers->get(resultIndex);
          dbResultIter = results.begin();
          UMS_Data::User_ptr user = ecoreFactory->createUser();
          user->setUserId(*dbResultIter);
          user->setPassword(*(++dbResultIter));
          user->setFirstname(*(++dbResultIter));
          user->setLastname(*(++dbResultIter));
          user->setPrivilege(vishnu::convertToInt(*(++dbResultIter)));
          user->setEmail(*(++dbResultIter));
          user->setStatus(vishnu::convertToInt(*(++dbResultIter)));

          mlistObject->getUsers().push_back(user);
        }
      }
    }
    else {
      UMSVishnuException e (ERRCODE_UNKNOWN_USER);
      throw e;
    }
    return mlistObject;


  }
Exemplo n.º 11
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;
}
Exemplo n.º 12
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;
}
Exemplo n.º 13
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;
}
Exemplo n.º 14
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;
}