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