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;
}
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);
}
}
}
}
}
}
}
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;
}
Aggregations