blob: 6e9c044cae615ce7930d8edda27d573f2ec090cb [file] [log] [blame]
package brooklyn.entity.osgi.karaf
import java.util.List
import java.util.Map
import brooklyn.entity.basic.EntityLocal;
import brooklyn.entity.basic.UsesJmx
import brooklyn.entity.basic.lifecycle.JavaStartStopSshDriver
import brooklyn.entity.webapp.PortPreconditions
import brooklyn.location.basic.SshMachineLocation
class KarafSshDriver extends JavaStartStopSshDriver {
// TODO getJmxJavaSystemProperties(), don't set via JAVA_OPTS; set ourselves manually
// (karaf reads from props files)
// but do set "java.rmi.server.hostname"
public KarafSshDriver(KarafContainer entity, SshMachineLocation machine) {
super(entity, machine)
}
@Override
public KarafContainer getEntity() { super.getEntity() }
@Override
protected String getLogFileLocation() { "${runDir}/data/karaf.out" }
protected String getUntarredDirName() { "apache-karaf-${version}" }
@Override
public void install() {
String url = "http://apache.mirror.anlx.net/karaf/${version}/apache-karaf-${version}.tar.gz"
String saveAs = "apache-karaf-${version}.tar.gz"
newScript(INSTALLING).
failOnNonZeroResultCode().
body.append(
"curl -L \"${url}\" -o ${saveAs} || exit 9",
"tar xzfv ${saveAs}",
).execute();
}
@Override
public void customize() {
PortPreconditions.checkPortsValid(jmxPort:jmxPort, rmiPort:rmiPort);
newScript(CUSTOMIZING).
body.append(
"cd ${runDir}",
"cp -R ${installDir}/$untarredDirName/{bin,etc,lib,system,deploy} . || exit \$!",
"sed -i.bk 's/rmiRegistryPort = 1099/rmiRegistryPort = ${jmxPort}/g' etc/org.apache.karaf.management.cfg",
"sed -i.bk 's/rmiServerPort = 44444/rmiServerPort = ${rmiPort}/g' etc/org.apache.karaf.management.cfg",
).execute();
}
@Override
public void launch() {
newScript(LAUNCHING, usePidFile:true).
body.append(
"nohup ./bin/start"
).execute();
}
@Override
public boolean isRunning() {
// TODO Can we use the pidFile, auto-generated by launch?
def pid = entity.getAttribute(KarafContainer.KARAF_PID)
// This method is called on startup, before JMX is initialised, so pid won't always be available.
if (pid != null) {
newScript(CHECK_RUNNING).
body.append(
"ps aux | grep 'karaf' | grep ${pid} > /dev/null"
).execute() == 0;
} else {
// Simple method isn't available, use pid in instance.properties.
newScript(CHECK_RUNNING).
body.append(
"cd ${runDir}/instances/",
"[ \$(uname) = \"Darwin\" ] && pid=\$(sed -n -e 's/.*pid=\\([0-9]*\\)\$/\\1/p' instance.properties) || pid=\$(sed -r -n -e 's/.*pid=([0-9]*)\$/\\1/p' instance.properties)",
"ps aux | grep 'karaf' | grep \$(echo \${pid:-X}) > /dev/null"
).execute() == 0;
}
}
@Override
public void stop() {
newScript(STOPPING).
body.append(
"${runDir}/bin/stop"
).execute();
}
@Override
protected List<String> getCustomJavaConfigOptions() {
return super.getCustomJavaConfigOptions() + ["-Xms200m", "-Xmx800m", "-XX:MaxPermSize=400m"]
}
// FIXME Playing around / experimenting with these jmx system properties to try to get it to work!
// With com.sun.management.jmxremote.port, then the Karaf container won't start at all; with that one removed then we just get "Not connected to JMX for entity Venue[id=ad7a6e47-e738-4687-b3bf-b9ad3aae449d,displayName=Venue:ad7a]"
@Override
protected Map getJmxJavaSystemProperties() {
// Map result = super.getJmxJavaSystemProperties()
// result.remove("com.sun.management.jmxremote.port")
// return result
return ["java.rmi.server.hostname" : machine.address.hostName]
}
}