List of usage examples for org.springframework.util StringUtils splitArrayElementsIntoProperties
@Nullable public static Properties splitArrayElementsIntoProperties(String[] array, String delimiter)
From source file:org.cloudfoundry.identity.uaa.config.EnvironmentPropertiesFactoryBeanTests.java
private Properties getProperties(String input) { Properties properties = StringUtils .splitArrayElementsIntoProperties(StringUtils.commaDelimitedListToStringArray(input), "="); return properties; }
From source file:org.cloudfoundry.identity.uaa.varz.VarzEndpointTests.java
@Test public void testVarzWithConfig() throws Exception { Properties properties = StringUtils.splitArrayElementsIntoProperties( StringUtils.commaDelimitedListToStringArray("foo=bar,password=spam,client.secret=baz"), "="); endpoint.setEnvironmentProperties(properties); Map<String, ?> varz = endpoint.getVarz("http://uua.vcap.me"); // System.err.println(varz); @SuppressWarnings("unchecked") Map<String, ?> map = (Map<String, ?>) varz.get("config"); assertNotNull(map);/*from w w w .j a v a 2s.co m*/ assertTrue(map.containsKey("foo")); assertEquals("#", map.get("password")); assertEquals("#", map.get("client.secret")); }
From source file:org.cloudfoundry.identity.uaa.config.EnvironmentMapFactoryBeanTests.java
private Map<String, ?> getProperties(String input) { HashMap<String, Object> result = new HashMap<String, Object>(); Properties properties = StringUtils .splitArrayElementsIntoProperties(StringUtils.commaDelimitedListToStringArray(input), "="); for (Enumeration<?> keys = properties.propertyNames(); keys.hasMoreElements();) { String key = (String) keys.nextElement(); result.put(key, properties.getProperty(key)); }/*www . j a va2s.c o m*/ return result; }
From source file:lcn.module.batch.core.launch.support.CommandLineRunner.java
/** * Batch Job? .//from w w w . ja v a 2 s . c o m * ? , Job ? / JobExecutionID, Job Parameter * CommandLineRunner Option ? . * * @param jobPath : Job Context ? XML ? * @param jobIdentifier : Job ? /JobExecutionID * @param parameters : Job Parameter * @param opts : CommandLineRunner (-restart, -next, -stop, -abandon) */ public int start(String jobPath, String jobIdentifier, String[] parameters, Set<String> opts) { ConfigurableApplicationContext context = null; try { // ApplicationContext ?. context = new ClassPathXmlApplicationContext(jobPath); context.getAutowireCapableBeanFactory().autowireBeanProperties(this, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, false); Assert.state(launcher != null, "A JobLauncher must be provided. Please add one to the configuration."); // ? Batch Job? , ? Batch Job? ? JobExplorer ?. if (opts.contains("-restart") || opts.contains("-next")) { Assert.state(jobExplorer != null, "A JobExplorer must be provided for a restart or start next operation. Please add one to the configuration."); } // Job? ?? . String jobName = jobIdentifier; // JobParameters ?. JobParameters jobParameters = jobParametersConverter .getJobParameters(StringUtils.splitArrayElementsIntoProperties(parameters, "=")); Assert.isTrue(parameters == null || parameters.length == 0 || !jobParameters.isEmpty(), "Invalid JobParameters " + Arrays.asList(parameters) + ". If parameters are provided they should be in the form name=value (no whitespace)."); // Batch Job? . if (opts.contains("-stop")) { List<JobExecution> jobExecutions = getRunningJobExecutions(jobIdentifier); if (jobExecutions == null) { throw new JobExecutionNotRunningException( "No running execution found for job=" + jobIdentifier); } for (JobExecution jobExecution : jobExecutions) { jobExecution.setStatus(BatchStatus.STOPPING); jobRepository.update(jobExecution); } return exitCodeMapper.intValue(ExitStatus.COMPLETED.getExitCode()); } // ? Batch Job? ? abandon . if (opts.contains("-abandon")) { List<JobExecution> jobExecutions = getStoppedJobExecutions(jobIdentifier); if (jobExecutions == null) { throw new JobExecutionNotStoppedException( "No stopped execution found for job=" + jobIdentifier); } for (JobExecution jobExecution : jobExecutions) { jobExecution.setStatus(BatchStatus.ABANDONED); jobRepository.update(jobExecution); } return exitCodeMapper.intValue(ExitStatus.COMPLETED.getExitCode()); } // Batch Job? . if (opts.contains("-restart")) { JobExecution jobExecution = getLastFailedJobExecution(jobIdentifier); if (jobExecution == null) { throw new JobExecutionNotFailedException( "No failed or stopped execution found for job=" + jobIdentifier); } jobParameters = jobExecution.getJobInstance().getJobParameters(); jobName = jobExecution.getJobInstance().getJobName(); } Job job; // JobLocator Job? null? ApplicationContext? Job? . if (jobLocator != null) { job = jobLocator.getJob(jobName); } else { job = (Job) context.getBean(jobName); } // ? Batch Job? Job Parameters ?. if (opts.contains("-next")) { JobParameters nextParameters = getNextJobParameters(job); Map<String, JobParameter> map = new HashMap<String, JobParameter>(nextParameters.getParameters()); map.putAll(jobParameters.getParameters()); jobParameters = new JobParameters(map); } // Batch Job? . JobExecution jobExecution = launcher.run(job, jobParameters); logger.warn("CommandLineRunner's Job Information"); logger.warn("jobName=" + jobExecution.getJobInstance().getJobName()); logger.warn("jobParamters=" + jobParameters.toString()); logger.warn("jobExecutionTime=" + (jobExecution.getEndTime().getTime() - jobExecution.getStartTime().getTime()) / 1000f + "s"); return exitCodeMapper.intValue(jobExecution.getExitStatus().getExitCode()); } catch (Throwable e) { String message = "Job Terminated in error: " + e.getMessage(); logger.error(message, e); CommandLineRunner.message = message; return exitCodeMapper.intValue(ExitStatus.FAILED.getExitCode()); } finally { if (context != null) { context.close(); } } }
From source file:egovframework.rte.bat.core.launch.support.EgovCommandLineRunner.java
/** * Batch Job? .//from ww w .j a v a 2 s . c o m * ? , Job ? / JobExecutionID, Job Parameter * CommandLineRunner Option ? . * * @param jobPath : Job Context ? XML ? * @param jobIdentifier : Job ? /JobExecutionID * @param parameters : Job Parameter * @param opts : CommandLineRunner (-restart, -next, -stop, -abandon) */ public int start(String jobPath, String jobIdentifier, String[] parameters, Set<String> opts) { ConfigurableApplicationContext context = null; try { // ApplicationContext ?. context = new ClassPathXmlApplicationContext(jobPath); context.getAutowireCapableBeanFactory().autowireBeanProperties(this, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, false); Assert.state(launcher != null, "A JobLauncher must be provided. Please add one to the configuration."); // ? Batch Job? , ? Batch Job? ? JobExplorer ?. if (opts.contains("-restart") || opts.contains("-next")) { Assert.state(jobExplorer != null, "A JobExplorer must be provided for a restart or start next operation. Please add one to the configuration."); } // Job? ?? . String jobName = jobIdentifier; // JobParameters ?. JobParameters jobParameters = jobParametersConverter .getJobParameters(StringUtils.splitArrayElementsIntoProperties(parameters, "=")); Assert.isTrue(parameters == null || parameters.length == 0 || !jobParameters.isEmpty(), "Invalid JobParameters " + Arrays.asList(parameters) + ". If parameters are provided they should be in the form name=value (no whitespace)."); // Batch Job? . if (opts.contains("-stop")) { List<JobExecution> jobExecutions = getRunningJobExecutions(jobIdentifier); if (jobExecutions == null) { throw new JobExecutionNotRunningException( "No running execution found for job=" + jobIdentifier); } for (JobExecution jobExecution : jobExecutions) { jobExecution.setStatus(BatchStatus.STOPPING); jobRepository.update(jobExecution); } return exitCodeMapper.intValue(ExitStatus.COMPLETED.getExitCode()); } // ? Batch Job? ? abandon . if (opts.contains("-abandon")) { List<JobExecution> jobExecutions = getStoppedJobExecutions(jobIdentifier); if (jobExecutions == null) { throw new JobExecutionNotStoppedException( "No stopped execution found for job=" + jobIdentifier); } for (JobExecution jobExecution : jobExecutions) { jobExecution.setStatus(BatchStatus.ABANDONED); jobRepository.update(jobExecution); } return exitCodeMapper.intValue(ExitStatus.COMPLETED.getExitCode()); } // Batch Job? . if (opts.contains("-restart")) { JobExecution jobExecution = getLastFailedJobExecution(jobIdentifier); if (jobExecution == null) { throw new JobExecutionNotFailedException( "No failed or stopped execution found for job=" + jobIdentifier); } jobParameters = jobExecution.getJobInstance().getJobParameters(); jobName = jobExecution.getJobInstance().getJobName(); } Job job; // JobLocator Job? null? ApplicationContext? Job? . if (jobLocator != null) { job = jobLocator.getJob(jobName); } else { job = (Job) context.getBean(jobName); } // ? Batch Job? Job Parameters ?. if (opts.contains("-next")) { JobParameters nextParameters = getNextJobParameters(job); Map<String, JobParameter> map = new HashMap<String, JobParameter>(nextParameters.getParameters()); map.putAll(jobParameters.getParameters()); jobParameters = new JobParameters(map); } // Batch Job? . JobExecution jobExecution = launcher.run(job, jobParameters); logger.warn("EgovCommandLineRunner's Job Information"); logger.warn("jobName=" + jobExecution.getJobInstance().getJobName()); logger.warn("jobParamters=" + jobParameters.toString()); logger.warn("jobExecutionTime=" + (jobExecution.getEndTime().getTime() - jobExecution.getStartTime().getTime()) / 1000f + "s"); return exitCodeMapper.intValue(jobExecution.getExitStatus().getExitCode()); } catch (Throwable e) { String message = "Job Terminated in error: " + e.getMessage(); logger.error(message, e); EgovCommandLineRunner.message = message; return exitCodeMapper.intValue(ExitStatus.FAILED.getExitCode()); } finally { if (context != null) { context.close(); } } }
From source file:org.springframework.batch.core.launch.support.CommandLineJobRunner.java
@SuppressWarnings("resource") int start(String jobPath, String jobIdentifier, String[] parameters, Set<String> opts) { ConfigurableApplicationContext context = null; try {//from w ww.j a v a 2 s .co m try { context = new AnnotationConfigApplicationContext(Class.forName(jobPath)); } catch (ClassNotFoundException cnfe) { context = new ClassPathXmlApplicationContext(jobPath); } context.getAutowireCapableBeanFactory().autowireBeanProperties(this, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, false); Assert.state(launcher != null, "A JobLauncher must be provided. Please add one to the configuration."); if (opts.contains("-restart") || opts.contains("-next")) { Assert.state(jobExplorer != null, "A JobExplorer must be provided for a restart or start next operation. Please add one to the configuration."); } String jobName = jobIdentifier; JobParameters jobParameters = jobParametersConverter .getJobParameters(StringUtils.splitArrayElementsIntoProperties(parameters, "=")); Assert.isTrue(parameters == null || parameters.length == 0 || !jobParameters.isEmpty(), "Invalid JobParameters " + Arrays.asList(parameters) + ". If parameters are provided they should be in the form name=value (no whitespace)."); if (opts.contains("-stop")) { List<JobExecution> jobExecutions = getRunningJobExecutions(jobIdentifier); if (jobExecutions == null) { throw new JobExecutionNotRunningException( "No running execution found for job=" + jobIdentifier); } for (JobExecution jobExecution : jobExecutions) { jobExecution.setStatus(BatchStatus.STOPPING); jobRepository.update(jobExecution); } return exitCodeMapper.intValue(ExitStatus.COMPLETED.getExitCode()); } if (opts.contains("-abandon")) { List<JobExecution> jobExecutions = getStoppedJobExecutions(jobIdentifier); if (jobExecutions == null) { throw new JobExecutionNotStoppedException( "No stopped execution found for job=" + jobIdentifier); } for (JobExecution jobExecution : jobExecutions) { jobExecution.setStatus(BatchStatus.ABANDONED); jobRepository.update(jobExecution); } return exitCodeMapper.intValue(ExitStatus.COMPLETED.getExitCode()); } if (opts.contains("-restart")) { JobExecution jobExecution = getLastFailedJobExecution(jobIdentifier); if (jobExecution == null) { throw new JobExecutionNotFailedException( "No failed or stopped execution found for job=" + jobIdentifier); } jobParameters = jobExecution.getJobParameters(); jobName = jobExecution.getJobInstance().getJobName(); } Job job = null; if (jobLocator != null) { try { job = jobLocator.getJob(jobName); } catch (NoSuchJobException e) { } } if (job == null) { job = (Job) context.getBean(jobName); } if (opts.contains("-next")) { JobParameters nextParameters = getNextJobParameters(job); Map<String, JobParameter> map = new HashMap<String, JobParameter>(nextParameters.getParameters()); map.putAll(jobParameters.getParameters()); jobParameters = new JobParameters(map); } JobExecution jobExecution = launcher.run(job, jobParameters); return exitCodeMapper.intValue(jobExecution.getExitStatus().getExitCode()); } catch (Throwable e) { String message = "Job Terminated in error: " + e.getMessage(); logger.error(message, e); CommandLineJobRunner.message = message; return exitCodeMapper.intValue(ExitStatus.FAILED.getExitCode()); } finally { if (context != null) { context.close(); } } }
From source file:org.springframework.boot.autoconfigure.batch.JobLauncherCommandLineRunner.java
@Override public void run(String... args) throws JobExecutionException { logger.info("Running default command line with: " + Arrays.asList(args)); launchJobFromProperties(StringUtils.splitArrayElementsIntoProperties(args, "=")); }
From source file:org.springframework.yarn.am.CommandLineAppmasterRunner.java
@Override protected ExitStatus handleBeanRun(YarnAppmaster 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 YarnAppmaster bean: " + StringUtils.arrayToCommaDelimitedString(parameters)); }//from w ww .jav a 2 s . c o m bean.addAppmasterStateListener(new AppmasterStateListener() { @Override public void state(AppmasterState state) { if (state == AppmasterState.COMPLETED) { latch.countDown(); } } }); bean.submitApplication(); if (log.isDebugEnabled()) { log.debug("Waiting latch to receive appmaster complete state"); } try { latch.await(); } catch (InterruptedException e) { log.debug("Latch interrupted"); } log.info("Bean run completed"); return ExitStatus.COMPLETED; }
From source file:org.springframework.yarn.batch.support.YarnJobLauncher.java
/** * Run the jobs.//w ww.ja va2 s . c om * * @param args the args * @throws JobExecutionException the job execution exception */ public void run(String... args) throws JobExecutionException { log.info("Running default command line with: " + Arrays.asList(args)); launchJobFromProperties(StringUtils.splitArrayElementsIntoProperties(args, "=")); }
From source file:org.springframework.yarn.boot.support.AppmasterLauncherRunner.java
protected void launchAppmaster(YarnAppmaster appmaster, String[] parameters) { Properties properties = StringUtils.splitArrayElementsIntoProperties(parameters, "="); if (properties == null) { properties = new Properties(); }/* w ww . j a v a 2s . c om*/ if (!properties.containsKey(AppmasterConstants.CONTAINER_COUNT)) { log.info("Setting container count set externally " + containerCount); properties.put(AppmasterConstants.CONTAINER_COUNT, Integer.toString(containerCount)); } appmaster.setParameters(properties); appmaster.setEnvironment(System.getenv()); log.info("Running YarnAppmaster with parameters [" + StringUtils.arrayToCommaDelimitedString(parameters) + "]"); appmaster.addAppmasterStateListener(new AppmasterStateListener() { @Override public void state(AppmasterState state) { if (state == AppmasterState.COMPLETED) { countDownLatch(); exit(ExitStatus.COMPLETED.getExitCode()); } else if (state == AppmasterState.FAILED) { countDownLatch(); exit(ExitStatus.FAILED.getExitCode()); } } }); appmaster.submitApplication(); if (isWaitLatch()) { log.info("Waiting latch to receive appmaster complete state"); waitLatch(); log.info("YarnAppmaster complete"); } }