use of io.fabric8.internal.ImmutableContainerBuilder in project fabric8 by jboss-fuse.
the class KarafContainerRegistration method configurationEvent.
/**
* Receives notification of a Configuration that has changed.
*
* @param event The <code>ConfigurationEvent</code>.
*/
@Override
public void configurationEvent(ConfigurationEvent event) {
if (isValid()) {
try {
Container current = new ImmutableContainerBuilder().id(runtimeIdentity).ip(ip).build();
RuntimeProperties sysprops = runtimeProperties.get();
String runtimeIdentity = sysprops.getRuntimeIdentity();
if (event.getPid().equals(SSH_PID) && event.getType() == ConfigurationEvent.CM_UPDATED) {
Configuration config = configAdmin.get().getConfiguration(SSH_PID, null);
int sshPort = Integer.parseInt((String) config.getProperties().get(SSH_BINDING_PORT_KEY));
int sshConnectionPort = getSshConnectionPort(current, sshPort);
String sshUrl = getSshUrl(runtimeIdentity, sshConnectionPort);
setData(curator.get(), CONTAINER_SSH.getPath(runtimeIdentity), sshUrl);
if (portService.get().lookupPort(current, SSH_PID, SSH_BINDING_PORT_KEY) != sshPort) {
portService.get().unregisterPort(current, SSH_PID);
portService.get().registerPort(current, SSH_PID, SSH_BINDING_PORT_KEY, sshPort);
}
}
if (event.getPid().equals(HTTP_PID) && event.getType() == ConfigurationEvent.CM_UPDATED) {
Configuration config = configAdmin.get().getConfiguration(HTTP_PID, null);
boolean httpEnabled = isHttpEnabled();
boolean httpsEnabled = isHttpsEnabled();
String protocol = httpsEnabled && !httpEnabled ? "https" : "http";
int httpConnectionPort = -1;
if (httpEnabled) {
int httpPort = Integer.parseInt((String) config.getProperties().get(HTTP_BINDING_PORT_KEY));
httpConnectionPort = getHttpConnectionPort(current, httpPort);
if (portService.get().lookupPort(current, HTTP_PID, HTTP_BINDING_PORT_KEY) != httpPort) {
portService.get().unregisterPort(current, HTTP_PID, HTTP_BINDING_PORT_KEY);
portService.get().registerPort(current, HTTP_PID, HTTP_BINDING_PORT_KEY, httpPort);
}
}
if (httpsEnabled) {
int httpsPort = Integer.parseInt((String) config.getProperties().get(HTTPS_BINDING_PORT_KEY));
if (httpConnectionPort == -1) {
httpConnectionPort = getHttpsConnectionPort(current, httpsPort);
}
if (portService.get().lookupPort(current, HTTP_PID, HTTPS_BINDING_PORT_KEY) != httpsPort) {
portService.get().unregisterPort(current, HTTP_PID, HTTPS_BINDING_PORT_KEY);
portService.get().registerPort(current, HTTP_PID, HTTPS_BINDING_PORT_KEY, httpsPort);
}
}
String httpUrl = getHttpUrl(protocol, runtimeIdentity, httpConnectionPort);
setData(curator.get(), CONTAINER_HTTP.getPath(runtimeIdentity), httpUrl);
}
if (event.getPid().equals(MANAGEMENT_PID) && event.getType() == ConfigurationEvent.CM_UPDATED) {
Configuration config = configAdmin.get().getConfiguration(MANAGEMENT_PID, null);
int rmiServerPort = Integer.parseInt((String) config.getProperties().get(RMI_SERVER_BINDING_PORT_KEY));
int rmiServerConnectionPort = getRmiServerConnectionPort(current, rmiServerPort);
int rmiRegistryPort = Integer.parseInt((String) config.getProperties().get(RMI_REGISTRY_BINDING_PORT_KEY));
int rmiRegistryConnectionPort = getRmiRegistryConnectionPort(current, rmiRegistryPort);
String jmxUrl = getJmxUrl(runtimeIdentity, rmiServerConnectionPort, rmiRegistryConnectionPort);
setData(curator.get(), CONTAINER_JMX.getPath(runtimeIdentity), jmxUrl);
// Whenever the JMX URL changes we need to make sure that the java.rmi.server.hostname points to a valid address.
System.setProperty(SystemProperties.JAVA_RMI_SERVER_HOSTNAME, current.getIp());
if (portService.get().lookupPort(current, MANAGEMENT_PID, RMI_REGISTRY_BINDING_PORT_KEY) != rmiRegistryPort || portService.get().lookupPort(current, MANAGEMENT_PID, RMI_SERVER_BINDING_PORT_KEY) != rmiServerPort) {
portService.get().unregisterPort(current, MANAGEMENT_PID);
portService.get().registerPort(current, MANAGEMENT_PID, RMI_SERVER_BINDING_PORT_KEY, rmiServerPort);
portService.get().registerPort(current, MANAGEMENT_PID, RMI_REGISTRY_BINDING_PORT_KEY, rmiRegistryPort);
}
}
} catch (Exception ex) {
LOGGER.error("Cannot reconfigure container", ex);
}
}
}
use of io.fabric8.internal.ImmutableContainerBuilder in project fabric8 by jboss-fuse.
the class KarafContainerRegistration method activateInternal.
private void activateInternal() {
RuntimeProperties sysprops = runtimeProperties.get();
runtimeIdentity = sysprops.getRuntimeIdentity();
String version = sysprops.getProperty("fabric.version", ZkDefs.DEFAULT_VERSION);
String profiles = sysprops.getProperty("fabric.profiles");
try {
if (profiles != null) {
String versionNode = CONFIG_CONTAINER.getPath(runtimeIdentity);
String profileNode = CONFIG_VERSIONS_CONTAINER.getPath(version, runtimeIdentity);
createDefault(curator.get(), versionNode, version);
createDefault(curator.get(), profileNode, profiles);
}
checkAlive();
String domainsNode = CONTAINER_DOMAINS.getPath(runtimeIdentity);
Stat stat = exists(curator.get(), domainsNode);
if (stat != null) {
deleteSafe(curator.get(), domainsNode);
}
boolean openshiftEnv = Strings.notEmpty(System.getenv("OPENSHIFT_FUSE_DIR"));
ZooKeeperUtils.createDefault(curator.get(), CONTAINER_BINDADDRESS.getPath(runtimeIdentity), bootstrapConfiguration.get().getBindAddress());
ZooKeeperUtils.createDefault(curator.get(), CONTAINER_RESOLVER.getPath(runtimeIdentity), getContainerResolutionPolicy(curator.get(), runtimeIdentity));
setData(curator.get(), CONTAINER_LOCAL_HOSTNAME.getPath(runtimeIdentity), HostUtils.getLocalHostName());
if (openshiftEnv) {
setData(curator.get(), CONTAINER_LOCAL_IP.getPath(runtimeIdentity), System.getenv("OPENSHIFT_FUSE_IP"));
setData(curator.get(), CONTAINER_PUBLIC_IP.getPath(runtimeIdentity), HostUtils.getLocalIp());
} else {
setData(curator.get(), CONTAINER_LOCAL_IP.getPath(runtimeIdentity), HostUtils.getLocalIp());
}
// Mostly usable for adding values when creating containers without an existing ensemble.
for (String resolver : ZkDefs.VALID_RESOLVERS) {
String address = (String) bootstrapConfiguration.get().getConfiguration().get(resolver);
if (address != null && !address.isEmpty() && exists(curator.get(), CONTAINER_ADDRESS.getPath(runtimeIdentity, resolver)) == null) {
setData(curator.get(), CONTAINER_ADDRESS.getPath(runtimeIdentity, resolver), address);
}
}
ip = getSubstitutedData(curator.get(), getContainerPointer(curator.get(), runtimeIdentity));
setData(curator.get(), CONTAINER_IP.getPath(runtimeIdentity), ip);
if (Boolean.parseBoolean(runtimeProperties.get().getProperty("service.geoip.enabled", "false"))) {
createDefault(curator.get(), CONTAINER_GEOLOCATION.getPath(runtimeIdentity), geoLocationService.get().getGeoLocation());
}
// We are creating a dummy container object, since this might be called before the actual container is ready.
Container current = new ImmutableContainerBuilder().id(runtimeIdentity).ip(ip).build();
if (System.getProperty(SystemProperties.JAVA_RMI_SERVER_HOSTNAME) == null) {
System.setProperty(SystemProperties.JAVA_RMI_SERVER_HOSTNAME, current.getIp());
}
registerJmx(current);
registerSsh(current);
registerHttp(current);
// Set the port range values
String minimumPort = sysprops.getProperty(ZkDefs.MINIMUM_PORT);
if (minimumPort == null) {
String minPort = (String) bootstrapConfiguration.get().getConfiguration().get("minimum.port");
minimumPort = minPort;
}
String maximumPort = sysprops.getProperty(ZkDefs.MAXIMUM_PORT);
if (maximumPort == null) {
String maxPort = (String) bootstrapConfiguration.get().getConfiguration().get("maximum.port");
maximumPort = maxPort;
}
createDefault(curator.get(), CONTAINER_PORT_MIN.getPath(runtimeIdentity), minimumPort);
createDefault(curator.get(), CONTAINER_PORT_MAX.getPath(runtimeIdentity), maximumPort);
} catch (Exception e) {
LOGGER.warn("Error updating Fabric Container information. This exception will be ignored.", e);
}
}
Aggregations