@Override public String toString() { return getClass().getSimpleName()+"["+ (Strings.isNonBlank(publicKeyData) ? publicKeyData : "no-public-key")+";"+ (Strings.isNonBlank(privateKeyData) ? "private-key-present" : "no-private-key")+","+ (password!=null ? "password(len="+password.length()+")" : "no-password")+"]"; } }
@Override protected String initAndLogIn(Map<String, String> config) { String tokenProperty = config.get("token"); checkArgument(Strings.isNonBlank(tokenProperty), "property not set: token"); return tokenProperty; } }
@Beta public static String makeCommandExecutingInDirectory(String command, String executionDir, Entity entity) { String finalCommand = command; String execDir = executionDir; if (Strings.isNonBlank(execDir) && !"~".equals(execDir)) { finalCommand = "(if exist \"" + execDir + "\" (rundll32) else (mkdir \""+execDir+"\")) && cd \""+execDir+"\" && "+finalCommand; } return finalCommand; }
public boolean hasKey() { infer(); // key has stricter non-blank check than password return Strings.isNonBlank(privateKeyData); } public boolean hasPassword() {
/** true iff given ZIP/JAR file contains a MANIFEST.MF file defining a bundle symbolic name */ public boolean hasOsgiManifest(File f) { Manifest mf = getManifest(f); if (mf==null) return false; String sn = mf.getMainAttributes().getValue(Constants.BUNDLE_SYMBOLICNAME); return Strings.isNonBlank(sn); }
protected String generateHostname(SshMachineLocation machine) { String hostnameTemplate = config.get(HOSTNAME_TEMPLATE); if (Strings.isNonBlank(hostnameTemplate)) { return TemplateProcessor.processTemplateContents(hostnameTemplate, machine, ImmutableMap.<String, Object>of()); } else { return null; } }
/** @return a {@link Maybe} object which is absent if the argument {@link #isBlank(CharSequence)} */ public static <T extends CharSequence> Maybe<T> maybeNonBlank(T s) { if (isNonBlank(s)) return Maybe.of(s); return Maybe.absent(); }
protected String findImageName(Entity entity, ConfigBag setup) { String result = entity.config().get(DockerContainer.IMAGE_NAME); if (Strings.isNonBlank(result)) return result; result = setup.get(IMAGE); if (Strings.isNonBlank(result)) return result; String osFamily = setup.get(OS_FAMILY); String osVersion = setup.get(OS_VERSION_REGEX); Optional<String> imageName = new ImageChooser().chooseImage(osFamily, osVersion); if (imageName.isPresent()) return imageName.get(); throw new IllegalStateException("No matching image found for " + entity + " (no explicit image name, osFamily=" + osFamily + "; osVersion=" + osVersion + ")"); }
private static String getNameOrSpec(LocationSummary o) { if (Strings.isNonBlank(o.getName())) return o.getName(); if (Strings.isNonBlank(o.getSpec())) return o.getSpec(); return o.getId(); }
protected void checkConfig() { String psScript = getConfig(PS_SCRIPT); String command = getConfig(COMMAND); if (!(isNonBlank(psScript) ^ isNonBlank(command))) { String psScriptName = PS_SCRIPT.getName(); String commandName = COMMAND.getName(); throw illegal("Must specify exactly one of", psScriptName, "and", commandName); } }
private void executeSuccessfully(ConfigKey<String> configKey, String label) { if(Strings.isNonBlank(getEntity().getConfig(configKey))) { log.debug("Executing {} on entity {}", label, entity.getDisplayName()); int result = execute(ImmutableList.of(getEntity().getConfig(configKey)), label); if (0 != result) { log.debug("Executing {} failed with return code {}", label, result); throw new IllegalStateException("commands for " + configKey.getName() + " failed with return code " + result); } } }
/** puts a prefix in front of the message, with the given separator if there is already a message; * if there is no message, it simply sets the prefix as the message. * if no prefix or blank, does nothing. */ public Builder prefixMessage(String prefix, String separatorIfMessageNotBlank) { if (Strings.isNonBlank(prefix)) { if (Strings.isBlank(message)) message(prefix); else message(prefix+separatorIfMessageNotBlank+message); } return this; }
@Override public void runPostInstallCommand() { if (Strings.isNonBlank(entity.getConfig(BrooklynConfigKeys.POST_INSTALL_COMMAND)) || Strings.isNonBlank(getEntity().getConfig(VanillaWindowsProcess.POST_INSTALL_POWERSHELL_COMMAND))) { executeCommandInTask( getEntity().getConfig(BrooklynConfigKeys.POST_INSTALL_COMMAND), getEntity().getConfig(VanillaWindowsProcess.POST_INSTALL_POWERSHELL_COMMAND), "post-install-command"); } }
public static ConfigKey<?> newInstance(ConfigBag keyDefs) { String typeName = Strings.toString(keyDefs.getStringKey("type")); if (Strings.isNonBlank(typeName)) { // TODO dynamic typing - see TYPE key commented out above; also see AddSensor.getType for type lookup log.warn("Setting 'type' is not currently supported for dynamic config keys; ignoring in definition of "+keyDefs); } Class<Object> type = Object.class; String name = keyDefs.get(NAME); String description = keyDefs.get(DESCRIPTION); Object defaultValue = keyDefs.get(DEFAULT_VALUE); return newConfigKey(type, name, description, defaultValue); }
@Override public void launch() { if (Strings.isNonBlank(getEntity().getConfig(VanillaWindowsProcess.LAUNCH_COMMAND)) || Strings.isNonBlank(getEntity().getConfig(VanillaWindowsProcess.LAUNCH_POWERSHELL_COMMAND))) { executeCommandInTask( getEntity().getConfig(VanillaWindowsProcess.LAUNCH_COMMAND), getEntity().getConfig(VanillaWindowsProcess.LAUNCH_POWERSHELL_COMMAND), "launch-command"); } }
protected String getNodeName() { // (node name is needed so we can node delete it) // TODO would be better if CHEF_NODE_NAME were a freemarker template, could access entity.id, or hostname, etc, // in addition to supporting hard-coded node names (which is all we support so far). String nodeName = entity().getConfig(ChefConfig.CHEF_NODE_NAME); if (Strings.isNonBlank(nodeName)) return Strings.makeValidFilename(nodeName); // node name is taken from ID of this entity, if not specified return entity().getId(); }
protected String getNodeName() { // (node name is needed so we can node delete it) // TODO would be better if CHEF_NODE_NAME were a freemarker template, could access entity.id, or hostname, etc, // in addition to supporting hard-coded node names (which is all we support so far). String nodeName = entity().getConfig(ChefConfig.CHEF_NODE_NAME); if (Strings.isNonBlank(nodeName)) return Strings.makeValidFilename(nodeName); // node name is taken from ID of this entity, if not specified return entity().getId(); }
@Override public String getRunDir() { if (runDir != null) return runDir; String existingVal = getEntity().getAttribute(SoftwareProcess.RUN_DIR); if (Strings.isNonBlank(existingVal)) { // e.g. on rebind runDir = existingVal; return runDir; } setRunDir(Os.tidyPath(ConfigToAttributes.apply(getEntity(), SoftwareProcess.RUN_DIR))); return runDir; }
@Override public void init() { LOG.info("Starting Calico network id {}", getId()); super.init(); EntitySpec<?> agentSpec = EntitySpec.create(config().get(CALICO_NODE_SPEC)); String calicoVersion = config().get(CALICO_VERSION); if (Strings.isNonBlank(calicoVersion)) { agentSpec.configure(SoftwareProcess.SUGGESTED_VERSION, calicoVersion); } sensors().set(SDN_AGENT_SPEC, agentSpec); }
@Override public void customize() { String customizeCommand = getEntity().config().get(VanillaSoftwareProcess.CUSTOMIZE_COMMAND); if (Strings.isNonBlank(customizeCommand)) { newScript(CUSTOMIZING) .failOnNonZeroResultCode() .body.append(customizeCommand) .execute(); } }