Package io.fabric8.api

Examples of io.fabric8.api.Container


                    image = DockerConstants.DEFAULT_IMAGE;
                }
                containerConfig.setImage(image);
            }
            containerType = "docker " + image;
            Container container = service.getContainer(containerId);
            if (container != null) {
                container.setType(containerType);
            }


            String[] cmd = containerConfig.getCmd();
            if (cmd == null || cmd.length == 0) {
                String value = configOverlayDockerProvider.getCmd();
                if (Strings.isNullOrBlank(value)) {
                    cmd = null;
                } else {
                    cmd = new String[]{value};
                }
                containerConfig.setCmd(cmd);
            }

            Map<String, Integer> internalPorts = options.getInternalPorts();
            Map<String, Integer> externalPorts = options.getExternalPorts();

            Map<String, Object> exposedPorts = new HashMap<>();
            Set<Integer> usedPortByHost = findUsedPortByHostAndDocker();
            Map<String, String> emptyMap = new HashMap<>();

            SortedMap<Integer, String> sortedInternalPorts = new TreeMap<>();
            for (Map.Entry<String, String> portEntry : ports.entrySet()) {
                String portName = portEntry.getKey();
                String portText = portEntry.getValue();
                if (portText != null && !Strings.isNullOrBlank(portText)) {
                    Integer port = null;
                    try {
                        port = Integer.parseInt(portText);
                    } catch (NumberFormatException e) {
                        LOG.warn("Ignoring bad port number for " + portName + " value '" + portText + "' in PID: " + Constants.PORTS_PID);
                    }
                    if (port != null) {
                        sortedInternalPorts.put(port, portName);
                        internalPorts.put(portName, port);
                        exposedPorts.put(portText + "/tcp", emptyMap);
                    } else {
                        LOG.info("No port for " + portName);
                    }
                }
            }

            String dockerHost = dockerFactory.getDockerHost();
            jolokiaUrl = null;

            Map<String, String> javaContainerConfig = Profiles.getOverlayConfiguration(service, profileIds, versionId, Constants.JAVA_CONTAINER_PID);
            JavaContainerConfig javaConfig = new JavaContainerConfig();
            getConfigurer().configure(javaContainerConfig, javaConfig);

            boolean isJavaContainer = ChildContainers.isJavaContainer(getFabricService(), options);

            // lets create the ports in sorted order
            for (Map.Entry<Integer, String> entry : sortedInternalPorts.entrySet()) {
                Integer port = entry.getKey();
                String portName = entry.getValue();
                int externalPort = createExternalPort(containerId, portName, usedPortByHost, options);
                externalPorts.put(portName, externalPort);
                environmentVariables.put("FABRIC8_" + portName + "_PORT", "" + port);
                environmentVariables.put("FABRIC8_" + portName + "_PROXY_PORT", "" + externalPort);

                if (portName.equals(JolokiaAgentHelper.JOLOKIA_PORT_NAME)) {
                    jolokiaUrl = "http://" + dockerHost + ":" + externalPort + "/jolokia/";
                    LOG.info("Found Jolokia URL: " + jolokiaUrl);

                    JolokiaAgentHelper.substituteEnvironmentVariables(javaConfig, environmentVariables, isJavaContainer, JolokiaAgentHelper.getJolokiaPortOverride(port), JolokiaAgentHelper.getJolokiaAgentIdOverride(getFabricService().getEnvironment()));
                } else {
                    JolokiaAgentHelper.substituteEnvironmentVariables(javaConfig, environmentVariables, isJavaContainer, JolokiaAgentHelper.getJolokiaAgentIdOverride(getFabricService().getEnvironment()));

                }
            }
            javaConfig.updateEnvironmentVariables(environmentVariables, isJavaContainer);


            LOG.info("Passing in manual ip: " + dockerHost);
            environmentVariables.put(EnvironmentVariables.FABRIC8_MANUALIP, dockerHost);
            if (container != null) {
                container.setManualIp(dockerHost);
            }
            if (!environmentVariables.containsKey(EnvironmentVariables.FABRIC8_LISTEN_ADDRESS)) {
                environmentVariables.put(EnvironmentVariables.FABRIC8_LISTEN_ADDRESS, dockerHost);
            }
            environmentVariables.put(EnvironmentVariables.FABRIC8_GLOBAL_RESOLVER, ZkDefs.MANUAL_IP);
            environmentVariables.put(EnvironmentVariables.FABRIC8_FABRIC_ENVIRONMENT, DockerConstants.SCHEME);

            // now the environment variables are all set lets see if we need to make a custom image
            String libDir = configOverlayDockerProvider.getJavaLibraryPath();
            String deployDir = configOverlayDockerProvider.getJavaDeployPath();
            String homeDir = configOverlayDockerProvider.getHomePath();
            if (Strings.isNotBlank(libDir) || Strings.isNotBlank(deployDir)) {
                if (container != null) {
                    container.setProvisionResult("preparing");
                    container.setAlive(true);
                }
                String imageRepository = configOverlayDockerProvider.getImageRepository();
                String entryPoint = configOverlayDockerProvider.getImageEntryPoint();
                List<String> names = new ArrayList<String>(profileIds);
                names.add(versionId);
                String newImageName = "fabric8-" + Strings.join(names, "-").replace('.', '-');
                String customImageUserName = configOverlayDockerProvider.getCustomImageUserName();

                DockerProviderConfig currentContainerDockerProviderConfig = null;
                Container currentContainer = service.getCurrentContainer();
                if (currentContainer != null) {
                    Map<String, String> configuration = currentContainer.getOverlayProfile().getConfiguration(DockerConstants.DOCKER_PROVIDER_PID);
                    if (configuration != null && !configuration.isEmpty()) {
                        Map<String, Map<String, String>> configurations = new HashMap<>();
                        configurations.put(DockerConstants.DOCKER_PROVIDER_PID, configuration);
                        service.substituteConfigurations(configurations);
                        configuration = configurations.get(DockerConstants.DOCKER_PROVIDER_PID);
View Full Code Here


        this.fabricService = fabricService;
    }

    protected Object doExecute() throws Exception {
        validateContainerName(container);
        Container found = FabricCommand.getContainer(fabricService, container);
        List<String> domains = found.getJmxDomains();
        for (String domain : domains) {
            System.out.println(domain);
        }
        return null;
    }
View Full Code Here

            Set<ContainerProxy> containers = ContainerBuilder.create(fabricProxy, 2).withName("cnt").withProfiles("default").assertProvisioningResult().build();
            try {

                LinkedList<Container> containerList = new LinkedList<Container>(containers);
                Container broker = containerList.removeLast();

                setData(curator, ZkPath.CONTAINER_PROVISION_RESULT.getPath(broker.getId()), "changing");
                System.out.println(executeCommand("fabric:container-change-profile " + broker.getId() + " mq-default"));
                Provision.provisioningSuccess(Arrays.asList(new Container[] { broker }), PROVISION_TIMEOUT);
                System.out.println(executeCommand("fabric:cluster-list"));

                for (Container c : containerList) {
                    setData(curator, ZkPath.CONTAINER_PROVISION_RESULT.getPath(c.getId()), "changing");
View Full Code Here

            provisioningStatus = status;
            provisioningError = result;
            provisionList = resources;

            if (fs != null) {
                Container container = fs.getCurrentContainer();
                String e;
                if (result == null) {
                    e = null;
                } else {
                    StringWriter sw = new StringWriter();
                    result.printStackTrace(new PrintWriter(sw));
                    e = sw.toString();
                }
                if (resources != null) {
                    List<String> uris = new ArrayList<String>();
                    for (Resource res : resources) {
                        uris.add(getUri(res));
                    }
                    container.setProvisionList(uris);
                }
                container.setProvisionResult(status);
                container.setProvisionException(e);

                java.util.Properties provisionChecksums = new java.util.Properties();
                putAllProperties(provisionChecksums, bundleChecksums);
/*
                putAllProperties(provisionChecksums, libChecksums);
                putAllProperties(provisionChecksums, endorsedChecksums);
                putAllProperties(provisionChecksums, extensionChecksums);
*/
                container.setProvisionChecksums(provisionChecksums);
            } else {
                LOGGER.info("FabricService not available");
            }
        } catch (Throwable e) {
            LOGGER.warn("Unable to set provisioning result");
View Full Code Here

            Set<ContainerProxy> containers = ContainerBuilder.create(fabricProxy, 3).withName("fabric-camel").withProfiles("feature-camel").assertProvisioningResult().build();
            try {
                //We will use the first container as a client and the rest as servers.
                LinkedList<Container> containerList = new LinkedList<Container>(containers);
                Container client = containerList.removeLast();

                LinkedList<Container> servers = new LinkedList<Container>(containerList);

                for (Container c : servers) {
                    Profile p = c.getVersion().getRequiredProfile("example-camel-cluster.server");
                    c.setProfiles(new Profile[]{p});
                }

                Provision.provisioningSuccess(servers, PROVISION_TIMEOUT);

                Profile p = client.getVersion().getRequiredProfile("example-camel-cluster.client");
                client.setProfiles(new Profile[]{p});

                Provision.provisioningSuccess(Arrays.asList(new Container[]{client}), PROVISION_TIMEOUT);

                System.out.println(executeCommand("fabric:container-list"));
                System.out.println(executeCommand("fabric:profile-display --overlay fabric-camel-server"));

                //Check that the entries have been properly propagated.
                Assert.assertNotNull(exists(curator, "/fabric/registry/camel/endpoints"));
                Assert.assertEquals(1, getChildren(curator, "/fabric/registry/camel/endpoints").size());

                Assert.assertTrue(Provision.waitForCondition(Arrays.asList(client), new ContainerCondition() {
                    @Override
                    public Boolean checkConditionOnContainer(final Container c) {
                        return getCompletedExchangesCount(c) > 0;
                    }
                }, 60000L));

                //We want to kill all but one server, so we take out the first and keep it to the end.
                Container lastActiveServerContainer = servers.removeLast();

                for (Container c : servers) {
                    try {
                        c.destroy(true);
                    } catch (Exception ex) {
View Full Code Here

    @Override
    public int complete(String buffer, int cursor, List<String> candidates) {
        StringsCompleter delegate = new StringsCompleter();
        try {
            Version version = getFabricService().getRequiredDefaultVersion();
            Container container = getFabricService().getCurrentContainer();
            try{
                container =  getFabricService().getContainer(getContainer(CommandSessionHolder.getSession(), containerArgumentIndex));
            } catch (Exception ex) {
                // Ignore and use current container.
            }

            Profile[] containerProfiles = container.getProfiles();
            List<String> containerProfileNames = new LinkedList<String>();
            if (containerProfiles != null) {
                for (Profile p : containerProfiles) {
                    containerProfileNames.add(p.getId());
                }
View Full Code Here

    protected void recompile() {
        LOG.debug("Looking for XSDs to recompile");

        Set<String> urls = new TreeSet<String>();
        FabricService fabric = getFabricService();
        Container container = fabric.getCurrentContainer();
        String versionId = container.getVersion().getId();
        List<String> profileIds = Containers.overlayProfiles(container);
        Collection<String> names = listFiles(versionId, profileIds, schemaPath);
        for (String name : names) {
            if (name.endsWith(".xsd")) {
                String prefix = schemaPath;
View Full Code Here

    /**
     * Checks the container is still alive and updates its provision list if its changed
     */
    public static void jolokiaKeepAliveCheck(ZooKeeperMasterCache zkMasterCache, FabricService fabric, String jolokiaUrl, String containerName) {
        Container container = null;
        try {
            container = fabric.getContainer(containerName);
        } catch (Exception e) {
            // ignore
        }
View Full Code Here

    }

    @Override
    public void stop(TaskContext context) {
        ProfileService profileService = fabricService.get().adapt(ProfileService.class);
        Container current = fabricService.get().getCurrentContainer();
        Version version = current.getVersion();
        String profileId = context.getConfiguration().get(TEMPLATE_PROFILE_PROPERTY_NAME) + "-" + name;
        if (version.hasProfile(profileId)) {
          String versionId = version.getId();
          profileService.deleteProfile(fabricService.get(), versionId, profileId, true);
        }
View Full Code Here

      }
    }

    private void manageProfile(TaskContext context) {
        ProfileService profileService = fabricService.get().adapt(ProfileService.class);
        Container current = fabricService.get().getCurrentContainer();
        ProfileData profileData = createProfileData(context);
        String profileId = context.getConfiguration().get(TEMPLATE_PROFILE_PROPERTY_NAME) + "-" + name;
        Version version = current.getVersion();
      String versionId = version.getId();

      // [TODO] Revisit lock in ProfileTemplateWorker
        try {
            if (lock.acquire(60, TimeUnit.SECONDS)) {
                if (profileData.isEmpty()) {
                    if (version.hasProfile(profileId)) {
                        profileService.deleteProfile(fabricService.get(), versionId, profileId, true);
                    }
                    return;
                }
               
                Profile managedProfile;
                if (version.hasProfile(profileId)) {
                    Profile profile = profileService.getRequiredProfile(versionId, profileId);
                    ProfileBuilder builder = ProfileBuilder.Factory.createFrom(profile);
                    builder.setFileConfigurations(profileData.getFiles());
                    managedProfile = profileService.updateProfile(builder.getProfile());
                } else {
                    ProfileBuilder builder = ProfileBuilder.Factory.create(versionId, profileId);
                    builder.setFileConfigurations(profileData.getFiles());
                    managedProfile = profileService.createProfile(builder.getProfile());
                }
               
                current.addProfiles(managedProfile);
            } else {
                throw new TimeoutException("Timed out waiting for lock");
            }
        } catch (Exception e) {
            LOGGER.error("Error managing work items.", e);
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.