示例#1
0
文件: api_tms.cpp 项目: Ecapo/vishnu
/**
 * \brief The getCompletedJobsOutput() function gets standard output and error output files
 * of completed jobs (applies only once for each job)
 * \param sessionKey : The session key
 * \param machineId : The id of the machine
 * \param listOfResults : Is the list of jobs results
 * \param outDir : The output directory where the files will be stored (default is current directory)
 * \return int : an error code
 */
int
vishnu::getCompletedJobsOutput(const std::string& sessionKey,
		const std::string& machineId,
		ListJobResults& listOfResults,
		const std::string& outDir)
throw (UMSVishnuException, TMSVishnuException, UserException, SystemException) {

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

	if((outDir.size()!=0)&&(!boost::filesystem::exists(outDir))) {
		throw UMSVishnuException(ERRCODE_INVALID_PARAM, "The directory "+outDir+" does not exist");
	}

	SessionProxy sessionProxy(sessionKey);
	JobOutputProxy jobOutputProxy(sessionProxy, machineId, outDir);

	TMS_Data::ListJobResults_ptr listJobResults_ptr = jobOutputProxy.getCompletedJobsOutput();

	if(listJobResults_ptr != NULL) {
		TMS_Data::TMS_DataFactory_ptr ecoreFactory = TMS_Data::TMS_DataFactory::_instance();
		for(unsigned int i = 0; i < listJobResults_ptr->getResults().size(); i++) {
			TMS_Data::JobResult_ptr jobResult = ecoreFactory->createJobResult();
			//To copy the content and not the pointer
			*jobResult = *listJobResults_ptr->getResults().get(i);
			listOfResults.getResults().push_back(jobResult);
		}
		listOfResults.setNbJobs(listJobResults_ptr->getNbJobs());
		delete listJobResults_ptr;
	}
	return 0;
}
示例#2
0
/**
 * \brief Gets standard output files of all completed jobs (applies only once for each job)
 * \param sessionKey : The session key
 * \param options: object containing options
 * \param listOfResults : Is the list of jobs results
   * \param options: Object containing options
 * \return int : an error code
 */
int
vishnu::getCompletedJobsOutput(const std::string& sessionKey,
                               TMS_Data::ListJobResults& listOfResults,
                               const TMS_Data::JobOutputOptions& options)
throw (UMSVishnuException, TMSVishnuException, UserException, SystemException) {

  checkEmptyString(sessionKey, "The session key");

  std::string outputDir = options.getOutputDir();
  if (! outputDir.empty() && ! boost::filesystem::exists(outputDir)) {
    throw UMSVishnuException(ERRCODE_INVALID_PARAM, "The ouput directory does not exist: "+outputDir);
  }

  UMS_Data::ListMachines machines;
  if (options.getMachineId().empty()) {
    vishnu::listMachinesWithUserLocalAccount(sessionKey, machines);
  } else {
    UMS_Data::Machine_ptr machine = new UMS_Data::Machine(); // delete by EMF
    machine->setMachineId(options.getMachineId());
    machines.getMachines().push_back(machine);
  }

  int machineCount = machines.getMachines().size();
  for (int index = 0; index < machineCount; ++index) {
    SessionProxy sessionProxy(sessionKey);
    JobOutputProxy jobOutputProxy(sessionProxy, machines.getMachines().get(index)->getMachineId());

    TMS_Data::ListJobResults_ptr listJobResults_ptr = jobOutputProxy.getCompletedJobsOutput(options);

    if (listJobResults_ptr != NULL) {
      TMS_Data::TMS_DataFactory_ptr ecoreFactory = TMS_Data::TMS_DataFactory::_instance();
      for(unsigned int i = 0; i < listJobResults_ptr->getResults().size(); i++) {
        TMS_Data::JobResult_ptr jobResult = ecoreFactory->createJobResult();
        //To copy the content and not the pointer
        *jobResult = *listJobResults_ptr->getResults().get(i);
        listOfResults.getResults().push_back(jobResult);
      }
      listOfResults.setNbJobs(listJobResults_ptr->getNbJobs());
      delete listJobResults_ptr;
    }
  }
  return 0;
}