use of org.apache.helix.controller.stages.BestPossibleStateCalcStage in project helix by apache.
the class TestP2PStateTransitionMessages method createPipeline.
private Pipeline createPipeline() {
Pipeline pipeline = new Pipeline("test");
pipeline.addStage(new ReadClusterDataStage());
pipeline.addStage(new BestPossibleStateCalcStage());
pipeline.addStage(new IntermediateStateCalcStage());
pipeline.addStage(new MessageGenerationPhase());
pipeline.addStage(new MessageSelectionStage());
pipeline.addStage(new MessageThrottleStage());
return pipeline;
}
use of org.apache.helix.controller.stages.BestPossibleStateCalcStage in project helix by apache.
the class TestRebalancerMetrics method testLoadBalanceMetrics.
@Test
public void testLoadBalanceMetrics() {
System.out.println("START testLoadBalanceMetrics 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(4);
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());
runStage(event, new BestPossibleStateCalcStage());
BestPossibleStateOutput bestPossibleStateOutput = event.getAttribute(AttributeName.BEST_POSSIBLE_STATE.name());
currentStateOutput = copyCurrentStateFromBestPossible(bestPossibleStateOutput, resource);
event.addAttribute(AttributeName.CURRENT_STATE.name(), currentStateOutput);
setupLiveInstances(4);
runStage(event, new ReadClusterDataStage());
ClusterDataCache cache = event.getAttribute(AttributeName.ClusterDataCache.name());
setupThrottleConfig(cache.getClusterConfig(), StateTransitionThrottleConfig.RebalanceType.LOAD_BALANCE, maxPending);
runStage(event, new BestPossibleStateCalcStage());
runStage(event, new IntermediateStateCalcStage());
ClusterStatusMonitor clusterStatusMonitor = event.getAttribute(AttributeName.clusterStatusMonitor.name());
ResourceMonitor resourceMonitor = clusterStatusMonitor.getResourceMonitor(resource);
long numPendingLoadBalance = resourceMonitor.getPendingLoadRebalancePartitionGauge();
Assert.assertTrue(numPendingLoadBalance > 0);
Assert.assertEquals(resourceMonitor.getLoadRebalanceThrottledPartitionGauge(), numPendingLoadBalance - maxPending);
System.out.println("END testLoadBalanceMetrics at " + new Date(System.currentTimeMillis()));
}
use of org.apache.helix.controller.stages.BestPossibleStateCalcStage in project helix by apache.
the class ClusterExternalViewVerifier method calculateBestPossibleState.
BestPossibleStateOutput calculateBestPossibleState(ClusterDataCache cache) throws Exception {
ClusterEvent event = new ClusterEvent(ClusterEventType.StateVerifier);
event.addAttribute(AttributeName.ClusterDataCache.name(), cache);
List<Stage> stages = new ArrayList<Stage>();
stages.add(new ResourceComputationStage());
stages.add(new CurrentStateComputationStage());
stages.add(new BestPossibleStateCalcStage());
for (Stage stage : stages) {
runStage(event, stage);
}
return event.getAttribute(AttributeName.BEST_POSSIBLE_STATE.name());
}
use of org.apache.helix.controller.stages.BestPossibleStateCalcStage in project helix by apache.
the class TestSkipBestPossibleCalculation method test.
@Test()
public void test() throws Exception {
int numResource = 5;
for (int i = 0; i < numResource; i++) {
String dbName = "TestDB_" + i;
_setupTool.addResourceToCluster(CLUSTER_NAME, dbName, _PARTITIONS, STATE_MODEL, IdealState.RebalanceMode.CUSTOMIZED.name());
_setupTool.rebalanceResource(CLUSTER_NAME, dbName, 3);
}
ClusterDataCache cache = new ClusterDataCache("CLUSTER_" + TestHelper.getTestClassName());
cache.setTaskCache(false);
cache.refresh(_manager.getHelixDataAccessor());
ClusterEvent event = new ClusterEvent(CLUSTER_NAME, ClusterEventType.IdealStateChange);
event.addAttribute(AttributeName.ClusterDataCache.name(), cache);
runStage(_manager, event, new ResourceComputationStage());
runStage(_manager, event, new CurrentStateComputationStage());
Assert.assertEquals(cache.getCachedResourceAssignments().size(), 0);
runStage(_manager, event, new BestPossibleStateCalcStage());
Assert.assertEquals(cache.getCachedResourceAssignments().size(), numResource);
cache.notifyDataChange(HelixConstants.ChangeType.INSTANCE_CONFIG);
cache.refresh(_manager.getHelixDataAccessor());
Assert.assertEquals(cache.getCachedResourceAssignments().size(), 0);
runStage(_manager, event, new BestPossibleStateCalcStage());
Assert.assertEquals(cache.getCachedResourceAssignments().size(), numResource);
cache.notifyDataChange(HelixConstants.ChangeType.IDEAL_STATE);
cache.refresh(_manager.getHelixDataAccessor());
Assert.assertEquals(cache.getCachedResourceAssignments().size(), 0);
runStage(_manager, event, new BestPossibleStateCalcStage());
Assert.assertEquals(cache.getCachedResourceAssignments().size(), numResource);
cache.notifyDataChange(HelixConstants.ChangeType.LIVE_INSTANCE);
cache.refresh(_manager.getHelixDataAccessor());
Assert.assertEquals(cache.getCachedResourceAssignments().size(), 0);
runStage(_manager, event, new BestPossibleStateCalcStage());
Assert.assertEquals(cache.getCachedResourceAssignments().size(), numResource);
cache.requireFullRefresh();
cache.refresh(_manager.getHelixDataAccessor());
Assert.assertEquals(cache.getCachedResourceAssignments().size(), 0);
runStage(_manager, event, new BestPossibleStateCalcStage());
Assert.assertEquals(cache.getCachedResourceAssignments().size(), numResource);
cache.notifyDataChange(HelixConstants.ChangeType.CURRENT_STATE);
cache.refresh(_manager.getHelixDataAccessor());
Assert.assertEquals(cache.getCachedResourceAssignments().size(), numResource);
cache.notifyDataChange(HelixConstants.ChangeType.RESOURCE_CONFIG);
cache.refresh(_manager.getHelixDataAccessor());
Assert.assertEquals(cache.getCachedResourceAssignments().size(), 0);
}
use of org.apache.helix.controller.stages.BestPossibleStateCalcStage in project helix by apache.
the class TaskTestUtil method calculateBestPossibleState.
public static BestPossibleStateOutput calculateBestPossibleState(ClusterDataCache cache, HelixManager manager) throws Exception {
ClusterEvent event = new ClusterEvent(ClusterEventType.Unknown);
event.addAttribute(AttributeName.ClusterDataCache.name(), cache);
event.addAttribute(AttributeName.helixmanager.name(), manager);
List<Stage> stages = new ArrayList<Stage>();
stages.add(new ReadClusterDataStage());
stages.add(new ResourceComputationStage());
stages.add(new CurrentStateComputationStage());
stages.add(new BestPossibleStateCalcStage());
for (Stage stage : stages) {
runStage(event, stage);
}
return event.getAttribute(AttributeName.BEST_POSSIBLE_STATE.name());
}
Aggregations