Examples of FabricRequirements


Examples of io.fabric8.api.FabricRequirements

    @Override
    public boolean scaleProfile(String profile, int numberOfInstances) throws IOException {
        if (numberOfInstances == 0) {
            throw new IllegalArgumentException("numberOfInstances should be greater or less than zero");
        }
        FabricRequirements requirements = getRequirements();
        ProfileRequirements profileRequirements = requirements.getOrCreateProfileRequirement(profile);
        Integer minimumInstances = profileRequirements.getMinimumInstances();
        List<Container> containers = Containers.containersForProfile(getContainers(), profile);
        int containerCount = containers.size();
        int newCount = containerCount + numberOfInstances;
        if (newCount < 0) {
View Full Code Here

Examples of io.fabric8.api.FabricRequirements

        if (is == null) {
            System.out.println("Could not open the URL " + jsonUrl);
            return null;
        }

        FabricRequirements requirements = RequirementsJson.readRequirements(is);
        if (requirements != null) {
            getFabricService().setRequirements(requirements);
            System.out.println("Imported the fabric requirements from " + jsonUrl);
        }
        return null;
View Full Code Here

Examples of io.fabric8.api.FabricRequirements

        autoScale();
    }

    private void autoScale() {
        FabricService service = fabricService.get();
        FabricRequirements requirements = service.getRequirements();
        List<ProfileRequirements> profileRequirements = requirements.getProfileRequirements();
        if (profileRequirements != null && !profileRequirements.isEmpty()) {
            AutoScaleStatus status = new AutoScaleStatus();
            for (ProfileRequirements profileRequirement : profileRequirements) {
                ContainerAutoScaler autoScaler = createAutoScaler(requirements, profileRequirement);
                if (autoScaler != null) {
View Full Code Here

Examples of io.fabric8.api.FabricRequirements

    @Override
    public FabricRequirements getRequirements() {
        assertValid();
        try {
            FabricRequirements answer = null;
            if (configCache.getCurrentData(REQUIREMENTS_JSON_PATH) != null) {
                String json = getStringData(configCache, REQUIREMENTS_JSON_PATH);
                answer = RequirementsJson.fromJSON(json);
            }
            if (answer == null) {
                answer = new FabricRequirements();
            }
            return answer;
        } catch (Exception e) {
            throw FabricException.launderThrowable(e);
        }
View Full Code Here

Examples of io.fabric8.api.FabricRequirements

        return fabricService.getRequirements();
    }

    @Override
    public String requirementsAsJson() {
        FabricRequirements dto = requirements();

        try {
            return getObjectMapper()
                    .writerWithDefaultPrettyPrinter()
                    .withType(FabricRequirements.class)
View Full Code Here

Examples of io.fabric8.api.FabricRequirements

            Set<String> previousValidProfileIds = new HashSet<String>();

            @Override
            public Boolean call() throws Exception {
                controller.setRequirements(requirements);
                FabricRequirements actual = controller.getRequirements();
                String actualVersion = actual.getVersion();
                // lets clear the actualVersion as we usually don't set one and it gets defaulted
                actual.setVersion(requirements.getVersion());

                // lets sort them both to ensure ordering
                requirements.sortProfilesRequirements();
                actual.sortProfilesRequirements();

                boolean valid = RequirementsJson.equal(requirements, actual);
                if (!valid) {
                    System.out.println("Expected: " + RequirementsJson.toJSON(requirements));
                    System.out.println("Actual:   " + RequirementsJson.toJSON(actual));
View Full Code Here

Examples of io.fabric8.api.FabricRequirements

    @Override
    protected Object doExecute() throws Exception {
        outputFile.getParentFile().mkdirs();

        FabricRequirements requirements = getFabricService().getRequirements();
        RequirementsJson.writeRequirements(new FileOutputStream(outputFile), requirements);
        System.out.println("Exported the fabric requirements to " + outputFile.getCanonicalPath());
        return null;
    }
View Full Code Here

Examples of io.fabric8.api.FabricRequirements

        return answer;
    }

    @Override
    public List<MQBrokerStatusDTO> loadBrokerStatus() throws Exception {
        FabricRequirements requirements = fabricService.getRequirements();
        List<MQBrokerStatusDTO> answer = new ArrayList<MQBrokerStatusDTO>();
        Version defaultVersion = fabricService.getDefaultVersion();
        Container[] containers = fabricService.getContainers();
        List<Profile> values = getActiveOrRequiredBrokerProfileMap(defaultVersion, requirements);
        for (Profile profile : values) {
            List<MQBrokerConfigDTO> list = createConfigDTOs(mqService, profile);
            for (MQBrokerConfigDTO configDTO : list) {
                ProfileRequirements profileRequirements = requirements.findProfileRequirements(profile.getId());
                int count = 0;
                for (Container container : containers) {
                    if (Containers.containerHasProfile(container, profile)) {
                        MQBrokerStatusDTO status = createStatusDTO(profile, configDTO, profileRequirements, container);
                        count++;
View Full Code Here

Examples of io.fabric8.api.FabricRequirements

    /**
     * Creates or updates the broker profile for the given DTO and updates the requirements so that the
     * minimum number of instances of the profile is updated
     */
    public static Profile createOrUpdateProfile(MQBrokerConfigDTO dto, FabricService fabricService, RuntimeProperties runtimeProperties) throws IOException {
        FabricRequirements requirements = fabricService.getRequirements();
        MQService mqService = createMQService(fabricService, runtimeProperties);
        Map<String, String> configuration = new HashMap<String, String>();

        List<String> properties = dto.getProperties();
        String version = dto.version();

        if (properties != null) {
            for (String entry : properties) {
                String[] parts = entry.split("=", 2);
                if (parts.length == 2) {
                    configuration.put(parts[0], parts[1]);
                } else {
                    configuration.put(parts[0], "");
                }
            }
        }

        String data = dto.getData();
        String profileName = dto.profile();
        String brokerName = dto.getBrokerName();
        if (data == null) {
            // lets use a relative path so we work on any karaf container
            data = "${runtime.data}" + brokerName;
        }
        configuration.put(DATA, data);


        for (Map.Entry<String,String> port: dto.getPorts().entrySet()) {
            configuration.put(port.getKey() + "-port", port.getValue());
        }

        BrokerKind kind = dto.kind();
        configuration.put(KIND, kind.toString());

        String config = dto.getConfigUrl();
        if (config != null) {
            configuration.put(CONFIG_URL, mqService.getConfig(version, config));
        }

        String group = dto.getGroup();
        if (group != null) {
            configuration.put(GROUP, group);
        }

        Maps.setStringValues(configuration, NETWORKS, dto.getNetworks());

        String networksUserName = dto.getNetworksUserName();
        if (networksUserName != null) {
            configuration.put(NETWORK_USER_NAME, networksUserName);
        }

        String networksPassword = dto.getNetworksPassword();
        if (networksPassword != null) {
            configuration.put(NETWORK_PASSWORD, networksPassword);
        }

        String parentProfile = dto.getParentProfile();
        if (parentProfile != null) {
            configuration.put(PARENT, parentProfile);
        }

        Boolean ssl = dto.getSsl();
        if (ssl != null) {
            configuration.put(SSL, ssl.toString());
        }

        Integer replicas = dto.getReplicas();
        if (replicas != null) {
            configuration.put(REPLICAS, replicas.toString());
        }
        Integer minInstances = dto.getMinimumInstances();
        if (minInstances != null) {
            configuration.put(MINIMUM_INSTANCES, minInstances.toString());
        }

        Profile profile = mqService.createOrUpdateMQProfile(version, profileName, brokerName, configuration, dto.kind().equals(BrokerKind.Replicated));
        String profileId = profile.getId();
        ProfileRequirements profileRequirement = requirements.getOrCreateProfileRequirement(profileId);
        Integer minimumInstances = profileRequirement.getMinimumInstances();

        // lets reload the DTO as we may have inherited some values from the parent profile
        List<MQBrokerConfigDTO> list = createConfigDTOs(mqService, profile);

View Full Code Here

Examples of io.fabric8.api.FabricRequirements

    }

    @Override
    protected Object doExecute() throws Exception {
        PrintStream out = System.out;
        FabricRequirements requirements = getFabricService().getRequirements();
        printRequirements(out, requirements);
        return null;
    }
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.