Search in sources :

Example 66 with FabricService

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

the class ContainerRegistrationTest method testContainerRegistration.

@Test
@SuppressWarnings("unchecked")
public void testContainerRegistration() throws Exception {
    System.out.println(CommandSupport.executeCommand("fabric:create --force --clean -n --wait-for-provisioning"));
    // 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();
        System.out.println(CommandSupport.executeCommand("fabric:profile-create --parent default child-profile"));
        Assert.assertTrue(ProvisionSupport.profileAvailable("child-profile", "1.0", ProvisionSupport.PROVISION_TIMEOUT));
        Set<Container> containers = ContainerBuilder.create(1, 1).withName("basic_cnt").withProfiles("child-profile").assertProvisioningResult().build(fabricService);
        try {
            Container cntA = containers.iterator().next();
            System.out.println(CommandSupport.executeCommand("fabric:profile-edit --import-pid --pid org.apache.karaf.shell child-profile"));
            System.out.println(CommandSupport.executeCommand("fabric:profile-edit --pid org.apache.karaf.shell/sshPort=8105 child-profile"));
            System.out.println(CommandSupport.executeCommand("fabric:profile-edit --import-pid --pid org.apache.karaf.management child-profile"));
            System.out.println(CommandSupport.executeCommand("fabric:profile-edit --pid org.apache.karaf.management/rmiServerPort=55555 child-profile"));
            System.out.println(CommandSupport.executeCommand("fabric:profile-edit --pid org.apache.karaf.management/rmiRegistryPort=1100 child-profile"));
            System.out.println(CommandSupport.executeCommand("fabric:profile-edit --pid org.apache.karaf.management/serviceUrl=service:jmx:rmi://localhost:55555/jndi/rmi://localhost:1099/karaf-" + cntA.getId() + " child-profile"));
            String sshUrl = cntA.getSshUrl();
            String jmxUrl = cntA.getJmxUrl();
            long end = System.currentTimeMillis() + ProvisionSupport.PROVISION_TIMEOUT;
            while (System.currentTimeMillis() < end && (!sshUrl.endsWith("8105") || !jmxUrl.contains("55555"))) {
                Thread.sleep(1000L);
                sshUrl = cntA.getSshUrl();
                jmxUrl = cntA.getJmxUrl();
            }
            Assert.assertTrue("sshUrl ends with 8105, but was: " + sshUrl, sshUrl.endsWith("8105"));
            Assert.assertTrue("jmxUrl contains 55555, but was: " + jmxUrl, jmxUrl.contains("55555"));
        } 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 67 with FabricService

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

the class ExtendedCreateChildContainerTest method testContainerWithPasswordChange.

@Test
public // [FABRIC-482] Fabric doesn't allow remote host user/password to be changed once the container is created.
void testContainerWithPasswordChange() throws Exception {
    System.out.println(CommandSupport.executeCommand("fabric:create --force --clean -n --wait-for-provisioning"));
    // 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();
        Set<Container> containers = ContainerBuilder.child(1).withName("basic_cnt_d").assertProvisioningResult().build(fabricService);
        try {
            Container cntD = containers.iterator().next();
            System.out.println(CommandSupport.executeCommands("jaas:manage --realm karaf --module io.fabric8.jaas.ZookeeperLoginModule", "jaas:userdel admin", "jaas:useradd admin newpassword", "jaas:roleadd admin admin", "jaas:update"));
            System.out.println(CommandSupport.executeCommand("fabric:container-stop --user admin --password newpassword " + cntD.getId()));
            ProvisionSupport.containersAlive(containers, false, ProvisionSupport.PROVISION_TIMEOUT);
            containers.remove(cntD);
        } 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 68 with FabricService

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

the class ExtendedEnsembleTest method testAddAndRemoveWithPartialVersionUpgrades.

/**
 * We want to test the ensemble health is not affected if part of the ensemble is switched to an other version.
 */
@Test
@SuppressWarnings("unchecked")
@Ignore
public void testAddAndRemoveWithPartialVersionUpgrades() throws Exception {
    System.out.println(CommandSupport.executeCommand("fabric:create --force --clean -n --wait-for-provisioning"));
    // 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();
        System.out.println(CommandSupport.executeCommand("fabric:version-create"));
        System.out.println(CommandSupport.executeCommand("fabric:container-upgrade --all 1.1"));
        Set<Container> containers = ContainerBuilder.create(2).withName("basic_ens_b").withProfiles("fabric").assertProvisioningResult().build(fabricService);
        try {
            LinkedList<Container> containerQueue = new LinkedList<Container>(containers);
            LinkedList<Container> addedContainers = new LinkedList<Container>();
            System.out.println(CommandSupport.executeCommand("fabric:version-create"));
            System.out.println(CommandSupport.executeCommand("fabric:container-upgrade --all 1.2"));
            Random rand = new Random();
            for (int version = 3; version < 5; version++) {
                ProvisionSupport.provisioningSuccess(Arrays.asList(fabricService.getContainers()), ProvisionSupport.PROVISION_TIMEOUT);
                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.out.println(CommandSupport.executeCommand("config:proplist --pid io.fabric8.zookeeper"));
                    System.out.println(CommandSupport.executeCommand("fabric:container-list"));
                    System.out.println(CommandSupport.executeCommand("fabric:ensemble-list"));
                    ZooKeeperClusterService zooKeeperClusterService = ServiceLocator.awaitService(ZooKeeperClusterService.class);
                    org.junit.Assert.assertNotNull(zooKeeperClusterService);
                    List<String> ensembleContainersResult = zooKeeperClusterService.getEnsembleContainers();
                    org.junit.Assert.assertTrue(ensembleContainersResult.contains(cnt1.getId()));
                    org.junit.Assert.assertTrue(ensembleContainersResult.contains(cnt2.getId()));
                    ProvisionSupport.provisioningSuccess(Arrays.asList(fabricService.getContainers()), ProvisionSupport.PROVISION_TIMEOUT);
                }
                int index = rand.nextInt(addedContainers.size());
                String randomContainer = addedContainers.get(index).getId();
                System.out.println(CommandSupport.executeCommand("fabric:version-create 1." + version));
                System.out.println(CommandSupport.executeCommand("fabric:container-upgrade 1." + version + " " + randomContainer));
                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.out.println(CommandSupport.executeCommand("config:proplist --pid io.fabric8.zookeeper"));
                    System.out.println(CommandSupport.executeCommand("fabric:container-list"));
                    System.out.println(CommandSupport.executeCommand("fabric:ensemble-list"));
                    ZooKeeperClusterService zooKeeperClusterService = ServiceLocator.awaitService(ZooKeeperClusterService.class);
                    org.junit.Assert.assertNotNull(zooKeeperClusterService);
                    List<String> ensembleContainersResult = zooKeeperClusterService.getEnsembleContainers();
                    org.junit.Assert.assertFalse(ensembleContainersResult.contains(cnt1.getId()));
                    org.junit.Assert.assertFalse(ensembleContainersResult.contains(cnt2.getId()));
                    ProvisionSupport.provisioningSuccess(Arrays.asList(fabricService.getContainers()), ProvisionSupport.PROVISION_TIMEOUT);
                }
                System.out.println(CommandSupport.executeCommand("fabric:container-rollback 1." + (version - 1) + " " + randomContainer));
            }
        } finally {
            ContainerBuilder.stop(fabricService, containers);
        }
    } finally {
        fabricProxy.close();
    }
}
Also used : Container(io.fabric8.api.Container) Random(java.util.Random) FabricService(io.fabric8.api.FabricService) ZooKeeperClusterService(io.fabric8.api.ZooKeeperClusterService) LinkedList(java.util.LinkedList) BundleContext(org.osgi.framework.BundleContext) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 69 with FabricService

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

the class ExtendedEnsembleTest method testAddAndRemoveWithVersions.

@Test
@SuppressWarnings("unchecked")
@Ignore
public void testAddAndRemoveWithVersions() 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();
        System.out.println(CommandSupport.executeCommand("fabric:version-create --parent 1.0 1.1"));
        System.out.println(CommandSupport.executeCommand("fabric:container-upgrade --all 1.1"));
        Set<Container> containers = ContainerBuilder.create(2).withName("basic_ens_a").withProfiles("default").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);
            }
            System.out.println(CommandSupport.executeCommand("fabric:version-create"));
            System.out.println(CommandSupport.executeCommand("fabric:container-upgrade --all 1.2"));
            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) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 70 with FabricService

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

the class ExtendedJoinTest method testJoinAndAddToEnsemble.

/**
 * This is a test for FABRIC-353.
 */
@Test
@Ignore
public void testJoinAndAddToEnsemble() throws Exception {
    System.err.println(CommandSupport.executeCommand("fabric:create --force --clean -n --wait-for-provisioning"));
    // 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();
        AdminService adminService = ServiceLocator.awaitService(AdminService.class);
        String version = System.getProperty("fabric.version");
        System.out.println(CommandSupport.executeCommand("admin:create --featureURL mvn:io.fabric8/fabric8-karaf/" + version + "/xml/features --feature fabric-git --feature fabric-agent --feature fabric-boot-commands basic_cnt_f"));
        System.out.println(CommandSupport.executeCommand("admin:create --featureURL mvn:io.fabric8/fabric8-karaf/" + version + "/xml/features --feature fabric-git --feature fabric-agent --feature fabric-boot-commands basic_cnt_g"));
        try {
            System.out.println(CommandSupport.executeCommand("admin:start basic_cnt_f"));
            System.out.println(CommandSupport.executeCommand("admin:start basic_cnt_g"));
            ProvisionSupport.instanceStarted(Arrays.asList("basic_cnt_f", "basic_cnt_g"), ProvisionSupport.PROVISION_TIMEOUT);
            System.out.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("basic_cnt_f").getSshPort() + " localhost " + WAIT_FOR_JOIN_SERVICE);
                Thread.sleep(1000);
            }
            response = "";
            for (int i = 0; i < 10 && !response.contains("true"); i++) {
                response = CommandSupport.executeCommand("ssh:ssh -l karaf -P karaf -p " + adminService.getInstance("basic_cnt_g").getSshPort() + " localhost " + WAIT_FOR_JOIN_SERVICE);
                Thread.sleep(1000);
            }
            System.err.println(CommandSupport.executeCommand("ssh:ssh -l karaf -P karaf -p " + adminService.getInstance("basic_cnt_f").getSshPort() + " localhost " + joinCommand));
            System.err.println(CommandSupport.executeCommand("ssh:ssh -l karaf -P karaf -p " + adminService.getInstance("basic_cnt_g").getSshPort() + " localhost " + joinCommand));
            ProvisionSupport.containersExist(Arrays.asList("basic_cnt_f", "basic_cnt_g"), ProvisionSupport.PROVISION_TIMEOUT);
            Container cntF = fabricService.getContainer("basic_cnt_f");
            Container cntG = fabricService.getContainer("basic_cnt_g");
            ProvisionSupport.containerStatus(Arrays.asList(cntF, cntG), "success", ProvisionSupport.PROVISION_TIMEOUT);
            EnsembleSupport.addToEnsemble(fabricService, cntF, cntG);
            System.out.println(CommandSupport.executeCommand("fabric:container-list"));
            EnsembleSupport.removeFromEnsemble(fabricService, cntF, cntG);
            System.out.println(CommandSupport.executeCommand("fabric:container-list"));
        } finally {
            System.out.println(CommandSupport.executeCommand("admin:stop basic_cnt_f"));
            System.out.println(CommandSupport.executeCommand("admin:stop basic_cnt_g"));
        }
    } 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) Ignore(org.junit.Ignore) 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