Java Code Examples for org.apache.brooklyn.util.text.Strings#isEmpty()
The following examples show how to use
org.apache.brooklyn.util.text.Strings#isEmpty() .
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: OsgiLauncherImpl.java From brooklyn-server with Apache License 2.0 | 6 votes |
@Override public OsgiLauncherImpl startPartOne() { // make sure brooklyn-core bundle is started brooklynVersion.getVersion(); Configuration brooklynConfig = getConfiguration(configAdmin, BROOKLYN_CONFIG_PID); // Note that this doesn't check whether the files exist, just that there are potential alternative sources for configuration. if (brooklynConfig == null && Strings.isEmpty(globalBrooklynProperties) && Strings.isEmpty(localBrooklynProperties)) { LOG.warn("Config Admin PID '" + BROOKLYN_CONFIG_PID + "' not found, not using external configuration. Create a brooklyn.cfg file in etc folder."); } configSupplier = new ConfigSupplier(brooklynConfig); BrooklynPropertiesFactoryHelper helper = new BrooklynPropertiesFactoryHelper( globalBrooklynProperties, localBrooklynProperties, configSupplier); setBrooklynPropertiesBuilder(helper.createPropertiesBuilder()); return super.startPartOne(); }
Example 2
Source File: KnifeTaskFactory.java From brooklyn-library with Apache License 2.0 | 6 votes |
protected void insertKnifeCompletionListenerIntoCompletionListenersList(List<Function<ProcessTaskWrapper<?>, Void>> listeners) { // give a nice warning if chef/knife not set up correctly Function<ProcessTaskWrapper<?>, Void> propagateIfKnifeConfigFileMissing = new Function<ProcessTaskWrapper<?>, Void>() { @Override public Void apply(@Nullable ProcessTaskWrapper<?> input) { if (input.getExitCode()!=0 && input.getStderr().indexOf("WARNING: No knife configuration file found")>=0) { String myConfig = knifeConfigFileOption(); if (Strings.isEmpty(myConfig)) throw new IllegalStateException("Config file for Chef knife must be specified in "+ChefConfig.KNIFE_CONFIG_FILE+" (or valid knife default set up)"); else throw new IllegalStateException("Error reading config file for Chef knife ("+myConfig+") -- does it exist?"); } return null; } }; listeners.add(propagateIfKnifeConfigFileMissing); }
Example 3
Source File: MariaDbSshDriver.java From brooklyn-library with Apache License 2.0 | 5 votes |
public String getMariaDbServerOptionsString() { Map<String, Object> options = entity.getConfig(MariaDbNode.MARIADB_SERVER_CONF); StringBuilder result = new StringBuilder(); if (groovyTruth(options)) { for (Map.Entry<String, Object> entry : options.entrySet()) { result.append(entry.getKey()); String value = entry.getValue().toString(); if (!Strings.isEmpty(value)) { result.append(" = ").append(value); } result.append('\n'); } } return result.toString(); }
Example 4
Source File: TestEndpointReachableImpl.java From brooklyn-server with Apache License 2.0 | 5 votes |
protected HostAndPort toHostAndPort(String endpoint) { if (Strings.isEmpty(endpoint)) { throw new IllegalArgumentException(String.format("The entity [%s] has no endpoint", getClass().getName())); } try { URI uri = URI.create(endpoint); int port; if (uri.getPort() != -1) { port = uri.getPort(); } else { if ("http".equalsIgnoreCase(uri.getScheme())) { port = 80; } else if ("https".equalsIgnoreCase(uri.getScheme())) { port = 443; } else { throw new IllegalArgumentException(String.format("The entity [%s] with endpoint [%s] has no port", getClass().getName(), endpoint)); } } return HostAndPort.fromParts(uri.getHost(), port); } catch (IllegalArgumentException e) { // Not a URL; fall-back to host-and-port } HostAndPort result = HostAndPort.fromString(endpoint); if (!result.hasPort()) { throw new IllegalArgumentException(String.format("The entity [%s] with endpoint [%s] has no port", getClass().getName(), endpoint)); } return result; }
Example 5
Source File: ServerResource.java From brooklyn-server with Apache License 2.0 | 5 votes |
private Duration parseDuration(String str, Duration defaultValue) { if (Strings.isEmpty(str)) { return defaultValue; } else { return Duration.parse(str); } }
Example 6
Source File: PhpHttpdSshDriver.java From SeaCloudsPlatform with Apache License 2.0 | 5 votes |
private void postDeploymentConfiguration(String targetNameApplication) { String configFile = targetNameApplication + "/" + getEntity().getConfigurationFile(); String configTemplate = targetNameApplication + "/" + getEntity().getConfigTemplate(); if (!Strings.isEmpty(configTemplate)) { copyTemplateToFile(configTemplate, configFile); processPhpTemplate(configFile); } else if (!Strings.isEmpty(getEntity().getConfigurationFile())) { // If no template specified, we assume the target file to be modified directly processPhpTemplate(configFile); } }
Example 7
Source File: Os.java From brooklyn-server with Apache License 2.0 | 5 votes |
/** merges paths using forward slash as the "local OS file separator", because it is recognised on windows, * making paths more consistent and avoiding problems with backslashes being escaped. * empty segments are omitted. */ public static String mergePaths(String ...items) { char separatorChar = '/'; StringBuilder result = new StringBuilder(); for (String item: items) { if (Strings.isEmpty(item)) continue; if (result.length() > 0 && !isSeparator(result.codePointAt(result.length()-1))) result.append(separatorChar); result.append(item); } return result.toString(); }
Example 8
Source File: MongoDBAuthenticationUtils.java From brooklyn-library with Apache License 2.0 | 5 votes |
public static String getRootPassword(Entity entity) { String password = entity.config().get(MongoDBAuthenticationMixins.ROOT_PASSWORD); if (Strings.isEmpty(password)) { LOG.debug(entity + " has no password specified for " + MongoDBAuthenticationMixins.ROOT_PASSWORD.getName() + "; using a random string"); password = Identifiers.makeRandomPassword(16); entity.sensors().set(MongoDBAuthenticationMixins.ROOT_PASSWORD, password); entity.config().set(MongoDBAuthenticationMixins.ROOT_PASSWORD, password); } return password; }
Example 9
Source File: PhpWebAppSoftwareProcessImpl.java From SeaCloudsPlatform with Apache License 2.0 | 5 votes |
private String inferCorrectAppTarballName() { String result; if (Strings.isEmpty(getConfig(APP_NAME))) { result = SourceNameResolver.getIdOfTarballFromUrl(getConfig(TARBALL_URL)); } else { result = getConfig(APP_NAME); } return result; }
Example 10
Source File: PaasWebAppCloudFoundryDriver.java From SeaCloudsPlatform with Apache License 2.0 | 5 votes |
private void manageService(Entity rawEntity){ CloudFoundryService cloudFoundryService; if (rawEntity instanceof CloudFoundryService){ cloudFoundryService = (CloudFoundryService) rawEntity; String serviceName = cloudFoundryService .getConfig(CloudFoundryService.SERVICE_INSTANCE_NAME); if (!Strings.isEmpty(serviceName)){ Entities.waitForServiceUp(cloudFoundryService, cloudFoundryService.getConfig(BrooklynConfigKeys.START_TIMEOUT)); bindingServiceToEntity(serviceName); setCredentialsOnService(cloudFoundryService); cloudFoundryService.operation(getEntity()); } else { log.error("Trying to get service instance name from {}, but getting null", cloudFoundryService); } } else { log.error("The service entity {} is not available from the application {}", new Object[]{rawEntity, getEntity()}); throw new NoSuchElementException("No entity matching id " + rawEntity.getId() + " in Management Context "+getEntity().getManagementContext()+ " during entity service binding "+getEntity().getId()); } }
Example 11
Source File: AuthHandler.java From brooklyn-server with Apache License 2.0 | 5 votes |
private String getExpectedCredentials() { if (Strings.isEmpty(password)) { return username; } else { return username + ":" + password; } }
Example 12
Source File: NginxTemplateConfigGenerator.java From brooklyn-library with Apache License 2.0 | 5 votes |
@Override public String generateConfigFile(NginxDriver driver, NginxController nginx) { // Check template URL exists String templateUrl = driver.getEntity().getConfig(NginxController.SERVER_CONF_TEMPLATE_URL); ResourceUtils.create(this).checkUrlExists(templateUrl); // Check SSL configuration ProxySslConfig ssl = driver.getEntity().getConfig(NginxController.SSL_CONFIG); if (ssl != null && Strings.isEmpty(ssl.getCertificateDestination()) && Strings.isEmpty(ssl.getCertificateSourceUrl())) { throw new IllegalStateException("ProxySslConfig can't have a null certificateDestination and null certificateSourceUrl. One or both need to be set"); } // For mapping by URL Iterable<UrlMapping> mappings = ((NginxController) driver.getEntity()).getUrlMappings(); Multimap<String, UrlMapping> mappingsByDomain = LinkedHashMultimap.create(); for (UrlMapping mapping : mappings) { Collection<String> addrs = mapping.getAttribute(UrlMapping.TARGET_ADDRESSES); if (addrs != null && addrs.size() > 0) { mappingsByDomain.put(mapping.getDomain(), mapping); } } Map<String, Object> substitutions = MutableMap.<String, Object>builder() .putIfNotNull("ssl", ssl) .put("urlMappings", mappings) .put("domainMappings", mappingsByDomain) .build(); // Get template contents and process String contents = ResourceUtils.create(driver.getEntity()).getResourceAsString(templateUrl); return TemplateProcessor.processTemplateContents(contents, driver, substitutions); }
Example 13
Source File: NginxDefaultConfigGenerator.java From brooklyn-library with Apache License 2.0 | 5 votes |
protected void appendCodeForProxySSLConfig(String id, StringBuilder out, String prefix, ProxySslConfig ssl) { if (ssl.getTargetIsSsl() && ssl.getVerifyClient()) { // Send 403 if not verified, otherwise pass on the client certificate we received out.append(prefix).append("if ($ssl_client_verify != SUCCESS) { return 403; }\n"); out.append(prefix).append("proxy_set_header ssl.client_cert $ssl_client_cert;\n"); // Use the configured SSL certificate and key for the proxied server String cert; if (Strings.isEmpty(ssl.getCertificateDestination())) { cert = "" + id + ".crt"; } else { cert = ssl.getCertificateDestination(); } out.append(prefix); out.append("proxy_ssl_certificate " + cert + ";\n"); String key; if (!Strings.isEmpty(ssl.getKeyDestination())) { key = ssl.getKeyDestination(); } else if (!Strings.isEmpty(ssl.getKeySourceUrl())) { key = "" + id + ".key"; } else { key = null; } if (key != null) { out.append(prefix); out.append("proxy_ssl_certificate_key " + key + ";\n"); } } }
Example 14
Source File: PhpHttpdSshDriver.java From SeaCloudsPlatform with Apache License 2.0 | 5 votes |
private String resolveConfigName(String inputName) { String result; if (Strings.isEmpty(inputName)) { result = getEntity().getAppName() + ".conf"; } else if (!inputName.endsWith(".conf")) { result = inputName + ".conf"; } else { result = inputName; } getEntity().setSiteConfigurationFile(result); // Updating the sensor return result; }
Example 15
Source File: SshMachineLocation.java From brooklyn-server with Apache License 2.0 | 5 votes |
public HostAndPort getSshHostAndPort() { String host = getConfig(SSH_HOST); if (host == null || Strings.isEmpty(host)) host = address.getHostName(); Integer port = getPort(); return HostAndPort.fromParts(host, port); }
Example 16
Source File: NginxDefaultConfigGenerator.java From brooklyn-library with Apache License 2.0 | 4 votes |
protected boolean appendSslConfig(String id, StringBuilder out, String prefix, ProxySslConfig ssl, boolean sslBlock, boolean certificateBlock) { if (ssl == null) return false; if (sslBlock) { out.append(prefix); out.append("ssl on;\n"); } if (ssl.getReuseSessions()) { out.append(prefix); out.append(""); } if (certificateBlock) { String cert; if (Strings.isEmpty(ssl.getCertificateDestination())) { cert = "" + id + ".crt"; } else { cert = ssl.getCertificateDestination(); } out.append(prefix); out.append("ssl_certificate " + cert + ";\n"); String key; if (!Strings.isEmpty(ssl.getKeyDestination())) { key = ssl.getKeyDestination(); } else if (!Strings.isEmpty(ssl.getKeySourceUrl())) { key = "" + id + ".key"; } else { key = null; } if (key != null) { out.append(prefix); out.append("ssl_certificate_key " + key + ";\n"); } if (ssl.getVerifyClient()) { out.append("ssl_verify_client on;\n"); String client; if (Strings.isEmpty(ssl.getClientCertificateDestination())) { client = "" + id + ".cli"; } else { client = ssl.getClientCertificateDestination(); } if (client != null) { out.append(prefix); out.append("ssl_client_certificate " + client + ";\n"); } } out.append("ssl_protocols TLSv1 TLSv1.1 TLSv1.2;\n"); } return true; }
Example 17
Source File: BrooklynMavenArtifacts.java From brooklyn-server with Apache License 2.0 | 4 votes |
public static MavenArtifact artifact(String subgroupUnderIoBrooklyn, String artifactId, String packaging, String classifier) { return new MavenArtifact( Strings.isEmpty(subgroupUnderIoBrooklyn) ? "org.apache.brooklyn" : "org.apache.brooklyn."+subgroupUnderIoBrooklyn, artifactId, packaging, classifier, BrooklynVersion.get()); }
Example 18
Source File: SshCliTool.java From brooklyn-server with Apache License 2.0 | 4 votes |
private int scpToServer(Map<String,?> props, File local, String remote) { String to = (Strings.isEmpty(getUsername()) ? "" : getUsername()+"@")+getHostAddress()+":"+remote; return scpExec(props, local.getAbsolutePath(), to); }
Example 19
Source File: NginxDefaultConfigGenerator.java From brooklyn-library with Apache License 2.0 | 4 votes |
protected void verifyConfig(ProxySslConfig proxySslConfig) { if(Strings.isEmpty(proxySslConfig.getCertificateDestination()) && Strings.isEmpty(proxySslConfig.getCertificateSourceUrl())){ throw new IllegalStateException("ProxySslConfig can't have a null certificateDestination and null certificateSourceUrl. One or both need to be set"); } }
Example 20
Source File: BrooklynWebServer.java From brooklyn-server with Apache License 2.0 | 4 votes |
private SslContextFactory createContextFactory() throws KeyStoreException { SslContextFactory sslContextFactory = new SslContextFactory(); // allow webconsole keystore & related properties to be set in brooklyn.properties String ksUrl = getKeystoreUrl(); String ksPassword = getConfig(keystorePassword, BrooklynWebConfig.KEYSTORE_PASSWORD); String ksCertAlias = getConfig(keystoreCertAlias, BrooklynWebConfig.KEYSTORE_CERTIFICATE_ALIAS); String trProtos = getConfig(transportProtocols, BrooklynWebConfig.TRANSPORT_PROTOCOLS); String trCiphers = getConfig(transportCiphers, BrooklynWebConfig.TRANSPORT_CIPHERS); if (ksUrl!=null) { sslContextFactory.setKeyStorePath(getLocalKeyStorePath(ksUrl)); if (Strings.isEmpty(ksPassword)) throw new IllegalArgumentException("Keystore password is required and non-empty if keystore is specified."); sslContextFactory.setKeyStorePassword(ksPassword); if (Strings.isNonEmpty(ksCertAlias)) sslContextFactory.setCertAlias(ksCertAlias); } else { log.info("No keystore specified but https enabled; creating a default keystore"); if (Strings.isEmpty(ksCertAlias)) ksCertAlias = "web-console"; // if password is blank the process will block and read from stdin ! if (Strings.isEmpty(ksPassword)) { ksPassword = Identifiers.makeRandomId(8); log.debug("created random password "+ksPassword+" for ad hoc internal keystore"); } KeyStore ks = SecureKeys.newKeyStore(); KeyPair key = SecureKeys.newKeyPair(); X509Certificate cert = new FluentKeySigner("brooklyn").newCertificateFor("web-console", key); ks.setKeyEntry(ksCertAlias, key.getPrivate(), ksPassword.toCharArray(), new Certificate[] { cert }); sslContextFactory.setKeyStore(ks); sslContextFactory.setKeyStorePassword(ksPassword); sslContextFactory.setCertAlias(ksCertAlias); } if (!Strings.isEmpty(truststorePath)) { sslContextFactory.setTrustStorePath(checkFileExists(truststorePath, "truststore")); sslContextFactory.setTrustStorePassword(trustStorePassword); } if (Strings.isNonBlank(trProtos)) { sslContextFactory.setIncludeProtocols(parseArray(trProtos)); } if (Strings.isNonBlank(trCiphers)) { sslContextFactory.setIncludeCipherSuites(parseArray(trCiphers)); } return sslContextFactory; }