Exemple #1
0
  /**
   * \brief Function to treat the ListMachinesServer options
   * \fn void processOptions(UserServer userServer,
   *                         const UMS_Data::ListMachineOptions_ptr& options,
   *                         std::string& sqlRequest)
   * \param userServer the object which encapsulates user information
   * \param options the object which contains the ListMachinesServer options values
   * \param sqlRequest the sql data base request
   * \return raises an exception on error
   */
  void processOptions(UserServer userServer, const UMS_Data::ListMachineOptions_ptr& options, std::string& sqlRequest)
  {
    std::string sqlListofMachinesWithJointure = "SELECT machineid, name, site, machine.status, lang, description, userid "
    " from machine, description, account, users where machine.nummachineid = description.machine_nummachineid "
    " and account.machine_nummachineid=machine.nummachineid and account.users_numuserid=users.numuserid";

    std::string sqlListofMachinesIntial =  sqlRequest;

    size_t userIdSize = options->getUserId().size();
    size_t machineIdSize = options->getMachineId().size();
    bool isListAll = options->isListAllMachine();

    if ((!userServer.isAdmin()) && userIdSize!=0) {
      UMSVishnuException e (ERRCODE_NO_ADMIN);
      throw e;
    }

    if(!isListAll) {
       sqlRequest = sqlListofMachinesWithJointure;
       addOptionRequest("userid", userServer.getData().getUserId(), sqlRequest);
    }

    //The admin option
    if(userIdSize!=0) {
      //To check if the user id is correct
      checkUserId(options->getUserId());

      sqlRequest = sqlListofMachinesWithJointure;
      addOptionRequest("userid", options->getUserId(), sqlRequest);
    }

    if(machineIdSize!=0) {
      //To check if the machine id is correct
      checkMachineId(options->getMachineId());

      if(!isListAll && userIdSize==0) {
         sqlRequest=sqlListofMachinesIntial;
      }
      addOptionRequest("machineid", options->getMachineId(), sqlRequest);
    }

 }
Exemple #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
   */
  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;

  }