@Override public int compare(String ins1, String ins2) { // condition : // 1. both in preference list, keep the order in preference list // 2. one them in preference list, the one in preference list has higher priority // 3. none of them in preference list, sort by state. if (_preferenceList.contains(ins1) && _preferenceList.contains(ins2)) { return _preferenceList.indexOf(ins1) - _preferenceList.indexOf(ins2); } else if (_preferenceList.contains(ins1)) { return -1; } else if (_preferenceList.contains(ins2)) { return 1; } Integer p1 = Integer.MAX_VALUE; Integer p2 = Integer.MAX_VALUE; Map<String, Integer> statesPriorityMap = _stateModelDef.getStatePriorityMap(); String state1 = _currentStateMap.get(ins1); String state2 = _currentStateMap.get(ins2); if (state1 != null && statesPriorityMap.containsKey(state1)) { p1 = statesPriorityMap.get(state1); } if (state2 != null && statesPriorityMap.containsKey(state2)) { p2 = statesPriorityMap.get(state2); } return p1.compareTo(p2); } }
@Override public int compare(String ins1, String ins2) { // condition : // 1. both in preference list, keep the order in preference list // 2. one them in preference list, the one in preference list has higher priority // 3. none of them in preference list, sort by state. if (_preferenceList.contains(ins1) && _preferenceList.contains(ins2)) { return _preferenceList.indexOf(ins1) - _preferenceList.indexOf(ins2); } else if (_preferenceList.contains(ins1)) { return -1; } else if (_preferenceList.contains(ins2)) { return 1; } Integer p1 = Integer.MAX_VALUE; Integer p2 = Integer.MAX_VALUE; Map<String, Integer> statesPriorityMap = _stateModelDef.getStatePriorityMap(); String state1 = _currentStateMap.get(ins1); String state2 = _currentStateMap.get(ins2); if (state1 != null && statesPriorityMap.containsKey(state1)) { p1 = statesPriorityMap.get(state1); } if (state2 != null && statesPriorityMap.containsKey(state2)) { p2 = statesPriorityMap.get(state2); } return p1.compareTo(p2); } }
/** * Check for a partition, whether all transitions for its replicas are downward transitions. Note * that this function does NOT check for ERROR states. * @param currentStateMap * @param bestPossibleMap * @param stateModelDef * @return true if there are; false otherwise */ private boolean isLoadBalanceDownwardForAllReplicas(Map<String, String> currentStateMap, Map<String, String> bestPossibleMap, StateModelDefinition stateModelDef) { Set<String> allInstances = new HashSet<>(); allInstances.addAll(currentStateMap.keySet()); allInstances.addAll(bestPossibleMap.keySet()); Map<String, Integer> statePriorityMap = stateModelDef.getStatePriorityMap(); for (String instance : allInstances) { String currentState = currentStateMap.get(instance); String bestPossibleState = bestPossibleMap.get(instance); if (currentState == null) { return false; // null -> state is upward } if (bestPossibleState != null) { // Compare priority values and return if an upward transition is found // Note that lower integer value implies higher priority if (statePriorityMap.get(currentState) > statePriorityMap.get(bestPossibleState)) { return false; } } } return true; }
allInstances.addAll(currentStateMap.keySet()); allInstances.addAll(bestPossibleMap.keySet()); Map<String, Integer> statePriorityMap = stateModelDef.getStatePriorityMap();