List of usage examples for org.apache.commons.cli Option setArgName
public void setArgName(String argName)
From source file:org.ow2.proactive.resourcemanager.utils.console.ResourceManagerController.java
public void load(String[] args) { Options options = new Options(); Option help = new Option("h", "help", false, "Display this help"); help.setRequired(false);/* www. j a v a2s. co m*/ options.addOption(help); Option username = new Option("l", "login", true, "The username to join the Resource Manager"); username.setArgName("login"); username.setArgs(1); username.setRequired(false); options.addOption(username); Option rmURL = new Option("u", "rmURL", true, "The Resource manager URL (default " + RM_DEFAULT_URL + ")"); rmURL.setArgName("rmURL"); rmURL.setArgs(1); rmURL.setRequired(false); options.addOption(rmURL); Option visual = new Option("g", "gui", false, "Start the console in a graphical view"); rmURL.setRequired(false); options.addOption(visual); addCommandLineOptions(options); boolean displayHelp = false; try { String pwdMsg = null; Parser parser = new GnuParser(); cmd = parser.parse(options, args); if (cmd.hasOption("h")) { displayHelp = true; } else { if (cmd.hasOption("environment")) { model.setInitEnv(cmd.getOptionValue("environment")); } String url; if (cmd.hasOption("u")) { url = cmd.getOptionValue("u"); } else { url = RM_DEFAULT_URL; } logger.info("Connecting to the RM on " + url); auth = RMConnection.join(url); logger.info("\t-> Connection established on " + url); if (cmd.hasOption("l")) { user = cmd.getOptionValue("l"); } if (cmd.hasOption("credentials")) { if (cmd.getOptionValues("credentials").length == 1) { System.setProperty(Credentials.credentialsPathProperty, cmd.getOptionValue("credentials")); } try { this.credentials = Credentials.getCredentials(); } catch (KeyException e) { logger.error("Could not retreive credentials... Try to adjust the System property: " + Credentials.credentialsPathProperty); throw e; } } else { ConsoleReader console = new ConsoleReader(System.in, new PrintWriter(System.out)); if (cmd.hasOption("l")) { pwdMsg = user + "'s password: "; } else { user = console.readLine("login: "); pwdMsg = "password: "; } //ask password to User try { console.setDefaultPrompt(pwdMsg); pwd = console.readLine('*'); } catch (IOException ioe) { logger.error("" + ioe); logger.debug("", ioe); } PublicKey pubKey = null; try { // first attempt at getting the pubkey : ask the RM RMAuthentication auth = RMConnection.join(url); pubKey = auth.getPublicKey(); logger.info("Retrieved public key from Resource Manager at " + url); } catch (Exception e) { try { // second attempt : try default location pubKey = Credentials.getPublicKey(Credentials.getPubKeyPath()); logger.info("Using public key at " + Credentials.getPubKeyPath()); } catch (Exception exc) { logger.error( "Could not find a public key. Contact the administrator of the Resource Manager."); logger.debug("", exc); System.exit(1); } } try { this.credentials = Credentials.createCredentials( new CredData(CredData.parseLogin(user), CredData.parseDomain(user), pwd), pubKey); } catch (KeyException e) { logger.error("Could not create credentials... " + e); throw e; } } //connect to the scheduler connect(); //connect JMX service connectJMXClient(); //start the command line or the interactive mode start(); } } catch (MissingArgumentException e) { logger.error(e.getLocalizedMessage()); logger.debug("", e); displayHelp = true; } catch (MissingOptionException e) { logger.error("Missing option: " + e.getLocalizedMessage()); logger.debug("", e); displayHelp = true; } catch (UnrecognizedOptionException e) { logger.error(e.getLocalizedMessage()); logger.debug("", e); displayHelp = true; } catch (AlreadySelectedException e) { logger.error(e.getClass().getSimpleName() + " : " + e.getLocalizedMessage()); logger.debug("", e); displayHelp = true; } catch (ParseException e) { logger.debug("", e); displayHelp = true; } catch (RMException e) { logger.error( "Error at connection : " + e.getMessage() + newline + "Shutdown the controller." + newline); logger.debug("", e); System.exit(2); } catch (LoginException e) { logger.error(e.getMessage() + newline + "Shutdown the controller." + newline); logger.debug("", e); System.exit(3); } catch (Exception e) { logger.error( "An error has occurred : " + e.getMessage() + newline + "Shutdown the controller." + newline, e); logger.debug("", e); System.exit(4); } if (displayHelp) { logger.info(""); HelpFormatter hf = new HelpFormatter(); hf.setWidth(160); String note = newline + "NOTE : if no " + control + " command is specified, the controller will start in interactive mode."; hf.printHelp(commandName + shellExtension(), "", options, note, true); System.exit(5); } // if execution reaches this point this means it must exit System.exit(0); }
From source file:org.ow2.proactive.resourcemanager.utils.console.ResourceManagerController.java
protected OptionGroup addCommandLineOptions(Options options) { OptionGroup actionGroup = new OptionGroup(); Option addNodesOpt = new Option("a", "addnodes", true, control + "Add nodes by their URLs"); addNodesOpt.setArgName("node URLs"); addNodesOpt.setRequired(false);//from www . j av a 2 s . com addNodesOpt.setArgs(Option.UNLIMITED_VALUES); actionGroup.addOption(addNodesOpt); Option removeNodesOpt = new Option("d", "removenodes", true, control + "Remove nodes by their URLs"); removeNodesOpt.setArgName("node URLs"); removeNodesOpt.setRequired(false); removeNodesOpt.setArgs(Option.UNLIMITED_VALUES); actionGroup.addOption(removeNodesOpt); Option lockNodesOpt = new Option("locknodes", true, control + "Lock nodes by their URLs"); lockNodesOpt.setArgName("node URLs"); lockNodesOpt.setRequired(false); lockNodesOpt.setArgs(Option.UNLIMITED_VALUES); actionGroup.addOption(lockNodesOpt); Option unlockNodesOpt = new Option("unlocknodes", true, control + "Unlock nodes by their URLs"); unlockNodesOpt.setArgName("node URLs"); unlockNodesOpt.setRequired(false); unlockNodesOpt.setArgs(Option.UNLIMITED_VALUES); actionGroup.addOption(unlockNodesOpt); Option createNSOpt = new Option("cn", "createns", true, control + "Create new node sources"); createNSOpt.setArgName("names"); createNSOpt.setRequired(false); createNSOpt.setArgs(Option.UNLIMITED_VALUES); actionGroup.addOption(createNSOpt); Option infrastuctureOpt = new Option("i", "infrastructure", true, "Specify an infrastructure when node source is created"); infrastuctureOpt.setArgName("params"); infrastuctureOpt.setRequired(false); infrastuctureOpt.setOptionalArg(true); infrastuctureOpt.setArgs(Option.UNLIMITED_VALUES); options.addOption(infrastuctureOpt); Option policyOpt = new Option("p", "policy", true, "Specify a policy when node source is created"); policyOpt.setArgName("params"); policyOpt.setOptionalArg(true); policyOpt.setRequired(false); policyOpt.setArgs(Option.UNLIMITED_VALUES); options.addOption(policyOpt); Option listNodesOpt = new Option("ln", "listnodes", true, control + "List nodes handled by Resource Manager. Display is : NODESOURCE HOSTNAME STATE NODE_URL"); listNodesOpt.setRequired(false); listNodesOpt.setOptionalArg(true); listNodesOpt.setArgName("nodeSourceName"); actionGroup.addOption(listNodesOpt); Option listNSOpt = new Option("lns", "listns", false, control + "List node sources on Resource Manager. Display is : NODESOURCE TYPE"); listNSOpt.setRequired(false); actionGroup.addOption(listNSOpt); Option topologyOpt = new Option("t", "topology", false, control + "Displays nodes topology."); topologyOpt.setRequired(false); actionGroup.addOption(topologyOpt); Option removeNSOpt = new Option("r", "removens", true, control + "Remove given node sources"); removeNSOpt.setArgName("names"); removeNSOpt.setRequired(false); removeNSOpt.setArgs(Option.UNLIMITED_VALUES); actionGroup.addOption(removeNSOpt); Option shutdownOpt = new Option("s", "shutdown", false, control + "Shutdown Resource Manager"); shutdownOpt.setRequired(false); actionGroup.addOption(shutdownOpt); Option acopt = new Option("stats", "statistics", false, control + "Display some statistics about the Resource Manager"); acopt.setRequired(false); acopt.setArgs(0); actionGroup.addOption(acopt); acopt = new Option("ma", "myaccount", false, control + "Display current user account informations"); acopt.setRequired(false); acopt.setArgs(0); actionGroup.addOption(acopt); acopt = new Option("ua", "useraccount", false, control + "Display account information by username"); acopt.setRequired(false); acopt.setArgs(1); acopt.setArgName("username"); actionGroup.addOption(acopt); acopt = new Option("ni", "nodeinfo", true, control + "Display node information"); acopt.setRequired(false); acopt.setArgs(1); acopt.setArgName("nodeURL"); actionGroup.addOption(acopt); acopt = new Option("rc", "reloadconfig", false, control + "Reloads the resource manager permission policy and log4j config"); acopt.setRequired(false); acopt.setArgs(0); actionGroup.addOption(acopt); options.addOptionGroup(actionGroup); Option nodeSourceNameOpt = new Option("ns", "nodesource", true, control + "Specify an existing node source name for adding nodes"); nodeSourceNameOpt.setArgName("nodes URLs"); nodeSourceNameOpt.setRequired(false); nodeSourceNameOpt.setArgs(1); options.addOption(nodeSourceNameOpt); Option preeemptiveRemovalOpt = new Option("f", "force", false, control + "Do not wait for busy nodes to be freed before " + "nodes removal, node source removal and shutdown actions (-d, -r and -s)"); preeemptiveRemovalOpt.setRequired(false); options.addOption(preeemptiveRemovalOpt); Option script = new Option("sf", "script", true, control + "Execute the given javascript file with optional arguments."); script.setArgName("filePath arg1=val1 arg2=val2 ..."); script.setArgs(Option.UNLIMITED_VALUES); script.setOptionalArg(true); script.setRequired(false); options.addOption(script); script = new Option("env", "environment", true, "Execute the given script and go into interactive mode"); script.setArgName("filePath"); script.setRequired(false); script.setOptionalArg(true); options.addOption(script); Option opt = new Option("c", "credentials", true, "Path to the credentials (" + Credentials.getCredentialsPath() + ")."); opt.setRequired(false); opt.setArgs(1); options.addOption(opt); return actionGroup; }
From source file:org.ow2.proactive.resourcemanager.utils.PAAgentServiceRMStarter.java
/** * Fills the command line options.//from w w w.j ava 2s.c o m * @param options the options to fill */ public static void fillOptions(final Options options) { // The path to the file that contains the credential final Option credentialFile = new Option("f", "credentialFile", true, "path to file that contains the credential"); credentialFile.setRequired(false); credentialFile.setArgName("path"); options.addOption(credentialFile); // The credential passed as environment variable final Option credentialEnv = new Option("e", "credentialEnv", true, "name of the environment variable that contains the credential"); credentialEnv.setRequired(false); credentialEnv.setArgName("name"); options.addOption(credentialEnv); // The credential passed as value final Option credVal = new Option("v", "credentialVal", true, "explicit value of the credential"); credVal.setRequired(false); credVal.setArgName("credential"); options.addOption(credVal); // The url of the resource manager final Option rmURL = new Option("r", "rmURL", true, "URL of the resource manager"); rmURL.setRequired(false); rmURL.setArgName("url"); options.addOption(rmURL); // The node name final Option nodeName = new Option("n", "nodeName", true, "node name (default is " + PAAGENT_DEFAULT_NODE_NAME + ")"); nodeName.setRequired(false); nodeName.setArgName("name"); options.addOption(nodeName); // The node source name final Option sourceName = new Option("s", "sourceName", true, "node source name"); sourceName.setRequired(false); sourceName.setArgName("name"); options.addOption(sourceName); // The wait on join timeout in millis final Option waitOnJoinTimeout = new Option("w", "waitOnJoinTimeout", true, "wait on join the resource manager timeout in millis (default is " + WAIT_ON_JOIN_TIMEOUT_IN_MS + ")"); waitOnJoinTimeout.setRequired(false); waitOnJoinTimeout.setArgName("millis"); options.addOption(waitOnJoinTimeout); // The ping delay in millis final Option pingDelay = new Option("p", "pingDelay", true, "ping delay in millis used by RMPinger thread that calls System.exit(1) if the resource manager is down (default is " + PING_DELAY_IN_MS + ")"); pingDelay.setRequired(false); pingDelay.setArgName("millis"); options.addOption(pingDelay); // The number of attempts option final Option addNodeAttempts = new Option("a", "addNodeAttempts", true, "number of attempts to add the local node to the resource manager before quitting (default is " + NB_OF_ADD_NODE_ATTEMPTS + ")"); addNodeAttempts.setRequired(false); addNodeAttempts.setArgName("number"); options.addOption(addNodeAttempts); // The delay between attempts option final Option addNodeAttemptsDelay = new Option("d", "addNodeAttemptsDelay", true, "delay in millis between attempts to add the local node to the resource manager (default is " + ADD_NODE_ATTEMPTS_DELAY_IN_MS + ")"); addNodeAttemptsDelay.setRequired(false); addNodeAttemptsDelay.setArgName("millis"); options.addOption(addNodeAttemptsDelay); // Displays the help final Option help = new Option("h", "help", false, "to display this help"); help.setRequired(false); options.addOption(help); }
From source file:org.ow2.proactive.resourcemanager.utils.RMNodeStarter.java
/** * Fills the command line options./*from ww w . ja va2s.c om*/ * @param options the options to fill */ protected void fillOptions(final Options options) { // The path to the file that contains the credential final Option credentialFile = new Option(Character.toString(OPTION_CREDENTIAL_FILE), "credentialFile", true, "path to file that contains the credential"); credentialFile.setRequired(false); credentialFile.setArgName("path"); options.addOption(credentialFile); // The credential passed as environment variable final Option credentialEnv = new Option(Character.toString(OPTION_CREDENTIAL_ENV), "credentialEnv", true, "name of the environment variable that contains the credential"); credentialEnv.setRequired(false); credentialEnv.setArgName("name"); options.addOption(credentialEnv); // The credential passed as value final Option credVal = new Option(Character.toString(OPTION_CREDENTIAL_VAL), "credentialVal", true, "explicit value of the credential"); credVal.setRequired(false); credVal.setArgName("credential"); options.addOption(credVal); // The url of the resource manager final Option rmURL = new Option(Character.toString(OPTION_RM_URL), "rmURL", true, "URL of the resource manager. If no URL is provided, the node won't register."); rmURL.setRequired(false); rmURL.setArgName("url"); options.addOption(rmURL); // The node name final Option nodeName = new Option(Character.toString(OPTION_NODE_NAME), "nodeName", true, "node name (default is hostname_pid)"); nodeName.setRequired(false); nodeName.setArgName("name"); options.addOption(nodeName); // The node source name final Option sourceName = new Option(Character.toString(OPTION_SOURCE_NAME), "sourceName", true, "node source name"); sourceName.setRequired(false); sourceName.setArgName("name"); options.addOption(sourceName); // The wait on join timeout in millis final Option waitOnJoinTimeout = new Option(OPTION_WAIT_AND_JOIN_TIMEOUT, "waitOnJoinTimeout", true, "wait on join the resource manager timeout in millis (default is " + WAIT_ON_JOIN_TIMEOUT_IN_MS + ")"); waitOnJoinTimeout.setRequired(false); waitOnJoinTimeout.setArgName("millis"); options.addOption(waitOnJoinTimeout); // The ping delay in millis final Option pingDelay = new Option(Character.toString(OPTION_PING_DELAY), "pingDelay", true, "ping delay in millis used by RMPinger thread that calls System.exit(1) if the resource manager is down (default is " + PING_DELAY_IN_MS + "). A null or negative frequency means no ping at all."); pingDelay.setRequired(false); pingDelay.setArgName("millis"); options.addOption(pingDelay); // The number of attempts option final Option addNodeAttempts = new Option(Character.toString(OPTION_ADD_NODE_ATTEMPTS), "addNodeAttempts", true, "number of attempts to add the node(s) to the resource manager. Default is " + NB_OF_ADD_NODE_ATTEMPTS + "). When 0 is specified node(s) remains alive without " + "trying to add itself to the RM. Otherwise the process is terminated when number " + "of attempts exceeded."); addNodeAttempts.setRequired(false); addNodeAttempts.setArgName("number"); options.addOption(addNodeAttempts); // The delay between attempts option final Option addNodeAttemptsDelay = new Option(Character.toString(OPTION_ADD_NODE_ATTEMPTS_DELAY), "addNodeAttemptsDelay", true, "delay in millis between attempts to add the node(s) to the resource manager (default is " + ADD_NODE_ATTEMPTS_DELAY_IN_MS + ")"); addNodeAttemptsDelay.setRequired(false); addNodeAttemptsDelay.setArgName("millis"); options.addOption(addNodeAttemptsDelay); // The discovery port final Option discoveryPort = new Option(OPTION_DISCOVERY_PORT, "discoveryPort", true, "port to use for RM discovery (default is " + this.discoveryPort + ")"); discoveryPort.setRequired(false); options.addOption(discoveryPort); // The discovery timeout final Option discoveryTimeout = new Option(OPTION_DISCOVERY_TIMEOUT, "discoveryTimeout", true, "timeout to use for RM discovery (default is " + discoveryTimeoutInMs + "ms)"); discoveryTimeout.setRequired(false); options.addOption(discoveryTimeout); // The number of workers final Option workers = new Option(OPTION_WORKERS, "workers", true, "Number of workers, i.e number of tasks that can be executed in parallel on this node (default is 1). If no value specified, number of cores."); workers.setRequired(false); workers.setOptionalArg(true); options.addOption(workers); final Option availabilityReportTimeout = new Option(OPTION_AVAILABILITY_REPORT_TIMEOUT, "availabilityReportTimeout", true, "The maximum time to wait in milliseconds for retrieving the answer for the node availability report that is pushed periodically."); availabilityReportTimeout.setRequired(false); availabilityReportTimeout.setArgName("timeInMilliseconds"); options.addOption(availabilityReportTimeout); // Displays the help final Option help = new Option(Character.toString(OPTION_HELP), "help", false, "to display this help"); help.setRequired(false); options.addOption(help); // Disable monitoring final Option monitorOption = new Option(OPTION_DISABLE_MONITORING, "disableMonitoring", false, "to disable JMX node monitoring functionality"); monitorOption.setRequired(false); options.addOption(monitorOption); }
From source file:org.ow2.proactive.resourcemanager.utils.RMStarter.java
private static void initOptions() { Option help = new Option("h", "help", false, "to display this help"); help.setArgName("help"); help.setRequired(false);/*from www . j a va 2 s. c om*/ options.addOption(help); Option noDeploy = new Option("ln", "localNodes", false, "start the resource manager deploying default 4 local nodes"); noDeploy.setArgName("localNodes"); noDeploy.setRequired(false); options.addOption(noDeploy); Option nodeTimeout = new Option("t", "timeout", true, "Timeout used to start the nodes (only useful with local nodes, default: " + DEFAULT_NODE_TIMEOUT + "ms)"); nodeTimeout.setArgName("timeout"); nodeTimeout.setRequired(false); options.addOption(nodeTimeout); }
From source file:org.ow2.proactive.resourcemanager.utils.VIRMNodeStarter.java
/** * Fills the command line options./*from w w w . ja v a 2 s . c om*/ * @param options the options to fill */ protected void fillOptions(final Options options) { // The name of the holding virtual machine final Option vmName = new Option(new Character(OPTION_TEMPLATE_NAME).toString(), "holdingVMName", true, "The name of the virtual machine within which one this RMNode is to be started."); vmName.setRequired(true); vmName.setArgName("name"); options.addOption(vmName); super.fillOptions(options); }
From source file:org.ow2.proactive.scheduler.authentication.ManageUsers.java
/** * Build the command line options and parse */// w ww . j a v a 2 s.c o m private static CommandLine getCommandLine(String[] args, String loginFilePath, String groupFilePath, Options options) throws ManageUsersException { Option opt = new Option(HELP_OPTION, HELP_OPTION_NAME, false, "Display this help"); opt.setRequired(false); options.addOption(opt); OptionGroup optionGroup = new OptionGroup(); optionGroup.setRequired(false); opt = new Option(CREATE_OPTION, CREATE_OPTION_NAME, true, "Action to create a user"); opt.setArgName(CREATE_OPTION_NAME.toUpperCase()); opt.setArgs(0); opt.setRequired(false); optionGroup.addOption(opt); opt = new Option(UPDATE_OPTION, UPDATE_OPTION_NAME, true, "Action to update an existing user. Updating a user means to change the user's password or group membership."); opt.setArgName(UPDATE_OPTION_NAME.toUpperCase()); opt.setArgs(0); opt.setRequired(false); optionGroup.addOption(opt); opt = new Option(DELETE_OPTION, DELETE_OPTION_NAME, true, "Action to delete an existing user"); opt.setArgName(DELETE_OPTION_NAME.toUpperCase()); opt.setArgs(0); opt.setRequired(false); optionGroup.addOption(opt); options.addOptionGroup(optionGroup); opt = new Option(LOGIN_OPTION, LOGIN_OPTION_NAME, true, "Generate credentials for this specific user, will be asked interactively if not specified"); opt.setArgName(LOGIN_OPTION_NAME.toUpperCase()); opt.setArgs(1); opt.setRequired(false); options.addOption(opt); opt = new Option(PWD_OPTION, PWD_OPTION_NAME, true, "Password of the user, if the user is created or updated, will be asked interactively if not specified"); opt.setArgName(PWD_OPTION_NAME.toUpperCase()); opt.setArgs(1); opt.setRequired(false); options.addOption(opt); opt = new Option(GROUPS_OPTION, GROUPS_OPTION_NAME, true, "A comma-separated list of groups the user must be member of. Can be used when the user is created or updated"); opt.setArgName(GROUPS_OPTION_NAME.toUpperCase()); opt.setArgs(1); opt.setRequired(false); options.addOption(opt); optionGroup.setRequired(false); opt = new Option(KEYFILE_OPTION, KEYFILE_OPTION_NAME, true, "Public key path on the local filesystem [default:" + getPublicKeyFilePath() + "]"); opt.setArgName(KEYFILE_OPTION_NAME.toUpperCase()); opt.setArgs(1); opt.setRequired(false); options.addOption(opt); opt = new Option(LOGINFILE_OPTION, LOGINFILE_OPTION_NAME, true, "Path to the login file in use [default:" + loginFilePath + "]"); opt.setArgName(LOGINFILE_OPTION_NAME.toUpperCase()); opt.setArgs(1); opt.setRequired(false); options.addOption(opt); opt = new Option(GROUPFILE_OPTION, GROUPFILE_OPTION_NAME, true, "Path to the group file in use [default:" + groupFilePath + "]"); opt.setArgName(GROUPFILE_OPTION_NAME.toUpperCase()); opt.setArgs(1); opt.setRequired(false); options.addOption(opt); opt = new Option(SOURCE_LOGINFILE_OPTION, SOURCE_LOGINFILE_OPTION_NAME, true, "Path to a source login file, used for bulk creation or bulk update. The source login file must contain clear text passwords in the format username:password"); opt.setArgName(SOURCE_LOGINFILE_OPTION_NAME.toUpperCase()); opt.setArgs(1); opt.setRequired(false); options.addOption(opt); opt = new Option(SOURCE_GROUPFILE_OPTION, SOURCE_GROUPFILE_OPTION_NAME, true, "Path to a source group file, used for bulk creation or bulk update. The source group file must contain group assignements in the format username:group"); opt.setArgName(SOURCE_GROUPFILE_OPTION_NAME.toUpperCase()); opt.setArgs(1); opt.setRequired(false); options.addOption(opt); CommandLineParser parser = new DefaultParser(); CommandLine cmd = null; try { cmd = parser.parse(options, args); } catch (Exception e) { exitWithErrorMessage(newline + e.getMessage() + newline, "type -h or --help to display help screen", null); } return cmd; }
From source file:org.ow2.proactive.scheduler.util.console.SchedulerController.java
public void load(String[] args) { Options options = new Options(); Option help = new Option("h", "help", false, "Display this help"); help.setRequired(false);// w w w. java2 s . c o m options.addOption(help); Option username = new Option("l", "login", true, "The username to join the Scheduler"); username.setArgName("login"); username.setArgs(1); username.setRequired(false); options.addOption(username); Option schedulerURL = new Option("u", "url", true, "The scheduler URL (default " + SCHEDULER_DEFAULT_URL + ")"); schedulerURL.setArgName("schedulerURL"); schedulerURL.setRequired(false); options.addOption(schedulerURL); Option keyfile = new Option("k", "key", true, "(Optional) The path to a private SSH key"); keyfile.setArgName("sshkeyFilePath"); keyfile.setArgs(1); keyfile.setRequired(false); options.addOption(keyfile); addCommandLineOptions(options); boolean displayHelp = false; try { String pwdMsg = null; Parser parser = new GnuParser(); cmd = parser.parse(options, args); if (cmd.hasOption("help")) { displayHelp = true; } else { if (cmd.hasOption("env")) { model.setInitEnv(cmd.getOptionValue("env")); } String url; if (cmd.hasOption("url")) { url = cmd.getOptionValue("url"); } else { url = SCHEDULER_DEFAULT_URL; } logger.info("Trying to connect Scheduler on " + url); auth = SchedulerConnection.join(url); logger.info("\t-> Connection established on " + url); logger.info(newline + "Connecting client to the Scheduler"); if (cmd.hasOption("login")) { user = cmd.getOptionValue("login"); } if (cmd.hasOption("credentials")) { if (cmd.getOptionValue("credentials") != null) { System.setProperty(Credentials.credentialsPathProperty, cmd.getOptionValue("credentials")); } try { this.credentials = Credentials.getCredentials(); } catch (KeyException e) { logger.error("Could not retreive credentials... Try to adjust the System property: " + Credentials.credentialsPathProperty + " or use the -c option."); throw e; } } else { ConsoleReader console = new ConsoleReader(System.in, new PrintWriter(System.out)); if (cmd.hasOption("login")) { pwdMsg = user + "'s password: "; } else { user = console.readLine("login: "); pwdMsg = "password: "; } //ask password to User try { console.setDefaultPrompt(pwdMsg); pwd = console.readLine('*'); } catch (IOException ioe) { logger.error("" + ioe); logger.debug("", ioe); } PublicKey pubKey = null; try { // first attempt at getting the pubkey : ask the scheduler SchedulerAuthenticationInterface auth = SchedulerConnection.join(url); pubKey = auth.getPublicKey(); logger.info("Retrieved public key from Scheduler at " + url); } catch (Exception e) { try { // second attempt : try default location pubKey = Credentials.getPublicKey(Credentials.getPubKeyPath()); logger.info("Using public key at " + Credentials.getPubKeyPath()); } catch (Exception exc) { logger.error( "Could not find a public key. Contact the administrator of the Scheduler."); logger.debug("", exc); System.exit(7); } } try { if (cmd.hasOption("key")) { byte[] keyfileContent = FileToBytesConverter .convertFileToByteArray(new File(cmd.getOptionValue("key"))); this.credentials = Credentials.createCredentials(new CredData(CredData.parseLogin(user), CredData.parseDomain(user), pwd, keyfileContent), pubKey); } else { this.credentials = Credentials.createCredentials( new CredData(CredData.parseLogin(user), CredData.parseDomain(user), pwd), pubKey); } } catch (FileNotFoundException fnfe) { logger.error("SSH keyfile not found : '" + cmd.getOptionValue("key") + "'"); logger.debug("", fnfe); System.exit(8); } catch (Exception e) { logger.error("Could not create credentials... " + e); throw e; } } //connect to the scheduler connect(); //connect JMX service connectJMXClient(); //start the command line or the interactive mode start(); } } catch (MissingArgumentException e) { logger.error(e.getLocalizedMessage()); logger.debug("", e); displayHelp = true; } catch (MissingOptionException e) { logger.error("Missing option: " + e.getLocalizedMessage()); logger.debug("", e); displayHelp = true; } catch (UnrecognizedOptionException e) { logger.error(e.getLocalizedMessage()); logger.debug("", e); displayHelp = true; } catch (AlreadySelectedException e) { logger.error(e.getClass().getSimpleName() + " : " + e.getLocalizedMessage()); logger.debug("", e); displayHelp = true; } catch (ParseException e) { displayHelp = true; } catch (LoginException e) { logger.error(getMessages(e) + "Shutdown the controller." + newline); logger.debug("", e); System.exit(3); } catch (SchedulerException e) { logger.error(getMessages(e) + "Shutdown the controller." + newline); logger.debug("", e); System.exit(4); } catch (Exception e) { logger.error(getMessages(e) + "Shutdown the controller." + newline, e); logger.debug("", e); System.exit(5); } if (displayHelp) { logger.info(""); HelpFormatter hf = new HelpFormatter(); hf.setWidth(135); String note = newline + "NOTE : if no " + control + "command is specified, the controller will start in interactive mode."; hf.printHelp(getCommandName() + Tools.shellExtension(), "", options, note, true); System.exit(6); } // if execution reaches this point this means it must exit System.exit(0); }
From source file:org.ow2.proactive.scheduler.util.console.SchedulerController.java
protected OptionGroup addCommandLineOptions(Options options) { OptionGroup actionGroup = new OptionGroup(); Option opt = new Option("s", "submit", true, control + "Submit the given job XML file"); opt.setArgName("XMLDescriptor"); opt.setRequired(false);//from ww w. j av a 2s. co m opt.setArgs(Option.UNLIMITED_VALUES); actionGroup.addOption(opt); opt = new Option("sa", "submitarchive", true, control + "Submit the given job archive"); opt.setArgName("jobarchive"); opt.setRequired(false); opt.setArgs(1); actionGroup.addOption(opt); opt = new Option("cmd", "command", false, control + "If mentionned, -submit argument becomes a command line, ie: -submit command args..."); opt.setRequired(false); options.addOption(opt); opt = new Option("cmdf", "commandf", false, control + "If mentionned, -submit argument becomes a text file path containing command lines to schedule"); opt.setRequired(false); options.addOption(opt); opt = new Option("ss", "selectscript", true, control + "Used with -cmd or -cmdf, specify a selection script"); opt.setArgName("selectScript"); opt.setRequired(false); opt.setArgs(1); options.addOption(opt); opt = new Option("jn", "jobname", true, control + "Used with -cmd or -cmdf, specify the job name"); opt.setArgName("jobName"); opt.setRequired(false); opt.setArgs(1); options.addOption(opt); opt = new Option("pj", "pausejob", true, control + "Pause the given job (pause every non-running tasks)"); opt.setArgName("jobId"); opt.setRequired(false); opt.setArgs(1); actionGroup.addOption(opt); opt = new Option("rj", "resumejob", true, control + "Resume the given job (restart every paused tasks)"); opt.setArgName("jobId"); opt.setRequired(false); opt.setArgs(1); actionGroup.addOption(opt); opt = new Option("kj", "killjob", true, control + "Kill the given job (cause the job to finish)"); opt.setArgName("jobId"); opt.setRequired(false); opt.setArgs(1); actionGroup.addOption(opt); opt = new Option("rmj", "removejob", true, control + "Remove the given job"); opt.setArgName("jobId"); opt.setRequired(false); opt.setArgs(1); actionGroup.addOption(opt); opt = new Option("pt", "preempttask", true, control + "Stop the given task and re-schedules it after specified delay."); opt.setArgName("jobId taskName delay"); opt.setRequired(false); opt.setArgs(3); actionGroup.addOption(opt); opt = new Option("rt", "restarttask", true, control + "Terminate the given task and re-schedules it after specified delay."); opt.setArgName("jobId taskName delay"); opt.setRequired(false); opt.setArgs(3); actionGroup.addOption(opt); opt = new Option("kt", "killtask", true, control + "Kill the given task."); opt.setArgName("jobId taskName"); opt.setRequired(false); opt.setArgs(2); actionGroup.addOption(opt); opt = new Option("jr", "jobresult", true, control + "Get the result of the given job"); opt.setArgName("jobId"); opt.setRequired(false); opt.setArgs(1); actionGroup.addOption(opt); opt = new Option("tr", "taskresult", true, control + "Get the result of the given task"); opt.setArgName("jobId taskName [inc]"); opt.setRequired(false); opt.setArgs(3); opt.setOptionalArg(true); actionGroup.addOption(opt); opt = new Option("jo", "joboutput", true, control + "Get the output of the given job"); opt.setArgName("jobId"); opt.setRequired(false); opt.setArgs(2); actionGroup.addOption(opt); opt = new Option("to", "taskoutput", true, control + "Get the output of the given task"); opt.setArgName("jobId taskName"); opt.setRequired(false); opt.setArgs(2); actionGroup.addOption(opt); opt = new Option("jp", "jobpriority", true, control + "Change the priority of the given job (Idle, Lowest, Low, Normal, High, Highest)"); opt.setArgName("jobId newPriority"); opt.setRequired(false); opt.setArgs(2); actionGroup.addOption(opt); opt = new Option("js", "jobstate", true, control + "Get the current state of the given job (Also tasks description)"); opt.setArgName("jobId"); opt.setRequired(false); opt.setArgs(2); actionGroup.addOption(opt); opt = new Option("lj", "listjobs", false, control + "Display the list of jobs managed by the scheduler"); opt.setRequired(false); opt.setArgs(0); actionGroup.addOption(opt); opt = new Option("stats", "statistics", false, control + "Display some statistics about the Scheduler"); opt.setRequired(false); opt.setArgs(0); actionGroup.addOption(opt); opt = new Option("ma", "myaccount", false, control + "Display current user account information"); opt.setRequired(false); opt.setArgs(0); actionGroup.addOption(opt); opt = new Option("ua", "useraccount", false, control + "Display account information by username"); opt.setRequired(false); opt.setArgs(1); opt.setArgName("username"); actionGroup.addOption(opt); opt = new Option("rc", "reloadconfig", false, control + "Reloads the scheduler permission policy and log4j config"); opt.setRequired(false); opt.setArgs(0); actionGroup.addOption(opt); opt = new Option("sf", "script", true, control + "Execute the given javascript file with optional arguments."); opt.setArgName("filePath arg1=val1 arg2=val2 ..."); opt.setRequired(false); opt.setArgs(Option.UNLIMITED_VALUES); opt.setOptionalArg(true); actionGroup.addOption(opt); opt = new Option("env", "environment", true, "Execute the given script as an environment for the interactive mode"); opt.setArgName("filePath"); opt.setRequired(false); opt.setArgs(1); actionGroup.addOption(opt); opt = new Option("test", false, control + "Test if the Scheduler is successfully started by committing some examples"); opt.setRequired(false); opt.setArgs(0); actionGroup.addOption(opt); opt = new Option("c", "credentials", true, "Path to the credentials (" + Credentials.getCredentialsPath() + ")."); opt.setRequired(false); opt.setOptionalArg(true); options.addOption(opt); options.addOptionGroup(actionGroup); opt = new Option("start", "schedulerstart", false, control + "Start the Scheduler"); opt.setRequired(false); actionGroup.addOption(opt); opt = new Option("stop", "schedulerstop", false, control + "Stop the Scheduler"); opt.setRequired(false); actionGroup.addOption(opt); opt = new Option("pause", "schedulerpause", false, control + "Pause the Scheduler (cause all non-running jobs to be paused)"); opt.setRequired(false); actionGroup.addOption(opt); opt = new Option("freeze", "schedulerfreeze", false, control + "Freeze the Scheduler (cause all non-running tasks to be paused)"); opt.setRequired(false); actionGroup.addOption(opt); opt = new Option("resume", "schedulerresume", false, control + "Resume the Scheduler"); opt.setRequired(false); actionGroup.addOption(opt); opt = new Option("shutdown", "schedulershutdown", false, control + "Shutdown the Scheduler"); opt.setRequired(false); actionGroup.addOption(opt); opt = new Option("kill", "schedulerkill", false, control + "Kill the Scheduler"); opt.setRequired(false); actionGroup.addOption(opt); opt = new Option("lrm", "linkrm", true, control + "Reconnect a RM to the scheduler"); opt.setArgName("rmURL"); opt.setRequired(false); opt.setArgs(1); actionGroup.addOption(opt); opt = new Option("pr", "policyreload", false, control + "Reload the policy configuration"); opt.setRequired(false); actionGroup.addOption(opt); opt = new Option("p", "policy", true, control + "Change the current scheduling policy"); opt.setArgName("fullName"); opt.setRequired(false); opt.setArgs(1); actionGroup.addOption(opt); opt = new Option("ll", "logs", true, control + "Get server logs of given job or task"); opt.setArgName("jobId [taskName]"); opt.setRequired(false); opt.setArgs(2); actionGroup.addOption(opt); options.addOptionGroup(actionGroup); return actionGroup; }
From source file:org.ow2.proactive.scheduler.util.SchedulerStarter.java
private static Options getOptions() { Options options = new Options(); Option help = new Option("h", "help", false, "to display this help"); help.setArgName("help"); help.setRequired(false);// w w w . j av a 2s. c o m options.addOption(help); Option rmURL = new Option("u", "rmURL", true, "the resource manager URL (default: localhost)"); rmURL.setArgName("rmURL"); rmURL.setRequired(false); options.addOption(rmURL); Option policy = new Option("p", "policy", true, "the complete name of the scheduling policy to use (default: org.ow2.proactive.scheduler.policy.DefaultPolicy)"); policy.setArgName("policy"); policy.setRequired(false); options.addOption(policy); Option noDeploy = new Option("ln", "localNodes", true, "the number of local nodes to start (can be 0; default: " + RMStarter.DEFAULT_NODES_NUMBER + ")"); noDeploy.setArgName("localNodes"); noDeploy.setRequired(false); options.addOption(noDeploy); Option nodeTimeout = new Option("t", "timeout", true, "timeout used to start the nodes (only useful with local nodes; default: " + DEFAULT_NODES_TIMEOUT + "ms)"); nodeTimeout.setArgName("timeout"); nodeTimeout.setRequired(false); options.addOption(nodeTimeout); options.addOption( new Option("c", "clean", false, "clean scheduler and resource manager databases (default: false)")); options.addOption(Option.builder().longOpt("clean-nodesources") .desc("drop all previously created nodesources from resource manager database (default: false)") .build()); options.addOption(Option.builder().longOpt("rm-only") .desc("start only resource manager (implies --no-rest; default: false)").build()); options.addOption(Option.builder().longOpt("no-rest") .desc("do not deploy REST server and wars from dist/war (default: false)").build()); options.addOption( Option.builder().longOpt("no-router").desc("do not deploy PAMR Router (default: false)").build()); options.addOption(Option.builder().longOpt("no-discovery") .desc("do not run discovery service for nodes (default: false)").build()); options.addOption(Option.builder("dp").longOpt("discovery-port") .desc("discovery service port for nodes (default: " + DISCOVERY_DEFAULT_PORT + ")").hasArg() .argName("port").build()); return options; }