Package io.fabric8.api

Examples of io.fabric8.api.Container


        }

        List<Container> toRollback = new ArrayList<Container>();
        List<Container> same = new ArrayList<Container>();
        for (String containerName : containerIds) {
            Container container = FabricCommand.getContainer(fabricService, containerName);

            // check first that all can rollback
            int num = ContainerUpgradeSupport.canRollback(version, container);
            if (num < 0) {
                throw new IllegalArgumentException("Container " + container.getId() + " has already lower version " + container.getVersion().getId()
                        + " than the requested version " + version.getId() + " to rollback.");
            } else if (num == 0) {
                // same version
                same.add(container);
            } else {
                // needs rollback
                toRollback.add(container);
            }
        }

        // report same version
        for (Container container : same) {
            System.out.println("Container " + container.getId() + " is already version " + version.getId());
        }

        // report and do rollbacks
        for (Container container : toRollback) {
            Version oldVersion = container.getVersion();
            // rollback version first
            container.setVersion(version);
            log.info("Rolled back container {} from {} to {}", new Object[]{container.getId(), oldVersion.getId(), version.getId()});
            System.out.println("Rolled back container " + container.getId() + " from version " + oldVersion.getId() + " to " + version.getId());
        }

    if (all) {
      fabricService.setDefaultVersionId(version.getId());
      System.out.println("Changed default version to " + version.getId());
View Full Code Here


        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);
            }
View Full Code Here

        if (!FabricCommand.doesContainerExist(fabricService, container)) {
            System.out.println("Container " + container + " does not exists!");
            return null;
        }

        Container containerInstance = FabricCommand.getContainerIfExists(fabricService, container);
        String type = containerInstance.getType();

        if (!"karaf".equals(type)) {
            System.out.println("Sorry, currently only \"karaf\" type container are supported");
            return null;
        }

        String jmxUrl = null;
        JMXConnector connector = null;
        MBeanServerConnection remote = null;
        HashMap<String, String[]> authenticationData = null;

        jmxUrl = containerInstance.getJmxUrl();
        authenticationData = prepareAuthenticationData();

        try {
            connector = connectOrRetry(authenticationData, jmxUrl);
        } catch (Exception e){
            username = null;
            password = null;
            System.out.println("Operation Failed. Check logs.");
            log.error("Unable to connect to JMX Server", e);
            return null;
        }

        remote = connector.getMBeanServerConnection();

        ObjectName objName = null;
        if (jvmOptions == null) {
            objName = new ObjectName(JAVA_LANG_OBJECT_NAME);

            try {
                String[] arguments = (String[]) remote.getAttribute(objName, "InputArguments");
                String output = Arrays.toString(arguments);
                output = output.replaceAll(",", "");
                output = output.substring(1, output.length() - 1);
                System.out.println(output);
            } catch (Exception e) {
                System.out.println("Operation Failed. Check logs.");
                log.error("Unable to fetch child jvm opts", e);
            }

        } else {
            jvmOptions = stripSlashes(jvmOptions);

            String providerType = null;
            CreateContainerMetadata<?> metadata = containerInstance.getMetadata();
            if(metadata == null){
                //root container
                //disallowed for the time being. something odd screws authentication
                // providerType = "child";
                System.out.println("Modifying current container is not allowed. Please turn the instance off and manually edit env variables");
                return null;
            }else{
                providerType = metadata.getCreateOptions().getProviderType();
            }


            switch(providerType){
                case "ssh":
                    //we need to operate on an ensamble member container
                    containerInstance= fabricService.getCurrentContainer();

                    jmxUrl = containerInstance.getJmxUrl();
                    authenticationData = prepareAuthenticationData();

                    connector = connectOrRetry(authenticationData, jmxUrl);
                    remote = connector.getMBeanServerConnection();
View Full Code Here

            System.out.println(CommandSupport.executeCommand("fabric:profile-create --parents default child-profile"));
            Assert.assertTrue(ProvisionSupport.profileAvailable("child-profile", "1.0", ProvisionSupport.PROVISION_TIMEOUT));

            Set<Container> containers = ContainerBuilder.create(1,1).withName("basic.cntA").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 {
View Full Code Here

            if (!force && FabricCommand.isPartOfEnsemble(fabricService, containerName)) {
                System.out.println("Container is part of the ensemble. If you still want to stop it, please use --force option.");
                return null;
            }

            Container found = FabricCommand.getContainer(fabricService, containerName);
            applyUpdatedCredentials(found);
            if (found.isAlive()) {
                found.stop(force);
                System.out.println("Container '" + found.getId() + "' stopped successfully.");
            } else {
                System.err.println("Container '" + found.getId() + "' already stopped.");
            }
        }
        return null;
    }
View Full Code Here

        return containerExists();
    }

    private boolean containerExists() {
        try {
            Container c = fabricService.getContainer(container);
            return c != null;
        } catch (Exception ex) {
            return false;
        }
    }
View Full Code Here

                throw new IllegalArgumentException("Can not use --all with a list of containers simultaneously.");
            }
        }

        for (String containerId : containerIds) {
            Container container = fabricService.getContainer(containerId);
            container.setResolver(resolver);
        }
        return null;
    }
View Full Code Here

    public Set<Container> call() throws Exception {
        Set<Container> containers = new HashSet<Container>();
        CreateContainerMetadata[] allMetadata = fabricService.createContainers(optionsBuilder.build());
        if (allMetadata != null && allMetadata.length > 0) {
            for (CreateContainerMetadata metadata : allMetadata) {
                Container container = metadata.getContainer();
                containers.add(container);
                if (!metadata.isSuccess()) {
                    throw new FabricException("Failed to create container." , metadata.getFailure());
                }
            }
View Full Code Here

        assertValid();
        String answer = runtimeProperties.get().getProperty(SystemProperties.FABRIC_ENVIRONMENT);
        if (answer == null) {
            // in case we've not updated the system properties in the JVM based on the profile
            // e.g. when adding/removing profiles
            Container currentContainer = getCurrentContainer();
            if (currentContainer != null) {
                Map<String, String> systemProperties = currentContainer.getOverlayProfile().getConfiguration(Constants.SYSTEM_PROPERTIES_PID);
                answer = systemProperties.get(SystemProperties.FABRIC_ENVIRONMENT);
            }

            // lets store the effective profile for later on
            if (answer != null) {
View Full Code Here

        List<String> containerIds = dataStore.get().getContainers();
        for (String containerId : containerIds) {
            String parentId = dataStore.get().getContainerParent(containerId);
            if (parentId.isEmpty()) {
                if (!containers.containsKey(containerId)) {
                    Container container = new ContainerImpl(null, containerId, this);
                    containers.put(containerId, container);
                }
            } else {
                Container parent = containers.get(parentId);
                if (parent == null) {
                    parent = new ContainerImpl(null, parentId, this);
                    containers.put(parentId, parent);
                }
                Container container = new ContainerImpl(parent, containerId, this);
                containers.put(containerId, container);
            }
        }
        return containers.values().toArray(new Container[containers.size()]);
    }
View Full Code Here

TOP

Related Classes of io.fabric8.api.Container

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.