Search in sources :

Example 41 with Configuration

use of io.fabric8.maven.core.model.Configuration in project fabric8 by jboss-fuse.

the class FabricDetectingGateway method activate.

@Activate
void activate(Map<String, ?> configuration) throws Exception {
    shutdownTacker = new ShutdownTracker();
    initialize(configuration);
}
Also used : ShutdownTracker(io.fabric8.common.util.ShutdownTracker)

Example 42 with Configuration

use of io.fabric8.maven.core.model.Configuration 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);
        }
    }
}
Also used : Container(io.fabric8.api.Container) BootstrapConfiguration(io.fabric8.zookeeper.bootstrap.BootstrapConfiguration) Configuration(org.osgi.service.cm.Configuration) ImmutableContainerBuilder(io.fabric8.internal.ImmutableContainerBuilder) RuntimeProperties(io.fabric8.api.RuntimeProperties) KeeperException(org.apache.zookeeper.KeeperException) IOException(java.io.IOException)

Example 43 with Configuration

use of io.fabric8.maven.core.model.Configuration in project fabric8 by jboss-fuse.

the class KarafContainerRegistration method isHttpsEnabled.

private boolean isHttpsEnabled() throws IOException {
    Configuration configuration = configAdmin.get().getConfiguration(HTTP_PID, null);
    Dictionary properties = configuration.getProperties();
    if (properties != null && properties.get(HTTPS_ENABLED) != null) {
        return Boolean.parseBoolean(String.valueOf(properties.get(HTTPS_ENABLED)));
    } else {
        return false;
    }
}
Also used : Dictionary(java.util.Dictionary) BootstrapConfiguration(io.fabric8.zookeeper.bootstrap.BootstrapConfiguration) Configuration(org.osgi.service.cm.Configuration)

Example 44 with Configuration

use of io.fabric8.maven.core.model.Configuration in project fabric8 by jboss-fuse.

the class KarafContainerRegistration method registerHttp.

private void registerHttp(Container container) throws Exception {
    boolean httpEnabled = isHttpEnabled();
    boolean httpsEnabled = isHttpsEnabled();
    Configuration configuration = configAdmin.get().getConfiguration(HTTP_PID, null);
    Dictionary<String, Object> dictionary = configuration == null ? null : configuration.getProperties();
    boolean changed = false;
    PortService.Lock lock = null;
    int httpPort = 0;
    int httpsPort = 0;
    if (httpEnabled) {
        try {
            lock = portService.get().acquirePortLock();
            httpPort = getHttpPort(container, lock);
            portService.get().registerPort(container, HTTP_PID, HTTP_BINDING_PORT_KEY, httpPort, lock);
        } finally {
            portService.get().releasePortLock(lock);
        }
        if (configuration != null) {
            changed = updateIfNeeded(dictionary, HTTP_BINDING_PORT_KEY, httpPort);
        }
    }
    if (httpsEnabled) {
        try {
            lock = portService.get().acquirePortLock();
            httpsPort = getHttpsPort(container, lock);
            portService.get().registerPort(container, HTTP_PID, HTTPS_BINDING_PORT_KEY, httpsPort, lock);
        } finally {
            portService.get().releasePortLock(lock);
        }
        changed |= updateIfNeeded(dictionary, HTTPS_BINDING_PORT_KEY, httpsPort);
    }
    String protocol = httpsEnabled && !httpEnabled ? "https" : "http";
    int httpConnectionPort = httpsEnabled && !httpEnabled ? getHttpsConnectionPort(container, httpsPort) : getHttpConnectionPort(container, httpPort);
    String httpUrl = getHttpUrl(protocol, container.getId(), httpConnectionPort);
    setData(curator.get(), CONTAINER_HTTP.getPath(container.getId()), httpUrl);
    if (configuration != null && changed) {
        configuration.update(dictionary);
    }
}
Also used : BootstrapConfiguration(io.fabric8.zookeeper.bootstrap.BootstrapConfiguration) Configuration(org.osgi.service.cm.Configuration) PortService(io.fabric8.api.PortService)

Example 45 with Configuration

use of io.fabric8.maven.core.model.Configuration in project fabric8 by jboss-fuse.

the class KarafContainerRegistration method isHttpEnabled.

private boolean isHttpEnabled() throws IOException {
    Configuration configuration = configAdmin.get().getConfiguration(HTTP_PID, null);
    Dictionary properties = configuration.getProperties();
    if (properties != null && properties.get(HTTP_ENABLED) != null) {
        return Boolean.parseBoolean(String.valueOf(properties.get(HTTP_ENABLED)));
    } else {
        return true;
    }
}
Also used : Dictionary(java.util.Dictionary) BootstrapConfiguration(io.fabric8.zookeeper.bootstrap.BootstrapConfiguration) Configuration(org.osgi.service.cm.Configuration)

Aggregations

ParallelTest (io.strimzi.test.annotations.ParallelTest)142 Kafka (io.strimzi.api.kafka.model.Kafka)138 KafkaBuilder (io.strimzi.api.kafka.model.KafkaBuilder)132 HashMap (java.util.HashMap)97 IOException (java.io.IOException)86 IntOrString (io.fabric8.kubernetes.api.model.IntOrString)83 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)80 Map (java.util.Map)79 StatefulSet (io.fabric8.kubernetes.api.model.apps.StatefulSet)76 ArrayList (java.util.ArrayList)76 List (java.util.List)70 TopologySpreadConstraint (io.fabric8.kubernetes.api.model.TopologySpreadConstraint)66 GenericKafkaListenerBuilder (io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerBuilder)66 Matchers.containsString (org.hamcrest.Matchers.containsString)58 Service (io.fabric8.kubernetes.api.model.Service)55 Collectors (java.util.stream.Collectors)55 Container (io.fabric8.kubernetes.api.model.Container)54 PersistentVolumeClaim (io.fabric8.kubernetes.api.model.PersistentVolumeClaim)50 Quantity (io.fabric8.kubernetes.api.model.Quantity)48 File (java.io.File)47