use of org.apache.helix.controller.stages.BestPossibleStateCalcStage in project helix by apache.
the class BestPossibleExternalViewVerifier method calcBestPossState.
/**
* calculate the best possible state note that DROPPED states are not checked since when
* kick off the BestPossibleStateCalcStage we are providing an empty current state map
*
* @param cache
* @return
* @throws Exception
*/
private BestPossibleStateOutput calcBestPossState(ClusterDataCache cache) throws Exception {
ClusterEvent event = new ClusterEvent(ClusterEventType.StateVerifier);
event.addAttribute(AttributeName.ClusterDataCache.name(), cache);
runStage(event, new ResourceComputationStage());
runStage(event, new CurrentStateComputationStage());
// TODO: be caution here, should be handled statelessly.
runStage(event, new BestPossibleStateCalcStage());
BestPossibleStateOutput output = event.getAttribute(AttributeName.BEST_POSSIBLE_STATE.name());
return output;
}
use of org.apache.helix.controller.stages.BestPossibleStateCalcStage in project helix by apache.
the class TestRebalancerMetrics method testRecoveryRebalanceMetrics.
@Test
public void testRecoveryRebalanceMetrics() {
System.out.println("START testRecoveryRebalanceMetrics at " + new Date(System.currentTimeMillis()));
String resource = "testResourceName";
int numPartition = 100;
int numReplica = 3;
int maxPending = 3;
setupIdealState(5, new String[] { resource }, numPartition, numReplica, IdealState.RebalanceMode.FULL_AUTO, BuiltInStateModelDefinitions.MasterSlave.name());
setupInstances(5);
setupLiveInstances(5);
setupStateModel();
Map<String, Resource> resourceMap = getResourceMap(new String[] { resource }, numPartition, BuiltInStateModelDefinitions.MasterSlave.name());
CurrentStateOutput currentStateOutput = new CurrentStateOutput();
event.addAttribute(AttributeName.RESOURCES.name(), resourceMap);
event.addAttribute(AttributeName.RESOURCES_TO_REBALANCE.name(), resourceMap);
event.addAttribute(AttributeName.CURRENT_STATE.name(), currentStateOutput);
ClusterStatusMonitor monitor = new ClusterStatusMonitor(_clusterName);
monitor.active();
event.addAttribute(AttributeName.clusterStatusMonitor.name(), monitor);
runStage(event, new ReadClusterDataStage());
ClusterDataCache cache = event.getAttribute(AttributeName.ClusterDataCache.name());
setupThrottleConfig(cache.getClusterConfig(), StateTransitionThrottleConfig.RebalanceType.RECOVERY_BALANCE, maxPending);
runStage(event, new BestPossibleStateCalcStage());
runStage(event, new IntermediateStateCalcStage());
ClusterStatusMonitor clusterStatusMonitor = event.getAttribute(AttributeName.clusterStatusMonitor.name());
ResourceMonitor resourceMonitor = clusterStatusMonitor.getResourceMonitor(resource);
Assert.assertEquals(resourceMonitor.getPendingRecoveryRebalancePartitionGauge(), numPartition);
Assert.assertEquals(resourceMonitor.getRecoveryRebalanceThrottledPartitionGauge(), numPartition - maxPending);
System.out.println("END testRecoveryRebalanceMetrics at " + new Date(System.currentTimeMillis()));
}
Aggregations