Пример #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;
}
Пример #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;
  }
Пример #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;
  }
Пример #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;
  }
Пример #5
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;
  }
Пример #6
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;
}
Пример #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;
  }
Пример #8
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;
  }
Пример #9
0
/**
* \brief Function to close the session
* \return raises an exception on error
*/
int
SessionServer::close() {

  std::string closePolicyStr = "";
  UserServer user = UserServer(SessionServer(msession.getSessionKey()));
  CommandServer commanderServer = CommandServer(SessionServer(msession.getSessionKey()));
  //The init function initializes login and password using the sessionKey
  user.init();
  //If The user exist
  if (user.exist()) {
    int state = getState();
    //if the session is not already closed
    if (state != 0) {
      //if no running commands
      if (!commanderServer.isRunning()) {
        mdatabaseVishnu->process((boost::format("UPDATE vsession"
                                                " SET state=0"
                                                " WHERE sessionkey='%1%';")%mdatabaseVishnu->escapeData(msession.getSessionKey())).str());
        mdatabaseVishnu->process((boost::format("UPDATE vsession"
                                                " SET closure=CURRENT_TIMESTAMP"
                                                " WHERE sessionkey='%1%';")%mdatabaseVishnu->escapeData(msession.getSessionKey())).str());
      } else {
        //To get the close policy associated to the session
        closePolicyStr = (boost::format(" WHERE sessionkey='%1%';")%mdatabaseVishnu->escapeData(msession.getSessionKey())).str();
        getAttribut(closePolicyStr, "closepolicy");
        //If the session close policy is CLOSE_ON_DISCONNECT
        if (convertToInt(closePolicyStr) == 2) {
          disconnetToTimeout(user);
        }  else {
          throw  UMSVishnuException (ERRCODE_COMMAND_RUNNING);
        }
      }
    } else {
      UMSVishnuException e (ERRCODE_SESSIONKEY_EXPIRED);
      throw e;
    }
  } //END If The user exist
  return 0;
}//END: close()
Пример #10
0
/**
* \brief Function to close the session
* \return raises an exception on error
*/
int
SessionServer::close() {
  UserServer user = UserServer(SessionServer(msession.getSessionKey()));
  CommandServer commanderServer = CommandServer(SessionServer(msession.getSessionKey()));

  // initialize and check the user
  user.init();
  if (! user.exist()) {
    throw UMSVishnuException (ERRCODE_UNKNOWN_USER, user.getData().getUserId());
  }

  if (getState() == vishnu::SESSION_CLOSED) {
    throw UMSVishnuException (ERRCODE_SESSIONKEY_EXPIRED);
  }

  if (! commanderServer.isRunning()) {
    mdatabase->process(boost::str(boost::format("UPDATE vsession"
                                                " SET state=%1%"
                                                " WHERE sessionkey='%2%';")
                                  % vishnu::SESSION_CLOSED
                                  % mdatabase->escapeData(msession.getSessionKey())));

    mdatabase->process(boost::str(boost::format("UPDATE vsession"
                                                " SET closure=CURRENT_TIMESTAMP"
                                                " WHERE sessionkey='%1%';")
                                  % mdatabase->escapeData(msession.getSessionKey())));
  } else {
    int closePolicy = vishnu::convertToInt(getAttributFromSessionKey(msession.getSessionKey(), "closepolicy"));
    if (closePolicy == vishnu::CLOSE_ON_DISCONNECT) {
      disconnetToTimeout();
    } else {
      throw  UMSVishnuException (ERRCODE_COMMAND_RUNNING);
    }
  }

  return 0;
}
Пример #11
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;


  }