Github user revans2 commented on a diff in the pull request: https://github.com/apache/storm/pull/2385#discussion_r149164076 --- Diff: storm-server/src/main/java/org/apache/storm/scheduler/resource/ResourceUtils.java --- @@ -129,41 +137,65 @@ public static String getJsonWithUpdatedResources(String jsonConf, Map<String, Do } } - public static void checkIntialization(Map<String, Double> topologyResources, String com, - Map<String, Object> topologyConf) { - checkInitMem(topologyResources, com, topologyConf); - checkInitCpu(topologyResources, com, topologyConf); - } + public static void checkInitialization(Map<String, Double> topologyResources, String componentId, Map topologyConf) { + StringBuilder msgBuilder = new StringBuilder(); - private static void checkInitMem(Map<String, Double> topologyResources, String com, - Map<String, Object> topologyConf) { - if (!topologyResources.containsKey(Config.TOPOLOGY_COMPONENT_RESOURCES_ONHEAP_MEMORY_MB)) { - Double onHeap = ObjectReader.getDouble( - topologyConf.get(Config.TOPOLOGY_COMPONENT_RESOURCES_ONHEAP_MEMORY_MB), null); - if (onHeap != null) { - topologyResources.put(Config.TOPOLOGY_COMPONENT_RESOURCES_ONHEAP_MEMORY_MB, onHeap); - debugMessage("ONHEAP", com, topologyConf); - } + Set<String> resourceNameSet = new HashSet<>(); + + resourceNameSet.add( + Config.TOPOLOGY_COMPONENT_CPU_PCORE_PERCENT + ); + resourceNameSet.add( + Config.TOPOLOGY_COMPONENT_RESOURCES_OFFHEAP_MEMORY_MB + ); + resourceNameSet.add( + Config.TOPOLOGY_COMPONENT_RESOURCES_ONHEAP_MEMORY_MB + ); + + Map<String, Double> topologyComponentResourcesMap = + (Map<String, Double>) topologyConf.getOrDefault( + Config.TOPOLOGY_COMPONENT_RESOURCES_MAP, Collections.emptyMap()); + + resourceNameSet.addAll(topologyResources.keySet()); + resourceNameSet.addAll(topologyComponentResourcesMap.keySet()); + + for (String resourceName : resourceNameSet) { + msgBuilder.append(checkInitResource(topologyResources, topologyConf, topologyComponentResourcesMap, resourceName)); } - if (!topologyResources.containsKey(Config.TOPOLOGY_COMPONENT_RESOURCES_OFFHEAP_MEMORY_MB)) { - Double offHeap = ObjectReader.getDouble( - topologyConf.get(Config.TOPOLOGY_COMPONENT_RESOURCES_OFFHEAP_MEMORY_MB), null); - if (offHeap != null) { - topologyResources.put(Config.TOPOLOGY_COMPONENT_RESOURCES_OFFHEAP_MEMORY_MB, offHeap); - debugMessage("OFFHEAP", com, topologyConf); - } + + Map<String, Double> normalizedTopologyResources = normalizedResourceMap(topologyResources); + topologyResources.clear(); + topologyResources.putAll(normalizedTopologyResources); + + if (msgBuilder.length() > 0) { + String resourceDefaults = msgBuilder.toString(); + LOG.debug( + "Unable to extract resource requirement for Component {} \n Resources : {}", + componentId, resourceDefaults); } } - private static void checkInitCpu(Map<String, Double> topologyResources, String com, - Map<String, Object> topologyConf) { - if (!topologyResources.containsKey(Config.TOPOLOGY_COMPONENT_CPU_PCORE_PERCENT)) { - Double cpu = ObjectReader.getDouble(topologyConf.get(Config.TOPOLOGY_COMPONENT_CPU_PCORE_PERCENT), null); - if (cpu != null) { - topologyResources.put(Config.TOPOLOGY_COMPONENT_CPU_PCORE_PERCENT, cpu); - debugMessage("CPU", com, topologyConf); + private static String checkInitResource(Map<String, Double> topologyResources, Map topologyConf, + Map<String, Double> topologyComponentResourcesMap, String resourceName) { + StringBuilder msgBuilder = new StringBuilder(); + String normalizedResourceName = resourceNameMapping.getOrDefault(resourceName, resourceName); + if (!topologyResources.containsKey(normalizedResourceName)) { + if (topologyConf.containsKey(resourceName)) { + Double resourceValue = ObjectReader.getDouble(topologyConf.get(resourceName)); + if(resourceValue!=null) { + topologyResources.put(normalizedResourceName, resourceValue); + } + } + + if (topologyComponentResourcesMap.containsKey(normalizedResourceName)) { + Double resourceValue = ObjectReader.getDouble(topologyComponentResourcesMap.get(resourceName)); + if(resourceValue!=null) { --- End diff -- nit: space after the if.
---