Search in sources :

Example 56 with Feature

use of io.fabric8.agent.model.Feature in project fabric8 by jboss-fuse.

the class JoinTest method testJoin.

@Test
public void testJoin() throws Exception {
    System.err.println(CommandSupport.executeCommand("fabric:create --force --clean -n --wait-for-provisioning"));
    BundleContext moduleContext = ServiceLocator.getSystemContext();
    ServiceProxy<FabricService> fabricProxy = ServiceProxy.createServiceProxy(moduleContext, FabricService.class);
    try {
        FabricService fabricService = fabricProxy.getService();
        AdminService adminService = ServiceLocator.awaitService(AdminService.class);
        String version = System.getProperty("fabric.version");
        System.err.println(CommandSupport.executeCommand("admin:create -o '-server -Xmx1536M -Dcom.sun.management.jmxremote -XX:+UnlockDiagnosticVMOptions -XX:+UnsyncloadClass -Dpatching.disabled=true -Djava.security.egd=file:/dev/./urandom' --featureURL mvn:io.fabric8/fabric8-karaf/" + version + "/xml/features --feature fabric-git --feature fabric-agent --feature fabric-boot-commands smoke_child_d"));
        try {
            System.err.println(CommandSupport.executeCommand("admin:start smoke_child_d"));
            ProvisionSupport.instanceStarted(Arrays.asList("smoke_child_d"), ProvisionSupport.PROVISION_TIMEOUT);
            System.err.println(CommandSupport.executeCommand("admin:list"));
            String joinCommand = "fabric:join -f --zookeeper-password " + fabricService.getZookeeperPassword() + " " + fabricService.getZookeeperUrl();
            String response = "";
            for (int i = 0; i < 10 && !response.contains("true"); i++) {
                response = CommandSupport.executeCommand("ssh:ssh -l karaf -P karaf -p " + adminService.getInstance("smoke_child_d").getSshPort() + " localhost " + WAIT_FOR_JOIN_SERVICE);
                Thread.sleep(1000);
            }
            System.err.println(CommandSupport.executeCommand("ssh:ssh -l karaf -P karaf -p " + adminService.getInstance("smoke_child_d").getSshPort() + " localhost " + joinCommand));
            ProvisionSupport.containersExist(Arrays.asList("smoke_child_d"), ProvisionSupport.PROVISION_TIMEOUT);
            Container childD = fabricService.getContainer("smoke_child_d");
            System.err.println(CommandSupport.executeCommand("fabric:container-list"));
            ProvisionSupport.containerStatus(Arrays.asList(childD), "success", ProvisionSupport.PROVISION_TIMEOUT);
            System.err.println(CommandSupport.executeCommand("fabric:container-list"));
        } finally {
            System.err.println(CommandSupport.executeCommand("admin:stop smoke_child_d"));
        }
    } finally {
        fabricProxy.close();
    }
}
Also used : Container(io.fabric8.api.Container) AdminService(org.apache.karaf.admin.AdminService) FabricService(io.fabric8.api.FabricService) BundleContext(org.osgi.framework.BundleContext) Test(org.junit.Test)

Example 57 with Feature

use of io.fabric8.agent.model.Feature in project fabric8 by jboss-fuse.

the class ContainerUpgradeAndRollbackTest method testContainerUpgradeAndRollback.

/**
 * This tests the simple scenario of
 * 1. create a child container
 * 2. create a new version
 * 3. modify the profile of the new version
 * 4. upgrade all containers
 * 5. verify that child is provisioned according to the new version
 * 6. rollback containers.
 * 7. verify that the child is provisioned according to the old version.
 */
@Test
@SuppressWarnings("unchecked")
public void testContainerUpgradeAndRollback() throws Exception {
    CommandSupport.executeCommand("fabric:create --force --clean -n  --wait-for-provisioning");
    BundleContext moduleContext = ServiceLocator.getSystemContext();
    ServiceProxy<FabricService> fabricProxy = ServiceProxy.createServiceProxy(moduleContext, FabricService.class);
    try {
        FabricService fabricService = fabricProxy.getService();
        Set<Container> containers = null;
        try {
            CommandSupport.executeCommand("fabric:version-create --parent 1.0 1.1");
            // Make sure that the profile change has been applied before changing the version
            CountDownLatch latch = WaitForConfigurationChange.on(fabricService);
            CommandSupport.executeCommand("fabric:profile-edit --feature camel-script --feature camel-hazelcast feature-camel 1.1");
            Assert.assertTrue(latch.await(5, TimeUnit.SECONDS));
            CommandSupport.executeCommand("fabric:profile-display --version 1.1 feature-camel");
            containers = ContainerBuilder.create().withName("smoke_camel").withProfiles("feature-camel").assertProvisioningResult().build(fabricService);
            CommandSupport.executeCommand("fabric:container-upgrade --all 1.1");
            ProvisionSupport.provisioningSuccess(containers, ProvisionSupport.PROVISION_TIMEOUT);
            CommandSupport.executeCommand("fabric:container-list");
            for (Container container : containers) {
                Assert.assertEquals("Container should have version 1.1", "1.1", container.getVersion().getId());
                String bundles = CommandSupport.executeCommand("fabric:container-connect -u admin -p admin " + container.getId() + " osgi:list -t 0 -s | grep camel-hazelcast");
                Assert.assertNotNull(bundles);
                System.out.println(bundles);
                Assert.assertFalse("Expected camel-hazelcast installed on container: " + container.getId(), bundles.isEmpty());
            }
            CommandSupport.executeCommand("fabric:container-rollback --all 1.0");
            ProvisionSupport.provisioningSuccess(containers, ProvisionSupport.PROVISION_TIMEOUT);
            CommandSupport.executeCommand("fabric:container-list");
            for (Container container : containers) {
                Assert.assertEquals("Container should have version 1.0", "1.0", container.getVersion().getId());
                String bundles = CommandSupport.executeCommand("fabric:container-connect -u admin -p admin " + container.getId() + " osgi:list -t 0 -s | grep camel-hazelcast");
                Assert.assertNotNull(bundles);
                System.out.println(bundles);
                Assert.assertTrue("Expected no camel-hazelcast installed on container: " + container.getId(), bundles.isEmpty());
            }
        } finally {
            ContainerBuilder.stop(fabricService, containers);
        }
    } finally {
        fabricProxy.close();
    }
}
Also used : Container(io.fabric8.api.Container) FabricService(io.fabric8.api.FabricService) CountDownLatch(java.util.concurrent.CountDownLatch) BundleContext(org.osgi.framework.BundleContext) Test(org.junit.Test)

Example 58 with Feature

use of io.fabric8.agent.model.Feature in project fabric8-maven-plugin by fabric8io.

the class KarafHealthCheckEnricher method discoverKarafProbe.

// 
// Karaf has a readiness/health URL exposed if the fabric8-karaf-check feature is installed.
// 
private Probe discoverKarafProbe(String path, int initialDelay) {
    for (Plugin plugin : this.getProject().getBuildPlugins()) {
        if ("karaf-maven-plugin".equals(plugin.getArtifactId())) {
            Xpp3Dom configuration = (Xpp3Dom) plugin.getConfiguration();
            if (configuration == null)
                return null;
            Xpp3Dom startupFeatures = configuration.getChild("startupFeatures");
            if (startupFeatures == null)
                return null;
            for (Xpp3Dom feature : startupFeatures.getChildren("feature")) {
                if ("fabric8-karaf-checks".equals(feature.getValue())) {
                    // TODO: handle the case where the user changes the default port
                    return new ProbeBuilder().withNewHttpGet().withNewPort(DEFAULT_HEALTH_CHECK_PORT).withPath(path).endHttpGet().withInitialDelaySeconds(initialDelay).build();
                }
            }
        }
    }
    return null;
}
Also used : Xpp3Dom(org.codehaus.plexus.util.xml.Xpp3Dom) ProbeBuilder(io.fabric8.kubernetes.api.model.ProbeBuilder) Plugin(org.apache.maven.model.Plugin)

Example 59 with Feature

use of io.fabric8.agent.model.Feature in project fabric8 by fabric8io.

the class Java2SwaggerJsonMojo method execute.

public void execute() throws MojoExecutionException {
    List<Class<?>> resourceClasses = loadResourceClasses();
    List<Object> resourceObjects = new ArrayList<Object>();
    for (Class<?> resourceClass : resourceClasses) {
        try {
            resourceObjects.add(resourceClass.newInstance());
        } catch (InstantiationException e) {
            throw new MojoExecutionException(e.getMessage(), e);
        } catch (IllegalAccessException e) {
            throw new MojoExecutionException(e.getMessage(), e);
        }
    }
    Thread.currentThread().setContextClassLoader(getClassLoader());
    List<Feature> features = new ArrayList<Feature>();
    features.add(new SwaggerFeature());
    JAXRSServerFactoryBean serverFacBean = new JAXRSServerFactoryBean();
    serverFacBean.setAddress(address);
    serverFacBean.setServiceBeans(resourceObjects);
    serverFacBean.setFeatures(features);
    Server server = serverFacBean.create();
    InputStream in = null;
    try {
        String serverAddress = server.getEndpoint().getEndpointInfo().getAddress();
        String apiDocs = serverAddress + "/swagger.json";
        URL url = new URL(apiDocs);
        in = url.openStream();
        String res = getStringFromInputStream(in);
        generateJson(resourceClasses, res);
    } catch (Exception e) {
        throw new MojoExecutionException(e.getMessage(), e);
    } finally {
        server.stop();
    }
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) Server(org.apache.cxf.endpoint.Server) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) JAXRSServerFactoryBean(org.apache.cxf.jaxrs.JAXRSServerFactoryBean) SwaggerFeature(io.fabric8.cxf.endpoint.SwaggerFeature) Feature(org.apache.cxf.feature.Feature) URL(java.net.URL) IOException(java.io.IOException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) SwaggerFeature(io.fabric8.cxf.endpoint.SwaggerFeature)

Aggregations

Test (org.junit.Test)20 HashMap (java.util.HashMap)18 FabricService (io.fabric8.api.FabricService)15 IOException (java.io.IOException)13 Feature (io.fabric8.agent.model.Feature)12 Container (io.fabric8.api.Container)11 Profile (io.fabric8.api.Profile)11 ArrayList (java.util.ArrayList)11 File (java.io.File)10 Map (java.util.Map)9 BundleContext (org.osgi.framework.BundleContext)9 HashSet (java.util.HashSet)8 URL (java.net.URL)7 BundleException (org.osgi.framework.BundleException)7 Repository (io.fabric8.agent.model.Repository)6 Version (io.fabric8.api.Version)6 LinkedHashSet (java.util.LinkedHashSet)6 Ignore (org.junit.Ignore)6 BundleInfo (io.fabric8.agent.model.BundleInfo)5 ContainerProxy (io.fabric8.itests.paxexam.support.ContainerProxy)5