コード例 #1
0
ファイル: OpenNebulaServer.cpp プロジェクト: SysFera/vishnu
/**
 * \brief Function to submit a job
 * \param scriptPath the path to the script containing the job characteristique
 * \param options the options to submit job
 * \param job The job data structure
 * \param envp The list of environment variables used by submission function
 * \return raises an exception on error
 */
int
OpenNebulaServer::submit(const std::string& scriptPath,
                         const TMS_Data::SubmitOptions& options,
                         TMS_Data::ListJobs& jobSteps,
                         char** envp)
{
  mjobId = vishnu::getVar("VISHNU_JOB_ID", false);
  mjobOutputDir = vishnu::getVar("VISHNU_OUTPUT_DIR", false);

  handleCloudInfo(options);
  setupJobDataDir(mjobId, scriptPath);

  replaceEnvVariables(scriptPath);
  OneRPCManager rpcManager(mcloudEndpoint);
  rpcManager.setMethod("one.vm.allocate");
  rpcManager.addParam(getSessionString());
  rpcManager.addParam(generateKvmTemplate(options));
  rpcManager.addParam(false);   // to create VM on pending state
  rpcManager.execute();

  if (! rpcManager.lastCallSucceeded()) {
    throw TMSVishnuException(ERRCODE_BATCH_SCHEDULER_ERROR, rpcManager.getStringResult());
  }

  TMS_Data::Job_ptr jobPtr = new TMS_Data::Job();

  OneCloudInstance oneCloud(mcloudEndpoint, getSessionString());
  VmT vmInfo;
  jobPtr->setVmId(vishnu::convertToString( rpcManager.getIntResult() ));
  if (oneCloud.loadVmInfo(vishnu::convertToInt(jobPtr->getVmId()), vmInfo) == 0) {
    jobPtr->setVmIp(vmInfo.ipAddr);
  }

  LOG(boost::str(boost::format("[INFO] Virtual machine created. ID: %1%, IP: %2%"
                               ) %  jobPtr->getVmId() % jobPtr->getVmIp()), LogInfo);

  //FIXME: job.setBatchJobId(vishnu::convertToString(jobPid));
  jobPtr->setStatus(vishnu::STATE_SUBMITTED);
  jobPtr->setName(returnInputOrDefaultIfEmpty(options.getName(), "PID_"+jobPtr->getBatchJobId()));

  jobPtr->setOutputPath(mbaseDataDir+"/stdout");
  jobPtr->setErrorPath(mbaseDataDir+"/stderr");
  jobPtr->setNbNodes(1);
  jobPtr->setLocalAccount(mvmUser);

  jobSteps.getJobs().push_back(jobPtr);
  return 0;
}
コード例 #2
0
ファイル: PosixServer.cpp プロジェクト: SysFera/vishnu
int
PosixServer::submit(const std::string& scriptPath,
                    const TMS_Data::SubmitOptions& options,
                    TMS_Data::ListJobs& jobSteps,
                    char** envp){
  int ret;
  struct trameJob resultat;
  struct trameSubmit op;
  std::string errorMsg;
  std::string strRet;

  memset(&op, 0, sizeof(op));
  strncpy(op.name, options.getName().c_str(), sizeof(op.name)-1);
  op.walltime = options.getWallTime();
  strncpy(op.outPutPath, options.getOutputPath().c_str(), sizeof(op.outPutPath)-1);
  strncpy(op.errorPath, options.getErrorPath().c_str(), sizeof(op.errorPath)-1);
  strncpy(op.workDir, options.getWorkingDir().c_str(), sizeof(op.workDir)-1);

  switch(fork()) {
  case -1:
    return -1;
  case 0:
    launchDaemon();
    exit(0);
    break;
  default:
    sleep(3); // TODO : fix, sleep because need synchronisation and can't wait child that has become a daemon
    break;
  }

  TMS_Data::Job_ptr jobPtr = new TMS_Data::Job();
  jobPtr->setStatus(vishnu::STATE_RUNNING);
  jobPtr->setQueue("posix");

  // If no name give a default job name
  if (options.getName().empty()){
    jobPtr->setName("posix_job");
  } else {
    jobPtr->setName(options.getName());
  }

  strncpy(op.jobName, jobPtr->getName().c_str(), sizeof(op.jobName)-1);

  ret = reqSubmit(scriptPath, &resultat, &op);

  if (ret == 0) {
    jobPtr->setOutputPath(std::string(resultat.outPutPath));
    jobPtr->setBatchJobId(std::string(resultat.jobId));

    jobPtr->setErrorPath(std::string(resultat.errorPath));
    jobPtr->setWallClockLimit(resultat.maxTime);

    jobSteps.getJobs().push_back(jobPtr);
  }
  else {
    strRet = boost::lexical_cast<std::string>(ret);
    errorMsg = "Error submiting job  error : "  + strRet + " ernno :" + std::string(strerror(errno));
    throw TMSVishnuException(ERRCODE_BATCH_SCHEDULER_ERROR, "POSIX ERROR: "+errorMsg);
  }
  return ret;
}