/** cats the given text to the given command, using bash << multi-line input syntax */ public static String pipeTextTo(String text, String command) { String id = Identifiers.makeRandomId(8); return "cat << EOF_"+id+" | "+command+"\n" +text +"\n"+"EOF_"+id+"\n"; }
/** @see {@link Identifiers#makeRandomId(int)} */ public static String makeRandomId(int l) { return Identifiers.makeRandomId(l); }
public BasicLocationDefinition(String name, String spec, Map<String,? extends Object> config) { this(Identifiers.makeRandomId(8), name, spec, config); }
private BasicPool(Builder<T> builder) { this.name = (builder.name != null) ? "Pool("+builder.name+")" : "Pool-"+Identifiers.makeRandomId(8); this.supplier = checkNotNull(builder.supplier, "supplier"); this.viabilityChecker = checkNotNull(builder.viabilityChecker, "viabilityChecker"); this.closer = checkNotNull(builder.closer, closer); }
private String newTimestampedDirName(String prefix, int randomSuffixLength) { return prefix + "-" + new SimpleDateFormat("yyyyMMdd-HHmmss").format(new Date()) + "-" + Identifiers.makeRandomId(randomSuffixLength); }
@SuppressWarnings("deprecation") protected void afterEnd(Map flags, Task<?> task) { activeTaskCount.decrementAndGet(); incompleteTaskCount.decrementAndGet(); if (log.isTraceEnabled()) log.trace(this+" afterEnd, task: "+task); ExecutionUtils.invoke(flags.get("newTaskEndCallback"), task); List l = (List)flags.get("tagLinkedPreprocessors"); Collections.reverse(l); for (Object li: l) { TaskPreprocessor t = (TaskPreprocessor)li; t.onEnd(flags, task); } PerThreadCurrentTaskHolder.perThreadCurrentTask.remove(); ((TaskInternal)task).setEndTimeUtc(System.currentTimeMillis()); //clear thread _after_ endTime set, so we won't get a null thread when there is no end-time if (RENAME_THREADS) { String newThreadName = "brooklyn-"+Identifiers.makeRandomId(8); task.getThread().setName(newThreadName); } ((TaskInternal)task).setThread(null); synchronized (task) { task.notifyAll(); } for (ExecutionListener listener : listeners) { try { listener.onTaskDone(task); } catch (Exception e) { log.warn("Error notifying listener "+listener+" of task "+task+" done", e); } } }
public String getSocketUid() { String result = getAttribute(MySqlNode.SOCKET_UID); if (Strings.isBlank(result)) { result = Identifiers.makeRandomId(6); setAttribute(MySqlNode.SOCKET_UID, result); } return result; }
public ConfigKey<V> subKey() { String subName = Identifiers.makeRandomId(8); return new SubElementConfigKey<V>(this, subType, getName()+"."+subName, "element of "+getName()+", uid "+subName, null); }
public String getSocketUid() { String result = getAttribute(MariaDbNode.SOCKET_UID); if (Strings.isBlank(result)) setAttribute(MariaDbNode.SOCKET_UID, (result = Identifiers.makeRandomId(6))); return result; }
public String getPassword() { String result = getAttribute(MySqlNode.PASSWORD); if (Strings.isBlank(result)) { result = Identifiers.makeRandomId(6); setAttribute(MySqlNode.PASSWORD, result); } return result; }
public ConfigKey<V> subKey() { String subName = Identifiers.makeRandomId(8); return new SubElementConfigKey<V>(this, subType, getName()+"."+subName, "element of "+getName()+", uid "+subName, null); }
public String getPassword() { String result = getAttribute(MariaDbNode.PASSWORD); if (Strings.isBlank(result)) setAttribute(MariaDbNode.PASSWORD, (result = Identifiers.makeRandomId(6))); return result; }
@POST @ApiOperation(value = "Create a new location", responseClass = "String") public Response create( @ApiParam(name = "locationSpec", value = "Location specification object", required = true) @Valid LocationSpec locationSpec) { String id = Identifiers.makeRandomId(8); LocationDefinition l = new BasicLocationDefinition(id, locationSpec.getName(), locationSpec.getSpec(), locationSpec.getConfig()); brooklyn().getLocationRegistry().updateDefinedLocation(l); return Response.created(URI.create(id)).build(); }
@Override public Response create(LocationSpec locationSpec) { String id = Identifiers.makeRandomId(8); LocationDefinition l = new BasicLocationDefinition(id, locationSpec.getName(), locationSpec.getSpec(), locationSpec.getConfig()); brooklyn().getLocationRegistry().updateDefinedLocation(l); return Response.created(URI.create(id)).build(); }
@Override public int execScript(Map<String,?> props, List<String> commands, Map<String,?> env) { try { OutputStream out = getOptionalVal(props, PROP_OUT_STREAM); OutputStream err = getOptionalVal(props, PROP_ERR_STREAM); String scriptDir = getOptionalVal(props, PROP_SCRIPT_DIR); Boolean noExtraOutput = getOptionalVal(props, PROP_NO_EXTRA_OUTPUT); Boolean runAsRoot = getOptionalVal(props, PROP_RUN_AS_ROOT); String separator = getOptionalVal(props, PROP_SEPARATOR); String scriptPath = scriptDir+"/brooklyn-"+System.currentTimeMillis()+"-"+Identifiers.makeRandomId(8)+".sh"; String scriptContents = toScript(props, commands, env); if (LOG.isTraceEnabled()) LOG.trace("Running shell process (process) as script:\n{}", scriptContents); File to = new File(scriptPath); Files.createParentDirs(to); Files.copy(ByteStreams.newInputStreamSupplier(scriptContents.getBytes()), to); List<String> cmds = buildRunScriptCommand(scriptPath, noExtraOutput, runAsRoot); cmds.add(0, "chmod +x "+scriptPath); return asInt(execProcesses(cmds, null, out, err, separator, getOptionalVal(props, PROP_LOGIN_SHELL), this), -1); } catch (IOException e) { throw Throwables.propagate(e); } }
@Override public int execScript(Map<String,?> props, List<String> commands, Map<String,?> env) { String separator = getOptionalVal(props, PROP_SEPARATOR); String scriptDir = getOptionalVal(props, PROP_SCRIPT_DIR); Boolean runAsRoot = getOptionalVal(props, PROP_RUN_AS_ROOT); Boolean noExtraOutput = getOptionalVal(props, PROP_NO_EXTRA_OUTPUT); String scriptPath = scriptDir+"/brooklyn-"+System.currentTimeMillis()+"-"+Identifiers.makeRandomId(8)+".sh"; String scriptContents = toScript(props, commands, env); if (LOG.isTraceEnabled()) LOG.trace("Running shell command at {} as script: {}", host, scriptContents); copyTempFileToServer(ImmutableMap.of("permissions", "0700"), writeTempFile(scriptContents), scriptPath); String cmd = Strings.join(buildRunScriptCommand(scriptPath, noExtraOutput, runAsRoot), separator); return asInt(sshExec(props, cmd), -1); }
smartSubdomainName += Identifiers.makeRandomId(8);
/** this assumes the download is an archive containing a single directory on the root which will be renamed to "cookbookName"; * if that directory already has the correct name cookbookName can be null, * but if e.g. taking from a github tarball it will typically be of the form cookbookName-master/ * hence the renaming */ // TODO support installing from classpath, and using the repository (tie in with those methods) public static final String downloadAndExpandCookbook(String source, @Nullable String cookbookName, boolean force) { String dl = downloadAndExpandCookbook(source); if (cookbookName==null) return dl; String tmpName = "tmp-"+Strings.makeValidFilename(cookbookName)+"-"+Identifiers.makeRandomId(4); String installCmd = BashCommands.chain("mkdir "+tmpName, "cd "+tmpName, dl, BashCommands.requireTest("`ls | wc -w` -eq 1", "The downloaded archive must contain exactly one directory; contained"), "COOKBOOK_EXPANDED_DIR=`ls`", "mv $COOKBOOK_EXPANDED_DIR '../"+cookbookName+"'", "cd ..", "rm -rf "+tmpName); if (!force) return BashCommands.alternatives("ls "+cookbookName, installCmd); else return BashCommands.alternatives("rm -rf "+cookbookName, installCmd); }
@VisibleForTesting public static void setupLocationRegistryForTesting(ManagementContext mgmt) { // ensure localhost is added (even on windows) LocationDefinition l = mgmt.getLocationRegistry().getDefinedLocationByName("localhost"); if (l==null) mgmt.getLocationRegistry().updateDefinedLocation( ((BasicLocationRegistry)mgmt.getLocationRegistry()).localhost(Identifiers.makeRandomId(8))); ((BasicLocationRegistry)mgmt.getLocationRegistry()).disablePersistence(); }
Boolean runAsRoot = getOptionalVal(props, PROP_RUN_AS_ROOT); String scriptPath = scriptDir+"/brooklyn-"+System.currentTimeMillis()+"-"+Identifiers.makeRandomId(8)+".sh";