Github user govind-menon commented on a diff in the pull request:

    https://github.com/apache/storm/pull/2752#discussion_r201717965
  
    --- Diff: storm-core/src/jvm/org/apache/storm/ui/UIHelpers.java ---
    @@ -295,9 +391,1104 @@ public static String getJsonResponseBody(Object 
data, String callback, boolean n
             return callback != null ? wrapJsonInCallback(callback, 
serializedData) : serializedData;
         }
     
    +    /**
    +     * Converts exception into json map.
    +     * @param ex Exception to be converted.
    +     * @param statusCode Status code to be returned.
    +     * @return Map to be converted into json.
    +     */
         public static Map exceptionToJson(Exception ex, int statusCode) {
             StringWriter sw = new StringWriter();
             ex.printStackTrace(new PrintWriter(sw));
    -        return ImmutableMap.of("error", statusCode + " " + 
HttpStatus.getMessage(statusCode), "errorMessage", sw.toString());
    +        return ImmutableMap.of(
    +                "error", statusCode
    +                        + " "
    +                        + HttpStatus.getMessage(statusCode),
    +                "errorMessage", sw.toString());
    +    }
    +
    +    /**
    +     * 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();
    +        List<SupervisorSummary> supervisorSummaries = 
clusterSummary.get_supervisors();
    +        List<TopologySummary> topologySummaries = 
clusterSummary.get_topologies();
    +
    +        Integer usedSlots =
    +                supervisorSummaries.stream().mapToInt(
    +                SupervisorSummary::get_num_used_workers).sum();
    +        Integer totalSlots =
    +                supervisorSummaries.stream().mapToInt(
    +                        SupervisorSummary::get_num_workers).sum();
    +
    +        Integer totalTasks =
    +                topologySummaries.stream().mapToInt(
    +                        TopologySummary::get_num_tasks).sum();
    +        Integer totalExecutors =
    +                topologySummaries.stream().mapToInt(
    +                        TopologySummary::get_num_executors).sum();
    +
    +        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();
    +
    +        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();
    +
    +        Double supervisorUsedMemory =
    +                
supervisorSummaries.stream().mapToDouble(SupervisorSummary::get_used_mem).sum();
    +        Double supervisorUsedCpu =
    +                
supervisorSummaries.stream().mapToDouble(SupervisorSummary::get_used_cpu).sum();
    +        Double supervisorFragementedCpu =
    +                supervisorSummaries.stream().mapToDouble(
    +                        SupervisorSummary::get_fragmented_cpu).sum();
    +        Double supervisorFragmentedMem =
    +                supervisorSummaries.stream().mapToDouble(
    +                        SupervisorSummary::get_fragmented_mem).sum();
    +
    +
    +        result.put("user", user);
    +        result.put("stormVersion", VersionInfo.getVersion());
    +        result.put("supervisors", supervisorSummaries.size());
    +        result.put("topologies", clusterSummary.get_topologies_size());
    +        result.put("slotsUsed", usedSlots);
    +        result.put("slotsTotal", totalSlots);
    +        result.put("slotsFree", totalSlots - usedSlots);
    +        result.put("tasksTotal", totalTasks);
    +        result.put("totalExecutors", totalExecutors);
    +
    +        result.put("totalMem", supervisorTotalMemory);
    +        result.put("totalCpu", supervisorTotalCpu);
    +        result.put("availMem", supervisorTotalMemory - 
supervisorUsedMemory);
    +        result.put("availCpu", supervisorTotalCpu - supervisorUsedCpu);
    +        result.put("fragmentedMem", supervisorFragmentedMem);
    +        result.put("fragmentedCpu", supervisorFragementedCpu);
    +        result.put("schedulerDisplayResource",
    +                conf.get(DaemonConfig.SCHEDULER_DISPLAY_RESOURCE));
    +        result.put("memAssignedPercentUtil", supervisorTotalMemory > 0
    +                ? ((supervisorTotalMemory - supervisorUsedMemory)  * 100.0)
    +                / supervisorTotalMemory : 0.0);
    +        result.put("cpuAssignedPercentUtil", supervisorTotalCpu > 0
    +                ? ((supervisorTotalCpu - 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));
    +        return result;
    +    }
    +
    +    /**
    +     * Prettify OwnerResourceSummary.
    +     * @param ownerResourceSummary
    +     * @return Map of prettified OwnerResourceSummary.
    +     */
    +    public static Map<String, Object> 
unpackOwnerResourceSummary(OwnerResourceSummary ownerResourceSummary) {
    +        Map<String, Object> result = new HashMap();
    +
    +        Double memoryGuarantee = Double.valueOf(-1);
    --- End diff --
    
    It now does that some lines below


---

Reply via email to