Search in sources :

Example 1 with MQBrokerStatusDTO

use of io.fabric8.api.jmx.MQBrokerStatusDTO 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 MQBrokerStatusDTO

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

the class MQManager method addMasterSlaveStatus.

protected void addMasterSlaveStatus(List<MQBrokerStatusDTO> answer) throws Exception {
    Map<String, Map<String, MQBrokerStatusDTO>> groupMap = new HashMap<String, Map<String, MQBrokerStatusDTO>>();
    for (MQBrokerStatusDTO status : answer) {
        String key = status.getGroup();
        Map<String, MQBrokerStatusDTO> list = groupMap.get(key);
        if (list == null) {
            list = new HashMap<String, MQBrokerStatusDTO>();
            groupMap.put(key, list);
        }
        String statusPath = String.format("%s/%s", status.getContainer(), status.getBrokerName());
        list.put(statusPath, status);
    }
    CuratorFramework curator = getCurator();
    // now lets check the cluster status for each group
    Set<Map.Entry<String, Map<String, MQBrokerStatusDTO>>> entries = groupMap.entrySet();
    for (Map.Entry<String, Map<String, MQBrokerStatusDTO>> entry : entries) {
        String group = entry.getKey();
        Map<String, MQBrokerStatusDTO> containerMap = entry.getValue();
        String groupPath = ZkPath.MQ_CLUSTER.getPath(group);
        List<String> children = getChildrenSafe(curator, groupPath);
        for (String child : children) {
            String childPath = groupPath + "/" + child;
            byte[] data = curator.getData().forPath(childPath);
            if (data != null && data.length > 0) {
                String text = new String(data).trim();
                if (!text.isEmpty()) {
                    ObjectMapper mapper = new ObjectMapper();
                    Map<String, Object> map = mapper.readValue(data, HashMap.class);
                    String id = stringValue(map, "id", "container");
                    if (id != null) {
                        String container = stringValue(map, "container", "agent");
                        String statusPath = String.format("%s/%s", container, id);
                        MQBrokerStatusDTO containerStatus = containerMap.get(statusPath);
                        if (containerStatus != null) {
                            Boolean master = null;
                            List services = listValue(map, "services");
                            if (services != null) {
                                if (!services.isEmpty()) {
                                    List<String> serviceTexts = new ArrayList<String>();
                                    for (Object service : services) {
                                        String serviceText = getSubstitutedData(curator, service.toString());
                                        if (Strings.isNotBlank(serviceText)) {
                                            serviceTexts.add(serviceText);
                                        }
                                        containerStatus.setServices(serviceTexts);
                                    }
                                    master = Boolean.TRUE;
                                } else {
                                    master = Boolean.FALSE;
                                }
                            } else {
                                master = Boolean.FALSE;
                            }
                            containerStatus.setMaster(master);
                        }
                    }
                }
            }
        }
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) MQBrokerStatusDTO(io.fabric8.api.jmx.MQBrokerStatusDTO) CuratorFramework(org.apache.curator.framework.CuratorFramework) List(java.util.List) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 3 with MQBrokerStatusDTO

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

the class MQManager method createStatusDTO.

protected MQBrokerStatusDTO createStatusDTO(Profile profile, MQBrokerConfigDTO configDTO, ProfileRequirements profileRequirements, Container container) {
    MQBrokerStatusDTO answer = new MQBrokerStatusDTO(configDTO);
    if (container != null) {
        answer.setContainer(container.getId());
        answer.setAlive(container.isAlive());
        answer.setProvisionResult(container.getProvisionResult());
        answer.setProvisionStatus(container.getProvisionStatus());
        answer.setJolokiaUrl(container.getJolokiaUrl());
    }
    if (profileRequirements != null) {
        Integer minimumInstances = profileRequirements.getMinimumInstances();
        if (minimumInstances != null) {
            answer.setMinimumInstances(minimumInstances);
        }
    }
    return answer;
}
Also used : MQBrokerStatusDTO(io.fabric8.api.jmx.MQBrokerStatusDTO)

Aggregations

MQBrokerStatusDTO (io.fabric8.api.jmx.MQBrokerStatusDTO)3 ArrayList (java.util.ArrayList)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Container (io.fabric8.api.Container)1 FabricRequirements (io.fabric8.api.FabricRequirements)1 Profile (io.fabric8.api.Profile)1 ProfileRequirements (io.fabric8.api.ProfileRequirements)1 Version (io.fabric8.api.Version)1 MQBrokerConfigDTO (io.fabric8.api.jmx.MQBrokerConfigDTO)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 CuratorFramework (org.apache.curator.framework.CuratorFramework)1