use of org.apache.helix.model.ClusterConfig in project helix by apache.
the class ZkIntegrationTestBase method enableTopologyAwareRebalance.
protected void enableTopologyAwareRebalance(ZkClient zkClient, String clusterName, Boolean enabled) {
ConfigAccessor configAccessor = new ConfigAccessor(zkClient);
ClusterConfig clusterConfig = configAccessor.getClusterConfig(clusterName);
clusterConfig.setTopologyAwareEnabled(enabled);
configAccessor.setClusterConfig(clusterName, clusterConfig);
}
use of org.apache.helix.model.ClusterConfig in project helix by apache.
the class TestPartitionMovementThrottle method setupThrottleConfig.
private void setupThrottleConfig() {
ClusterConfig clusterConfig = _configAccessor.getClusterConfig(CLUSTER_NAME);
StateTransitionThrottleConfig resourceLoadThrottle = new StateTransitionThrottleConfig(StateTransitionThrottleConfig.RebalanceType.LOAD_BALANCE, StateTransitionThrottleConfig.ThrottleScope.RESOURCE, 2);
StateTransitionThrottleConfig instanceLoadThrottle = new StateTransitionThrottleConfig(StateTransitionThrottleConfig.RebalanceType.LOAD_BALANCE, StateTransitionThrottleConfig.ThrottleScope.INSTANCE, 2);
StateTransitionThrottleConfig clusterLoadThrottle = new StateTransitionThrottleConfig(StateTransitionThrottleConfig.RebalanceType.LOAD_BALANCE, StateTransitionThrottleConfig.ThrottleScope.CLUSTER, 100);
StateTransitionThrottleConfig resourceRecoveryThrottle = new StateTransitionThrottleConfig(StateTransitionThrottleConfig.RebalanceType.RECOVERY_BALANCE, StateTransitionThrottleConfig.ThrottleScope.RESOURCE, 3);
StateTransitionThrottleConfig clusterRecoveryThrottle = new StateTransitionThrottleConfig(StateTransitionThrottleConfig.RebalanceType.RECOVERY_BALANCE, StateTransitionThrottleConfig.ThrottleScope.CLUSTER, 100);
clusterConfig.setStateTransitionThrottleConfigs(Arrays.asList(resourceLoadThrottle, instanceLoadThrottle, clusterLoadThrottle, resourceRecoveryThrottle, clusterRecoveryThrottle));
clusterConfig.setPersistIntermediateAssignment(true);
_configAccessor.setClusterConfig(CLUSTER_NAME, clusterConfig);
}
use of org.apache.helix.model.ClusterConfig in project helix by apache.
the class TestPartitionMovementThrottle method setSingleThrottlingConfig.
private void setSingleThrottlingConfig(StateTransitionThrottleConfig.RebalanceType rebalanceType, StateTransitionThrottleConfig.ThrottleScope scope, int maxStateTransitions) {
ClusterConfig clusterConfig = _configAccessor.getClusterConfig(CLUSTER_NAME);
StateTransitionThrottleConfig anyTypeInstanceThrottle = new StateTransitionThrottleConfig(rebalanceType, scope, maxStateTransitions);
List<StateTransitionThrottleConfig> currentThrottleConfigs = clusterConfig.getStateTransitionThrottleConfigs();
currentThrottleConfigs.add(anyTypeInstanceThrottle);
clusterConfig.setStateTransitionThrottleConfigs(currentThrottleConfigs);
_configAccessor.setClusterConfig(CLUSTER_NAME, clusterConfig);
}
use of org.apache.helix.model.ClusterConfig in project helix by apache.
the class TestPersistAssignmentStage method testSimple.
/**
* Case where we have one resource in IdealState
* @throws Exception
*/
@Test
public void testSimple() throws Exception {
int nodes = 2;
List<String> instances = new ArrayList<String>();
for (int i = 0; i < nodes; i++) {
instances.add("localhost_" + i);
}
int partitions = 10;
int replicas = 1;
String resourceName = "testResource";
ZNRecord record = DefaultIdealStateCalculator.calculateIdealState(instances, partitions, replicas, resourceName, "ONLINE", "OFFLINE");
IdealState idealState = new IdealState(record);
idealState.setStateModelDefRef("OnlineOffline");
// Read and load current state into event
HelixDataAccessor accessor = _manager.getHelixDataAccessor();
PropertyKey.Builder keyBuilder = accessor.keyBuilder();
accessor.setProperty(keyBuilder.idealStates(resourceName), idealState);
runStage(_manager, event, new ReadClusterDataStage());
runStage(_manager, event, new ResourceComputationStage());
// Ensure persist best possible assignment is true
ClusterConfig clusterConfig = new ClusterConfig(CLUSTER_NAME);
clusterConfig.setPersistBestPossibleAssignment(true);
ClusterDataCache cache = event.getAttribute(AttributeName.ClusterDataCache.name());
cache.setClusterConfig(clusterConfig);
// 1. Change best possible state (simulate a new rebalancer run)
BestPossibleStateOutput bestPossibleStateOutput = new BestPossibleStateOutput();
for (String partition : idealState.getPartitionSet()) {
bestPossibleStateOutput.setState(resourceName, new Partition(partition), "localhost_3", "OFFLINE");
}
// 2. At the same time, set DelayRebalanceEnabled = true (simulate a Admin operation at the same time)
idealState.setDelayRebalanceEnabled(true);
accessor.setProperty(keyBuilder.idealStates(resourceName), idealState);
// Persist new assignment
PersistAssignmentStage stage = new PersistAssignmentStage();
event.addAttribute(AttributeName.BEST_POSSIBLE_STATE.name(), bestPossibleStateOutput);
runStage(_manager, event, stage);
IdealState newIdealState = accessor.getProperty(keyBuilder.idealStates(resourceName));
// 1. New assignment should be set
Assert.assertEquals(newIdealState.getPartitionSet().size(), idealState.getPartitionSet().size());
for (String partition : idealState.getPartitionSet()) {
Map<String, String> assignment = newIdealState.getInstanceStateMap(partition);
Assert.assertNotNull(assignment);
Assert.assertEquals(assignment.size(), 1);
Assert.assertTrue(assignment.containsKey("localhost_3") && assignment.get("localhost_3").equals("OFFLINE"));
}
// 2. Admin config should be set
Assert.assertTrue(newIdealState.isDelayRebalanceEnabled());
}
use of org.apache.helix.model.ClusterConfig in project helix by apache.
the class TestClusterAccessor method beforeClass.
@BeforeClass
public void beforeClass() {
for (String cluster : _clusters) {
ClusterConfig clusterConfig = createClusterConfig(cluster);
_configAccessor.setClusterConfig(cluster, clusterConfig);
}
}
Aggregations