List of usage examples for org.springframework.util StringUtils arrayToCommaDelimitedString
public static String arrayToCommaDelimitedString(@Nullable Object[] arr)
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(); }//from w w w . j av 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"); } }
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/*w ww .ja v a2s . c o m*/ 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.configuration.EnvironmentFactoryBean.java
@Override public void afterPropertiesSet() throws Exception { environment = createEnvironment();//ww w. j a va 2 s . co m if (properties != null) { // if we have properties, merge those into environment CollectionUtils.mergePropertiesIntoMap(properties, environment); } boolean addDelimiter = false; // set CLASSPATH variable if there's something to set StringBuilder classPathEnv = new StringBuilder(); if (StringUtils.hasText(classpath)) { classPathEnv.append(classpath); addDelimiter = true; } ArrayList<String> paths = new ArrayList<String>(); if (includeBaseDirectory) { paths.add("./*"); } if (useDefaultYarnClasspath) { if (log.isDebugEnabled()) { log.debug("Trying to use a default yarn classpath"); } String defaultYarnClasspathString = ""; if (StringUtils.hasText(defaultYarnAppClasspath)) { defaultYarnClasspathString = defaultYarnAppClasspath; } else if (configuration != null) { defaultYarnClasspathString = configuration.get(YarnConfiguration.YARN_APPLICATION_CLASSPATH); if (!StringUtils.hasText(defaultYarnClasspathString)) { // 2.3.x changed yarn.application.classpath to be empty in yarn-default.xml, so // if we got empty, fall back to DEFAULT_YARN_APPLICATION_CLASSPATH defaultYarnClasspathString = StringUtils .arrayToCommaDelimitedString(YarnConfiguration.DEFAULT_YARN_APPLICATION_CLASSPATH); log.info("Yarn classpath from configuration empty, fall back to " + defaultYarnClasspathString); } else { log.info("Yarn classpath from configuration " + defaultYarnClasspathString); } } paths.addAll(StringUtils.commaDelimitedListToSet(defaultYarnClasspathString)); } if (useDefaultMapreduceClasspath) { if (log.isDebugEnabled()) { log.debug("Trying to use a mr yarn classpath"); } String defaultMapreduceClasspathString = ""; if (StringUtils.hasText(defaultMapreduceAppClasspath)) { defaultMapreduceClasspathString = defaultMapreduceAppClasspath; } else if (configuration != null) { defaultMapreduceClasspathString = configuration.get("mapreduce.application.classpath"); if (!StringUtils.hasText(defaultMapreduceClasspathString)) { // using reflection with this because we don't have these // classes in a project classpath and this is just // a fall back for default value defaultMapreduceClasspathString = readStaticField("org.apache.hadoop.mapreduce.MRJobConfig", "DEFAULT_MAPREDUCE_APPLICATION_CLASSPATH", getClass().getClassLoader()); log.info("Mapreduce classpath from configuration empty, fall back to " + defaultMapreduceClasspathString); } else { log.info("Mapreduce classpath from configuration " + defaultMapreduceClasspathString); } } paths.addAll(StringUtils.commaDelimitedListToSet(defaultMapreduceClasspathString)); } Iterator<String> iterator = paths.iterator(); // add delimiter if we're about to add something if (iterator.hasNext()) { classPathEnv.append(addDelimiter ? delimiter : ""); } while (iterator.hasNext()) { classPathEnv.append(iterator.next()); if (iterator.hasNext()) { classPathEnv.append(delimiter); } } String classpathString = classPathEnv.toString(); if (StringUtils.hasText(classpathString)) { environment.put("CLASSPATH", classpathString); log.info("Adding CLASSPATH=" + classpathString); } }
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 w w.j ava2s . c om // 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.test.context.YarnClusterInjectingAnnotationConfigContextLoader.java
@Override protected void loadBeanDefinitions(GenericApplicationContext context, MergedContextConfiguration mergedConfig) { String[] activeProfiles = context.getEnvironment().getActiveProfiles(); log.info("Active profiles: " + StringUtils.arrayToCommaDelimitedString(activeProfiles)); // let parent do its magic super.loadBeanDefinitions(context, mergedConfig); if (!ObjectUtils.containsElement(activeProfiles, YarnTestSystemConstants.PROFILE_ID_NOMINICLUSTER)) { YarnClusterInjectUtils.handleClusterInject(context, mergedConfig); }//w ww .j a v a 2 s. co m }
From source file:org.springmodules.commons.validator.DefaultValidatorFactory.java
/** * Sets the locations of the validation configuration files from which to load validation rules. Creates an instance * of <code>ValidatorResources</code> from the specified configuration files. * * @see Resource/* www . jav a 2 s .c om*/ * @see ValidatorResources */ public void setValidationConfigLocations(Resource[] validationConfigLocations) { if (log.isInfoEnabled()) { log.info("Loading validation configurations from [" + StringUtils.arrayToCommaDelimitedString(validationConfigLocations) + "]"); } try { InputStream[] inputStreams = new InputStream[validationConfigLocations.length]; for (int i = 0; i < inputStreams.length; i++) { inputStreams[i] = validationConfigLocations[i].getInputStream(); } this.validatorResources = new ValidatorResources(inputStreams); } catch (IOException e) { throw new FatalBeanException("Unable to read validation configuration due to IOException.", e); } catch (SAXException e) { throw new FatalBeanException("Unable to parse validation configuration XML", e); } }
From source file:org.tinygroup.beanwrapper.TypeConverterDelegate.java
/** * Convert the value to the required type (if necessary from a String), * using the given property editor./*from w ww . java 2 s. c o m*/ * @param oldValue the previous value, if available (may be <code>null</code>) * @param newValue the proposed new value * @param requiredType the type we must convert to * (or <code>null</code> if not known, for example in case of a collection element) * @param editor the PropertyEditor to use * @return the new value, possibly the result of type conversion * @throws IllegalArgumentException if type conversion failed */ protected Object doConvertValue(Object oldValue, Object newValue, Class requiredType, PropertyEditor editor) { Object convertedValue = newValue; boolean sharedEditor = false; if (editor != null) { sharedEditor = this.propertyEditorRegistry.isSharedEditor(editor); } if (editor != null && !(convertedValue instanceof String)) { // Not a String -> use PropertyEditor's setValue. // With standard PropertyEditors, this will return the very same object; // we just want to allow special PropertyEditors to override setValue // for type conversion from non-String values to the required type. try { Object newConvertedValue = null; if (sharedEditor) { // Synchronized access to shared editor instance. synchronized (editor) { editor.setValue(convertedValue); newConvertedValue = editor.getValue(); } } else { // Unsynchronized access to non-shared editor instance. editor.setValue(convertedValue); newConvertedValue = editor.getValue(); } if (newConvertedValue != convertedValue) { convertedValue = newConvertedValue; // Reset PropertyEditor: It already did a proper conversion. // Don't use it again for a setAsText call. editor = null; } } catch (Exception ex) { if (logger.isDebugEnabled()) { logger.debug( "PropertyEditor [" + editor.getClass().getName() + "] does not support setValue call", ex); } // Swallow and proceed. } } if (requiredType != null && !requiredType.isArray() && convertedValue instanceof String[]) { // Convert String array to a comma-separated String. // Only applies if no PropertyEditor converted the String array before. // The CSV String will be passed into a PropertyEditor's setAsText method, if any. if (logger.isTraceEnabled()) { logger.trace("Converting String array to comma-delimited String [" + convertedValue + "]"); } convertedValue = StringUtils.arrayToCommaDelimitedString((String[]) convertedValue); } if (editor != null && convertedValue instanceof String) { // Use PropertyEditor's setAsText in case of a String value. if (logger.isTraceEnabled()) { logger.trace("Converting String to [" + requiredType + "] using property editor [" + editor + "]"); } String newTextValue = (String) convertedValue; if (sharedEditor) { // Synchronized access to shared editor instance. synchronized (editor) { return doConvertTextValue(oldValue, newTextValue, editor); } } else { // Unsynchronized access to non-shared editor instance. return doConvertTextValue(oldValue, newTextValue, editor); } } return convertedValue; }
From source file:ubic.gemma.web.util.WebContextLoader.java
@Override public ApplicationContext loadContext(String... locations) { if (WebContextLoader.logger.isDebugEnabled()) { WebContextLoader.logger.debug("Loading WebApplicationContext for locations [" + StringUtils.arrayToCommaDelimitedString(locations) + "]."); }/* www. jav a 2 s . co m*/ ConfigurableWebApplicationContext context = new XmlWebApplicationContext(); context.setConfigLocations(locations); context.setServletContext(new MockServletContext("")); context.refresh(); AnnotationConfigUtils.registerAnnotationConfigProcessors((BeanDefinitionRegistry) context.getBeanFactory()); context.registerShutdownHook(); return context; }