public static List < Collection < Integer > > sortHostIdByHGDistance ( int hostId , Map < Integer , String > hostGroups ) { String localHostGroup = hostGroups . get ( hostId ) ; Preconditions . checkArgument ( localHostGroup != null ) ; HAGroup localHaGroup = new HAGroup ( localHostGroup ) ; // Memorize the distance, map the distance to host ids. Multimap < Integer , Integer > distanceMap = MultimapBuilder . treeKeys ( Comparator . < Integer > naturalOrder ( ) . reversed ( ) ) . arrayListValues ( ) . build ( ) ; for ( Map . Entry < Integer , String > entry : hostGroups . entrySet ( ) ) { if ( hostId == entry . getKey ( ) ) { continue ; } distanceMap . put ( localHaGroup . getRelationshipTo ( entry . getValue ( ) ) . m_distance , entry . getKey ( ) ) ; } return new ArrayList <> ( distanceMap . asMap ( ) . values ( ) ) ; }
Sort all nodes in reverse hostGroup distance order then group by rack - aware group local host id is excluded .