Github user kanakb commented on a diff in the pull request: https://github.com/apache/helix/pull/31#discussion_r33892312 --- Diff: helix-core/src/main/java/org/apache/helix/spectator/RoutingTableProvider.java --- @@ -235,8 +376,94 @@ PartitionInfo get(String stateUnitKey) { } } + class ResourceGroupInfo { + // store PartitionInfo for each partition for all resources in the resource group + HashMap<String, PartitionInfo> partitionInfoMap; + // stores the Set of Instances in a given state for all resources in the resource group + HashMap<String, Set<InstanceConfig>> stateInfoMap; + // stores the ResourceInfo for each resource with different instance tag. + HashMap<String, ResourceInfo> tagResourceInfoMap; + + public ResourceGroupInfo() { + partitionInfoMap = new HashMap<String, RoutingTableProvider.PartitionInfo>(); + stateInfoMap = new HashMap<String, Set<InstanceConfig>>(); + tagResourceInfoMap = new HashMap<String, ResourceInfo>(); + } + + public void addEntry(String resourceTag, String stateUnitKey, String state, InstanceConfig config) { + // add + if (!stateInfoMap.containsKey(state)) { + Comparator<InstanceConfig> comparator = new Comparator<InstanceConfig>() { + + @Override + public int compare(InstanceConfig o1, InstanceConfig o2) { + if (o1 == o2) { + return 0; + } + if (o1 == null) { + return -1; + } + if (o2 == null) { + return 1; + } + + int compareTo = o1.getHostName().compareTo(o2.getHostName()); + if (compareTo == 0) { + return o1.getPort().compareTo(o2.getPort()); + } else { + return compareTo; + } + + } + }; + stateInfoMap.put(state, new TreeSet<InstanceConfig>(comparator)); + } + Set<InstanceConfig> set = stateInfoMap.get(state); + set.add(config); + + if (!partitionInfoMap.containsKey(stateUnitKey)) { + partitionInfoMap.put(stateUnitKey, new PartitionInfo()); + } + PartitionInfo stateUnitKeyInfo = partitionInfoMap.get(stateUnitKey); + stateUnitKeyInfo.addEntry(state, config); + + if (!tagResourceInfoMap.containsKey(resourceTag)) { + tagResourceInfoMap.put(resourceTag, new ResourceInfo()); + } + ResourceInfo resourceInfo = tagResourceInfoMap.get(resourceTag); + resourceInfo.addEntry(stateUnitKey, state, config); + } + + public Set<InstanceConfig> getInstances(String state) { + Set<InstanceConfig> instanceSet = stateInfoMap.get(state); + return instanceSet; + } + + public Set<InstanceConfig> getInstances(String state, String resourceTag) { + ResourceInfo resourceInfo = tagResourceInfoMap.get(resourceTag); --- End diff -- What if multiple resources have the same tag?
--- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---