Search in sources :

Example 46 with ClusterConfig

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);
}
Also used : ConfigAccessor(org.apache.helix.ConfigAccessor) ClusterConfig(org.apache.helix.model.ClusterConfig)

Example 47 with 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);
}
Also used : StateTransitionThrottleConfig(org.apache.helix.api.config.StateTransitionThrottleConfig) ClusterConfig(org.apache.helix.model.ClusterConfig)

Example 48 with 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);
}
Also used : StateTransitionThrottleConfig(org.apache.helix.api.config.StateTransitionThrottleConfig) ClusterConfig(org.apache.helix.model.ClusterConfig)

Example 49 with 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());
}
Also used : Partition(org.apache.helix.model.Partition) PersistAssignmentStage(org.apache.helix.controller.stages.PersistAssignmentStage) BestPossibleStateOutput(org.apache.helix.controller.stages.BestPossibleStateOutput) ResourceComputationStage(org.apache.helix.controller.stages.ResourceComputationStage) ClusterDataCache(org.apache.helix.controller.stages.ClusterDataCache) ReadClusterDataStage(org.apache.helix.controller.stages.ReadClusterDataStage) ArrayList(java.util.ArrayList) IdealState(org.apache.helix.model.IdealState) HelixDataAccessor(org.apache.helix.HelixDataAccessor) ZNRecord(org.apache.helix.ZNRecord) PropertyKey(org.apache.helix.PropertyKey) ClusterConfig(org.apache.helix.model.ClusterConfig) Test(org.testng.annotations.Test)

Example 50 with ClusterConfig

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);
    }
}
Also used : ClusterConfig(org.apache.helix.model.ClusterConfig) BeforeClass(org.testng.annotations.BeforeClass)

Aggregations

ClusterConfig (org.apache.helix.model.ClusterConfig)61 Test (org.testng.annotations.Test)23 ConfigAccessor (org.apache.helix.ConfigAccessor)17 ZNRecord (org.apache.helix.ZNRecord)13 IdealState (org.apache.helix.model.IdealState)10 InstanceConfig (org.apache.helix.model.InstanceConfig)9 ArrayList (java.util.ArrayList)8 HashMap (java.util.HashMap)8 Map (java.util.Map)8 Resource (org.apache.helix.model.Resource)7 HelixDataAccessor (org.apache.helix.HelixDataAccessor)6 HelixException (org.apache.helix.HelixException)6 StateTransitionThrottleConfig (org.apache.helix.api.config.StateTransitionThrottleConfig)6 ClusterControllerManager (org.apache.helix.integration.manager.ClusterControllerManager)6 List (java.util.List)5 ZKHelixDataAccessor (org.apache.helix.manager.zk.ZKHelixDataAccessor)5 BeforeClass (org.testng.annotations.BeforeClass)5 HelixManager (org.apache.helix.HelixManager)4 MockParticipantManager (org.apache.helix.integration.manager.MockParticipantManager)4 ExternalView (org.apache.helix.model.ExternalView)4