List of usage examples for org.apache.commons.cli MissingOptionException getMessage
public String getMessage()
From source file:eu.stratosphere.client.CliFrontend.java
/** * Executions the run action./*from w w w. j a v a2 s. com*/ * * @param args Command line arguments for the run action. */ protected int run(String[] args) { // Parse command line options CommandLine line; try { line = parser.parse(RUN_OPTIONS, args, false); evaluateGeneralOptions(line); } catch (MissingOptionException e) { System.out.println(e.getMessage()); printHelpForRun(); return 1; } catch (UnrecognizedOptionException e) { System.out.println(e.getMessage()); printHelpForRun(); return 2; } catch (Exception e) { return handleError(e); } // ------------ check for help first -------------- if (printHelp) { printHelpForRun(); return 0; } try { PackagedProgram program = buildProgram(line); if (program == null) { printHelpForRun(); return 1; } Client client = getClient(line); if (client == null) { printHelpForRun(); return 1; } int parallelism = -1; if (line.hasOption(PARALLELISM_OPTION.getOpt())) { String parString = line.getOptionValue(PARALLELISM_OPTION.getOpt()); try { parallelism = Integer.parseInt(parString); } catch (NumberFormatException e) { System.out.println("The value " + parString + " is invalid for the degree of parallelism."); printHelpForRun(); return 1; } if (parallelism <= 0) { System.out.println( "Invalid value for the degree-of-parallelism. Parallelism must be greater than zero."); printHelpForRun(); return 1; } } return executeProgram(program, client, parallelism); } catch (Throwable t) { return handleError(t); } }
From source file:eu.stratosphere.client.CliFrontend.java
/** * Executes the cancel action./*ww w . j a v a 2 s.c o m*/ * * @param args Command line arguments for the cancel action. */ protected int cancel(String[] args) { // Parse command line options CommandLine line; try { line = parser.parse(CANCEL_OPTIONS, args, false); } catch (MissingOptionException e) { System.out.println(e.getMessage()); printHelpForCancel(); return 1; } catch (UnrecognizedOptionException e) { System.out.println(e.getMessage()); printHelpForCancel(); return 2; } catch (Exception e) { return handleError(e); } if (printHelp) { printHelpForCancel(); return 0; } JobID jobId; if (line.hasOption(ID_OPTION.getOpt())) { String jobIdString = line.getOptionValue(ID_OPTION.getOpt()); try { jobId = new JobID(StringUtils.hexStringToByte(jobIdString)); } catch (Exception e) { System.out.println("Error: The value for the Job ID is not a valid ID."); printHelpForCancel(); return 1; } } else { System.out.println("Error: Specify a Job ID to cancel a job."); printHelpForCancel(); return 1; } ExtendedManagementProtocol jmConn = null; try { jmConn = getJobManagerConnection(line); if (jmConn == null) { printHelpForCancel(); return 1; } jmConn.cancelJob(jobId); return 0; } catch (Throwable t) { return handleError(t); } finally { if (jmConn != null) { try { RPC.stopProxy(jmConn); } catch (Throwable t) { System.out.println("Warning: Could not cleanly shut down connection to the JobManager."); } } jmConn = null; } }
From source file:eu.stratosphere.client.CliFrontend.java
/** * Executes the info action.//from w w w . j a va 2 s . com * * @param args Command line arguments for the info action. */ protected int info(String[] args) { // Parse command line options CommandLine line; try { line = parser.parse(INFO_OPTIONS, args, false); evaluateGeneralOptions(line); } catch (MissingOptionException e) { System.out.println(e.getMessage()); printHelpForInfo(); return 1; } catch (UnrecognizedOptionException e) { System.out.println(e.getMessage()); printHelpForInfo(); return 2; } catch (Exception e) { return handleError(e); } if (printHelp) { printHelpForInfo(); return 0; } boolean description = line.hasOption(DESCR_OPTION.getOpt()); boolean plan = line.hasOption(PLAN_OPTION.getOpt()); if (!description && !plan) { System.out.println("ERROR: Specify the information to display."); printHelpForInfo(); return 1; } // -------- build the packaged program ------------- PackagedProgram program; try { program = buildProgram(line); } catch (Throwable t) { return handleError(t); } if (program == null) { printHelpForInfo(); return 1; } int parallelism = -1; if (line.hasOption(PARALLELISM_OPTION.getOpt())) { String parString = line.getOptionValue(PARALLELISM_OPTION.getOpt()); try { parallelism = Integer.parseInt(parString); } catch (NumberFormatException e) { System.out.println("The value " + parString + " is invalid for the degree of parallelism."); printHelpForRun(); return 1; } if (parallelism <= 0) { System.out.println( "Invalid value for the degree-of-parallelism. Parallelism must be greater than zero."); printHelpForRun(); return 1; } } try { // check for description request if (description) { String descr = program.getDescription(); if (descr != null) { System.out.println("-------------------- Program Description ---------------------"); System.out.println(descr); System.out.println("--------------------------------------------------------------"); } else { System.out.println("No description available for this program."); } } // check for json plan request if (plan) { Client client = getClient(line); String jsonPlan = client.getOptimizedPlanAsJson(program, parallelism); if (jsonPlan != null) { System.out.println("----------------------- Execution Plan -----------------------"); System.out.println(jsonPlan); System.out.println("--------------------------------------------------------------"); } else { System.out.println("JSON plan could not be compiled."); } } return 0; } catch (Throwable t) { return handleError(t); } finally { program.deleteExtractedLibraries(); } }
From source file:eu.stratosphere.client.CliFrontend.java
/** * Executes the list action.//ww w .jav a2 s .c om * * @param args Command line arguments for the list action. */ protected int list(String[] args) { // Parse command line options CommandLine line; try { line = parser.parse(LIST_OPTIONS, args, false); } catch (MissingOptionException e) { System.out.println(e.getMessage()); printHelpForList(); return 1; } catch (UnrecognizedOptionException e) { System.out.println(e.getMessage()); printHelpForList(); return 2; } catch (Exception e) { return handleError(e); } if (printHelp) { printHelpForList(); return 0; } // get list options boolean running = line.hasOption(RUNNING_OPTION.getOpt()); boolean scheduled = line.hasOption(SCHEDULED_OPTION.getOpt()); if (!running && !scheduled) { System.out.println("Error: Specify the status of the jobs to list."); printHelpForList(); return 1; } ExtendedManagementProtocol jmConn = null; try { jmConn = getJobManagerConnection(line); if (jmConn == null) { printHelpForList(); return 1; } List<RecentJobEvent> recentJobs = jmConn.getRecentJobs(); ArrayList<RecentJobEvent> runningJobs = null; ArrayList<RecentJobEvent> scheduledJobs = null; if (running) { runningJobs = new ArrayList<RecentJobEvent>(); } if (scheduled) { scheduledJobs = new ArrayList<RecentJobEvent>(); } for (RecentJobEvent rje : recentJobs) { if (running && rje.getJobStatus().equals(JobStatus.RUNNING)) { runningJobs.add(rje); } if (scheduled && rje.getJobStatus().equals(JobStatus.SCHEDULED)) { scheduledJobs.add(rje); } } SimpleDateFormat df = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss"); Comparator<RecentJobEvent> njec = new Comparator<RecentJobEvent>() { @Override public int compare(RecentJobEvent o1, RecentJobEvent o2) { return (int) (o1.getTimestamp() - o2.getTimestamp()); } }; if (running) { if (runningJobs.size() == 0) { System.out.println("No running jobs."); } else { Collections.sort(runningJobs, njec); System.out.println("------------------------ Running Jobs ------------------------"); for (RecentJobEvent je : runningJobs) { System.out.println(df.format(new Date(je.getTimestamp())) + " : " + je.getJobID().toString() + " : " + je.getJobName()); } System.out.println("--------------------------------------------------------------"); } } if (scheduled) { if (scheduledJobs.size() == 0) { System.out.println("No scheduled jobs."); } else { Collections.sort(scheduledJobs, njec); System.out.println("----------------------- Scheduled Jobs -----------------------"); for (RecentJobEvent je : scheduledJobs) { System.out.println(df.format(new Date(je.getTimestamp())) + " : " + je.getJobID().toString() + " : " + je.getJobName()); } System.out.println("--------------------------------------------------------------"); } } return 0; } catch (Throwable t) { return handleError(t); } finally { if (jmConn != null) { try { RPC.stopProxy(jmConn); } catch (Throwable t) { System.out.println("Could not cleanly shut down connection from compiler to job manager"); } } jmConn = null; } }
From source file:org.apache.directory.server.tools.BaseCommand.java
public CommandLine getCommandLine(String command, String[] args) { Options all = allOptions(command);/*from ww w . j a v a2 s . c o m*/ CommandLineParser parser = new PosixParser(); CommandLine cmdline = null; try { cmdline = parser.parse(all, args); } catch (AlreadySelectedException ase) { System.err.println("Command line parsing failed for " + command + ". Reason: already selected " + ase.getMessage()); System.exit(1); } catch (MissingArgumentException mae) { System.err.println("Command line parsing failed for " + command + ". Reason: missing argument " + mae.getMessage()); System.exit(1); } catch (MissingOptionException moe) { System.err.println( "Command line parsing failed for " + command + ". Reason: missing option " + moe.getMessage()); System.exit(1); } catch (UnrecognizedOptionException uoe) { System.err.println("Command line parsing failed for " + command + ". Reason: unrecognized option" + uoe.getMessage()); System.exit(1); } catch (ParseException pe) { System.err.println("Command line parsing failed for " + command + ". Reason: " + pe.getClass()); System.exit(1); } return cmdline; }
From source file:org.apache.felix.ipojo.task.IPojoc.java
/** * The main entry point/*from w w w . j a va 2s . c o m*/ * @param args the arguments */ public static void main(String[] args) { Options options = buildOptions(); CommandLine cmd = null; try { cmd = buildCommandLine(args, options); if (cmd.hasOption('h')) { printHelp(options); } else { IPojoc compiler = new IPojoc(); compiler.execute(cmd); } } catch (MissingOptionException e) { for (String opt : (List<String>) e.getMissingOptions()) { System.err.println("The '" + opt + "' option is missing"); } printHelp(options); } catch (MissingArgumentException e) { System.err.println("The option '" + e.getOption() + "' requires an argument"); printHelp(options); } catch (Exception e) { System.out.printf("Manipulation failed: %s%n", e.getMessage()); if ((cmd != null) && cmd.hasOption('X')) { e.printStackTrace(System.out); } else { System.out.printf("Use -X option to print the full stack trace%n"); } } }
From source file:org.apache.flink.yarn.Client.java
public void run(String[] args) throws Exception { if (UserGroupInformation.isSecurityEnabled()) { throw new RuntimeException("Flink YARN client does not have security support right now." + "File a bug, we will fix it asap"); }/* w ww . j ava 2 s .c om*/ //Utils.logFilesInCurrentDirectory(LOG); // // Command Line Options // Options options = new Options(); options.addOption(VERBOSE); options.addOption(FLINK_CONF_DIR); options.addOption(FLINK_JAR); options.addOption(JM_MEMORY); options.addOption(TM_MEMORY); options.addOption(TM_CORES); options.addOption(CONTAINER); options.addOption(GEN_CONF); options.addOption(QUEUE); options.addOption(QUERY); options.addOption(SHIP_PATH); options.addOption(SLOTS); options.addOption(DYNAMIC_PROPERTIES); CommandLineParser parser = new PosixParser(); CommandLine cmd = null; try { cmd = parser.parse(options, args); } catch (MissingOptionException moe) { System.out.println(moe.getMessage()); printUsage(); System.exit(1); } // Jar Path Path localJarPath; if (cmd.hasOption(FLINK_JAR.getOpt())) { String userPath = cmd.getOptionValue(FLINK_JAR.getOpt()); if (!userPath.startsWith("file://")) { userPath = "file://" + userPath; } localJarPath = new Path(userPath); } else { localJarPath = new Path( "file://" + Client.class.getProtectionDomain().getCodeSource().getLocation().getPath()); } if (cmd.hasOption(GEN_CONF.getOpt())) { LOG.info("Placing default configuration in current directory"); File outFile = generateDefaultConf(localJarPath); LOG.info("File written to " + outFile.getAbsolutePath()); System.exit(0); } // Conf Path Path confPath = null; String confDirPath = ""; if (cmd.hasOption(FLINK_CONF_DIR.getOpt())) { confDirPath = cmd.getOptionValue(FLINK_CONF_DIR.getOpt()) + "/"; File confFile = new File(confDirPath + CONFIG_FILE_NAME); if (!confFile.exists()) { LOG.error("Unable to locate configuration file in " + confFile); System.exit(1); } confPath = new Path(confFile.getAbsolutePath()); } else { System.out.println("No configuration file has been specified"); // no configuration path given. // -> see if there is one in the current directory File currDir = new File("."); File[] candidates = currDir.listFiles(new FilenameFilter() { @Override public boolean accept(final File dir, final String name) { return name != null && name.endsWith(".yaml"); } }); if (candidates == null || candidates.length == 0) { System.out.println( "No configuration file has been found in current directory.\n" + "Copying default."); File outFile = generateDefaultConf(localJarPath); confPath = new Path(outFile.toURI()); } else { if (candidates.length > 1) { System.out.println("Multiple .yaml configuration files were found in the current directory\n" + "Please specify one explicitly"); System.exit(1); } else if (candidates.length == 1) { confPath = new Path(candidates[0].toURI()); } } } List<File> shipFiles = new ArrayList<File>(); // path to directory to ship if (cmd.hasOption(SHIP_PATH.getOpt())) { String shipPath = cmd.getOptionValue(SHIP_PATH.getOpt()); File shipDir = new File(shipPath); if (shipDir.isDirectory()) { shipFiles = new ArrayList<File>(Arrays.asList(shipDir.listFiles(new FilenameFilter() { @Override public boolean accept(File dir, String name) { return !(name.equals(".") || name.equals("..")); } }))); } else { LOG.warn("Ship directory is not a directory!"); } } boolean hasLogback = false; boolean hasLog4j = false; //check if there is a logback or log4j file if (confDirPath.length() > 0) { File logback = new File(confDirPath + "/logback.xml"); if (logback.exists()) { shipFiles.add(logback); hasLogback = true; } File log4j = new File(confDirPath + "/log4j.properties"); if (log4j.exists()) { shipFiles.add(log4j); hasLog4j = true; } } // queue String queue = "default"; if (cmd.hasOption(QUEUE.getOpt())) { queue = cmd.getOptionValue(QUEUE.getOpt()); } // JobManager Memory int jmMemory = 512; if (cmd.hasOption(JM_MEMORY.getOpt())) { jmMemory = Integer.valueOf(cmd.getOptionValue(JM_MEMORY.getOpt())); } if (jmMemory < MIN_JM_MEMORY) { System.out.println("The JobManager memory is below the minimum required memory amount " + "of " + MIN_JM_MEMORY + " MB"); System.exit(1); } // Task Managers memory int tmMemory = 1024; if (cmd.hasOption(TM_MEMORY.getOpt())) { tmMemory = Integer.valueOf(cmd.getOptionValue(TM_MEMORY.getOpt())); } if (tmMemory < MIN_TM_MEMORY) { System.out.println("The TaskManager memory is below the minimum required memory amount " + "of " + MIN_TM_MEMORY + " MB"); System.exit(1); } if (cmd.hasOption(SLOTS.getOpt())) { slots = Integer.valueOf(cmd.getOptionValue(SLOTS.getOpt())); } String[] dynamicProperties = null; if (cmd.hasOption(DYNAMIC_PROPERTIES.getOpt())) { dynamicProperties = cmd.getOptionValues(DYNAMIC_PROPERTIES.getOpt()); } String dynamicPropertiesEncoded = StringUtils.join(dynamicProperties, CliFrontend.YARN_DYNAMIC_PROPERTIES_SEPARATOR); // Task Managers vcores int tmCores = 1; if (cmd.hasOption(TM_CORES.getOpt())) { tmCores = Integer.valueOf(cmd.getOptionValue(TM_CORES.getOpt())); } Utils.getFlinkConfiguration(confPath.toUri().getPath()); int jmPort = GlobalConfiguration.getInteger(ConfigConstants.JOB_MANAGER_IPC_PORT_KEY, 0); if (jmPort == 0) { LOG.warn("Unable to find job manager port in configuration!"); jmPort = ConfigConstants.DEFAULT_JOB_MANAGER_IPC_PORT; } conf = Utils.initializeYarnConfiguration(); // intialize HDFS LOG.info("Copy App Master jar from local filesystem and add to local environment"); // Copy the application master jar to the filesystem // Create a local resource to point to the destination jar path final FileSystem fs = FileSystem.get(conf); // hard coded check for the GoogleHDFS client because its not overriding the getScheme() method. if (!fs.getClass().getSimpleName().equals("GoogleHadoopFileSystem") && fs.getScheme().startsWith("file")) { LOG.warn("The file system scheme is '" + fs.getScheme() + "'. This indicates that the " + "specified Hadoop configuration path is wrong and the sytem is using the default Hadoop configuration values." + "The Flink YARN client needs to store its files in a distributed file system"); } // Create yarnClient yarnClient = YarnClient.createYarnClient(); yarnClient.init(conf); yarnClient.start(); // Query cluster for metrics if (cmd.hasOption(QUERY.getOpt())) { showClusterMetrics(yarnClient); } if (!cmd.hasOption(CONTAINER.getOpt())) { LOG.error("Missing required argument " + CONTAINER.getOpt()); printUsage(); yarnClient.stop(); System.exit(1); } // TM Count final int taskManagerCount = Integer.valueOf(cmd.getOptionValue(CONTAINER.getOpt())); System.out.println("Using values:"); System.out.println("\tContainer Count = " + taskManagerCount); System.out.println("\tJar Path = " + localJarPath.toUri().getPath()); System.out.println("\tConfiguration file = " + confPath.toUri().getPath()); System.out.println("\tJobManager memory = " + jmMemory); System.out.println("\tTaskManager memory = " + tmMemory); System.out.println("\tTaskManager cores = " + tmCores); // Create application via yarnClient YarnClientApplication app = yarnClient.createApplication(); GetNewApplicationResponse appResponse = app.getNewApplicationResponse(); Resource maxRes = appResponse.getMaximumResourceCapability(); if (tmMemory > maxRes.getMemory() || tmCores > maxRes.getVirtualCores()) { LOG.error("The cluster does not have the requested resources for the TaskManagers available!\n" + "Maximum Memory: " + maxRes.getMemory() + ", Maximum Cores: " + tmCores); yarnClient.stop(); System.exit(1); } if (jmMemory > maxRes.getMemory()) { LOG.error("The cluster does not have the requested resources for the JobManager available!\n" + "Maximum Memory: " + maxRes.getMemory()); yarnClient.stop(); System.exit(1); } int totalMemoryRequired = jmMemory + tmMemory * taskManagerCount; ClusterResourceDescription freeClusterMem = getCurrentFreeClusterResources(yarnClient); if (freeClusterMem.totalFreeMemory < totalMemoryRequired) { LOG.error("This YARN session requires " + totalMemoryRequired + "MB of memory in the cluster. " + "There are currently only " + freeClusterMem.totalFreeMemory + "MB available."); yarnClient.stop(); System.exit(1); } if (tmMemory > freeClusterMem.containerLimit) { LOG.error("The requested amount of memory for the TaskManagers (" + tmMemory + "MB) is more than " + "the largest possible YARN container: " + freeClusterMem.containerLimit); yarnClient.stop(); System.exit(1); } if (jmMemory > freeClusterMem.containerLimit) { LOG.error("The requested amount of memory for the JobManager (" + jmMemory + "MB) is more than " + "the largest possible YARN container: " + freeClusterMem.containerLimit); yarnClient.stop(); System.exit(1); } // respect custom JVM options in the YAML file final String javaOpts = GlobalConfiguration.getString(ConfigConstants.FLINK_JVM_OPTIONS, ""); // Set up the container launch context for the application master ContainerLaunchContext amContainer = Records.newRecord(ContainerLaunchContext.class); String amCommand = "$JAVA_HOME/bin/java" + " -Xmx" + Utils.calculateHeapSize(jmMemory) + "M " + javaOpts; if (hasLogback || hasLog4j) { amCommand += " -Dlog.file=\"" + ApplicationConstants.LOG_DIR_EXPANSION_VAR + "/jobmanager-main.log\""; } if (hasLogback) { amCommand += " -Dlogback.configurationFile=file:logback.xml"; } if (hasLog4j) { amCommand += " -Dlog4j.configuration=file:log4j.properties"; } amCommand += " " + ApplicationMaster.class.getName() + " " + " 1>" + ApplicationConstants.LOG_DIR_EXPANSION_VAR + "/jobmanager-stdout.log" + " 2>" + ApplicationConstants.LOG_DIR_EXPANSION_VAR + "/jobmanager-stderr.log"; amContainer.setCommands(Collections.singletonList(amCommand)); System.err.println("amCommand=" + amCommand); // Set-up ApplicationSubmissionContext for the application ApplicationSubmissionContext appContext = app.getApplicationSubmissionContext(); final ApplicationId appId = appContext.getApplicationId(); /** * All network ports are offsetted by the application number * to avoid version port clashes when running multiple Flink sessions * in parallel */ int appNumber = appId.getId(); jmPort = Utils.offsetPort(jmPort, appNumber); // Setup jar for ApplicationMaster LocalResource appMasterJar = Records.newRecord(LocalResource.class); LocalResource flinkConf = Records.newRecord(LocalResource.class); Path remotePathJar = Utils.setupLocalResource(conf, fs, appId.toString(), localJarPath, appMasterJar, fs.getHomeDirectory()); Path remotePathConf = Utils.setupLocalResource(conf, fs, appId.toString(), confPath, flinkConf, fs.getHomeDirectory()); Map<String, LocalResource> localResources = new HashMap<String, LocalResource>(2); localResources.put("flink.jar", appMasterJar); localResources.put("flink-conf.yaml", flinkConf); // setup security tokens (code from apache storm) final Path[] paths = new Path[3 + shipFiles.size()]; StringBuffer envShipFileList = new StringBuffer(); // upload ship files for (int i = 0; i < shipFiles.size(); i++) { File shipFile = shipFiles.get(i); LocalResource shipResources = Records.newRecord(LocalResource.class); Path shipLocalPath = new Path("file://" + shipFile.getAbsolutePath()); paths[3 + i] = Utils.setupLocalResource(conf, fs, appId.toString(), shipLocalPath, shipResources, fs.getHomeDirectory()); localResources.put(shipFile.getName(), shipResources); envShipFileList.append(paths[3 + i]); if (i + 1 < shipFiles.size()) { envShipFileList.append(','); } } paths[0] = remotePathJar; paths[1] = remotePathConf; sessionFilesDir = new Path(fs.getHomeDirectory(), ".flink/" + appId.toString() + "/"); FsPermission permission = new FsPermission(FsAction.ALL, FsAction.ALL, FsAction.ALL); fs.setPermission(sessionFilesDir, permission); // set permission for path. Utils.setTokensFor(amContainer, paths, this.conf); amContainer.setLocalResources(localResources); fs.close(); int amRPCPort = GlobalConfiguration.getInteger(ConfigConstants.YARN_AM_PRC_PORT, ConfigConstants.DEFAULT_YARN_AM_RPC_PORT); amRPCPort = Utils.offsetPort(amRPCPort, appNumber); // Setup CLASSPATH for ApplicationMaster Map<String, String> appMasterEnv = new HashMap<String, String>(); Utils.setupEnv(conf, appMasterEnv); // set configuration values appMasterEnv.put(Client.ENV_TM_COUNT, String.valueOf(taskManagerCount)); appMasterEnv.put(Client.ENV_TM_CORES, String.valueOf(tmCores)); appMasterEnv.put(Client.ENV_TM_MEMORY, String.valueOf(tmMemory)); appMasterEnv.put(Client.FLINK_JAR_PATH, remotePathJar.toString()); appMasterEnv.put(Client.ENV_APP_ID, appId.toString()); appMasterEnv.put(Client.ENV_CLIENT_HOME_DIR, fs.getHomeDirectory().toString()); appMasterEnv.put(Client.ENV_CLIENT_SHIP_FILES, envShipFileList.toString()); appMasterEnv.put(Client.ENV_CLIENT_USERNAME, UserGroupInformation.getCurrentUser().getShortUserName()); appMasterEnv.put(Client.ENV_AM_PRC_PORT, String.valueOf(amRPCPort)); appMasterEnv.put(Client.ENV_SLOTS, String.valueOf(slots)); appMasterEnv.put(Client.ENV_APP_NUMBER, String.valueOf(appNumber)); if (dynamicPropertiesEncoded != null) { appMasterEnv.put(Client.ENV_DYNAMIC_PROPERTIES, dynamicPropertiesEncoded); } amContainer.setEnvironment(appMasterEnv); // Set up resource type requirements for ApplicationMaster Resource capability = Records.newRecord(Resource.class); capability.setMemory(jmMemory); capability.setVirtualCores(1); appContext.setApplicationName("Flink"); // application name appContext.setAMContainerSpec(amContainer); appContext.setResource(capability); appContext.setQueue(queue); // file that we write into the conf/ dir containing the jobManager address and the dop. yarnPropertiesFile = new File(confDirPath + CliFrontend.YARN_PROPERTIES_FILE); LOG.info("Submitting application master " + appId); yarnClient.submitApplication(appContext); ApplicationReport appReport = yarnClient.getApplicationReport(appId); YarnApplicationState appState = appReport.getYarnApplicationState(); boolean told = false; char[] el = { '/', '|', '\\', '-' }; int i = 0; int numTaskmanagers = 0; int numMessages = 0; BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); while (appState != YarnApplicationState.FINISHED && appState != YarnApplicationState.KILLED && appState != YarnApplicationState.FAILED) { if (!told && appState == YarnApplicationState.RUNNING) { System.err.println("Flink JobManager is now running on " + appReport.getHost() + ":" + jmPort); System.err.println("JobManager Web Interface: " + appReport.getTrackingUrl()); // write jobmanager connect information Properties yarnProps = new Properties(); yarnProps.setProperty(CliFrontend.YARN_PROPERTIES_JOBMANAGER_KEY, appReport.getHost() + ":" + jmPort); if (slots != -1) { yarnProps.setProperty(CliFrontend.YARN_PROPERTIES_DOP, Integer.toString(slots * taskManagerCount)); } // add dynamic properties if (dynamicProperties != null) { yarnProps.setProperty(CliFrontend.YARN_PROPERTIES_DYNAMIC_PROPERTIES_STRING, dynamicPropertiesEncoded); } OutputStream out = new FileOutputStream(yarnPropertiesFile); yarnProps.store(out, "Generated YARN properties file"); out.close(); yarnPropertiesFile.setReadable(true, false); // readable for all. // connect RPC service cmc = new ClientMasterControl(new InetSocketAddress(appReport.getHost(), amRPCPort)); cmc.start(); Runtime.getRuntime().addShutdownHook(new ClientShutdownHook()); told = true; } if (!told) { System.err.print(el[i++] + "\r"); if (i == el.length) { i = 0; } Thread.sleep(500); // wait for the application to switch to RUNNING } else { int newTmCount = cmc.getNumberOfTaskManagers(); if (numTaskmanagers != newTmCount) { System.err.println("Number of connected TaskManagers changed to " + newTmCount + ". " + "Slots available: " + cmc.getNumberOfAvailableSlots()); numTaskmanagers = newTmCount; } // we also need to show new messages. if (cmc.getFailedStatus()) { System.err.println("The Application Master failed!\nMessages:\n"); for (Message m : cmc.getMessages()) { System.err.println("Message: " + m.getMessage()); } System.err.println("Requesting Application Master shutdown"); cmc.shutdownAM(); cmc.close(); System.err.println("Application Master closed."); } if (cmc.getMessages().size() != numMessages) { System.err.println("Received new message(s) from the Application Master"); List<Message> msg = cmc.getMessages(); while (msg.size() > numMessages) { System.err.println("Message: " + msg.get(numMessages).getMessage()); numMessages++; } } // wait until CLIENT_POLLING_INTERVALL is over or the user entered something. long startTime = System.currentTimeMillis(); while ((System.currentTimeMillis() - startTime) < CLIENT_POLLING_INTERVALL * 1000 && !in.ready()) { Thread.sleep(200); } if (in.ready()) { String command = in.readLine(); evalCommand(command); } } appReport = yarnClient.getApplicationReport(appId); appState = appReport.getYarnApplicationState(); } LOG.info("Application " + appId + " finished with" + " state " + appState + " and " + "final state " + appReport.getFinalApplicationStatus() + " at " + appReport.getFinishTime()); if (appState == YarnApplicationState.FAILED || appState == YarnApplicationState.KILLED) { LOG.warn("Application failed. Diagnostics " + appReport.getDiagnostics()); LOG.warn("If log aggregation is activated in the Hadoop cluster, we recommend to retreive " + "the full application log using this command:\n" + "\tyarn logs -applicationId " + appReport.getApplicationId() + "\n" + "(It sometimes takes a few seconds until the logs are aggregated)"); } }
From source file:org.codehaus.continuum.cli.ContinuumCC.java
public int work(String[] args) throws Exception { if (embedder == null) { throw new ContinuumException("Must be started first."); }//from w w w .ja va2 s. c o m commands = plexus.lookupMap(CliCommand.ROLE); if (args.length == 0) { throw new Exception("The first argument on the command line must be the command name."); } String commandName = args[0]; CliCommand command = getCommand(commandName); try { // Remove the first argument which is the command name. List argsList = new ArrayList(Arrays.asList(args)); argsList.remove(0); args = (String[]) argsList.toArray(new String[args.length - 1]); command.execute(args); } catch (MissingOptionException ex) { System.err.println(ex.getMessage()); System.err.println(command.getCommandLineHelp()); return -1; } catch (UnrecognizedOptionException ex) { System.err.println(ex.getMessage()); System.err.println(command.getCommandLineHelp()); return -1; } catch (ContinuumException ex) { ex.printStackTrace(System.out); return -1; } return 0; }
From source file:org.dcm4che2.tool.dcmwado.DcmWado.java
private static CommandLine parse(String[] args) { Options opts = new Options(); OptionBuilder.withArgName("suid:Suid:iuid"); OptionBuilder.hasArgs(3);/*from ww w . jav a 2s. c om*/ OptionBuilder.withValueSeparator(':'); OptionBuilder.withDescription( "Retrieve object with given Study " + "Instance UID, Series Instance UID and SOP Instance UID."); opts.addOption(OptionBuilder.create("uid")); OptionBuilder.withArgName("Suid:iuid"); OptionBuilder.hasArgs(2); OptionBuilder.withValueSeparator(':'); OptionBuilder.withDescription("Series Instance UID and SOP Instance UID " + "of the presentation state storage object to be applied to the " + "image."); opts.addOption(OptionBuilder.create("pr")); opts.addOption("dcm", false, "Request DICOM object. (MIME type: application/dicom)"); opts.addOption("jpeg", false, "Request JPEG image. (MIME type: image/jpeg)"); opts.addOption("gif", false, "Request GIF image. (MIME type: image/gif)"); opts.addOption("png", false, "Request PNG image. (MIME type: image/png)"); opts.addOption("jp2", false, "Request JPEG 2000 image. (MIME type: image/jp2)"); opts.addOption("mpeg", false, "Request MPEG video. (MIME type: video/mpeg)"); opts.addOption("txt", false, "Request plain text document. (MIME type: text/plain)"); opts.addOption("html", false, "Request HTML document. (MIME type: text/html)"); opts.addOption("xml", false, "Request XML document. (MIME type: text/xml)"); opts.addOption("rtf", false, "Request RTF document. (MIME type: text/rtf)"); opts.addOption("pdf", false, "Request PDF document. (MIME type: application/pdf)"); opts.addOption("cda1", false, "Request CDA Level 1 document. " + "(MIME type: application/x-hl7-cda-level-one+xml)"); OptionBuilder.withArgName("type"); OptionBuilder.hasArg(); OptionBuilder.withDescription("Request document with the specified MIME type." + "Alternative MIME types can be specified by additional -mime options."); opts.addOption(OptionBuilder.create("mime")); OptionBuilder.withArgName("uid"); OptionBuilder.hasArg(); OptionBuilder.withDescription("Returned object shall be encoded with " + "the specified Transfer Syntax. Alternative Transfer Syntaxes " + "can be specified by additional -ts options."); opts.addOption(OptionBuilder.create("ts")); OptionBuilder.withArgName("name"); OptionBuilder.hasArg(); OptionBuilder.withDescription( "Returned object shall be encoded with " + "specified Character set. Alternative Character sets " + "can be specified by additional -charset options."); opts.addOption(OptionBuilder.create("charset")); opts.addOption("anonymize", false, "Remove all patient identification" + "information from returned DICOM Object"); OptionBuilder.withArgName("type"); OptionBuilder.hasArg(); OptionBuilder.withDescription( "Burn in patient information" + "(-annotation=patient) and/or technique information " + "(-annotation=technique) in returned pixel data."); opts.addOption(OptionBuilder.create("annotation")); OptionBuilder.withArgName("num"); OptionBuilder.hasArg(); OptionBuilder.withDescription("Maximal number of pixel rows in returned image."); opts.addOption(OptionBuilder.create("rows")); OptionBuilder.withArgName("num"); OptionBuilder.hasArg(); OptionBuilder.withDescription("Maximal number of pixel columns in returned image."); opts.addOption(OptionBuilder.create("columns")); OptionBuilder.withArgName("num"); OptionBuilder.hasArg(); OptionBuilder .withDescription("Return single frame with that number " + "within a multi-frame image object."); opts.addOption(OptionBuilder.create("frame")); OptionBuilder.withArgName("x1:y1:x2:y2"); OptionBuilder.hasArgs(4); OptionBuilder.withValueSeparator(':'); OptionBuilder.withDescription("Return rectangular region of image " + "matrix specified by top left (x1,y1) and bottom right (x2,y2) " + "corner in relative coordinates within the range 0.0 to 1.0."); opts.addOption(OptionBuilder.create("window")); OptionBuilder.withArgName("center/width"); OptionBuilder.hasArgs(2); OptionBuilder.withValueSeparator('/'); OptionBuilder .withDescription("Specifies center and width of the " + "VOI window to be applied to the image."); opts.addOption(OptionBuilder.create("window")); OptionBuilder.withArgName("num"); OptionBuilder.hasArg(); OptionBuilder.withDescription( "Quality of the image to be returned " + "within the range 1 to 100, 100 being the best quality."); opts.addOption(OptionBuilder.create("quality")); OptionBuilder.withArgName("path"); OptionBuilder.hasArg(); OptionBuilder.withDescription("Directory to store retrieved objects, " + "working directory by default"); opts.addOption(OptionBuilder.create("dir")); OptionBuilder.withArgName("dirpath"); OptionBuilder.hasArg(); OptionBuilder.withDescription("Directory to store retrieved objects, " + "working directory by default"); opts.addOption(OptionBuilder.create("dir")); OptionBuilder.withArgName("file"); OptionBuilder.hasArg(); OptionBuilder.withDescription("Store retrieved object to specified file, " + "use SOP Instance UID + format specific file extension as " + "file name by default."); opts.addOption(OptionBuilder.create("o")); opts.addOption("nostore", false, "Do not store retrieved objects to files."); opts.addOption("nokeepalive", false, "Close TCP connection after each response."); opts.addOption("noredirect", false, "Disable HTTP redirects."); OptionBuilder.withArgName("kB"); OptionBuilder.hasArg(); OptionBuilder.withDescription( "Size of byte buffer in KB " + "used for copying the retrieved object to disk, 8 KB by default."); opts.addOption(OptionBuilder.create("buffersize")); opts.addOption("h", "help", false, "print this message"); opts.addOption("V", "version", false, "print the version information and exit"); CommandLine cl = null; try { cl = new GnuParser().parse(opts, args); } catch (MissingOptionException e) { exit("dcmwado: Missing required option " + e.getMessage()); throw new RuntimeException("unreachable"); } catch (ParseException e) { exit("dcmwado: " + e.getMessage()); throw new RuntimeException("unreachable"); } if (cl.hasOption('V')) { Package p = DcmWado.class.getPackage(); System.out.println("dcmwado v" + p.getImplementationVersion()); System.exit(0); } if (cl.hasOption('h') || cl.getArgList().isEmpty()) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(USAGE, DESCRIPTION, opts, EXAMPLE); System.exit(0); } int narg = cl.getArgList().size(); if (narg == 0) exit("Missing url of WADO server"); if (narg == 1) { if (!cl.hasOption("uid")) { exit("You must either option -uid <uids> or <file>|<directory> specify"); } } else { if (cl.hasOption("uid")) { exit("You may not specify option -uid <uids> together with " + "<file>|<directory>."); } } return cl; }
From source file:org.krysalis.barcode4j.cli.Main.java
/** * Handles the command line. The method calls the exit handler upon * completion./*from w w w . jav a2s . c o m*/ * @param args the command line arguments */ public void handleCommandLine(String[] args) { CommandLine cl; String[] msg; try { CommandLineParser clp = new PosixParser(); cl = clp.parse(getOptions(), args); //Message msg = cl.getArgs(); if (msg.length == 0) { throw new ParseException("No message"); } if (msg.length > 1) { throw new ParseException("Too many parameters: " + msg.length); } } catch (MissingOptionException moe) { printHelp(new PrintWriter(stdout)); exitHandler.failureExit(this, "Bad command line. Missing option: " + moe.getMessage(), null, -2); return; //never reached } catch (ParseException pe) { printHelp(new PrintWriter(stdout)); //pe.printStackTrace(); exitHandler.failureExit(this, "Bad command line: " + pe.getMessage(), null, -2); return; //never reached } try { OutputStream out; if (!cl.hasOption("o")) { log = new AdvancedConsoleLogger(AdvancedConsoleLogger.LEVEL_ERROR, false, stderr, stderr); printAppHeader(); out = stdout; } else { int logLevel = AdvancedConsoleLogger.LEVEL_INFO; if (cl.hasOption('v')) { logLevel = AdvancedConsoleLogger.LEVEL_DEBUG; } log = new AdvancedConsoleLogger(logLevel, false, stdout, stderr); printAppHeader(); File outFile = new File(cl.getOptionValue("o")); if (log.isDebugEnabled()) { log.debug("Output to: " + outFile.getCanonicalPath()); } out = new java.io.FileOutputStream(outFile); } log.debug("Message: " + msg[0]); //Output format String format = MimeTypes.expandFormat(cl.getOptionValue("f", MimeTypes.MIME_SVG)); int orientation = 0; log.info("Generating " + format + "..."); BarcodeUtil util = BarcodeUtil.getInstance(); BarcodeGenerator gen = util.createBarcodeGenerator(getConfiguration(cl)); if (MimeTypes.MIME_SVG.equals(format)) { //Create Barcode and render it to SVG SVGCanvasProvider svg = new SVGCanvasProvider(false, orientation); gen.generateBarcode(svg, msg[0]); //Serialize SVG barcode try { TransformerFactory factory = TransformerFactory.newInstance(); Transformer trans = factory.newTransformer(); Source src = new javax.xml.transform.dom.DOMSource(svg.getDOMFragment()); Result res = new javax.xml.transform.stream.StreamResult(out); trans.transform(src, res); } catch (TransformerException te) { exitHandler.failureExit(this, "XML/XSLT library error", te, -6); } } else if (MimeTypes.MIME_EPS.equals(format)) { EPSCanvasProvider eps = new EPSCanvasProvider(out, orientation); gen.generateBarcode(eps, msg[0]); eps.finish(); } else { int dpi = Integer.parseInt(cl.getOptionValue('d', "300")); log.debug("Resolution: " + dpi + "dpi"); BitmapCanvasProvider bitmap; if (cl.hasOption("bw")) { log.debug("Black/white image (1-bit)"); bitmap = new BitmapCanvasProvider(out, format, dpi, BufferedImage.TYPE_BYTE_BINARY, false, orientation); } else { log.debug("Grayscale image (8-bit) with anti-aliasing"); bitmap = new BitmapCanvasProvider(out, format, dpi, BufferedImage.TYPE_BYTE_GRAY, true, orientation); } gen.generateBarcode(bitmap, msg[0]); bitmap.finish(); } out.close(); log.info("done."); exitHandler.successfulExit(this); } catch (IOException ioe) { exitHandler.failureExit(this, "Error writing output file: " + ioe.getMessage(), null, -5); } catch (ConfigurationException ce) { exitHandler.failureExit(this, "Configuration problem: " + ce.getMessage(), ce, -6); } catch (BarcodeException be) { exitHandler.failureExit(this, "Error generating the barcode", be, -3); } }