Beispiel #1
0
/**
 * \brief Function to parse the string representing the version
 * \param version the string representing the version
 * \return  The version object
 */
UMS_Data::Version_ptr
vishnu::parseVersion(const std::string& version) {
  UMS_Data::Version_ptr vers = NULL;
  std::string major;
  std::string minor;
  std::string patch;

  size_t found = version.find_first_of(".");
  if (found != std::string::npos) {
    major = version.substr(0, found) ;
    std::string rest = version.substr(found+1, version.size()) ;
    found = rest.find_first_of(".");
    if (found != std::string::npos) {
      minor = rest.substr(0, found);
      patch = rest.substr(found+1, rest.size());
    }
    //if the string major, minor, patch are not empty
    if ((major.size() != 0) && (minor.size() != 0)
        && (patch.size() != 0)) {
      //if the values major, minor, patch are positives and major value higher than zero
      if ((convertToInt(major) > 0) && (convertToInt(minor) >= 0)
          && (convertToInt(patch) >= 0)) {
        UMS_Data::UMS_DataFactory_ptr ecoreFactory = UMS_Data::UMS_DataFactory::_instance();
        vers = ecoreFactory->createVersion();
        vers->setMajor(convertToInt(major));
        vers->setMinor(convertToInt(minor));
        vers->setPatch(convertToInt(patch));
        vers->setStringformat(version);
      }
    }
  }

  return vers;
}
Beispiel #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;
  }
Beispiel #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;
  }
Beispiel #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;
  }
  /**
   * \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;
  }
Beispiel #6
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 #7
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 #8
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;


  }