Search in sources :

Example 1 with MQService

use of io.fabric8.api.MQService in project fabric8 by jboss-fuse.

the class MQManager method loadBrokerStatus.

@Override
public List<MQBrokerStatusDTO> loadBrokerStatus(String versionId) throws Exception {
    FabricRequirements requirements = fabricService.getRequirements();
    List<MQBrokerStatusDTO> answer = new ArrayList<MQBrokerStatusDTO>();
    Version version = versionId == null ? fabricService.getDefaultVersion() : profileService.getVersion(versionId);
    Container[] containers = fabricService.getContainers();
    List<Profile> values = getActiveOrRequiredBrokerProfileMap(version, 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++;
                    answer.add(status);
                }
            }
            // if there are no containers yet, lets create a record anyway
            if (count == 0) {
                MQBrokerStatusDTO status = createStatusDTO(profile, configDTO, profileRequirements, null);
                answer.add(status);
            }
        }
    }
    addMasterSlaveStatus(answer);
    return answer;
}
Also used : ProfileRequirements(io.fabric8.api.ProfileRequirements) ArrayList(java.util.ArrayList) Profile(io.fabric8.api.Profile) MQBrokerStatusDTO(io.fabric8.api.jmx.MQBrokerStatusDTO) MQBrokerConfigDTO(io.fabric8.api.jmx.MQBrokerConfigDTO) Container(io.fabric8.api.Container) Version(io.fabric8.api.Version) FabricRequirements(io.fabric8.api.FabricRequirements)

Example 2 with MQService

use of io.fabric8.api.MQService in project fabric8 by jboss-fuse.

the class MQManager method createConfigDTOs.

public static List<MQBrokerConfigDTO> createConfigDTOs(MQService mqService, Profile profile) {
    List<MQBrokerConfigDTO> answer = new ArrayList<MQBrokerConfigDTO>();
    Map<String, Map<String, String>> configurations = profile.getConfigurations();
    Set<Map.Entry<String, Map<String, String>>> entries = configurations.entrySet();
    for (Map.Entry<String, Map<String, String>> entry : entries) {
        String key = entry.getKey();
        Map<String, String> configuration = entry.getValue();
        if (isBrokerConfigPid(key)) {
            String brokerName = getBrokerNameFromPID(key);
            String profileId = profile.getId();
            MQBrokerConfigDTO dto = new MQBrokerConfigDTO();
            dto.setProfile(profileId);
            dto.setBrokerName(brokerName);
            String version = profile.getVersion();
            dto.setVersion(version);
            List<String> parentIds = profile.getParentIds();
            if (parentIds.size() > 0) {
                dto.setParentProfile(parentIds.get(0));
            }
            if (configuration != null) {
                dto.setData(configuration.get(DATA));
                dto.setConfigUrl(configuration.get(CONFIG_URL));
                dto.setGroup(configuration.get(GROUP));
                dto.setKind(BrokerKind.fromValue(configuration.get(KIND)));
                dto.setMinimumInstances(Maps.integerValue(configuration, MINIMUM_INSTANCES));
                dto.setNetworks(Maps.stringValues(configuration, NETWORKS));
                dto.setNetworksUserName(configuration.get(NETWORK_USER_NAME));
                dto.setNetworksPassword(configuration.get(NETWORK_PASSWORD));
                dto.setReplicas(Maps.integerValue(configuration, REPLICAS));
                for (Map.Entry<String, String> configurationEntry : configuration.entrySet()) {
                    if (configurationEntry.getKey().endsWith("-port")) {
                        dto.getPorts().put(configurationEntry.getKey().substring(0, configurationEntry.getKey().indexOf("-port")), configurationEntry.getValue());
                    }
                }
            }
            answer.add(dto);
        }
    }
    return answer;
}
Also used : MQBrokerConfigDTO(io.fabric8.api.jmx.MQBrokerConfigDTO) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap)

Example 3 with MQService

use of io.fabric8.api.MQService in project fabric8 by jboss-fuse.

the class MQManager method loadBrokerConfiguration.

@Override
public List<MQBrokerConfigDTO> loadBrokerConfiguration() {
    List<MQBrokerConfigDTO> answer = new ArrayList<MQBrokerConfigDTO>();
    Collection<Profile> values = getActiveOrRequiredBrokerProfileMap();
    for (Profile profile : values) {
        List<MQBrokerConfigDTO> list = createConfigDTOs(mqService, profile);
        answer.addAll(list);
    }
    return answer;
}
Also used : MQBrokerConfigDTO(io.fabric8.api.jmx.MQBrokerConfigDTO) ArrayList(java.util.ArrayList) Profile(io.fabric8.api.Profile)

Example 4 with MQService

use of io.fabric8.api.MQService in project fabric8 by jboss-fuse.

the class MQManager method createOrUpdateProfile.

/**
 * 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();
    boolean changeInCurrentVersion = requirements.getVersion().equals(dto.getVersion());
    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();
    try {
        FabricValidations.validateProfileName(profileName);
    } catch (IllegalArgumentException e) {
        // we do not want exception in the server log, so print the error message to the console
        System.out.println(e.getMessage());
        return null;
    }
    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);
    // lets assume 2 required instances for master/slave unless folks use
    // N+1 or replicated
    int requiredInstances = 2;
    if (list.size() == 1) {
        MQBrokerConfigDTO loadedDTO = list.get(0);
        requiredInstances = loadedDTO.requiredInstances();
    } else {
        // assume N+1 broker as there's more than one broker in the profile; so lets set the required size to N+1
        requiredInstances = list.size() + 1;
    }
    if (changeInCurrentVersion && (minimumInstances == null || minimumInstances.intValue() < requiredInstances)) {
        profileRequirement.setMinimumInstances(requiredInstances);
        fabricService.setRequirements(requirements);
    }
    String clientProfile = dto.clientProfile();
    if (Strings.isNotBlank(clientProfile)) {
        String clientParentProfile = dto.getClientParentProfile();
        if (Strings.isNullOrBlank(clientParentProfile)) {
            clientParentProfile = "mq-client-base";
        }
        mqService.createOrUpdateMQClientProfile(version, clientProfile, group, clientParentProfile);
    }
    return profile;
}
Also used : MQService(io.fabric8.api.MQService) ProfileRequirements(io.fabric8.api.ProfileRequirements) BrokerKind(io.fabric8.api.jmx.BrokerKind) HashMap(java.util.HashMap) Profile(io.fabric8.api.Profile) MQBrokerConfigDTO(io.fabric8.api.jmx.MQBrokerConfigDTO) FabricRequirements(io.fabric8.api.FabricRequirements) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

MQBrokerConfigDTO (io.fabric8.api.jmx.MQBrokerConfigDTO)4 Profile (io.fabric8.api.Profile)3 ArrayList (java.util.ArrayList)3 FabricRequirements (io.fabric8.api.FabricRequirements)2 ProfileRequirements (io.fabric8.api.ProfileRequirements)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Container (io.fabric8.api.Container)1 MQService (io.fabric8.api.MQService)1 Version (io.fabric8.api.Version)1 BrokerKind (io.fabric8.api.jmx.BrokerKind)1 MQBrokerStatusDTO (io.fabric8.api.jmx.MQBrokerStatusDTO)1