Search in sources :

Example 31 with ClusterConfig

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

the class TestClusterInMaintenanceModeWhenReachingMaxPartition method testDisableCluster.

@Test
public void testDisableCluster() throws Exception {
    ConfigAccessor configAccessor = new ConfigAccessor(_gZkClient);
    ClusterConfig clusterConfig = configAccessor.getClusterConfig(CLUSTER_NAME);
    clusterConfig.setMaxPartitionsPerInstance(10);
    configAccessor.setClusterConfig(CLUSTER_NAME, clusterConfig);
    int i = 0;
    for (String stateModel : TestStateModels) {
        String db = "Test-DB-" + i++;
        createResourceWithDelayedRebalance(CLUSTER_NAME, db, stateModel, _PARTITIONS, _replica, _replica, -1);
        _testDBs.add(db);
    }
    Thread.sleep(100);
    Assert.assertTrue(_clusterVerifier.verify());
    MaintenanceSignal maintenanceSignal = _dataAccessor.getProperty(_dataAccessor.keyBuilder().maintenance());
    Assert.assertNull(maintenanceSignal);
    for (i = 2; i < NUM_NODE; i++) {
        _participants.get(i).syncStop();
    }
    Thread.sleep(500);
    maintenanceSignal = _dataAccessor.getProperty(_dataAccessor.keyBuilder().maintenance());
    Assert.assertNotNull(maintenanceSignal);
    Assert.assertNotNull(maintenanceSignal.getReason());
}
Also used : MaintenanceSignal(org.apache.helix.model.MaintenanceSignal) ConfigAccessor(org.apache.helix.ConfigAccessor) ClusterConfig(org.apache.helix.model.ClusterConfig) Test(org.testng.annotations.Test)

Example 32 with ClusterConfig

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

the class TestP2PMessageSemiAuto method enableP2PInCluster.

private void enableP2PInCluster(boolean enable) {
    // enable p2p message in cluster.
    if (enable) {
        ClusterConfig clusterConfig = _configAccessor.getClusterConfig(CLUSTER_NAME);
        clusterConfig.enableP2PMessage(true);
        _configAccessor.setClusterConfig(CLUSTER_NAME, clusterConfig);
    } else {
        ClusterConfig clusterConfig = _configAccessor.getClusterConfig(CLUSTER_NAME);
        clusterConfig.getRecord().getSimpleFields().remove(HelixConfigProperty.P2P_MESSAGE_ENABLED.name());
        _configAccessor.setClusterConfig(CLUSTER_NAME, clusterConfig);
    }
}
Also used : ClusterConfig(org.apache.helix.model.ClusterConfig)

Example 33 with ClusterConfig

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

the class TestJobFailureTaskNotStarted method beforeClass.

@BeforeClass
public void beforeClass() throws Exception {
    _participants = new MockParticipantManager[_numNodes];
    _numDbs = 1;
    _numNodes = 2;
    _numParitions = 2;
    _numReplicas = 1;
    String namespace = "/" + CLUSTER_NAME;
    if (_gZkClient.exists(namespace)) {
        _gZkClient.deleteRecursively(namespace);
    }
    _setupTool = new ClusterSetup(ZK_ADDR);
    _setupTool.addCluster(CLUSTER_NAME, true);
    setupParticipants();
    setupDBs();
    startParticipantsWithStuckTaskStateModelFactory();
    createManagers();
    _controller = new ClusterControllerManager(ZK_ADDR, CLUSTER_NAME, CONTROLLER_PREFIX);
    _controller.syncStart();
    // Enable cancellation
    ConfigAccessor _configAccessor = new ConfigAccessor(_gZkClient);
    ClusterConfig clusterConfig = _configAccessor.getClusterConfig(CLUSTER_NAME);
    clusterConfig.stateTransitionCancelEnabled(true);
    _configAccessor.setClusterConfig(CLUSTER_NAME, clusterConfig);
}
Also used : ClusterControllerManager(org.apache.helix.integration.manager.ClusterControllerManager) ConfigAccessor(org.apache.helix.ConfigAccessor) ClusterSetup(org.apache.helix.tools.ClusterSetup) ClusterConfig(org.apache.helix.model.ClusterConfig) BeforeClass(org.testng.annotations.BeforeClass)

Example 34 with ClusterConfig

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

the class ClusterSetup method swapInstance.

public void swapInstance(String clusterName, String oldInstanceName, String newInstanceName) {
    ZKHelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(_zkClient));
    Builder keyBuilder = accessor.keyBuilder();
    InstanceConfig oldConfig = accessor.getProperty(keyBuilder.instanceConfig(oldInstanceName));
    if (oldConfig == null) {
        String error = "Old instance " + oldInstanceName + " does not exist, cannot swap";
        _logger.warn(error);
        throw new HelixException(error);
    }
    InstanceConfig newConfig = accessor.getProperty(keyBuilder.instanceConfig(newInstanceName));
    if (newConfig == null) {
        String error = "New instance " + newInstanceName + " does not exist, cannot swap";
        _logger.warn(error);
        throw new HelixException(error);
    }
    ClusterConfig clusterConfig = accessor.getProperty(keyBuilder.clusterConfig());
    // ensure old instance is disabled, otherwise fail
    if (oldConfig.getInstanceEnabled() && (clusterConfig.getDisabledInstances() == null || !clusterConfig.getDisabledInstances().containsKey(oldInstanceName))) {
        String error = "Old instance " + oldInstanceName + " is enabled, it need to be disabled and turned off";
        _logger.warn(error);
        throw new HelixException(error);
    }
    // ensure old instance is down, otherwise fail
    List<String> liveInstanceNames = accessor.getChildNames(accessor.keyBuilder().liveInstances());
    if (liveInstanceNames.contains(oldInstanceName)) {
        String error = "Old instance " + oldInstanceName + " is still on, it need to be disabled and turned off";
        _logger.warn(error);
        throw new HelixException(error);
    }
    dropInstanceFromCluster(clusterName, oldInstanceName);
    List<IdealState> existingIdealStates = accessor.getChildValues(accessor.keyBuilder().idealStates());
    for (IdealState idealState : existingIdealStates) {
        swapInstanceInIdealState(idealState, oldInstanceName, newInstanceName);
        accessor.setProperty(accessor.keyBuilder().idealStates(idealState.getResourceName()), idealState);
    }
}
Also used : HelixException(org.apache.helix.HelixException) InstanceConfig(org.apache.helix.model.InstanceConfig) ConstraintItemBuilder(org.apache.helix.model.builder.ConstraintItemBuilder) OptionBuilder(org.apache.commons.cli.OptionBuilder) HelixConfigScopeBuilder(org.apache.helix.model.builder.HelixConfigScopeBuilder) Builder(org.apache.helix.PropertyKey.Builder) ZNRecord(org.apache.helix.ZNRecord) IdealState(org.apache.helix.model.IdealState) ZKHelixDataAccessor(org.apache.helix.manager.zk.ZKHelixDataAccessor) ClusterConfig(org.apache.helix.model.ClusterConfig)

Example 35 with ClusterConfig

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

the class ClusterSetup method dropInstanceFromCluster.

public void dropInstanceFromCluster(String clusterName, String instanceId) {
    ZKHelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(_zkClient));
    Builder keyBuilder = accessor.keyBuilder();
    InstanceConfig instanceConfig = InstanceConfig.toInstanceConfig(instanceId);
    instanceId = instanceConfig.getInstanceName();
    // ensure node is stopped
    LiveInstance liveInstance = accessor.getProperty(keyBuilder.liveInstance(instanceId));
    if (liveInstance != null) {
        throw new HelixException("Can't drop " + instanceId + ", please stop " + instanceId + " before drop it");
    }
    InstanceConfig config = accessor.getProperty(keyBuilder.instanceConfig(instanceId));
    if (config == null) {
        String error = "Node " + instanceId + " does not exist, cannot drop";
        _logger.warn(error);
        throw new HelixException(error);
    }
    ClusterConfig clusterConfig = accessor.getProperty(keyBuilder.clusterConfig());
    // ensure node is disabled, otherwise fail
    if (config.getInstanceEnabled() && (clusterConfig.getDisabledInstances() == null || !clusterConfig.getDisabledInstances().containsKey(instanceId))) {
        String error = "Node " + instanceId + " is enabled, cannot drop";
        _logger.warn(error);
        throw new HelixException(error);
    }
    _admin.dropInstance(clusterName, config);
}
Also used : HelixException(org.apache.helix.HelixException) InstanceConfig(org.apache.helix.model.InstanceConfig) LiveInstance(org.apache.helix.model.LiveInstance) ConstraintItemBuilder(org.apache.helix.model.builder.ConstraintItemBuilder) OptionBuilder(org.apache.commons.cli.OptionBuilder) HelixConfigScopeBuilder(org.apache.helix.model.builder.HelixConfigScopeBuilder) Builder(org.apache.helix.PropertyKey.Builder) ZNRecord(org.apache.helix.ZNRecord) ZKHelixDataAccessor(org.apache.helix.manager.zk.ZKHelixDataAccessor) ClusterConfig(org.apache.helix.model.ClusterConfig)

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