Search in sources :

Example 6 with RuntimeProperties

use of io.fabric8.api.RuntimeProperties in project fabric8 by jboss-fuse.

the class ComponentConfigurer method configure.

@Override
public <T> Map<String, ?> configure(final Map<String, ?> configuration, T target, String... ignorePrefix) throws Exception {
    assertValid();
    Map<String, Object> result = new HashMap<>();
    final PropertiesProvider runtimeProperties = new PropertiesProvider() {

        @Override
        public Object getProperty(String key) {
            return bundleContext.getProperty(key);
        }

        @Override
        public Object getRequiredProperty(String key) {
            String value = bundleContext.getProperty(key);
            IllegalStateAssertion.assertNotNull(value, "Cannot obtain property: " + key);
            return value;
        }

        @Override
        public Object getProperty(String key, Object defaultValue) {
            String value = bundleContext.getProperty(key);
            return value != null ? value : defaultValue;
        }
    };
    final PropertiesProvider configurationProvider = new MapPropertiesProvider((Map<String, Object>) configuration);
    final PropertiesProvider[] propertiesProviders = new PropertiesProvider[] { configurationProvider, runtimeProperties };
    PropertiesProvider provider = new SubstitutionPropertiesProvider(propertiesProviders);
    for (Map.Entry<String, ?> entry : configuration.entrySet()) {
        String key = entry.getKey();
        Object value = provider.getProperty(key);
        result.put(key, value);
    }
    ConfigInjection.applyConfiguration(result, target, ignorePrefix);
    return result;
}
Also used : MapPropertiesProvider(io.fabric8.api.gravia.MapPropertiesProvider) PropertiesProvider(io.fabric8.api.gravia.PropertiesProvider) SubstitutionPropertiesProvider(io.fabric8.api.gravia.SubstitutionPropertiesProvider) SubstitutionPropertiesProvider(io.fabric8.api.gravia.SubstitutionPropertiesProvider) MapPropertiesProvider(io.fabric8.api.gravia.MapPropertiesProvider) HashMap(java.util.HashMap) HashMap(java.util.HashMap) Map(java.util.Map)

Example 7 with RuntimeProperties

use of io.fabric8.api.RuntimeProperties in project fabric8 by jboss-fuse.

the class ProfileServiceImpl method getOverlayAudit.

private OverlayAudit getOverlayAudit() {
    synchronized (runtimeProperties) {
        RuntimeProperties sysprops = runtimeProperties.get();
        OverlayAudit audit = sysprops.getRuntimeAttribute(OverlayAudit.class);
        if (audit == null) {
            sysprops.putRuntimeAttribute(OverlayAudit.class, audit = new OverlayAudit());
        }
        return audit;
    }
}
Also used : RuntimeProperties(io.fabric8.api.RuntimeProperties)

Example 8 with RuntimeProperties

use of io.fabric8.api.RuntimeProperties in project fabric8 by jboss-fuse.

the class ClusterBootstrapManager method createCluster.

@Override
public void createCluster(Map<String, Object> options) {
    assertValid();
    RuntimeProperties sysprops = runtimeProperties.get();
    CreateEnsembleOptions createEnsembleOptions = ClusterBootstrapManager.getCreateEnsembleOptions(sysprops, options);
    bootstrap.get().create(createEnsembleOptions);
}
Also used : CreateEnsembleOptions(io.fabric8.api.CreateEnsembleOptions) RuntimeProperties(io.fabric8.api.RuntimeProperties)

Example 9 with RuntimeProperties

use of io.fabric8.api.RuntimeProperties in project fabric8 by jboss-fuse.

the class ClusterServiceManager method removeFromCluster.

@Override
public void removeFromCluster(List<String> containers, Map<String, Object> options) {
    assertValid();
    RuntimeProperties sysprops = runtimeProperties.get();
    CreateEnsembleOptions createEnsembleOptions = ClusterBootstrapManager.getCreateEnsembleOptions(sysprops, options);
    removeFromCluster(containers, createEnsembleOptions);
}
Also used : CreateEnsembleOptions(io.fabric8.api.CreateEnsembleOptions) RuntimeProperties(io.fabric8.api.RuntimeProperties)

Example 10 with RuntimeProperties

use of io.fabric8.api.RuntimeProperties 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)

Aggregations

RuntimeProperties (io.fabric8.api.RuntimeProperties)24 IOException (java.io.IOException)12 File (java.io.File)9 AbstractRuntimeProperties (io.fabric8.api.scr.AbstractRuntimeProperties)6 BootstrapConfiguration (io.fabric8.zookeeper.bootstrap.BootstrapConfiguration)6 HashMap (java.util.HashMap)6 FabricException (io.fabric8.api.FabricException)5 MavenResolver (io.fabric8.maven.MavenResolver)5 CreateEnsembleOptions (io.fabric8.api.CreateEnsembleOptions)4 CountDownLatch (java.util.concurrent.CountDownLatch)4 HttpServletRequest (javax.servlet.http.HttpServletRequest)4 HttpServletResponse (javax.servlet.http.HttpServletResponse)4 Configuration (org.osgi.service.cm.Configuration)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 Map (java.util.Map)3 KeeperException (org.apache.zookeeper.KeeperException)3 Server (org.eclipse.jetty.server.Server)3 ServerConnector (org.eclipse.jetty.server.ServerConnector)3 Container (io.fabric8.api.Container)2 GitContext (io.fabric8.api.GitContext)2