Exemple #1
0
  /**
     * \brief To parse command line options
     * \param opt the description of the command line options
     * \param isEmpty To check if command line does not contain option
     * \param ac The number of command line arguments
     * \param av The command line arguments
     * \param signature The signature of the command
     */
  void
  processListOpt(const boost::shared_ptr<Options>& opt,
                 bool& isEmpty,
                 int ac, char*  av[],
                 const std::string& signature = "")
  {
    CLICmd cmd = CLICmd(ac, av, opt);

    try {
      opt->parse_cli(ac, av);

      isEmpty = opt->empty(); //if no value was given in the command line
      int rc = cmd.parse(env_name_mapper());

      if (rc != 0) {
        helpUsage(*opt, signature);
        exit(rc);
      }

      // PreProcess (adapt some parameters if necessary)
      checkVishnuConfig(*opt);
      if (opt->count("help")) {
        helpUsage(*opt, signature);
        exit(0);
      }
    } catch(const po::error&) { // catch all other bad parameter errors
      helpUsage(*opt, signature);
      exit(ERRCODE_INVALID_PARAM);
    } catch(const std::exception& ex) {// catch all std runtime error
      errorUsage(av[0],ex.what());
      exit(ERRCODE_INVALID_PARAM);
    }
  }
Exemple #2
0
int main (int ac, char* av[]){


  /******* Parsed value containers ****************/

  string dietConfig;

  /********** EMF data ************/

  UMS_Data::AuthAccount authAccount;
  
  /******** Callback functions ******************/

  StringcallBackType fAuthSystemId( boost::bind(&UMS_Data::AuthAccount::setAuthSystemId,boost::ref(authAccount),_1));
  
  StringcallBackType fUserId( boost::bind(&UMS_Data::AuthAccount::setUserId,boost::ref(authAccount),_1));
  
  StringcallBackType fAcLogin( boost::bind(&UMS_Data::AuthAccount::setAcLogin,boost::ref(authAccount),_1));
 


  /**************** Describe options *************/

boost::shared_ptr<Options> opt= makeAuthAccountOptions(av[0],dietConfig, fAuthSystemId,fUserId,fAcLogin);

CLICmd cmd = CLICmd (ac, av, opt);

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

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

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

  UpdateAuthenticationAccountFunc apiFunc(authAccount);
  return GenericCli().run(apiFunc, dietConfig, ac, av);

}// end of main
int main (int ac, char* av[]){



  /******* Parsed value containers ****************/

  string dietConfig;

  /********** EMF data ************/

  UMS_Data::LocalAccount upAcLogin;
  /******** Callback functions ******************/

  boost::function1<void,string> fUserId( boost::bind(&UMS_Data::LocalAccount::setUserId,boost::ref(upAcLogin),_1));
  boost::function1<void,string> fMachineId( boost::bind(&UMS_Data::LocalAccount::setMachineId,boost::ref(upAcLogin),_1));
  boost::function1<void,string> fAcLogin( boost::bind(&UMS_Data::LocalAccount::setAcLogin,boost::ref(upAcLogin),_1));
  boost::function1<void,string> fSshKeyPath( boost::bind(&UMS_Data::LocalAccount::setSshKeyPath,boost::ref(upAcLogin),_1));
  boost::function1<void,string> fHomeDirectory( boost::bind(&UMS_Data::LocalAccount::setHomeDirectory,boost::ref(upAcLogin),_1));

  /**************** Describe options *************/

  boost::shared_ptr<Options> opt=makeLocalAccountOptions(av[0], fUserId,dietConfig,fMachineId,
                                                         fAcLogin,fSshKeyPath,fHomeDirectory);

  CLICmd cmd = CLICmd (ac, av, opt);
  
  int ret = cmd.parse(env_name_mapper());

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

  // PreProcess (adapt some parameters if necessary)
  checkVishnuConfig(*opt);
  if ( opt->count("help")){
    helpUsage(*opt,"userId machineId");
    return 0;
  }
 
  UpdateLocalAccountFunc apiFunc(upAcLogin);
  return GenericCli().run(apiFunc, dietConfig, ac, av);

}// end of main
Exemple #4
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;
}