Search in sources :

Example 11 with ConfigAccessor

use of org.apache.helix.ConfigAccessor in project helix by apache.

the class TestCrushAutoRebalanceNonRack method beforeClass.

@BeforeClass
public void beforeClass() throws Exception {
    System.out.println("START " + CLASS_NAME + " at " + new Date(System.currentTimeMillis()));
    String namespace = "/" + CLUSTER_NAME;
    if (_gZkClient.exists(namespace)) {
        _gZkClient.deleteRecursively(namespace);
    }
    _setupTool = new ClusterSetup(_gZkClient);
    _setupTool.addCluster(CLUSTER_NAME, true);
    ConfigAccessor configAccessor = new ConfigAccessor(_gZkClient);
    ClusterConfig clusterConfig = configAccessor.getClusterConfig(CLUSTER_NAME);
    clusterConfig.setTopology("/instance");
    clusterConfig.setFaultZoneType("instance");
    configAccessor.setClusterConfig(CLUSTER_NAME, clusterConfig);
    for (int i = 0; i < NUM_NODE; i++) {
        String storageNodeName = PARTICIPANT_PREFIX + "_" + (START_PORT + i);
        _setupTool.addInstanceToCluster(CLUSTER_NAME, storageNodeName);
        _nodes.add(storageNodeName);
        String tag = "tag-" + i % 2;
        _setupTool.getClusterManagementTool().addInstanceTag(CLUSTER_NAME, storageNodeName, tag);
        _nodeToTagMap.put(storageNodeName, tag);
        InstanceConfig instanceConfig = configAccessor.getInstanceConfig(CLUSTER_NAME, storageNodeName);
        instanceConfig.setDomain("instance=" + storageNodeName);
        configAccessor.setInstanceConfig(CLUSTER_NAME, storageNodeName, instanceConfig);
    }
    // start dummy participants
    for (String node : _nodes) {
        MockParticipantManager participant = new MockParticipantManager(ZK_ADDR, CLUSTER_NAME, node);
        participant.syncStart();
        _participants.add(participant);
    }
    // start controller
    String controllerName = CONTROLLER_PREFIX + "_0";
    _controller = new ClusterControllerManager(ZK_ADDR, CLUSTER_NAME, controllerName);
    _controller.syncStart();
    enablePersistBestPossibleAssignment(_gZkClient, CLUSTER_NAME, true);
// enableTopologyAwareRebalance(_gZkClient, CLUSTER_NAME, true);
}
Also used : ClusterControllerManager(org.apache.helix.integration.manager.ClusterControllerManager) MockParticipantManager(org.apache.helix.integration.manager.MockParticipantManager) ConfigAccessor(org.apache.helix.ConfigAccessor) ClusterSetup(org.apache.helix.tools.ClusterSetup) BeforeClass(org.testng.annotations.BeforeClass)

Example 12 with ConfigAccessor

use of org.apache.helix.ConfigAccessor in project helix by apache.

the class TestCrushAutoRebalanceNonRack method testLackEnoughInstances.

@Test(dataProvider = "rebalanceStrategies", enabled = true, dependsOnMethods = { "testLackEnoughLiveInstances" })
public void testLackEnoughInstances(String rebalanceStrategyName, String rebalanceStrategyClass) throws Exception {
    System.out.println("TestLackEnoughInstances " + rebalanceStrategyName);
    enablePersistBestPossibleAssignment(_gZkClient, CLUSTER_NAME, true);
    // shutdown participants, keep only two left
    for (int i = 2; i < _participants.size(); i++) {
        MockParticipantManager p = _participants.get(i);
        p.syncStop();
        _setupTool.getClusterManagementTool().enableInstance(CLUSTER_NAME, p.getInstanceName(), false);
        Thread.sleep(50);
        _setupTool.dropInstanceFromCluster(CLUSTER_NAME, p.getInstanceName());
    }
    int j = 0;
    for (String stateModel : _testModels) {
        String db = "Test-DB-" + rebalanceStrategyName + "-" + j++;
        _setupTool.addResourceToCluster(CLUSTER_NAME, db, _PARTITIONS, stateModel, RebalanceMode.FULL_AUTO + "", rebalanceStrategyClass);
        _setupTool.rebalanceStorageCluster(CLUSTER_NAME, db, _replica);
        _allDBs.add(db);
    }
    Thread.sleep(300);
    HelixClusterVerifier _clusterVerifier = new StrictMatchExternalViewVerifier.Builder(CLUSTER_NAME).setZkAddr(ZK_ADDR).setResources(_allDBs).build();
    Assert.assertTrue(_clusterVerifier.verify());
    for (String db : _allDBs) {
        IdealState is = _setupTool.getClusterManagementTool().getResourceIdealState(CLUSTER_NAME, db);
        ExternalView ev = _setupTool.getClusterManagementTool().getResourceExternalView(CLUSTER_NAME, db);
        validateIsolation(is, ev, 2);
    }
    // recover test environment
    ConfigAccessor configAccessor = new ConfigAccessor(_gZkClient);
    for (int i = 2; i < _participants.size(); i++) {
        String storageNodeName = _participants.get(i).getInstanceName();
        _setupTool.addInstanceToCluster(CLUSTER_NAME, storageNodeName);
        InstanceConfig instanceConfig = configAccessor.getInstanceConfig(CLUSTER_NAME, storageNodeName);
        instanceConfig.setDomain("instance=" + storageNodeName);
        configAccessor.setInstanceConfig(CLUSTER_NAME, storageNodeName, instanceConfig);
        MockParticipantManager participant = new MockParticipantManager(ZK_ADDR, CLUSTER_NAME, storageNodeName);
        participant.syncStart();
        _participants.set(i, participant);
    }
}
Also used : StrictMatchExternalViewVerifier(org.apache.helix.tools.ClusterVerifiers.StrictMatchExternalViewVerifier) HelixClusterVerifier(org.apache.helix.tools.ClusterVerifiers.HelixClusterVerifier) MockParticipantManager(org.apache.helix.integration.manager.MockParticipantManager) ConfigAccessor(org.apache.helix.ConfigAccessor) Test(org.testng.annotations.Test)

Example 13 with ConfigAccessor

use of org.apache.helix.ConfigAccessor in project helix by apache.

the class TestRoutingTableProviderFromCurrentStates method beforeClass.

@BeforeClass
public void beforeClass() throws Exception {
    String namespace = "/" + CLUSTER_NAME;
    _participants = new MockParticipantManager[NUM_NODES];
    if (_gZkClient.exists(namespace)) {
        _gZkClient.deleteRecursively(namespace);
    }
    _setupTool = new ClusterSetup(ZK_ADDR);
    _setupTool.addCluster(CLUSTER_NAME, true);
    _participants = new MockParticipantManager[NUM_NODES];
    for (int i = 0; i < NUM_NODES; i++) {
        String storageNodeName = PARTICIPANT_PREFIX + "_" + (START_PORT + i);
        _setupTool.addInstanceToCluster(CLUSTER_NAME, storageNodeName);
    }
    for (int i = 0; i < NUM_NODES; i++) {
        String instanceName = PARTICIPANT_PREFIX + "_" + (START_PORT + i);
        _participants[i] = new MockParticipantManager(ZK_ADDR, CLUSTER_NAME, instanceName);
        _participants[i].syncStart();
    }
    _manager = HelixManagerFactory.getZKHelixManager(CLUSTER_NAME, "Admin", InstanceType.ADMINISTRATOR, ZK_ADDR);
    _manager.connect();
    String controllerName = CONTROLLER_PREFIX + "_0";
    _controller = new ClusterControllerManager(ZK_ADDR, CLUSTER_NAME, controllerName);
    _controller.syncStart();
    ConfigAccessor _configAccessor = _manager.getConfigAccessor();
    ClusterConfig clusterConfig = _configAccessor.getClusterConfig(CLUSTER_NAME);
    clusterConfig.enableTargetExternalView(true);
    _configAccessor.setClusterConfig(CLUSTER_NAME, clusterConfig);
}
Also used : ClusterControllerManager(org.apache.helix.integration.manager.ClusterControllerManager) MockParticipantManager(org.apache.helix.integration.manager.MockParticipantManager) ConfigAccessor(org.apache.helix.ConfigAccessor) ClusterSetup(org.apache.helix.tools.ClusterSetup) ClusterConfig(org.apache.helix.model.ClusterConfig) BeforeClass(org.testng.annotations.BeforeClass)

Example 14 with ConfigAccessor

use of org.apache.helix.ConfigAccessor in project helix by apache.

the class TestRoutingTableProviderFromTargetEV method beforeClass.

@BeforeClass
public void beforeClass() throws Exception {
    String namespace = "/" + CLUSTER_NAME;
    _participants = new MockParticipantManager[NUM_NODES];
    if (_gZkClient.exists(namespace)) {
        _gZkClient.deleteRecursively(namespace);
    }
    _setupTool = new ClusterSetup(ZK_ADDR);
    _setupTool.addCluster(CLUSTER_NAME, true);
    _participants = new MockParticipantManager[NUM_NODES];
    for (int i = 0; i < NUM_NODES; i++) {
        String storageNodeName = PARTICIPANT_PREFIX + "_" + (START_PORT + i);
        _setupTool.addInstanceToCluster(CLUSTER_NAME, storageNodeName);
    }
    _setupTool.addResourceToCluster(CLUSTER_NAME, WorkflowGenerator.DEFAULT_TGT_DB, NUM_PARTITIONS, MASTER_SLAVE_STATE_MODEL, IdealState.RebalanceMode.FULL_AUTO.name());
    _setupTool.rebalanceStorageCluster(CLUSTER_NAME, WorkflowGenerator.DEFAULT_TGT_DB, NUM_REPLICAS);
    for (int i = 0; i < NUM_NODES; i++) {
        String instanceName = PARTICIPANT_PREFIX + "_" + (START_PORT + i);
        _participants[i] = new MockParticipantManager(ZK_ADDR, CLUSTER_NAME, instanceName);
        // add a delayed state model
        StateMachineEngine stateMachine = _participants[i].getStateMachineEngine();
        MockDelayMSStateModelFactory delayFactory = new MockDelayMSStateModelFactory().setDelay(-300000L);
        stateMachine.registerStateModelFactory(MASTER_SLAVE_STATE_MODEL, delayFactory);
        _participants[i].syncStart();
    }
    _manager = HelixManagerFactory.getZKHelixManager(CLUSTER_NAME, "Admin", InstanceType.ADMINISTRATOR, ZK_ADDR);
    _manager.connect();
    String controllerName = CONTROLLER_PREFIX + "_0";
    _controller = new ClusterControllerManager(ZK_ADDR, CLUSTER_NAME, controllerName);
    _controller.syncStart();
    _configAccessor = new ConfigAccessor(_gZkClient);
}
Also used : ClusterControllerManager(org.apache.helix.integration.manager.ClusterControllerManager) StateMachineEngine(org.apache.helix.participant.StateMachineEngine) MockDelayMSStateModelFactory(org.apache.helix.mock.participant.MockDelayMSStateModelFactory) MockParticipantManager(org.apache.helix.integration.manager.MockParticipantManager) ConfigAccessor(org.apache.helix.ConfigAccessor) ClusterSetup(org.apache.helix.tools.ClusterSetup) BeforeClass(org.testng.annotations.BeforeClass)

Example 15 with ConfigAccessor

use of org.apache.helix.ConfigAccessor in project helix by apache.

the class ZkIntegrationTestBase method enablePersistIntermediateAssignment.

protected void enablePersistIntermediateAssignment(ZkClient zkClient, String clusterName, Boolean enabled) {
    ConfigAccessor configAccessor = new ConfigAccessor(zkClient);
    ClusterConfig clusterConfig = configAccessor.getClusterConfig(clusterName);
    clusterConfig.setPersistIntermediateAssignment(enabled);
    configAccessor.setClusterConfig(clusterName, clusterConfig);
}
Also used : ConfigAccessor(org.apache.helix.ConfigAccessor) ClusterConfig(org.apache.helix.model.ClusterConfig)

Aggregations

ConfigAccessor (org.apache.helix.ConfigAccessor)41 ClusterConfig (org.apache.helix.model.ClusterConfig)15 ClusterControllerManager (org.apache.helix.integration.manager.ClusterControllerManager)14 BeforeClass (org.testng.annotations.BeforeClass)14 MockParticipantManager (org.apache.helix.integration.manager.MockParticipantManager)10 ClusterSetup (org.apache.helix.tools.ClusterSetup)9 Date (java.util.Date)7 HelixConfigScope (org.apache.helix.model.HelixConfigScope)7 HelixConfigScopeBuilder (org.apache.helix.model.builder.HelixConfigScopeBuilder)7 Test (org.testng.annotations.Test)7 HelixException (org.apache.helix.HelixException)6 Path (javax.ws.rs.Path)5 BestPossibleExternalViewVerifier (org.apache.helix.tools.ClusterVerifiers.BestPossibleExternalViewVerifier)4 HelixClusterVerifier (org.apache.helix.tools.ClusterVerifiers.HelixClusterVerifier)4 IOException (java.io.IOException)3 HashMap (java.util.HashMap)3 GET (javax.ws.rs.GET)3 HelixManager (org.apache.helix.HelixManager)3 ZNRecord (org.apache.helix.ZNRecord)3 ZKHelixDataAccessor (org.apache.helix.manager.zk.ZKHelixDataAccessor)3