use of org.apache.storm.utils.IVersionInfo in project storm by apache.
the class UIHelpers method getClusterSummary.
/**
* Converts thrift call result into map fit for UI/api.
* @param clusterSummary Obtained from Nimbus.
* @param user User Making request
* @param conf Storm Conf
* @return Cluster Summary for display on UI/monitoring purposes via API
*/
public static Map<String, Object> getClusterSummary(ClusterSummary clusterSummary, String user, Map<String, Object> conf) {
Map<String, Object> result = new HashMap();
if (MEMORIZED_VERSIONS.get() == null) {
// Races are okay this is just to avoid extra work for each page load.
NavigableMap<String, IVersionInfo> versionsMap = Utils.getAlternativeVersionsMap(conf);
List<Map<String, String>> versionList = new ArrayList<>();
for (Map.Entry<String, IVersionInfo> entry : versionsMap.entrySet()) {
Map<String, String> single = new HashMap<>(toJsonStruct(entry.getValue()));
single.put("versionMatch", entry.getKey());
versionList.add(single);
}
MEMORIZED_VERSIONS.set(versionList);
}
List<Map<String, String>> versions = MEMORIZED_VERSIONS.get();
if (!versions.isEmpty()) {
result.put("alternativeWorkerVersions", versions);
}
if (MEMORIZED_FULL_VERSION.get() == null) {
MEMORIZED_FULL_VERSION.set(toJsonStruct(VersionInfo.OUR_FULL_VERSION));
}
result.put("user", user);
result.put("stormVersion", VersionInfo.getVersion());
result.put("stormVersionInfo", MEMORIZED_FULL_VERSION.get());
List<SupervisorSummary> supervisorSummaries = clusterSummary.get_supervisors();
result.put("supervisors", supervisorSummaries.size());
result.put("topologies", clusterSummary.get_topologies_size());
int usedSlots = supervisorSummaries.stream().mapToInt(SupervisorSummary::get_num_used_workers).sum();
result.put("slotsUsed", usedSlots);
int totalSlots = supervisorSummaries.stream().mapToInt(SupervisorSummary::get_num_workers).sum();
result.put("slotsTotal", totalSlots);
result.put("slotsFree", totalSlots - usedSlots);
List<TopologySummary> topologySummaries = clusterSummary.get_topologies();
int totalTasks = topologySummaries.stream().mapToInt(TopologySummary::get_num_tasks).sum();
result.put("tasksTotal", totalTasks);
int totalExecutors = topologySummaries.stream().mapToInt(TopologySummary::get_num_executors).sum();
result.put("executorsTotal", totalExecutors);
double supervisorTotalMemory = supervisorSummaries.stream().mapToDouble(x -> x.get_total_resources().getOrDefault(Constants.COMMON_TOTAL_MEMORY_RESOURCE_NAME, x.get_total_resources().get(Config.SUPERVISOR_MEMORY_CAPACITY_MB))).sum();
result.put("totalMem", supervisorTotalMemory);
double supervisorTotalCpu = supervisorSummaries.stream().mapToDouble(x -> x.get_total_resources().getOrDefault(Constants.COMMON_CPU_RESOURCE_NAME, x.get_total_resources().get(Config.SUPERVISOR_CPU_CAPACITY))).sum();
result.put("totalCpu", supervisorTotalCpu);
double supervisorUsedMemory = supervisorSummaries.stream().mapToDouble(SupervisorSummary::get_used_mem).sum();
result.put("availMem", supervisorTotalMemory - supervisorUsedMemory);
double supervisorUsedCpu = supervisorSummaries.stream().mapToDouble(SupervisorSummary::get_used_cpu).sum();
result.put("availCpu", supervisorTotalCpu - supervisorUsedCpu);
result.put("fragmentedMem", supervisorSummaries.stream().mapToDouble(SupervisorSummary::get_fragmented_mem).sum());
result.put("fragmentedCpu", supervisorSummaries.stream().mapToDouble(SupervisorSummary::get_fragmented_cpu).sum());
result.put("schedulerDisplayResource", conf.get(DaemonConfig.SCHEDULER_DISPLAY_RESOURCE));
result.put("memAssignedPercentUtil", supervisorTotalMemory > 0 ? StatsUtil.floatStr((supervisorUsedMemory * 100.0) / supervisorTotalMemory) : "0.0");
result.put("cpuAssignedPercentUtil", supervisorTotalCpu > 0 ? StatsUtil.floatStr((supervisorUsedCpu * 100.0) / supervisorTotalCpu) : "0.0");
result.put("bugtracker-url", conf.get(DaemonConfig.UI_PROJECT_BUGTRACKER_URL));
result.put("central-log-url", conf.get(DaemonConfig.UI_CENTRAL_LOGGING_URL));
Map<String, Double> usedGenericResources = new HashMap<>();
Map<String, Double> totalGenericResources = new HashMap<>();
for (SupervisorSummary ss : supervisorSummaries) {
usedGenericResources = NormalizedResourceRequest.addResourceMap(usedGenericResources, ss.get_used_generic_resources());
totalGenericResources = NormalizedResourceRequest.addResourceMap(totalGenericResources, ss.get_total_resources());
}
Map<String, Double> availGenericResources = NormalizedResourceRequest.subtractResourceMap(totalGenericResources, usedGenericResources);
result.put("availGenerics", prettifyGenericResources(availGenericResources));
result.put("totalGenerics", prettifyGenericResources(totalGenericResources));
return result;
}
Aggregations