Package io.fabric8.api

Examples of io.fabric8.api.FabricService


        //System.out.println(executeCommand("fabric:profile-list"));

        ModuleContext moduleContext = RuntimeLocator.getRequiredRuntime().getModuleContext();
        ServiceProxy<FabricService> fabricProxy = ServiceProxy.createServiceProxy(moduleContext, FabricService.class);
        try {
            FabricService fabricService = fabricProxy.getService();
            CuratorFramework curator = fabricService.adapt(CuratorFramework.class);

            Set<Container> containers = ContainerBuilder.create(1, 1).withName("basic.cntG").withProfiles("default").assertProvisioningResult().build(fabricService);
            try {
                Container cntG = containers.iterator().next();

                Assert.assertEquals("manualip", getSubstitutedPath(curator, ZkPath.CONTAINER_RESOLVER.getPath(cntG.getId())));
                Assert.assertEquals("manualip", fabricService.getCurrentContainer().getResolver());

                //We stop the config admin bridge, since the next step is going to hung the container if we do propagate the change to config admin.
                //new BundleUtils(bundleContext).findAndStopBundle("io.fabric8.fabric-configadmin");
                //We want to make sure that the child points to the parent, so we change the parent resolvers and assert.
                System.out.println(CommandSupport.executeCommand("fabric:container-resolver-set --container root localip"));
View Full Code Here


    public void testAddAndRemoveWithVersions() throws Exception {
        System.err.println(CommandSupport.executeCommand("fabric:create --force --clean -n"));
        ModuleContext moduleContext = RuntimeLocator.getRequiredRuntime().getModuleContext();
        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 {
View Full Code Here

        //System.out.println(executeCommand("fabric:profile-list"));

        ModuleContext moduleContext = RuntimeLocator.getRequiredRuntime().getModuleContext();
        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);
View Full Code Here

        //System.out.println(executeCommand("fabric:profile-list"));

        ModuleContext moduleContext = RuntimeLocator.getRequiredRuntime().getModuleContext();
        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"));
            Set<Container> containers = ContainerBuilder.create().withName("basic_camel_a").withProfiles("feature-camel").assertProvisioningResult().build(fabricService);
            try {
                //Make sure that the profile change has been applied before changing the version
                CountDownLatch latch = WaitForConfigurationChange.on(fabricService);
View Full Code Here

        //System.out.println(executeCommand("fabric:profile-list"));

        ModuleContext moduleContext = RuntimeLocator.getRequiredRuntime().getModuleContext();
        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().withName("basic_camel_b").withProfiles("feature-camel").assertProvisioningResult().build(fabricService);
            try {
                System.out.println(CommandSupport.executeCommand("fabric:container-rollback --all 1.0"));
View Full Code Here

        //System.out.println(executeCommand("fabric:profile-list"));

        ModuleContext moduleContext = RuntimeLocator.getRequiredRuntime().getModuleContext();
        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"));
View Full Code Here

    }
   
    @Test
    public void testFabricCreate() throws Exception {

        FabricService fabricService = ServiceLocator.getRequiredService(FabricService.class);
        Container[] containers = fabricService.getContainers();
        Assert.assertNotNull("Containers not null", containers);

        // Verify other required services
        ServiceLocator.getRequiredService(CuratorFramework.class);
        ServiceLocator.getRequiredService(GitService.class);
View Full Code Here

        LOGGER.debug("Configuration has changed; so checking the auto-scaling requirements");
        healthCheck();
    }

    private void healthCheck() {
        FabricService service = fabricService.get();
        Kubernetes kubernetes = getKubernetes();
        if (kubernetes != null && service != null) {
            try {
                Map<String, PodSchema> podMap = KubernetesHelper.getPodMap(kubernetes);
                Container[] containerArray = service.getContainers();
                Collection<PodSchema> pods = podMap.values();
                if (!pods.isEmpty()) {
                    Map<String, Container> containerMap = createPodIdToContainerMap(containerArray);

                    for (PodSchema item : pods) {
View Full Code Here

    public void testAddAndRemove() throws Exception {
        System.err.println(CommandSupport.executeCommand("fabric:create --force --clean -n"));
        ModuleContext moduleContext = RuntimeLocator.getRequiredRuntime().getModuleContext();
        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(moduleContext, 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(moduleContext, 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 {
View Full Code Here

    @Override
    public void createContainers(AutoScaleRequest request) throws Exception {
        int count = request.getDelta();
        String profile = request.getProfile();
        String version = request.getVersion();
        FabricService fabricService = request.getFabricService();
        CreateChildContainerOptions.Builder builder = null;
        if (fabricService != null) {
            builder = createAutoScaleOptions(request, fabricService);
        }
        if (builder != null) {
            Set<String> ignoreContainerNames = new HashSet<>();
            for (int i = 0; i < count; i++) {
                final CreateChildContainerOptions.Builder configuredBuilder = builder.number(1).version(version).profiles(profile);

                Container[] containers = fabricService.getContainers();
                NameValidator nameValidator = Containers.createNameValidator(containers);
                String name = Containers.createContainerName(containers, profile, containerProvider.getScheme(), nameValidator);
                ignoreContainerNames.add(name);

                CreateChildContainerOptions options = configuredBuilder.name(name).build();
                LOG.info("Creating container name " + name + " version " + version + " profile " + profile + " " + count + " container(s)");
                fabricService.createContainers(options);
            }
        } else {
            LOG.warn("Could not create version " + version + " profile " + profile + " due to missing autoscale configuration");
        }
    }
View Full Code Here

TOP

Related Classes of io.fabric8.api.FabricService

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.