Exemplo n.º 1
0
/**
 * \brief The listJobs function gets a list of all submitted jobs
 * \param sessionKey : The session key
 * \param listOfJobs : The constructed object list of jobs
 * \param options : Additional options for jobs listing
 * \return int : an error code
 */
int
vishnu::listJobs(const std::string& sessionKey,
                 TMS_Data::ListJobs& listOfJobs,
                 const TMS_Data::ListJobsOptions& options)
throw (UMSVishnuException, TMSVishnuException, UserException, SystemException) {

  checkEmptyString(sessionKey, "The session key");

  UMS_Data::Machine_ptr machine = new UMS_Data::Machine();
  const std::string machineId = ALL_KEYWORD;

  // Here the list of machine should contain only a single machine
  machine->setMachineId(machineId);

  listOfJobs.setNbJobs(0);
  listOfJobs.setNbRunningJobs(0);
  listOfJobs.setNbWaitingJobs(0);


  std::string serviceName = (boost::format("%1%") % SERVICES_TMS[GETLISTOFJOBS_ALL]).str();
  SessionProxy sessionProxy(sessionKey);

  checkJobStatus(options.getStatus()); // check the job status options
  checkJobPriority(options.getPriority()); //check the job priority options

  QueryProxy<TMS_Data::ListJobsOptions, TMS_Data::ListJobs>
      query(options, sessionProxy, serviceName, machine->getMachineId());
  TMS_Data::ListJobs* listJobs_ptr = NULL;
  try {
    listJobs_ptr = query.list();
  } catch(...) {
    throw ;
  }
  if (listJobs_ptr != NULL) {

    TMS_Data::TMS_DataFactory_ptr ecoreFactory = TMS_Data::TMS_DataFactory::_instance();
    for (unsigned int j = 0; j < listJobs_ptr->getJobs().size(); j++) {
      TMS_Data::Job_ptr job = ecoreFactory->createJob();
      //copy the content and not the pointer
      *job = *listJobs_ptr->getJobs().get(j);
      listOfJobs.getJobs().push_back(job);
    }
    listOfJobs.setNbJobs(listOfJobs.getNbJobs()+listJobs_ptr->getJobs().size());
    listOfJobs.setNbRunningJobs(listOfJobs.getNbRunningJobs()+listJobs_ptr->getNbRunningJobs());
    listOfJobs.setNbWaitingJobs(listOfJobs.getNbWaitingJobs()+listJobs_ptr->getNbWaitingJobs());
    delete listJobs_ptr;
  }
  return 0;
}
Exemplo n.º 2
0
/**
 * \brief The listJobs function gets a list of all submitted jobs
 * \param sessionKey : The session key
 * \param machineId : The id of the machine
 * \param listOfJobs : The constructed object list of jobs
 * \param options : Additional options for jobs listing
 * \return int : an error code
 */
int
vishnu::listJobs(const std::string& sessionKey,
		const std::string& machineId,
		ListJobs& listOfJobs,
		const ListJobsOptions& options)
throw (UMSVishnuException, TMSVishnuException, UserException, SystemException) {

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

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

	SessionProxy sessionProxy(sessionKey);

	//To check the job status options
	checkJobStatus(options.getStatus());
	//To check the job priority options
	checkJobPriority(options.getPriority());

	QueryProxy<TMS_Data::ListJobsOptions, TMS_Data::ListJobs>
	query(options, sessionProxy, serviceName, machineId);

	TMS_Data::ListJobs* listJobs_ptr = query.list();

	if(listJobs_ptr != NULL) {
		TMS_Data::TMS_DataFactory_ptr ecoreFactory = TMS_Data::TMS_DataFactory::_instance();
		for(unsigned int i = 0; i < listJobs_ptr->getJobs().size(); i++) {
			TMS_Data::Job_ptr job = ecoreFactory->createJob();
			//To copy the content and not the pointer
			*job = *listJobs_ptr->getJobs().get(i);
			listOfJobs.getJobs().push_back(job);
		}
		listOfJobs.setNbJobs(listJobs_ptr->getJobs().size());
		listOfJobs.setNbRunningJobs(listJobs_ptr->getNbRunningJobs());
		listOfJobs.setNbWaitingJobs(listJobs_ptr->getNbWaitingJobs());
		delete listJobs_ptr;
	}
	return 0;
}