Exemple #1
0
/**
 * @brief Validate session key and return details on the user and the session
 * @param authKey The authentication key
 * @param machineId The machine Id
 * @param databasePtr A pointer to a database instance
 * @param info The resulting information
 */
void
vishnu::validateAuthKey(const std::string& authKey,
                        const std::string& machineId,
                        Database* database,
                        UserSessionInfo& info)
{
  std::string sqlQuery = boost::str(boost::format("SELECT vsession.numsessionid, "
                                                  "  machine.address, machine.nummachineid,"
                                                  "  users.numuserid, users.userid, users.privilege, "
                                                  "  account.aclogin, account.home"
                                                  " FROM vsession, users, account, machine"
                                                  " WHERE vsession.sessionkey='%1%'"
                                                  "  AND vsession.state=%2%"
                                                  "  AND users.numuserid=vsession.users_numuserid"
                                                  "  AND users.numuserid=account.users_numuserid"
                                                  "  AND account.status=%3%"
                                                  "  AND account.machine_nummachineid=machine.nummachineid"
                                                  "  AND machine.machineid='%4%';"
                                                  )
                                    % database->escapeData(authKey)
                                    % vishnu::SESSION_ACTIVE
                                    % vishnu::STATUS_ACTIVE
                                    % database->escapeData(machineId));

  boost::scoped_ptr<DatabaseResult> sqlResult(database->getResult(sqlQuery));
  if (sqlResult->getNbTuples() < 1) {
    throw TMSVishnuException(ERRCODE_PERMISSION_DENIED,
                             "Can't get user information from the session token provided");
  }

  std::vector<std::string> rowResult = sqlResult->get(0);
  std::vector<std::string>::iterator rowResultIter = rowResult.begin();

  info.num_session = vishnu::convertToInt(*rowResultIter++);
  info.machine_address = *rowResultIter++;
  info.num_machine = *rowResultIter++;
  info.num_user = vishnu::convertToInt(*rowResultIter++);
  info.userid = *rowResultIter++;
  info.user_privilege = vishnu::convertToInt(*rowResultIter++);
  info.user_aclogin = *rowResultIter++;
  info.user_achome = *rowResultIter++;
}
Exemple #2
0
/**
 * @brief Validate session key and return details on the user and the session
 * @param authKey The authentication key
 * @param databasePtr A pointer to a database instance
 * @param info The resulting information
 */
void
vishnu::validateAuthKey(const std::string& authKey,
                        Database* database,
                        UserSessionInfo& info)
{
  std::string sqlQuery = boost::str(
                           boost::format("SELECT vsession.numsessionid, "
                                         "  users.numuserid, users.userid, users.privilege, "
                                         "  account.aclogin, account.home"
                                         " FROM vsession, users, account"
                                         " WHERE vsession.sessionkey='%1%'"
                                         "  AND vsession.state=%2%"
                                         "  AND account.status=%3%"
                                         "  AND vsession.users_numuserid=users.numuserid"
                                         "  AND vsession.users_numuserid=account.users_numuserid"
                                         )
                           % database->escapeData(authKey)
                           % vishnu::SESSION_ACTIVE
                           % vishnu::STATUS_ACTIVE
                           );
  boost::scoped_ptr<DatabaseResult> sqlResult(database->getResult(sqlQuery));
  if (sqlResult->getNbTuples() < 1) {
    throw TMSVishnuException(ERRCODE_INVALID_PARAM,
                             "Can't get user local account. Check that:\n"
                             "  * your session is still active\n"
                             "  * you have a local account on this server");
  }

  std::vector<std::string> rowResult = sqlResult->get(0);
  std::vector<std::string>::iterator rowResultIter = rowResult.begin();

  info.num_session = vishnu::convertToInt(*rowResultIter++);
  info.num_user = vishnu::convertToInt(*rowResultIter++);
  info.userid = *rowResultIter++;
  info.user_privilege = vishnu::convertToInt(*rowResultIter++);
  info.user_aclogin = *rowResultIter++;
  info.user_achome = *rowResultIter++;
}
Exemple #3
0
  /**
   * \brief Function to list sessions information
   * \return The pointer to the UMS_Data::ListSessions containing sessions information
   * \return raises an exception on error
   */
  TMS_Data::ListProgression*
  list(TMS_Data::ProgressOptions_ptr options) {

    std::vector<std::string> results;
    std::vector<std::string>::iterator iter;
    std::string batchJobId;
    int status;
    long startTime;
    long walltime;

    TMS_Data::TMS_DataFactory_ptr ecoreFactory = TMS_Data::TMS_DataFactory::_instance();
    mlistObject = ecoreFactory->createListProgression();

    std::string sqlRequest = "SELECT jobId, jobName, wallClockLimit, endDate, status, batchJobId "
                             " FROM vsession, job "
      " WHERE vsession.numsessionid=job.vsession_numsessionid ";

    std::string machineId = options->getMachineId();
    if (!machineId.empty()){
      checkMachineId(machineId);
      sqlRequest += "  AND submitMachineId='"+mdatabaseInstance->escapeData(machineId)+"'";
    }

    if (! options->getJobId().empty()) {
      std::string jobId = options->getJobId();
      sqlRequest.append(" and jobId='"+mdatabaseInstance->escapeData(jobId)+"'");
      boost::scoped_ptr<DatabaseResult> sqlResult(ServerXMS::getInstance()->getDatabaseVishnu()->getResult(sqlRequest.c_str()));
      if(sqlResult->getNbTuples() == 0) {
        throw TMSVishnuException(ERRCODE_UNKNOWN_JOBID);
      }
    } else {
      sqlRequest.append(" and owner='"+mdatabaseInstance->escapeData(options->getUser())+"'");
    }

    sqlRequest.append("  and status < 5 order by jobId");

    boost::scoped_ptr<DatabaseResult> sqlResult(ServerXMS::getInstance()->getDatabaseVishnu()->getResult(sqlRequest.c_str()));

    if (sqlResult->getNbTuples() != 0){
      for (size_t i = 0; i < sqlResult->getNbTuples(); ++i) {

        results.clear();
        results = sqlResult->get(i);
        iter = results.begin();

        TMS_Data::Progression_ptr job = ecoreFactory->createProgression();

        job->setJobId(*iter);
        job->setJobName(*(++iter));
        walltime = vishnu::convertToInt(*(++iter));
        job->setWallTime(walltime);
        job->setEndTime(vishnu::convertToLong(*(++iter)));
        status = vishnu::convertToInt(*(++iter));
        job->setStatus(status);
        batchJobId = *(++iter);

        BatchFactory factory;
        BatchType batchType  = ServerXMS::getInstance()->getBatchType();
        std::string batchVersion  = ServerXMS::getInstance()->getBatchVersion();
        boost::scoped_ptr<BatchServer> batchServer(factory.getBatchServerInstance(batchType,
                                                                                  batchVersion));

        startTime = batchServer->getJobStartTime(batchJobId);
        if(startTime!=0) {
          job->setStartTime(startTime);

          if (status == vishnu::STATE_COMPLETED) {
            job->setPercent(100);
          } else if(status == vishnu::STATE_RUNNING) {
            time_t currentTime = vishnu::getCurrentTimeInUTC();
            int percent = 0;
            time_t gap = currentTime-startTime;
            if (walltime == 0) {
              walltime = 60;
            }

            if (gap < walltime) {
              double ratio =  100*(double(gap)/walltime);
              if(ratio > 0.0 && ratio <= 1.0) {
                percent = 1;
              } else {
                percent = static_cast<int>(ratio);
              }
            } else {
              percent = 99;
            }
            job->setPercent(percent);
          } else {
            job->setPercent(0);
          }
        } else {
          job->setPercent(0);
        }
        mlistObject->getProgress().push_back(job);
      }
    }

    mlistObject->setNbJobs(mlistObject->getProgress().size());

    return mlistObject;

  }