List of usage examples for org.springframework.util StringUtils splitArrayElementsIntoProperties
@Nullable public static Properties splitArrayElementsIntoProperties(String[] array, String delimiter)
From source file:org.springframework.yarn.boot.support.ContainerLauncherRunner.java
protected void launchContainer(YarnContainer container, String[] parameters) { Properties properties = StringUtils.splitArrayElementsIntoProperties(parameters, "="); container.setParameters(properties != null ? properties : new Properties()); container.setEnvironment(System.getenv()); log.info("Running YarnContainer with parameters [" + StringUtils.arrayToCommaDelimitedString(parameters) + "]"); // use latch if container wants to be long running if (container instanceof LongRunningYarnContainer && ((LongRunningYarnContainer) container).isWaitCompleteState()) { log.info("Container requested that we wait state, setting up latch"); latch = new CountDownLatch(1); ((LongRunningYarnContainer) container).addContainerStateListener(new ContainerStateListener() { @Override/*from w ww . j a va 2s. c om*/ public void state(ContainerState state, Object exit) { if (log.isDebugEnabled()) { log.debug("Got state ContainerState=" + state + " and exit=" + exit); } stateWrapper.state = state; stateWrapper.exit = exit; latch.countDown(); } }); } // tell container to do its stuff container.run(); if (waitLatch) { if (latch != null) { try { // TODO: should we use timeout? latch.await(); } catch (InterruptedException e) { log.info("YarnContainer latch wait interrupted"); } } log.info("YarnContainer complete"); int exitCode = 0; if (stateWrapper.state != null) { if (stateWrapper.exit != null) { if (stateWrapper.exit instanceof String) { exitCode = exitCodeMapper.intValue((String) stateWrapper.exit); } else if (stateWrapper.exit instanceof Boolean) { exitCode = exitCodeMapper.intValue((Boolean) stateWrapper.exit); } else if (stateWrapper.exit instanceof Integer) { exitCode = (Integer) stateWrapper.exit; } } } log.info("Exiting with exitCode=" + exitCode); systemExiter.exit(exitCode); } }
From source file:org.springframework.yarn.container.CommandLineContainerRunner.java
@Override protected ExitStatus handleBeanRun(YarnContainer bean, String[] parameters, Set<String> opts) { Properties properties = StringUtils.splitArrayElementsIntoProperties(parameters, "="); bean.setParameters(properties != null ? properties : new Properties()); bean.setEnvironment(System.getenv()); if (log.isDebugEnabled()) { log.debug("Starting YarnClient bean: " + StringUtils.arrayToCommaDelimitedString(parameters)); }/* w ww . j a va 2 s . c o m*/ // use latch if container wants to be long running if (bean instanceof LongRunningYarnContainer && ((LongRunningYarnContainer) bean).isWaitCompleteState()) { latch = new CountDownLatch(1); ((LongRunningYarnContainer) bean).addContainerStateListener(new ContainerStateListener() { @Override public void state(ContainerState state, Object exit) { stateWrapper.state = state; // TODO: should handle exit value latch.countDown(); } }); } bean.run(); if (latch != null) { try { // TODO: should we use timeout? latch.await(); } catch (InterruptedException e) { log.debug("Latch interrupted"); } } if (log.isDebugEnabled()) { log.debug("YarnClient bean complete"); } if (stateWrapper.state != null && stateWrapper.state == ContainerState.FAILED) { return ExitStatus.FAILED; } else { return ExitStatus.COMPLETED; } }
From source file:org.springframework.yarn.examples.Main.java
public static void main(String args[]) { Properties properties = StringUtils.splitArrayElementsIntoProperties(args, "="); if (properties == null) { properties = new Properties(); }//from ww w .j a v a 2 s . c o m boolean nokill = Boolean.parseBoolean(properties.getProperty("nokill")); String appid = properties.getProperty("appid"); if (nokill) { new Main().doMain(new String[] { YarnSystemConstants.DEFAULT_CONTEXT_FILE_CLIENT, YarnSystemConstants.DEFAULT_ID_CLIENT, CommandLineClientRunner.OPT_SUBMIT }); } else if (appid != null) { new Main().doMain(new String[] { YarnSystemConstants.DEFAULT_CONTEXT_FILE_CLIENT, YarnSystemConstants.DEFAULT_ID_CLIENT, CommandLineClientRunner.OPT_KILL, CommandLineClientRunner.ARG_APPLICATION_ID + "=" + appid }); } else if (!nokill) { ConfigurableApplicationContext context = null; try { context = new ClassPathXmlApplicationContext("application-context.xml"); System.out.println("Submitting kill-application example"); YarnClient client = (YarnClient) context.getBean("yarnClient"); ApplicationId applicationId = client.submitApplication(); System.out.println("Submitted kill-application example"); System.out.println("Waiting 30 seconds before aborting the application"); Thread.sleep(30000); System.out.println( "Asking resource manager to abort application with applicationid=" + applicationId); client.killApplication(applicationId); } catch (Throwable e) { log.error("Error in main method", e); } finally { if (context != null) { context.close(); } } } }