예제 #1
0
파일: api_tms.cpp 프로젝트: Ecapo/vishnu
/**
 * \brief The getJobProgress function gets the progression status of jobs
 * \param sessionKey : The session key
 * \param machineId : Is the id of the machine to get the jobs progression.
 * \param listOfProgress : Is the object containing jobs progression information
 * \param options : Is an object containing the available options jobs for progression .
 * \return int : an error code
 */
int
vishnu::getJobProgress(const std::string& sessionKey,
		const std::string& machineId,
		ListProgression& listOfProgress,
		const ProgressOptions& options)
throw (UMSVishnuException, TMSVishnuException, UserException, SystemException) {

	checkEmptyString(sessionKey, "The session key");
	checkEmptyString(machineId, "The machine id");

	std::string serviceName = "getJobsProgression_";
	serviceName.append(machineId);

	SessionProxy sessionProxy(sessionKey);

	QueryProxy<TMS_Data::ProgressOptions, TMS_Data::ListProgression>
	query(options, sessionProxy, serviceName, machineId);

	TMS_Data::ListProgression* listProgression_ptr = query.list();

	if(listProgression_ptr != NULL) {
		TMS_Data::TMS_DataFactory_ptr ecoreFactory = TMS_Data::TMS_DataFactory::_instance();
		for(unsigned int i = 0; i < listProgression_ptr->getProgress().size(); i++) {
			TMS_Data::Progression_ptr progression = ecoreFactory->createProgression();
			//To copy the content and not the pointer
			*progression = *listProgression_ptr->getProgress().get(i);
			listOfProgress.getProgress().push_back(progression);
		}
		listOfProgress.setNbJobs(listProgression_ptr->getProgress().size());
		delete listProgression_ptr;
	}
	return 0;
}
예제 #2
0
파일: api_tms.cpp 프로젝트: SysFera/vishnu
/**
 * \brief getJobProgress: function gets the progression status of jobs
 * \param sessionKey: The session key
 * \param listOfProgress: The object containing jobs progression information
 * \param options: The object containing the available options jobs for progression .
 * \return int: an error code
 */
int
vishnu::getJobProgress(const std::string& sessionKey,
                       TMS_Data::ListProgression& listOfProgress,
                       const TMS_Data::ProgressOptions& options)
throw (UMSVishnuException, TMSVishnuException, UserException, SystemException) {

  checkEmptyString(sessionKey, "The session key");

  std::string machineId = options.getMachineId();
  UMS_Data::ListMachines machines;
  if (! machineId.empty() && machineId != ALL_KEYWORD) {
    // Use the specified machine
    UMS_Data::Machine_ptr machine = new UMS_Data::Machine();
    machine->setMachineId(machineId);
    machines.getMachines().push_back(machine);
  } else {
    listMachinesWithUserLocalAccount(sessionKey, machines);
  }

  // Now perform the request
  listOfProgress.setNbJobs(0);
  for(int i=0; i< machines.getMachines().size(); i++) {

    UMS_Data::Machine_ptr machine = machines.getMachines().get(i);
    std::string serviceName = (boost::format("%1%@%2%") % SERVICES_TMS[GETJOBSPROGRESSION] % machine->getMachineId()).str();

    SessionProxy sessionProxy(sessionKey);
    QueryProxy<TMS_Data::ProgressOptions, TMS_Data::ListProgression>
        query(options, sessionProxy, serviceName, machine->getMachineId());

    TMS_Data::ListProgression* listProgression_ptr = NULL ;
    try {
      listProgression_ptr = query.list();
    } catch(...) {
      // Means that the machine is not active or the user doesn't have a local account on it
      if(machineId != ALL_KEYWORD) {
        throw ;
      } else {
        continue ;
      }
    }

    if (listProgression_ptr != NULL) {
      TMS_Data::TMS_DataFactory_ptr ecoreFactory = TMS_Data::TMS_DataFactory::_instance();
      for(unsigned int i = 0; i < listProgression_ptr->getProgress().size(); i++) {
        TMS_Data::Progression_ptr progression = ecoreFactory->createProgression();
        //To copy the content and not the pointer
        *progression = *listProgression_ptr->getProgress().get(i);
        listOfProgress.getProgress().push_back(progression);
      }
      listOfProgress.setNbJobs(listOfProgress.getNbJobs()+listProgression_ptr->getProgress().size());
      delete listProgression_ptr;
    }
  }

  return 0;
}
예제 #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;

  }