/** 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"; }
protected boolean isKeyValidForNodeName(String key) { // return false to always write as <entry key="key" ...; otherwise only use that when key is not valid xml return Identifiers.isValidToken(key, VALID_XML_NODE_NAME_CHARS, VALID_XML_NODE_NAME_CHARS); }
public static String makeRandomBase64Id(int length) { StringBuilder s = new StringBuilder(); while (length>0) { appendBase64IdFromValueOfLength(randomLong(), length>10 ? 10 : length, s); length -= 10; } return s.toString(); } public static String getBase64IdFromValue(long value) {
public static String getBase64IdFromValue(long value) { return getBase64IdFromValue(value, 10); } public static String getBase64IdFromValue(long value, int length) {
public static String getBase64IdFromValue(long value, int length) { StringBuilder s = new StringBuilder(); appendBase64IdFromValueOfLength(value, length, s); return s.toString(); } public static void appendBase64IdFromValueOfLength(long value, int length, StringBuffer sb) {
/** returns null in a sane DNS environment, but if DNS provides a bogus address for made-up hostnames, this returns that address */ public synchronized static String getAddressOfUnresolvableHostname() { if (triedUnresolvableHostname) return cachedAddressOfUnresolvableHostname; String h = "noexistent-machine-"+Identifiers.makeRandomBase64Id(8); try { cachedAddressOfUnresolvableHostname = InetAddress.getByName(h).getHostAddress(); log.info("Networking detected "+cachedAddressOfUnresolvableHostname+" being returned by DNS for bogus hostnames ("+h+")"); } catch (Exception e) { log.debug("Networking detected failure on DNS resolution of unknown hostname ("+h+" throws "+e+")"); cachedAddressOfUnresolvableHostname = null; } triedUnresolvableHostname = true; return cachedAddressOfUnresolvableHostname; }
/** @see {@link Identifiers#makeRandomId(int)} */ public static String makeRandomId(int l) { return Identifiers.makeRandomId(l); }
/** @deprecated since 0.6.0 incomplete logic, and not needed */ public static boolean isValidJavaToken(String s) { return isValidToken(s, JAVA_VALID_START_CHARS, JAVA_VALID_NONSTART_CHARS); }
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 String getPassword() { String result = getAttribute(MariaDbNode.PASSWORD); if (Strings.isBlank(result)) setAttribute(MariaDbNode.PASSWORD, (result = Identifiers.makeRandomId(6))); 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); }
@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(); }