Search in sources :

Example 6 with ResourceConfig

use of org.apache.helix.model.ResourceConfig in project helix by apache.

the class TestMixedModeAutoRebalance method removePartitionFromUserDefinedList.

private void removePartitionFromUserDefinedList(String db, List<String> userDefinedPartitions) {
    ResourceConfig resourceConfig = _configAccessor.getResourceConfig(CLUSTER_NAME, db);
    Map<String, List<String>> lists = resourceConfig.getPreferenceLists();
    lists.remove(userDefinedPartitions.get(0));
    resourceConfig.setPreferenceLists(lists);
    userDefinedPartitions.remove(0);
    _configAccessor.setResourceConfig(CLUSTER_NAME, db, resourceConfig);
    // TODO: Touch IS, remove this once Helix controller is listening on resource config changes.
    RebalanceScheduler.invokeRebalance(_dataAccessor, db);
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) ResourceConfig(org.apache.helix.model.ResourceConfig)

Example 7 with ResourceConfig

use of org.apache.helix.model.ResourceConfig in project helix by apache.

the class TestP2PMessageSemiAuto method enableP2PInResource.

private void enableP2PInResource(String dbName, boolean enable) {
    if (enable) {
        ResourceConfig resourceConfig = new ResourceConfig.Builder(dbName).setP2PMessageEnabled(true).build();
        _configAccessor.setResourceConfig(CLUSTER_NAME, dbName, resourceConfig);
    } else {
        // remove P2P Message in resource config
        ResourceConfig resourceConfig = _configAccessor.getResourceConfig(CLUSTER_NAME, dbName);
        if (resourceConfig != null) {
            resourceConfig.getRecord().getSimpleFields().remove(HelixConfigProperty.P2P_MESSAGE_ENABLED.name());
            _configAccessor.setResourceConfig(CLUSTER_NAME, dbName, resourceConfig);
        }
    }
}
Also used : ResourceConfig(org.apache.helix.model.ResourceConfig)

Example 8 with ResourceConfig

use of org.apache.helix.model.ResourceConfig in project helix by apache.

the class TestStateTransitionTimeoutWithResource method testStateTransitionTimeOut.

@Test
public void testStateTransitionTimeOut() throws Exception {
    _setupTool.addResourceToCluster(CLUSTER_NAME, TEST_DB, _PARTITIONS, STATE_MODEL);
    _setupTool.getClusterManagementTool().enableResource(CLUSTER_NAME, TEST_DB, false);
    _setupTool.rebalanceStorageCluster(CLUSTER_NAME, TEST_DB, 3);
    // Set the timeout values
    StateTransitionTimeoutConfig stateTransitionTimeoutConfig = new StateTransitionTimeoutConfig(new ZNRecord(TEST_DB));
    stateTransitionTimeoutConfig.setStateTransitionTimeout("SLAVE", "MASTER", 300);
    ResourceConfig resourceConfig = new ResourceConfig.Builder(TEST_DB).setStateTransitionTimeoutConfig(stateTransitionTimeoutConfig).setRebalanceConfig(new RebalanceConfig(new ZNRecord(TEST_DB))).setNumPartitions(_PARTITIONS).setHelixEnabled(false).build();
    _configAccessor.setResourceConfig(CLUSTER_NAME, TEST_DB, resourceConfig);
    setParticipants(TEST_DB);
    _setupTool.getClusterManagementTool().enableResource(CLUSTER_NAME, TEST_DB, true);
    boolean result = ClusterStateVerifier.verifyByZkCallback(new MasterNbInExtViewVerifier(ZK_ADDR, CLUSTER_NAME));
    Assert.assertTrue(result);
    verify(TEST_DB);
}
Also used : MasterNbInExtViewVerifier(org.apache.helix.tools.ClusterStateVerifier.MasterNbInExtViewVerifier) StateTransitionTimeoutConfig(org.apache.helix.api.config.StateTransitionTimeoutConfig) ResourceConfig(org.apache.helix.model.ResourceConfig) ZNRecord(org.apache.helix.ZNRecord) RebalanceConfig(org.apache.helix.api.config.RebalanceConfig) Test(org.testng.annotations.Test)

Example 9 with ResourceConfig

use of org.apache.helix.model.ResourceConfig in project helix by apache.

the class TestMixedModeAutoRebalance method testUserDefinedPreferenceListsInFullAuto.

@Test(dataProvider = "stateModels")
public void testUserDefinedPreferenceListsInFullAuto(String stateModel, boolean delayEnabled) throws Exception {
    String db = "Test-DB-" + stateModel;
    if (delayEnabled) {
        createResourceWithDelayedRebalance(CLUSTER_NAME, db, stateModel, _PARTITIONS, _replica, _replica - 1, 200, CrushRebalanceStrategy.class.getName());
    } else {
        createResourceWithDelayedRebalance(CLUSTER_NAME, db, stateModel, _PARTITIONS, _replica, _replica, 0, CrushRebalanceStrategy.class.getName());
    }
    IdealState idealState = _gSetupTool.getClusterManagementTool().getResourceIdealState(CLUSTER_NAME, db);
    Map<String, List<String>> userDefinedPreferenceLists = idealState.getPreferenceLists();
    List<String> userDefinedPartitions = new ArrayList<>();
    for (String partition : userDefinedPreferenceLists.keySet()) {
        List<String> preferenceList = new ArrayList<>();
        for (int k = _replica; k >= 0; k--) {
            String instance = _participants.get(k).getInstanceName();
            preferenceList.add(instance);
        }
        userDefinedPreferenceLists.put(partition, preferenceList);
        userDefinedPartitions.add(partition);
    }
    ResourceConfig resourceConfig = new ResourceConfig.Builder(db).setPreferenceLists(userDefinedPreferenceLists).build();
    _configAccessor.setResourceConfig(CLUSTER_NAME, db, resourceConfig);
    // TODO: Trigger rebalancer, remove this once Helix controller is listening on resource config changes.
    RebalanceScheduler.invokeRebalance(_dataAccessor, db);
    while (userDefinedPartitions.size() > 0) {
        Thread.sleep(100);
        Assert.assertTrue(_clusterVerifier.verify());
        verifyUserDefinedPreferenceLists(db, userDefinedPreferenceLists, userDefinedPartitions);
        removePartitionFromUserDefinedList(db, userDefinedPartitions);
    }
}
Also used : ArrayList(java.util.ArrayList) CrushRebalanceStrategy(org.apache.helix.controller.rebalancer.strategy.CrushRebalanceStrategy) MultiRoundCrushRebalanceStrategy(org.apache.helix.controller.rebalancer.strategy.MultiRoundCrushRebalanceStrategy) ArrayList(java.util.ArrayList) List(java.util.List) ResourceConfig(org.apache.helix.model.ResourceConfig) IdealState(org.apache.helix.model.IdealState) Test(org.testng.annotations.Test)

Example 10 with ResourceConfig

use of org.apache.helix.model.ResourceConfig in project helix by apache.

the class TestMixedModeAutoRebalance method testUserDefinedPreferenceListsInFullAutoWithErrors.

@Test
public void testUserDefinedPreferenceListsInFullAutoWithErrors() throws Exception {
    String db = "Test-DB-1";
    createResourceWithDelayedRebalance(CLUSTER_NAME, db, BuiltInStateModelDefinitions.MasterSlave.name(), 5, _replica, _replica, 0, CrushRebalanceStrategy.class.getName());
    IdealState idealState = _gSetupTool.getClusterManagementTool().getResourceIdealState(CLUSTER_NAME, db);
    Map<String, List<String>> userDefinedPreferenceLists = idealState.getPreferenceLists();
    List<String> newNodes = new ArrayList<>();
    for (int i = NUM_NODE; i < NUM_NODE + _replica; i++) {
        String instance = PARTICIPANT_PREFIX + "_" + (START_PORT + i);
        _gSetupTool.addInstanceToCluster(CLUSTER_NAME, instance);
        // start dummy participants
        MockParticipantManager participant = new TestMockParticipantManager(ZK_ADDR, CLUSTER_NAME, instance);
        participant.syncStart();
        _participants.add(participant);
        newNodes.add(instance);
    }
    List<String> userDefinedPartitions = new ArrayList<>();
    for (String partition : userDefinedPreferenceLists.keySet()) {
        userDefinedPreferenceLists.put(partition, newNodes);
        userDefinedPartitions.add(partition);
    }
    ResourceConfig resourceConfig = new ResourceConfig.Builder(db).setPreferenceLists(userDefinedPreferenceLists).build();
    _configAccessor.setResourceConfig(CLUSTER_NAME, db, resourceConfig);
    // TODO: Trigger rebalancer, remove this once Helix controller is listening on resource config changes.
    RebalanceScheduler.invokeRebalance(_dataAccessor, db);
    Thread.sleep(1000);
    ExternalView ev = _gSetupTool.getClusterManagementTool().getResourceExternalView(CLUSTER_NAME, db);
    IdealState is = _gSetupTool.getClusterManagementTool().getResourceIdealState(CLUSTER_NAME, db);
    validateMinActiveAndTopStateReplica(is, ev, _replica, NUM_NODE);
}
Also used : ExternalView(org.apache.helix.model.ExternalView) MockParticipantManager(org.apache.helix.integration.manager.MockParticipantManager) ArrayList(java.util.ArrayList) CrushRebalanceStrategy(org.apache.helix.controller.rebalancer.strategy.CrushRebalanceStrategy) MultiRoundCrushRebalanceStrategy(org.apache.helix.controller.rebalancer.strategy.MultiRoundCrushRebalanceStrategy) IdealState(org.apache.helix.model.IdealState) ArrayList(java.util.ArrayList) List(java.util.List) ResourceConfig(org.apache.helix.model.ResourceConfig) Test(org.testng.annotations.Test)

Aggregations

ResourceConfig (org.apache.helix.model.ResourceConfig)14 List (java.util.List)5 ZNRecord (org.apache.helix.ZNRecord)5 IdealState (org.apache.helix.model.IdealState)5 ArrayList (java.util.ArrayList)4 Test (org.testng.annotations.Test)4 HashMap (java.util.HashMap)3 Path (javax.ws.rs.Path)3 ConfigAccessor (org.apache.helix.ConfigAccessor)3 LinkedHashMap (java.util.LinkedHashMap)2 Map (java.util.Map)2 GET (javax.ws.rs.GET)2 CrushRebalanceStrategy (org.apache.helix.controller.rebalancer.strategy.CrushRebalanceStrategy)2 MultiRoundCrushRebalanceStrategy (org.apache.helix.controller.rebalancer.strategy.MultiRoundCrushRebalanceStrategy)2 ClusterConfig (org.apache.helix.model.ClusterConfig)2 ExternalView (org.apache.helix.model.ExternalView)2 IOException (java.io.IOException)1 HashSet (java.util.HashSet)1 POST (javax.ws.rs.POST)1 HelixAdmin (org.apache.helix.HelixAdmin)1