Examples of FabricService


Examples of io.fabric8.api.FabricService

            // allow values to be extracted from the profile configuration
            // such as the image
            Set<String> profileIds = options.getProfiles();
            String versionId = options.getVersion();
            FabricService service = getFabricService();
            Map<String, String> configOverlay = new HashMap<>();
            Map<String, String> ports = null;
            Map<String, String> dockerProviderConfig = new HashMap<>();

            List<Profile> profileOverlays = new ArrayList<>();
            Version version = null;
            if (profileIds != null && versionId != null) {
                ProfileService profileService = service.adapt(ProfileService.class);
                version = profileService.getVersion(versionId);
                if (version != null) {
                    for (String profileId : profileIds) {
                        Profile profile = version.getRequiredProfile(profileId);
                        if (profile != null) {
                            Profile overlay = profileService.getOverlayProfile(profile);
                            profileOverlays.add(overlay);
                            Map<String, String> dockerConfig = overlay.getConfiguration(DockerConstants.DOCKER_PROVIDER_PID);
                            if (dockerConfig != null) {
                                configOverlay.putAll(dockerConfig);
                            }
                            if (ports == null || ports.size() == 0) {
                                ports = overlay.getConfiguration(Constants.PORTS_PID);
                            }
                        }
                    }
                    if (version.hasProfile(DockerConstants.DOCKER_PROVIDER_PROFILE_ID)) {
                        Profile profile = version.getRequiredProfile(DockerConstants.DOCKER_PROVIDER_PROFILE_ID);
                        if (profile != null) {
                            Profile overlay = profileService.getOverlayProfile(profile);
                            Map<String, String> dockerConfig = overlay.getConfiguration(DockerConstants.DOCKER_PROVIDER_PID);
                            if (dockerConfig != null) {
                                dockerProviderConfig.putAll(dockerConfig);
                            }
                        }
                    }
                }
            }
            if (ports == null || ports.size() == 0) {
                // lets find the defaults from the docker profile
                if (version == null) {
                    version = service.getRequiredDefaultVersion();
                }
                Profile dockerProfile = version.getRequiredProfile("docker");
                ports = dockerProfile.getConfiguration(Constants.PORTS_PID);
                if (ports == null || ports.size() == 0) {
                    LOG.warn("Could not a docker ports configuration for: " + Constants.PORTS_PID);
                    ports = new HashMap<String, String>();
                }
            }
            LOG.info("Got port configuration: " + ports);

            environmentVariables = ChildContainers.getEnvironmentVariables(service, options, DockerConstants.SCHEME);

            DockerProviderConfig configOverlayDockerProvider = createDockerProviderConfig(configOverlay, environmentVariables);

            CuratorFramework curatorOptional = getCuratorFramework();
            String image = JolokiaAgentHelper.substituteVariableExpression(containerConfig.getImage(), environmentVariables, service, curatorOptional, true);

            if (Strings.isNullOrBlank(image)) {
                image = configOverlayDockerProvider.getImage();
                if (Strings.isNullOrBlank(image)) {
                    DockerProviderConfig dockerProviderConfigObject = createDockerProviderConfig(dockerProviderConfig, environmentVariables);
                    image = dockerProviderConfigObject.getImage();
                }
                if (Strings.isNullOrBlank(image)) {
                    image = System.getenv(DockerConstants.EnvironmentVariables.FABRIC8_DOCKER_DEFAULT_IMAGE);
                }
                if (Strings.isNullOrBlank(image)) {
                    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);
                        configuration = JolokiaAgentHelper.substituteEnvironmentVariableExpressionKeysAndValues(configuration, System.getenv());
                        currentContainerDockerProviderConfig = createDockerProviderConfig(configuration);
                    }
                }
                if (Strings.isNullOrBlank(customImageUserName) && currentContainerDockerProviderConfig != null) {
                    customImageUserName = currentContainerDockerProviderConfig.getCustomImageUserName();
                }
                Boolean customImagePushValue = configOverlayDockerProvider.getCustomImagePush();
                if (customImagePushValue == null && currentContainerDockerProviderConfig != null) {
                    customImagePushValue = currentContainerDockerProviderConfig.getCustomImagePush();
                }
                boolean customImagePush = customImagePushValue != null && customImagePushValue.booleanValue();
                if (Strings.isNotBlank(customImageUserName)) {
                    newImageName = customImageUserName + "/" + newImageName;
                } else {
                    customImagePush = false;
                }

                CustomDockerContainerImageBuilder builder = new CustomDockerContainerImageBuilder();
                CustomDockerContainerImageOptions customDockerContainerImageOptions = new CustomDockerContainerImageOptions(image, imageRepository, newImageName, libDir, deployDir, homeDir, entryPoint, configOverlayDockerProvider.getOverlayFolder(), configOverlayDockerProvider.isMavenJavaLibraryPathLayout());

                String actualImage = builder.generateContainerImage(service, container, profileOverlays, docker, customDockerContainerImageOptions, options, downloadExecutor, environmentVariables);
                if (actualImage != null) {
                    containerConfig.setImage(actualImage);

                    if (customImagePush) {
                        LOG.info("Pushing image to repository " + newImageName + " actualImage: " + actualImage);
                        Auth authConfig = new Auth();
                        authConfig.setEmail("person@fabric8.io");
                        authConfig.setUsername(service.getZooKeeperUser());
                        authConfig.setPassword(service.getZookeeperPassword());
                        try {
                            docker.imagePush(newImageName, "latest", authConfig);
                            LOG.info("Image pushed to repository " + newImageName);
                        } catch (Exception e) {
                            LOG.info("Failed to push image " + newImageName + ": " + e + Dockers.dockerErrorMessage(e), e);
View Full Code Here

Examples of io.fabric8.api.FabricService

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

        ServiceProxy<FabricService> fabricProxy = ServiceProxy.createServiceProxy(bundleContext, FabricService.class);
        try {
            FabricService fabricService = fabricProxy.getService();
            CuratorFramework curator = fabricService.adapt(CuratorFramework.class);

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

                LinkedList<Container> containerList = new LinkedList<Container>(containers);
View Full Code Here

Examples of io.fabric8.api.FabricService

        config.setSettings(new MavenSettingsImpl(config.getSettingsFileUrl(), config.useFallbackRepositories()));
        manager = new DownloadManager(config, getDownloadExecutor());
        fabricService = new ServiceTracker<FabricService, FabricService>(systemBundleContext, FabricService.class, new ServiceTrackerCustomizer<FabricService, FabricService>() {
            @Override
            public FabricService addingService(ServiceReference<FabricService> reference) {
                FabricService service = systemBundleContext.getService(reference);
                if (provisioningStatus != null) {
                    updateStatus(service, provisioningStatus, provisioningError, provisionList, false);
                }
                return service;
            }
View Full Code Here

Examples of io.fabric8.api.FabricService

        updateStatus(status, result, null, false);
    }

    private void updateStatus(String status, Throwable result, Collection<Resource> resources, boolean force) {
        try {
            FabricService fs;
            if (force) {
                fs = fabricService.waitForService(0);
            } else {
                fs = fabricService.getService();
            }
View Full Code Here

Examples of io.fabric8.api.FabricService

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

        ServiceProxy<FabricService> fabricProxy = ServiceProxy.createServiceProxy(bundleContext, FabricService.class);
        try {
            FabricService fabricService = fabricProxy.getService();
            CuratorFramework curator = fabricService.adapt(CuratorFramework.class);

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

Examples of io.fabric8.api.FabricService

    private DeploymentUpdater createDeployTask(Container container, Map<String,String> openshiftConfiguration) throws MalformedURLException {
        String webappDir = relativePath(container, openshiftConfiguration, OpenShiftConstants.PROPERTY_DEPLOY_WEBAPPS);
        String deployDir = relativePath(container, openshiftConfiguration, OpenShiftConstants.PROPERTY_DEPLOY_JARS);
        if (webappDir != null || deployDir != null) {
            FabricService fabric = fabricService.get();
            DownloadManager downloadManager = DownloadManagers.createDownloadManager(fabric, downloadExecutor);
            DeploymentUpdater deploymentUpdater = new DeploymentUpdater(downloadManager, fabric, container, webappDir, deployDir);
            deploymentUpdater.setRepositories(Maps.stringValue(openshiftConfiguration, OpenShiftConstants.PROPERTY_REPOSITORIES, OpenShiftConstants.DEFAULT_REPOSITORIES));
            deploymentUpdater.setCopyFilesIntoGit(Maps.booleanValue(openshiftConfiguration, OpenShiftConstants.PROPERTY_COPY_BINARIES_TO_GIT, false));
            return deploymentUpdater;
View Full Code Here

Examples of io.fabric8.api.FabricService

    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")) {
View Full Code Here

Examples of io.fabric8.api.FabricService

        Name containerDomain = Name.fromString(containerSubDomain, domainRoot);
        Name serivceDomain = Name.fromString(serviceSubDomain, domainRoot);
        Name ns = Name.fromString(nameServer, domainRoot);
        Name admin = Name.fromString(adminServer, domainRoot);

        FabricService service = fabricService.get();
        List<Record> records = new ArrayList<>();
        //TODO: At some point we need to manage the serial number.
        records.add(new SOARecord(domainRoot, DClass.IN, DAY, ns, admin, 1, refresh, retry, expire, minimumTtl));
        records.add(new NSRecord(domainRoot, DClass.IN, DAY, ns));
        return new Zone(domainRoot, records.toArray(new Record[records.size()]));
View Full Code Here

Examples of io.fabric8.api.FabricService

    @Override
    protected void onConfigured() throws Exception {
        LOG.debug("onConfigured. mockOutputs: " + mockOutputs + " mockInputs: " + mockInputs + " messageFolder: " + messageFolder);

        FabricService fabricService = this.fabricService.getOptional();

        // lets find the camel contexts to test in this container
        MBeanServer mbeanServerValue = mbeanServer;
        if (mbeanServerValue != null && fabricService != null) {
            Profile overlayProfile = fabricService.getCurrentContainer().getOverlayProfile();
            Profile effectiveProfile = Profiles.getEffectiveProfile(fabricService, overlayProfile);
            Set<String> configurationFileNames = effectiveProfile.getConfigurationFileNames();
            for (CamelContext camelContext : camelContexts.values()) {
                String camelContextID = camelContext.getName();
                // check we only add testing stuff to each context once
View Full Code Here

Examples of io.fabric8.api.FabricService

    @Override
    public void createContainers(AutoScaleRequest request) throws Exception {
        int count = request.getDelta();
        String profile = request.getProfile();
        String version = request.getVersion();
        FabricService fabricService = request.getFabricService();

        CreateOpenshiftContainerOptions.Builder builder = null;
        if (fabricService != null) {
            builder = createAutoScaleOptions(fabricService);
        }
        if (builder != null) {
            // TODO this is actually generic to all providers! :)
            for (int i = 0; i < count; i++) {
                Container[] containers = fabricService.getContainers();
                final CreateOpenshiftContainerOptions.Builder configuredBuilder = builder.number(1).version(version).profiles(profile);

                NameValidator openShiftValidator = containerProvider.createNameValidator(configuredBuilder.build());
                NameValidator fabricNameValidator = Containers.createNameValidator(fabricService.getContainers());
                NameValidator nameValidator = Containers.joinNameValidators(openShiftValidator, fabricNameValidator);

                String name = Containers.createContainerName(containers, profile, containerProvider.getScheme(), nameValidator);

                CreateOpenshiftContainerOptions 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
Copyright © 2018 www.massapi.com. 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.