Search in sources :

Example 66 with io.fabric8.kubernetes.api.model

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

the class ZooKeeperClusterBootstrapImpl method cleanInternal.

private BootstrapConfiguration cleanInternal(final BundleContext syscontext, final BootstrapConfiguration bootConfig, RuntimeProperties runtimeProps) throws TimeoutException {
    LOGGER.debug("Begin clean fabric");
    try {
        Configuration zkClientCfg = null;
        Configuration zkServerCfg = null;
        Configuration[] configsSet = configAdmin.get().listConfigurations("(|(service.factoryPid=io.fabric8.zookeeper.server)(service.pid=io.fabric8.zookeeper))");
        if (configsSet != null) {
            for (Configuration cfg : configsSet) {
                // let's explicitly delete client config first
                if ("io.fabric8.zookeeper".equals(cfg.getPid())) {
                    zkClientCfg = cfg;
                }
                if ("io.fabric8.zookeeper.server".equals(cfg.getFactoryPid())) {
                    zkServerCfg = cfg;
                }
            }
        }
        File karafData = new File(data);
        // Setup the listener for unregistration of {@link BootstrapConfiguration}
        final CountDownLatch unregisterLatch = new CountDownLatch(1);
        ServiceListener listener = new ServiceListener() {

            @Override
            public void serviceChanged(ServiceEvent event) {
                if (event.getType() == ServiceEvent.UNREGISTERING) {
                    LOGGER.debug("Unregistering BootstrapConfiguration");
                    bootConfig.getComponentContext().getBundleContext().removeServiceListener(this);
                    unregisterLatch.countDown();
                }
            }
        };
        String filter = "(objectClass=" + BootstrapConfiguration.class.getName() + ")";
        // FABRIC-1052: register listener using the same bundle context that is used for listeners related to SCR
        bootConfig.getComponentContext().getBundleContext().addServiceListener(listener, filter);
        CountDownLatch unregisterLatch2 = null;
        if (syscontext.getServiceReference(CuratorComplete.class) != null) {
            unregisterLatch2 = new CountDownLatch(1);
            final CountDownLatch finalUnregisterLatch = unregisterLatch2;
            listener = new ServiceListener() {

                @Override
                public void serviceChanged(ServiceEvent event) {
                    if (event.getType() == ServiceEvent.UNREGISTERING) {
                        LOGGER.debug("Unregistering CuratorComplete");
                        bootConfig.getComponentContext().getBundleContext().removeServiceListener(this);
                        finalUnregisterLatch.countDown();
                    }
                }
            };
            bootConfig.getComponentContext().getBundleContext().addServiceListener(listener, "(objectClass=" + CuratorComplete.class.getName() + ")");
        }
        // Disable the BootstrapConfiguration component
        // ENTESB-4827: disabling BootstrapConfiguration leads to deactivation of FabricService and ProfileUrlHandler
        // and we have race condition if we're --cleaning after recently created fabric. previous fabric
        // started FabricConfigAdminBridge which scheduled CM updates for tens of PIDs - among others,
        // org.ops4j.pax.web, which leads to an attempt to reconfigure Jetty with "profile:jetty.xml"
        // and if we disable ProfileUrlHandler we may loose Jetty instance
        LOGGER.debug("Disable BootstrapConfiguration");
        ComponentContext componentContext = bootConfig.getComponentContext();
        componentContext.disableComponent(BootstrapConfiguration.COMPONENT_NAME);
        if (!unregisterLatch.await(30, TimeUnit.SECONDS))
            throw new TimeoutException("Timeout for unregistering BootstrapConfiguration service");
        if (unregisterLatch2 != null && !unregisterLatch2.await(30, TimeUnit.SECONDS))
            throw new TimeoutException("Timeout for unregistering CuratorComplete service");
        // Do the cleanup
        runtimeProps.clearRuntimeAttributes();
        cleanConfigurations(syscontext, zkClientCfg, zkServerCfg);
        cleanZookeeperDirectory(karafData);
        cleanGitDirectory(karafData);
        // Setup the registration listener for the new {@link BootstrapConfiguration}
        final CountDownLatch registerLatch = new CountDownLatch(1);
        final AtomicReference<ServiceReference<?>> sref = new AtomicReference<ServiceReference<?>>();
        listener = new ServiceListener() {

            @Override
            public void serviceChanged(ServiceEvent event) {
                if (event.getType() == ServiceEvent.REGISTERED) {
                    LOGGER.debug("Registered BootstrapConfiguration");
                    syscontext.removeServiceListener(this);
                    sref.set(event.getServiceReference());
                    registerLatch.countDown();
                }
            }
        };
        syscontext.addServiceListener(listener, "(objectClass=" + BootstrapConfiguration.class.getName() + ")");
        // Enable the {@link BootstrapConfiguration} component and await the registration of the respective service
        LOGGER.debug("Enable BootstrapConfiguration");
        componentContext.enableComponent(BootstrapConfiguration.COMPONENT_NAME);
        if (!registerLatch.await(30, TimeUnit.SECONDS))
            throw new TimeoutException("Timeout for registering BootstrapConfiguration service");
        return (BootstrapConfiguration) syscontext.getService(sref.get());
    } catch (RuntimeException rte) {
        throw rte;
    } catch (TimeoutException toe) {
        throw toe;
    } catch (Exception ex) {
        throw new FabricException("Unable to delete zookeeper configuration", ex);
    } finally {
        LOGGER.debug("End clean fabric");
    }
}
Also used : ServiceListener(org.osgi.framework.ServiceListener) BootstrapConfiguration(io.fabric8.zookeeper.bootstrap.BootstrapConfiguration) Configuration(org.osgi.service.cm.Configuration) ComponentContext(org.osgi.service.component.ComponentContext) BootstrapConfiguration(io.fabric8.zookeeper.bootstrap.BootstrapConfiguration) FabricException(io.fabric8.api.FabricException) AtomicReference(java.util.concurrent.atomic.AtomicReference) CuratorComplete(io.fabric8.api.CuratorComplete) CountDownLatch(java.util.concurrent.CountDownLatch) TimeoutException(java.util.concurrent.TimeoutException) BundleException(org.osgi.framework.BundleException) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) FabricException(io.fabric8.api.FabricException) IOException(java.io.IOException) ServiceReference(org.osgi.framework.ServiceReference) ServiceEvent(org.osgi.framework.ServiceEvent) File(java.io.File) TimeoutException(java.util.concurrent.TimeoutException)

Example 67 with io.fabric8.kubernetes.api.model

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

the class ZooKeeperClusterServiceImpl method publicPort.

private String publicPort(String containerName, final String port) {
    FabricService fabric = fabricService.get();
    Container container = fabric.getContainer(containerName);
    String user = ZooKeeperUtils.getContainerLogin(runtimeProperties.get());
    String password = "";
    try {
        Properties containerTokens = ZooKeeperUtils.getContainerTokens(obtainValid(curator));
        password = containerTokens.getProperty(user);
    } catch (Exception e) {
        LOGGER.error("Unable to get temp ZK user/pass for administrative purposes", e);
    }
    ContainerTemplate containerTemplate = new ContainerTemplate(container, user, password, false);
    return containerTemplate.execute(new JmxTemplateSupport.JmxConnectorCallback<String>() {

        @Override
        public String doWithJmxConnector(JMXConnector connector) throws Exception {
            return connector.getMBeanServerConnection().invoke(new ObjectName("io.fabric8:type=Fabric"), "getPublicPortOnCurrentContainer", new Object[] { new Integer(port) }, new String[] { "int" }).toString();
        }
    });
}
Also used : ContainerTemplate(io.fabric8.service.ContainerTemplate) JmxTemplateSupport(io.fabric8.service.JmxTemplateSupport) JMXConnector(javax.management.remote.JMXConnector) Properties(java.util.Properties) ObjectName(javax.management.ObjectName)

Example 68 with io.fabric8.kubernetes.api.model

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

the class FabricManagerTest method toJson.

@Test
public void toJson() throws JsonProcessingException {
    JMXRequest r = new JMXRequest();
    r.setId("id");
    r.withObjectName("io.fabric8:type=manager");
    r.withParam(Boolean.class, true);
    System.out.println(om().writeValueAsString(r));
    JMXResult res = new JMXResult();
    res.setCode(0);
    res.setMessage("OK");
    res.setCorrelationId("id");
    GitVersion v = new GitVersion("1.0");
    v.setSha1("SHA1");
    GitVersions versions = new GitVersions();
    versions.getVersions().addAll(Arrays.asList(v, v, v));
    res.setResponse(versions);
    System.out.println(om().writeValueAsString(res));
    System.out.println(om().writeValueAsString(versions));
}
Also used : GitVersion(io.fabric8.api.commands.GitVersion) JMXRequest(io.fabric8.api.commands.JMXRequest) GitVersions(io.fabric8.api.commands.GitVersions) JMXResult(io.fabric8.api.commands.JMXResult) Test(org.junit.Test)

Example 69 with io.fabric8.kubernetes.api.model

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

the class FabricManagerTest method fromJson.

@Test
public void fromJson() throws IOException {
    JMXResult res = om().readValue("{\"correlationId\":\"id\",\"code\":0,\"message\":\"OK\",\"response\":{\"@class\":\"io.fabric8.api.commands.GitVersions\",\"versions\":[{\"version\":\"1.0\",\"sha1\":\"SHA1\",\"timestamp\":null,\"message\":null},{\"version\":\"1.0\",\"sha1\":\"SHA1\",\"timestamp\":null,\"message\":null},{\"version\":\"1.0\",\"sha1\":\"SHA1\",\"timestamp\":null,\"message\":null}]}}", JMXResult.class);
    assertNotNull(res);
    assertThat(res.getMessage(), equalTo("OK"));
    assertThat(((GitVersions) res.getResponse()).getVersions().get(2).getSha1(), equalTo("SHA1"));
    assertThat(((GitVersions) res.getResponse()).getVersions().size(), equalTo(3));
}
Also used : GitVersions(io.fabric8.api.commands.GitVersions) JMXResult(io.fabric8.api.commands.JMXResult) Test(org.junit.Test)

Example 70 with io.fabric8.kubernetes.api.model

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

the class ExtendedCreateChildContainerTest method deployment.

@Deployment
@StartLevelAware(autostart = true)
public static Archive<?> deployment() {
    final JavaArchive archive = ShrinkWrap.create(JavaArchive.class, "extended-child-container-test.jar");
    archive.addPackage(CommandSupport.class.getPackage());
    archive.setManifest(new Asset() {

        @Override
        public InputStream openStream() {
            OSGiManifestBuilder builder = OSGiManifestBuilder.newInstance();
            builder.addBundleManifestVersion(2);
            builder.addBundleSymbolicName(archive.getName());
            builder.addBundleVersion("1.0.0");
            builder.addImportPackages(ServiceLocator.class, FabricService.class);
            builder.addImportPackages("io.fabric8.git");
            builder.addImportPackages(AbstractCommand.class, Action.class);
            builder.addImportPackage("org.apache.felix.service.command;status=provisional");
            builder.addImportPackages(ConfigurationAdmin.class, ServiceTracker.class, Logger.class);
            builder.addImportPackages(CuratorFramework.class, ZooKeeperUtils.class, ZkPath.class);
            return builder.openStream();
        }
    });
    return archive;
}
Also used : Action(org.apache.felix.gogo.commands.Action) ServiceTracker(org.osgi.util.tracker.ServiceTracker) InputStream(java.io.InputStream) AbstractCommand(org.apache.felix.gogo.commands.basic.AbstractCommand) ZooKeeperUtils(io.fabric8.zookeeper.utils.ZooKeeperUtils) ZkPath(io.fabric8.zookeeper.ZkPath) Logger(org.slf4j.Logger) JavaArchive(org.jboss.shrinkwrap.api.spec.JavaArchive) ServiceLocator(io.fabric8.api.gravia.ServiceLocator) CuratorFramework(org.apache.curator.framework.CuratorFramework) FabricService(io.fabric8.api.FabricService) OSGiManifestBuilder(org.jboss.osgi.metadata.OSGiManifestBuilder) Asset(org.jboss.shrinkwrap.api.asset.Asset) ConfigurationAdmin(org.osgi.service.cm.ConfigurationAdmin) CommandSupport(io.fabric8.itests.support.CommandSupport) StartLevelAware(org.jboss.arquillian.osgi.StartLevelAware) Deployment(org.jboss.arquillian.container.test.api.Deployment)

Aggregations

Test (org.junit.Test)29 FabricService (io.fabric8.api.FabricService)26 File (java.io.File)22 ConfigurationAdmin (org.osgi.service.cm.ConfigurationAdmin)18 InputStream (java.io.InputStream)16 Logger (org.slf4j.Logger)16 ServiceLocator (io.fabric8.api.gravia.ServiceLocator)15 CommandSupport (io.fabric8.itests.support.CommandSupport)15 Deployment (org.jboss.arquillian.container.test.api.Deployment)15 StartLevelAware (org.jboss.arquillian.osgi.StartLevelAware)15 OSGiManifestBuilder (org.jboss.osgi.metadata.OSGiManifestBuilder)15 Asset (org.jboss.shrinkwrap.api.asset.Asset)15 JavaArchive (org.jboss.shrinkwrap.api.spec.JavaArchive)15 ServiceTracker (org.osgi.util.tracker.ServiceTracker)15 IOException (java.io.IOException)14 Action (org.apache.felix.gogo.commands.Action)14 AbstractCommand (org.apache.felix.gogo.commands.basic.AbstractCommand)14 MavenResolver (io.fabric8.maven.MavenResolver)11 Container (io.fabric8.api.Container)10 BundleContext (org.osgi.framework.BundleContext)9