@Override protected Map getCustomJavaSystemProperties() { VanillaJavaApp entity = getEntity(); Map result = new HashMap(); result.putAll(super.getCustomJavaSystemProperties()); result.putAll(entity.getJvmDefines()); return result; }
public void installJmxSupport() { if (isJmxEnabled()) { newScript("JMX_SETUP_PREINSTALL").body.append("mkdir -p "+getRunDir()).execute(); new JmxSupport(getEntity(), getRunDir()).install(); } }
@Override protected List<String> getCustomJavaConfigOptions() { VanillaJavaApp entity = getEntity(); List<String> result = new LinkedList<String>(); result.addAll(super.getCustomJavaConfigOptions()); result.addAll(entity.getJvmXArgs()); return result; } }
/** * Return any JVM arguments required, other than the -D defines returned by {@link #getJmxJavaSystemProperties()} */ protected List<String> getJmxJavaConfigOptions() { List<String> result = new ArrayList<String>(); if (isJmxEnabled()) { result.addAll(new JmxSupport(getEntity(), getRunDir()).getJmxJavaConfigOptions()); } return result; }
@Override public Map<String, String> getShellEnvironment() { Map<String, String> orig = super.getShellEnvironment(); String origClasspath = orig.get("CLASSPATH"); String newClasspath = (origClasspath == null ? "" : origClasspath+":") + getRunDir()+"/conf/" + ":" + getRunDir()+"/lib/\"*\""; Map<String,String> results = new LinkedHashMap<String,String>(); results.putAll(orig); results.put("BROOKLYN_CLASSPATH", newClasspath); results.put("BROOKLYN_HOME", getBrooklynHome()); results.put("RUN", getRunDir()); return results; }
/** * Returns the complete set of Java system properties (-D defines) to set for the application. * <p> * This is exposed to the JVM as the contents of the {@code JAVA_OPTS} environment variable. Default * set contains config key, custom system properties, and JMX defines. * <p> * Null value means to set -Dkey otherwise it is -Dkey=value. * <p> * See {@link #getShellEnvironment()} for discussion of quoting/escaping strategy. */ protected Map<String,?> getJavaSystemProperties() { return MutableMap.<String,Object>builder() .putAll(getCustomJavaSystemProperties()) .putAll(isJmxEnabled() ? getJmxJavaSystemProperties() : Collections.<String,Object>emptyMap()) .putAll(entity.getConfig(UsesJava.JAVA_SYSPROPS)) .build(); }
Iterable<String> sysprops = Iterables.transform(getJavaSystemProperties().entrySet(), new Function<Map.Entry<String, ?>, String>() { public String apply(Map.Entry<String, ?> entry) { addAll(getJmxJavaConfigOptions()). addAll(getCustomJavaConfigOptions()). addAll(sysprops). build();
public void checkJavaHostnameBug() { try { ProcessTaskWrapper<Integer> hostnameLen = DynamicTasks.queue(SshEffectorTasks.ssh("hostname -f | wc | awk '{print $3}'")).block(); if (hostnameLen.getExitCode()==0) { Integer len = Integer.parseInt(hostnameLen.getStdout().trim()); if (len > 63) { // likely to cause a java crash due to java bug 7089443 -- set a new short hostname // http://mail.openjdk.java.net/pipermail/net-dev/2012-July/004603.html String newHostname = "br-"+getEntity().getId(); log.info("Detected likelihood of Java hostname bug with hostname length "+len+" for "+getEntity()+"; renaming "+getMachine()+" to hostname "+newHostname); DynamicTasks.queue(SshEffectorTasks.ssh( "hostname "+newHostname, "echo 127.0.0.1 "+newHostname+" > /etc/hosts").runAsRoot()).block(); } } } catch (Exception e) { log.warn("Error checking/fixing Java hostname bug: "+e, e); } }
@Override public BrooklynNodeImpl getEntity() { return (BrooklynNodeImpl) super.getEntity(); }
@Override public void start() { DynamicTasks.queue("install java", new Runnable() { public void run() { installJava(); }}); if (isJmxEnabled()) { DynamicTasks.queue("install jmx", new Runnable() { public void run() { installJmxSupport(); }}); } if (getEntity().getConfig(UsesJava.CHECK_JAVA_HOSTNAME_BUG)) { DynamicTasks.queue("check java hostname bug", new Runnable() { public void run() { checkJavaHostnameBug(); }}); } super.start(); }
public boolean installJava() { try { getLocation().acquireMutex("install:" + getLocation().getDisplayName(), "installing Java at " + getLocation()); log.debug("checking for java at " + entity + " @ " + getLocation()); int result = getLocation().execCommands("check java", Arrays.asList("which java")); if (result == 0) { log.debug("java detected at " + entity + " @ " + getLocation()); return true; } else { log.debug("java not detected at " + entity + " @ " + getLocation() + ", installing using BashCommands.installJava6"); result = newScript("INSTALL_OPENJDK").body.append( BashCommands.installJava6OrFail() log.warn("Unable to install Java at " + getLocation() + " for " + entity + " (and Java not detected); invalid result "+result+". " + "Will retry."); Time.sleep(Duration.TEN_SECONDS); result = newScript("INSTALL_OPENJDK").body.append( BashCommands.installJava6OrFail() ).execute(); if (result==0) { log.info("Succeeded installing Java at " + getLocation() + " for " + entity + " after retry."); return true; log.error("Unable to install Java at " + getLocation() + " for " + entity + " (and Java not detected), including one retry; invalid result "+result+". " + "Processes may fail to start.");
/** * Sets all JVM options (-X.. -D..) in an environment var JAVA_OPTS. * <p> * That variable is constructed from getJavaOpts(), then wrapped _unescaped_ in double quotes. An * error is thrown if there is an unescaped double quote in the string. All other unescaped * characters are permitted, but unless $var expansion or `command` execution is desired (although * this is not confirmed as supported) the generally caller should escape any such characters, for * example using {@link BashStringEscapes#escapeLiteralForDoubleQuotedBash(String)}. */ @Override public Map<String, String> getShellEnvironment() { for (String it : getJavaOpts()) { BashStringEscapes.assertValidForDoubleQuotingInBash(it); } // do not double quote here; the env var is double quoted subsequently; // spaces should be preceded by double-quote // (if dbl quotes are needed we could pass on the command-line instead of in an env var) String sJavaOpts = Joiner.on(" ").join(getJavaOpts()); // println "using java opts: $sJavaOpts" return MutableMap.<String, String> builder().putAll(super.getShellEnvironment()).put("JAVA_OPTS", sJavaOpts).build(); }
/** * Use RMI agent to provide JMX. */ @Override public Map<String, String> getShellEnvironment() { Map<String, String> orig = super.getShellEnvironment(); String kafkaJmxOpts = orig.remove("JAVA_OPTS"); return MutableMap.<String, String>builder() .putAll(orig) .putIfNotNull("KAFKA_JMX_OPTS", kafkaJmxOpts) .build(); }
/** * Return the configuration properties required to enable JMX for a Java application. * * These should be set as properties in the {@code JAVA_OPTS} environment variable when calling the * run script for the application. */ protected Map<String, ?> getJmxJavaSystemProperties() { MutableMap.Builder<String, Object> result = MutableMap.<String, Object> builder(); if (isJmxEnabled()) { new JmxSupport(getEntity(), getRunDir()).applyJmxJavaSystemProperties(result); } return result.build(); }
public VanillaJavaApp getEntity() { return (VanillaJavaApp) super.getEntity(); }
@Override public Map<String, String> getShellEnvironment() { return MutableMap.<String, String>builder() .putAll(super.getShellEnvironment()) .put("CASSANDRA_CONF", String.format("%s/conf", getRunDir())) .renameKey("JAVA_OPTS", "JVM_OPTS") .build(); } }
@Override protected Map getCustomJavaSystemProperties() { return MutableMap.<String, String>builder() .putAll(super.getCustomJavaSystemProperties()) .put("cassandra.confing", getCassandraConfigFileName()) .build(); }
public JavaWebAppSoftwareProcessImpl getEntity() { return (JavaWebAppSoftwareProcessImpl) super.getEntity(); }
@Override public Map<String, String> getShellEnvironment() { Map<String,String> orig = super.getShellEnvironment(); return MutableMap.<String,String>builder() .putAll(orig) .put("ACTIVEMQ_HOME", getRunDir()) .put("ACTIVEMQ_PIDFILE", getPidFile()) .put("ACTIVEMQ_OPTS", orig.get("JAVA_OPTS") != null ? orig.get("JAVA_OPTS") : "") .put("JAVA_OPTS", "") .build(); } }
public Map<String, Object> getCustomJavaSystemProperties() { return MutableMap.<String, Object>builder() .putAll(super.getCustomJavaSystemProperties()) .put("connector.port", getAmqpPort()) .put("management.enabled", "true") .put("management.jmxport.registryServer", getRmiRegistryPort()) .put("management.jmxport.connectorServer", getJmxPort()) .put("management.http.enabled", getHttpManagementPort() != null ? "true" : "false") .putIfNotNull("management.http.port", getHttpManagementPort()) .build(); }