Java Code Examples for org.apache.brooklyn.util.text.Strings#join()
The following examples show how to use
org.apache.brooklyn.util.text.Strings#join() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: XmlMementoSerializer.java From brooklyn-server with Apache License 2.0 | 6 votes |
@SuppressWarnings("deprecation") protected String getContextDescription(Object contextHinter) { List<String> entries = MutableList.of(); entries.add("in"); entries.add(lookupContext.getContextDescription()); if (contextHinter instanceof ReferencingMarshallingContext) entries.add("at "+((ReferencingMarshallingContext)contextHinter).currentPath()); else if (contextHinter instanceof ReferenceByXPathUnmarshaller) { try { Method m = ReferenceByXPathUnmarshaller.class.getDeclaredMethod("getCurrentReferenceKey"); m.setAccessible(true); entries.add("at "+m.invoke(contextHinter)); } catch (Exception e) { Exceptions.propagateIfFatal(e); // ignore otherwise - we just won't have the position in the file } } return Strings.join(entries, " "); }
Example 2
Source File: KnifeTaskFactory.java From brooklyn-library with Apache License 2.0 | 5 votes |
/** creates the command for running knife. * in some cases knife may be added multiple times, * and in that case the parameter here tells which time it is being added, * on a single run. */ protected String buildKnifeCommand(int knifeCommandIndex) { MutableList<String> words = new MutableList<String>(); words.add(knifeExecutable()); words.addAll(initialKnifeParameters()); words.addAll(knifeParameters()); String x = knifeConfigFileOption(); if (Strings.isNonBlank(x)) words.add(knifeConfigFileOption()); return Strings.join(words, " "); }
Example 3
Source File: ServiceStateLogic.java From brooklyn-server with Apache License 2.0 | 5 votes |
protected Object computeServiceProblems() { Map<Entity, Lifecycle> values = getValues(SERVICE_STATE_ACTUAL); int numRunning=0; List<Entity> onesNotHealthy=MutableList.of(); Set<Lifecycle> ignoreStates = getConfig(IGNORE_ENTITIES_WITH_THESE_SERVICE_STATES); for (Map.Entry<Entity,Lifecycle> state: values.entrySet()) { if (state.getValue()==Lifecycle.RUNNING) numRunning++; else if (!ignoreStates.contains(state.getValue())) onesNotHealthy.add(state.getKey()); } QuorumCheck qc = getConfig(RUNNING_QUORUM_CHECK); if (qc!=null) { if (qc.isQuorate(numRunning, onesNotHealthy.size()+numRunning)) // quorate return null; if (onesNotHealthy.isEmpty()) return "Not enough entities running to be quorate"; } else { if (onesNotHealthy.isEmpty()) return null; } return "Required entit"+Strings.ies(onesNotHealthy.size())+" not healthy: "+ (onesNotHealthy.size()>3 ? nameOfEntity(onesNotHealthy.get(0))+" and "+(onesNotHealthy.size()-1)+" others" : Strings.join(nameOfEntity(onesNotHealthy), ", ")); }
Example 4
Source File: BasicBrooklynCatalog.java From brooklyn-server with Apache License 2.0 | 5 votes |
private String makeAsIndentedList(String yaml) { String[] lines = yaml.split("\n"); lines[0] = "- "+lines[0]; for (int i=1; i<lines.length; i++) lines[i] = " " + lines[i]; return Strings.join(lines, "\n"); }
Example 5
Source File: ExecWithLoggingHelpers.java From brooklyn-server with Apache License 2.0 | 4 votes |
public int execWithLogging(Map<String,?> props, final String summaryForLogging, final List<String> commands, final Map<String,?> env, String expectedCommandHeaders, final ExecRunner execCommand) { if (commandLogger!=null && commandLogger.isDebugEnabled()) { String allcmds = (Strings.isBlank(expectedCommandHeaders) ? "" : expectedCommandHeaders + " ; ") + Strings.join(commands, " ; "); commandLogger.debug("{}, initiating "+shortName.toLowerCase()+" on machine {}{}: {}", new Object[] {summaryForLogging, getTargetName(), env!=null && !env.isEmpty() ? " (env "+Sanitizer.sanitize(env)+")": "", allcmds}); } if (commands.isEmpty()) { if (commandLogger!=null && commandLogger.isDebugEnabled()) commandLogger.debug("{}, on machine {}, ending: no commands to run", summaryForLogging, getTargetName()); return 0; } final ConfigBag execFlags = new ConfigBag().putAll(props); // some props get overridden in execFlags, so remove them from the tool flags final ConfigBag toolFlags = new ConfigBag().putAll(props).removeAll( LOG_PREFIX, STDOUT, STDERR, ShellTool.PROP_NO_EXTRA_OUTPUT); execFlags.configure(ShellTool.PROP_SUMMARY, summaryForLogging); preExecChecks(); String logPrefix = execFlags.get(LOG_PREFIX); if (logPrefix==null) logPrefix = constructDefaultLoggingPrefix(execFlags); if (!execFlags.get(NO_STDOUT_LOGGING)) { String stdoutLogPrefix = "["+(logPrefix != null ? logPrefix+":stdout" : "stdout")+"] "; OutputStream outO = LoggingOutputStream.builder() .outputStream(execFlags.get(STDOUT)) .logger(commandLogger) .logPrefix(stdoutLogPrefix) .build(); execFlags.put(STDOUT, outO); } if (!execFlags.get(NO_STDERR_LOGGING)) { String stderrLogPrefix = "["+(logPrefix != null ? logPrefix+":stderr" : "stderr")+"] "; OutputStream outE = LoggingOutputStream.builder() .outputStream(execFlags.get(STDERR)) .logger(commandLogger) .logPrefix(stderrLogPrefix) .build(); execFlags.put(STDERR, outE); } Tasks.setBlockingDetails(shortName+" executing, "+summaryForLogging); try { return execWithTool(MutableMap.copyOf(toolFlags.getAllConfig()), new Function<ShellTool, Integer>() { @Override public Integer apply(ShellTool tool) { int result = execCommand.exec(tool, MutableMap.copyOf(execFlags.getAllConfig()), commands, env); if (commandLogger!=null && commandLogger.isDebugEnabled()) commandLogger.debug("{}, on machine {}, completed: return status {}", new Object[] {summaryForLogging, getTargetName(), result}); return result; }}); } finally { Tasks.setBlockingDetails(null); } }
Example 6
Source File: AbstractMain.java From brooklyn-server with Apache License 2.0 | 4 votes |
/** throw {@link ParseException} iff there are arguments */ protected void failIfArguments() { if (arguments.isEmpty()) return ; throw new ParseException("Invalid subcommand arguments '"+Strings.join(arguments, " ")+"'"); }
Example 7
Source File: BashCommands.java From brooklyn-server with Apache License 2.0 | 4 votes |
/** As {@link #alternativesSubshell(Collection)} */ public static String alternativesSubshell(String ...commands) { return "( " + Strings.join(commands, " || ") + " )"; }
Example 8
Source File: BashCommands.java From brooklyn-server with Apache License 2.0 | 4 votes |
/** As {@link #alternatives(Collection)}, but explicitly using ( ) grouping characters * to ensure exits are caught. */ public static String alternativesSubshell(Collection<String> commands) { // the spaces are not required, but it might be possible that a (( expr )) is interpreted differently // (won't hurt to have the spaces in any case!) return "( " + Strings.join(commands, " || ") + " )"; }
Example 9
Source File: BashCommands.java From brooklyn-server with Apache License 2.0 | 4 votes |
/** As {@link #alternativesGroup(Collection)} */ public static String alternativesGroup(String ...commands) { return "{ " + Strings.join(commands, " || ") + " ; }"; }
Example 10
Source File: BashCommands.java From brooklyn-server with Apache License 2.0 | 4 votes |
/** As {@link #alternatives(Collection)}, but explicitly using { } grouping characters * to ensure exits are propagated. */ public static String alternativesGroup(Collection<String> commands) { // spaces required around curly braces return "{ " + Strings.join(commands, " || ") + " ; }"; }
Example 11
Source File: BashCommands.java From brooklyn-server with Apache License 2.0 | 4 votes |
/** As {@link #alternatives(Collection)} */ public static String alternatives(String ...commands) { return "( " + Strings.join(commands, " || ") + " )"; }
Example 12
Source File: BashCommands.java From brooklyn-server with Apache License 2.0 | 4 votes |
/** As {@link #chainSubshell(Collection)} */ public static String chainSubshell(String ...commands) { return "( " + Strings.join(commands, " && ") + " )"; }
Example 13
Source File: BashCommands.java From brooklyn-server with Apache License 2.0 | 4 votes |
/** As {@link #chain(Collection)}, but explicitly using ( ) grouping characters * to ensure exits are caught. */ public static String chainSubshell(Collection<String> commands) { // the spaces are not required, but it might be possible that a (( expr )) is interpreted differently // (won't hurt to have the spaces in any case!) return "( " + Strings.join(commands, " && ") + " )"; }
Example 14
Source File: BashCommands.java From brooklyn-server with Apache License 2.0 | 4 votes |
/** As {@link #chainGroup(Collection)} */ public static String chainGroup(String ...commands) { return "{ " + Strings.join(commands, " && ") + " ; }"; }
Example 15
Source File: BashCommands.java From brooklyn-server with Apache License 2.0 | 4 votes |
/** Convenience for {@link #chain(Collection)} */ public static String chain(String ...commands) { return "( " + Strings.join(commands, " && ") + " )"; }
Example 16
Source File: Time.java From brooklyn-server with Apache License 2.0 | 4 votes |
private static String options(String ...patterns) { return "("+Strings.join(patterns,"|")+")"; }
Example 17
Source File: MavenArtifact.java From brooklyn-server with Apache License 2.0 | 4 votes |
/** returns a "groupId:artifactId:version:(classifier:)packaging" string * which maven refers to as the co-ordinate */ public String getCoordinate() { return Strings.join(MutableList.<String>of().append(groupId, artifactId, packaging). appendIfNotNull(classifier).append(version), ":"); }
Example 18
Source File: BashCommands.java From brooklyn-server with Apache License 2.0 | 2 votes |
/** * Returns a sequence of chained commands that runs until one of them succeeds (i.e. joined by '||'). * This currently runs as a subshell (so exits are swallowed) but behaviour may be changed imminently. * (Use {@link #alternativesGroup(Collection)} or {@link #alternativesSubshell(Collection)} to be clear.) */ public static String alternatives(Collection<String> commands) { return "( " + Strings.join(commands, " || ") + " )"; }
Example 19
Source File: BashCommands.java From brooklyn-server with Apache License 2.0 | 2 votes |
/** * Returns a sequence of chained commands that runs until one of them fails (i.e. joined by '&&') * This currently runs as a subshell (so exits are swallowed) but behaviour may be changed imminently. * (Use {@link #chainGroup(Collection)} or {@link #chainSubshell(Collection)} to be clear.) */ public static String chain(Collection<String> commands) { return "( " + Strings.join(commands, " && ") + " )"; }
Example 20
Source File: ConstraintSerialization.java From brooklyn-server with Apache License 2.0 | votes |
private static String NOT_CHARSET(String ...in) { return "[^"+Strings.join(in, "")+"]"; }