Search in sources :

Example 71 with FabricService

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

the class ResolverTest method testCreateWithGlobalAndLocalResolver.

@Test
public void testCreateWithGlobalAndLocalResolver() throws Exception {
    System.out.println(CommandSupport.executeCommand("fabric:create --force --clean -n --wait-for-provisioning -g manualip -r localhostname --manual-ip localhost"));
    // System.out.println(executeCommand("shell:info"));
    // System.out.println(executeCommand("fabric:info"));
    // System.out.println(executeCommand("fabric:profile-list"));
    BundleContext moduleContext = ServiceLocator.getSystemContext();
    ServiceProxy<FabricService> fabricProxy = ServiceProxy.createServiceProxy(moduleContext, FabricService.class);
    try {
        FabricService fabricService = fabricProxy.getService();
        Container current = fabricService.getCurrentContainer();
        Assert.assertEquals("localhostname", current.getResolver());
    } finally {
        fabricProxy.close();
    }
}
Also used : Container(io.fabric8.api.Container) FabricService(io.fabric8.api.FabricService) BundleContext(org.osgi.framework.BundleContext) Test(org.junit.Test)

Example 72 with FabricService

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

the class DeploymentAgentTest method testFeatureRepoResolution.

@Test
@SuppressWarnings("unchecked")
public void testFeatureRepoResolution() throws Exception {
    CommandSupport.executeCommand("fabric:create --force --clean -n --wait-for-provisioning");
    // We are just want to use a feature repository that is not part of the distribution.
    CommandSupport.executeCommand("fabric:profile-create --parent feature-camel test-profile");
    CommandSupport.executeCommand("fabric:version-create --parent 1.0 1.1");
    CommandSupport.executeCommand("fabric:profile-edit --repository mvn:io.fabric8.examples.fabric-camel-dosgi/features/" + System.getProperty("fabric.version") + "/xml/features test-profile 1.1");
    CommandSupport.executeCommand("fabric:profile-edit --feature fabric-dosgi test-profile 1.1");
    // We remove all repositories from agent config but the maven central to rely on the fabric-maven-proxy.
    // Also remove local repository
    CommandSupport.executeCommand("fabric:profile-edit --pid io.fabric8.agent/org.ops4j.pax.url.mvn.repositories=http://repo1.maven.org/maven2@id=m2central default 1.1");
    CommandSupport.executeCommand("fabric:profile-edit --pid test-profile 1.1");
    BundleContext moduleContext = ServiceLocator.getSystemContext();
    ServiceProxy<FabricService> fabricProxy = ServiceProxy.createServiceProxy(moduleContext, FabricService.class);
    try {
        FabricService fabricService = fabricProxy.getService();
        Set<Container> containers = ContainerBuilder.create().withName("smoke_cnt_a").withProfiles("test-profile").assertProvisioningResult().build(fabricService);
        try {
            // We want to remove all repositories from fabric-agent.
            for (Container container : containers) {
                CommandSupport.executeCommand("fabric:container-upgrade 1.1 " + container.getId());
                System.out.flush();
            }
            ProvisionSupport.provisioningSuccess(containers, ProvisionSupport.PROVISION_TIMEOUT);
            CommandSupport.executeCommand("fabric:container-list");
            for (Container container : containers) {
                CommandSupport.executeCommand("fabric:container-connect -u admin -p admin " + container.getId() + " osgi:list");
                CommandSupport.executeCommand("fabric:container-connect -u admin -p admin " + container.getId() + " config:proplist --pid org.ops4j.pax.url.mvn");
                System.out.flush();
            }
        } finally {
            ContainerBuilder.stop(fabricService, containers);
        }
    } finally {
        fabricProxy.close();
    }
}
Also used : Container(io.fabric8.api.Container) FabricService(io.fabric8.api.FabricService) BundleContext(org.osgi.framework.BundleContext) Test(org.junit.Test)

Example 73 with FabricService

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

the class EnsembleTest method testAddAndRemove.

// @Ignore("ENTESB-3580")
@Test
@SuppressWarnings("unchecked")
public void testAddAndRemove() 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();
        Set<Container> containers = ContainerBuilder.create(2).withName("smoke_ens_a").assertProvisioningResult().build(fabricService);
        try {
            Deque<Container> containerQueue = new LinkedList<Container>(containers);
            Deque<Container> addedContainers = new LinkedList<Container>();
            for (int e = 0; e < 3 && containerQueue.size() >= 2 && containerQueue.size() % 2 == 0; e++) {
                Container cnt1 = containerQueue.removeFirst();
                Container cnt2 = containerQueue.removeFirst();
                addedContainers.add(cnt1);
                addedContainers.add(cnt2);
                EnsembleSupport.addToEnsemble(fabricService, cnt1, cnt2);
                System.err.println(CommandSupport.executeCommand("config:proplist --pid io.fabric8.zookeeper"));
                System.err.println(CommandSupport.executeCommand("fabric:container-list"));
                System.err.println(CommandSupport.executeCommand("fabric:ensemble-list"));
                ZooKeeperClusterService zooKeeperClusterService = ServiceLocator.awaitService(ZooKeeperClusterService.class);
                Assert.assertNotNull(zooKeeperClusterService);
                List<String> ensembleContainersResult = zooKeeperClusterService.getEnsembleContainers();
                Assert.assertTrue(ensembleContainersResult.contains(cnt1.getId()));
                Assert.assertTrue(ensembleContainersResult.contains(cnt2.getId()));
                ProvisionSupport.provisioningSuccess(Arrays.asList(fabricService.getContainers()), ProvisionSupport.PROVISION_TIMEOUT);
            }
            for (int e = 0; e < 3 && addedContainers.size() >= 2 && addedContainers.size() % 2 == 0; e++) {
                Container cnt1 = addedContainers.removeFirst();
                Container cnt2 = addedContainers.removeFirst();
                containerQueue.add(cnt1);
                containerQueue.add(cnt2);
                EnsembleSupport.removeFromEnsemble(fabricService, cnt1, cnt2);
                System.err.println(CommandSupport.executeCommand("config:proplist --pid io.fabric8.zookeeper"));
                System.err.println(CommandSupport.executeCommand("fabric:container-list"));
                System.err.println(CommandSupport.executeCommand("fabric:ensemble-list"));
                ZooKeeperClusterService zooKeeperClusterService = ServiceLocator.awaitService(ZooKeeperClusterService.class);
                Assert.assertNotNull(zooKeeperClusterService);
                List<String> ensembleContainersResult = zooKeeperClusterService.getEnsembleContainers();
                Assert.assertFalse(ensembleContainersResult.contains(cnt1.getId()));
                Assert.assertFalse(ensembleContainersResult.contains(cnt2.getId()));
                ProvisionSupport.provisioningSuccess(Arrays.asList(fabricService.getContainers()), ProvisionSupport.PROVISION_TIMEOUT);
            }
        } finally {
            ContainerBuilder.stop(fabricService, containers);
        }
    } finally {
        fabricProxy.close();
    }
}
Also used : Container(io.fabric8.api.Container) FabricService(io.fabric8.api.FabricService) ZooKeeperClusterService(io.fabric8.api.ZooKeeperClusterService) LinkedList(java.util.LinkedList) BundleContext(org.osgi.framework.BundleContext) Test(org.junit.Test)

Example 74 with FabricService

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

the class CreateChildContainerTest method testCreateChildContainerWithCustomZKServerPort.

@Test
public void testCreateChildContainerWithCustomZKServerPort() throws Exception {
    System.err.println(CommandSupport.executeCommand("fabric:create --force --clean -n --wait-for-provisioning --zookeeper-server-port 2345"));
    System.err.println(CommandSupport.executeCommand("fabric:profile-create --parent default p1"));
    System.err.println(CommandSupport.executeCommand("fabric:profile-edit --feature fabric-zookeeper-commands p1"));
    BundleContext moduleContext = ServiceLocator.getSystemContext();
    ServiceProxy<FabricService> fabricProxy = ServiceProxy.createServiceProxy(moduleContext, FabricService.class);
    try {
        FabricService fabricService = fabricProxy.getService();
        Set<Container> containers = ContainerBuilder.child(1).withName("smoke_child_b").withProfiles("p1").build(fabricService);
        ProvisionSupport.provisioningSuccess(containers, ProvisionSupport.PROVISION_TIMEOUT);
        try {
            Container child = containers.iterator().next();
            String ensembleUrl = CommandSupport.executeCommand("fabric:container-connect -u admin -p admin " + child.getId() + " zk:get /fabric/configs/ensemble/url");
            Assert.assertTrue("Child should use custom ZK server port, but was: " + ensembleUrl, ensembleUrl.contains("${zk:root/ip}:2345"));
        } finally {
            ContainerBuilder.stop(fabricService, containers);
        }
    } finally {
        fabricProxy.close();
    }
}
Also used : Container(io.fabric8.api.Container) FabricService(io.fabric8.api.FabricService) BundleContext(org.osgi.framework.BundleContext) Test(org.junit.Test)

Example 75 with FabricService

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

the class CreateChildContainerTest method testCreateChildWithMergedConfiguration.

@Test
public void testCreateChildWithMergedConfiguration() throws Exception {
    CommandSupport.executeCommand("fabric:create --force --clean -n --wait-for-provisioning");
    CommandSupport.executeCommand("fabric:profile-create --parent karaf test");
    // will wipe out other properties
    CommandSupport.executeCommand("fabric:profile-edit --pid org.apache.karaf.log/size=102 test");
    // will *not* wipe out other properties
    CommandSupport.executeCommand("fabric:profile-edit --pid org.apache.karaf.shell/fabric.config.merge=true test");
    CommandSupport.executeCommand("fabric:profile-edit --pid org.apache.karaf.shell/sshIdleTimeout=1800002 test");
    BundleContext moduleContext = ServiceLocator.getSystemContext();
    ServiceProxy<FabricService> fabricProxy = ServiceProxy.createServiceProxy(moduleContext, FabricService.class);
    try {
        FabricService fabricService = fabricProxy.getService();
        Set<Container> containers = ContainerBuilder.child(1).withName("smoke_child_c").withProfiles("test").assertProvisioningResult().build(fabricService);
        try {
            Assert.assertEquals("One container", 1, containers.size());
            Container child = containers.iterator().next();
            Assert.assertEquals("smoke_child_c", child.getId());
            Assert.assertEquals("root", child.getParent().getId());
            String logPid = CommandSupport.executeCommand("fabric:container-connect -u admin -p admin " + child.getId() + " config:proplist --pid org.apache.karaf.log");
            String shellPid = CommandSupport.executeCommand("fabric:container-connect -u admin -p admin " + child.getId() + " config:proplist --pid org.apache.karaf.shell");
            Assert.assertFalse(logPid.contains("pattern"));
            Assert.assertTrue(logPid.contains("size = 102"));
            Assert.assertTrue(shellPid.contains("sshHost"));
            Assert.assertTrue(shellPid.contains("sshIdleTimeout = 1800002"));
        } finally {
            ContainerBuilder.stop(fabricService, containers);
        }
    } finally {
        fabricProxy.close();
    }
}
Also used : Container(io.fabric8.api.Container) FabricService(io.fabric8.api.FabricService) BundleContext(org.osgi.framework.BundleContext) Test(org.junit.Test)

Aggregations

FabricService (io.fabric8.api.FabricService)80 Container (io.fabric8.api.Container)76 Test (org.junit.Test)52 Profile (io.fabric8.api.Profile)50 BundleContext (org.osgi.framework.BundleContext)29 Version (io.fabric8.api.Version)24 ArrayList (java.util.ArrayList)21 ProfileService (io.fabric8.api.ProfileService)19 HashMap (java.util.HashMap)16 CuratorFramework (org.apache.curator.framework.CuratorFramework)16 HashSet (java.util.HashSet)14 Map (java.util.Map)13 FabricException (io.fabric8.api.FabricException)12 IOException (java.io.IOException)12 ContainerProxy (io.fabric8.itests.paxexam.support.ContainerProxy)11 Ignore (org.junit.Ignore)10 File (java.io.File)9 LinkedList (java.util.LinkedList)9 Path (javax.ws.rs.Path)8 FabricRequirements (io.fabric8.api.FabricRequirements)7