Esempio n. 1
0
int
main (int argc, char* argv[]) {
  /******* Parsed value containers ****************/
  std::string configFile;
  std::string sessionKey;
  std::string stateStr = "";
  int state;
  std::string fromDate;
  std::string toDate;

  int retCode = 0;
  /********** EMF data ************/
  TMS_Data::ListJobsOptions jobOp;

  /******** Callback functions ******************/
  boost::function1<void,string> setMachineIdFct(boost::bind(&TMS_Data::ListJobsOptions::setMachineId,boost::ref(jobOp),_1));
  boost::function1<void,string> setJobIdFct(boost::bind(&TMS_Data::ListJobsOptions::setJobId,boost::ref(jobOp),_1));
  boost::function1<void,int> setNbCpuFct(boost::bind(&TMS_Data::ListJobsOptions::setNbCpu,boost::ref(jobOp),_1));
  boost::function1<void,string> setOwnerFct(boost::bind(&TMS_Data::ListJobsOptions::setOwner,boost::ref(jobOp),_1));
  boost::function1<void,TMS_Data::JobPriority> setPriorityFct(boost::bind(&TMS_Data::ListJobsOptions::setPriority,boost::ref(jobOp),_1));
  boost::function1<void,string> setQueueFct(boost::bind(&TMS_Data::ListJobsOptions::setQueue,boost::ref(jobOp),_1));
  boost::function1<void,string> setMultipleStatusesFct(boost::bind(&TMS_Data::ListJobsOptions::setMultipleStatus,boost::ref(jobOp),_1));
  boost::function1<void,long long> setWorkIdFct(boost::bind(&TMS_Data::ListJobsOptions::setWorkId,boost::ref(jobOp),_1));

  /*********** Out parameters *********************/
  TMS_Data::ListJobs jobs;

  /**************** Describe options *************/
  boost::shared_ptr<Options> opt = makeListJobOp(argv[0],
                                                 setMachineIdFct,
                                                 setJobIdFct,
                                                 setNbCpuFct,
                                                 fromDate,
                                                 toDate,
                                                 setOwnerFct,
                                                 stateStr,
                                                 setPriorityFct,
                                                 setQueueFct,
                                                 setMultipleStatusesFct,
                                                 setWorkIdFct,
                                                 sessionKey,
                                                 configFile);

  opt->add("isListAll,l",
           "allows to list all information",
           CONFIG);

  // pre-process options
  bool isEmpty;
  GenericCli().processListOpt(opt, isEmpty, argc, argv);

  // Process command
  try {
    if (stateStr.size()!=0) {
      size_t pos = stateStr.find_first_not_of("0123456789");
      if (pos!=std::string::npos) {
        if (stateStr.size() == 1) {
          switch(stateStr[0]) {
          case 'S' :
            state = vishnu::STATE_SUBMITTED;
            break;
          case 'Q' :
            state = vishnu::STATE_QUEUED;
            break;
          case 'W' :
            state = vishnu::STATE_WAITING;
            break;
          case 'R' :
            state = vishnu::STATE_RUNNING;
            break;
          case 'T' :
            state = vishnu::STATE_COMPLETED;
            break;
          case 'C' :
            state = vishnu::STATE_CANCELLED;
            break;
          case 'D' :
            state = vishnu::STATE_DOWNLOADED;
            break;
          case 'F' :
            state = vishnu::STATE_FAILED;
            break;
          default:
            state = vishnu::STATE_UNDEFINED;
            break;
          }
        }
        if (stateStr.size() > 1 || state < 0) {
          std::cerr <<  (boost::format("Unknown job state: %1%")%stateStr).str();
          return CLI_ERROR_INVALID_PARAMETER;
        }
      } else {
        state = convertToInt(stateStr);
      }
      jobOp.setStatus(state);
    }
    //convert the date in long format
    if (opt->count("fromSubmitDate")) {
      jobOp.setFromSubmitDate(string_to_time_t(fromDate));
    }

    if (opt->count("toSubmitDate")) {
      jobOp.setToSubmitDate(string_to_time_t(toDate));
    }

    if (opt->count("isListAll")) {
      jobOp.setListAll(true);
    }

    if (vishnuInitialize(const_cast<char*>(configFile.c_str()), argc, argv)) {
      errorUsage(argv[0],communicationErrorMsg,EXECERROR);
      return  CLI_ERROR_COMMUNICATION ;
    }

    // Process list job
    // get the sessionKey
    if(sessionKey.empty()){
      sessionKey=getLastSessionKey(getppid());
    }

    // vishnu call: submit
    if(! sessionKey.empty()){
      listJobs(sessionKey, jobs, jobOp);
    }

    if (jobOp.getJobId().empty()
        && jobOp.getNbCpu() <= 0
        && jobOp.getFromSubmitDate() <= 0
        && jobOp.getToSubmitDate() <= 0
        && !jobOp.isListAll())
    {
      std::cout << jobs << "\n";
    } else {
      displayListJobs(jobs);
    }
  } catch(VishnuException& e) {// catch all Vishnu runtime error
    std::string  msg = e.getMsg();
    if (e.getMsgComp().compare("Bus initialization failure")==0){
      msg += " ["+e.getMsgComp()+", machineId may be invalid]";
    } else {
      msg += " ["+e.getMsgComp()+"]";
    }
    errorUsage(argv[0], msg,EXECERROR);
    //check the bad session key
    if (checkBadSessionKeyError(e)) {
      removeBadSessionKeyFromFile(getppid());
    }
    retCode = e.getMsgI();
  } catch(std::exception& e) {// catch all std runtime error
    errorUsage(argv[0],e.what());
    retCode = CLI_ERROR_RUNTIME;
  }
  return retCode;
}
Esempio n. 2
0
int main (int argc, char* argv[]){

	int ret; // Return value

	/******* Parsed value containers ****************/
	string dietConfig;
	string sessionKey;
	string machineId;
	string statusStr = "";
	int status;
	std::string fromDate;
	std::string toDate;

	/********** EMF data ************/
	TMS_Data::ListJobsOptions jobOp;

	/******** Callback functions ******************/
	boost::function1<void,string> fjid(boost::bind(&TMS_Data::ListJobsOptions::setJobId,boost::ref(jobOp),_1));
	boost::function1<void,int> fnbCpu(boost::bind(&TMS_Data::ListJobsOptions::setNbCpu,boost::ref(jobOp),_1));
	boost::function1<void,string> fown(boost::bind(&TMS_Data::ListJobsOptions::setOwner,boost::ref(jobOp),_1));
	boost::function1<void,JobPriority> fpriority(boost::bind(&TMS_Data::ListJobsOptions::setPriority,boost::ref(jobOp),_1));
	boost::function1<void,string> fqueue(boost::bind(&TMS_Data::ListJobsOptions::setQueue,boost::ref(jobOp),_1));
	boost::function1<void,string> fmutlStatus(boost::bind(&TMS_Data::ListJobsOptions::setMultipleStatus,boost::ref(jobOp),_1));
	boost::function1<void,long long> fworkId(boost::bind(&TMS_Data::ListJobsOptions::setWorkId,boost::ref(jobOp),_1));
	/*********** Out parameters *********************/
	TMS_Data::ListJobs job;

	/**************** Describe options *************/
	boost::shared_ptr<Options> opt=makeListJobOp(argv[0],
			fjid,
			fnbCpu,
			fromDate,
			toDate,
			fown,
			statusStr,
			fpriority,
			fqueue,
			fmutlStatus,
			fworkId,
			dietConfig);

	opt->add("isBatchJob,b",
			"allows to select all jobs submitted  through the underlying"
			" batch scheduler (jobs submitted through vishnu and out of vishnu)",
			CONFIG);

  opt->add("isListAll,l",
      "allows to list all information",
      CONFIG);

	opt->add("machineId,m",
			"represents the id of the machine",
			HIDDEN,
			machineId,1);
	opt->setPosition("machineId",1);

	CLICmd cmd = CLICmd (argc, argv, opt);

	// Process command
	try {

		// Parse the cli and setting the options found
		ret = cmd.parse(env_name_mapper());

		if (ret != CLI_SUCCESS){
			helpUsage(*opt,"[options] machineId");
			return ret;
		}

		// PreProcess (adapt some parameters if necessary)
		checkVishnuConfig(*opt);
		if ( opt->count("help")){
			helpUsage(*opt,"[options] machineId");
			return 0;
		}

		if(statusStr.size()!=0) {
			size_t pos = statusStr.find_first_not_of("0123456789");
			if(pos!=std::string::npos) {
				if(statusStr.size()==1) {
					switch(statusStr[0]) {
					case 'S' :
						status = 1;
						break;
					case 'Q' :
						status = 2;
						break;
					case 'W' :
						status = 3;
						break;
					case 'R' :
						status = 4;
						break;
					case 'T' :
						status = 5;
						break;
					case 'C' :
						status = 6;
						break;
					case 'D' :
						status = 7;
						break;
					default:
						status = -1;
						break;
					}
				}
				if ((statusStr.size() > 1) || (status == -1)) {
					std::cerr << "Unknown job status " << statusStr << std::endl;
					return 0;
				}
			} else {
				status = convertToInt(statusStr);
			}
			jobOp.setStatus(status);
		}
		//convert the date in long format
		if(opt->count("fromSubmitDate")){
			jobOp.setFromSubmitDate(convertLocaltimeINUTCtime(string_to_time_t(fromDate)));
		}

		if(opt->count("toSubmitDate")){
			jobOp.setToSubmitDate(convertLocaltimeINUTCtime(string_to_time_t(toDate)));
		}

		if(opt->count("isBatchJob")) {
			jobOp.setBatchJob(true);
		}

    if (opt->count("isListAll")) {
      jobOp.setListAll(true);
    }

		// initializing DIET
		if (vishnuInitialize(const_cast<char*>(dietConfig.c_str()), argc, argv)) {
			errorUsage(argv[0],dietErrorMsg,EXECERROR);
			return  CLI_ERROR_DIET ;
		}

		// get the sessionKey
		sessionKey=getLastSessionKey(getppid());

		// DIET call : submit
		if(false==sessionKey.empty()){
			printSessionKeyMessage();
			listJobs(sessionKey, machineId, job, jobOp);
		}

		if(jobOp.getOwner().size()==0 && jobOp.getJobId().size()==0  && jobOp.getNbCpu() <= 0
				&& jobOp.getFromSubmitDate() <= 0 && jobOp.getToSubmitDate() <= 0 && !jobOp.isListAll()) {
			std::cout << job << std::endl;
		} else {
			displayListJobs(job);
		}
		printSuccessMessage();
	} catch(VishnuException& e){// catch all Vishnu runtime error
		std::string  msg = e.getMsg()+" ["+e.getMsgComp()+"]";
		errorUsage(argv[0], msg,EXECERROR);
		//check the bad session key
		if (checkBadSessionKeyError(e)){
			removeBadSessionKeyFromFile(getppid());
		}
		return e.getMsgI() ;
	} catch(std::exception& e){// catch all std runtime error
		errorUsage(argv[0],e.what());
		return CLI_ERROR_RUNTIME;
	}
	return 0;
}