Search in sources :

Example 6 with ClusterConfig

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

the class TestIdealStateAssignment method testIdealStateAssignment.

@Test(dataProvider = "IdealStateInput")
public void testIdealStateAssignment(String clusterName, List<String> instances, List<String> partitions, String numReplicas, String stateModeDef, String strategyName, Map<String, Map<String, String>> expectedMapping) throws IllegalAccessException, InstantiationException, ClassNotFoundException {
    ClusterConfig clusterConfig = new ClusterConfig(clusterName);
    List<InstanceConfig> instanceConfigs = new ArrayList<>();
    for (String instance : instances) {
        instanceConfigs.add(new InstanceConfig(instance));
    }
    IdealState idealState = new IdealState("TestResource");
    idealState.setStateModelDefRef(stateModeDef);
    idealState.setNumPartitions(partitions.size());
    idealState.setReplicas(numReplicas);
    Map<String, Map<String, String>> idealStateMapping = HelixUtil.getIdealAssignmentForFullAuto(clusterConfig, instanceConfigs, instances, idealState, partitions, strategyName);
    Assert.assertEquals(idealStateMapping, expectedMapping);
}
Also used : InstanceConfig(org.apache.helix.model.InstanceConfig) ArrayList(java.util.ArrayList) Map(java.util.Map) IdealState(org.apache.helix.model.IdealState) ClusterConfig(org.apache.helix.model.ClusterConfig) Test(org.testng.annotations.Test)

Example 7 with ClusterConfig

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

the class TestTopStateHandoffMetrics method testTopStateFailedHandoff.

@Test(dataProvider = "failedCurrentStateInput")
public void testTopStateFailedHandoff(Map<String, Map<String, String>> initialCurrentStates, Map<String, Map<String, String>> handOffCurrentStates, Long expectedDuration) {
    preSetup();
    ClusterConfig clusterConfig = new ClusterConfig(_clusterName);
    clusterConfig.setMissTopStateDurationThreshold(5000L);
    setClusterConfig(clusterConfig);
    runCurrentStage(initialCurrentStates, handOffCurrentStates);
    ClusterStatusMonitor clusterStatusMonitor = event.getAttribute(AttributeName.clusterStatusMonitor.name());
    ResourceMonitor monitor = clusterStatusMonitor.getResourceMonitor(TEST_RESOURCE);
    // Should have 1 transition failed due to threshold.
    Assert.assertEquals(monitor.getFailedTopStateHandoffCounter(), 1);
    // No duration updated.
    Assert.assertEquals(monitor.getSuccessfulTopStateHandoffDurationCounter(), (long) expectedDuration);
    Assert.assertEquals(monitor.getMaxSinglePartitionTopStateHandoffDurationGauge(), (long) expectedDuration);
}
Also used : ClusterConfig(org.apache.helix.model.ClusterConfig) Test(org.testng.annotations.Test) BaseStageTest(org.apache.helix.controller.stages.BaseStageTest)

Example 8 with ClusterConfig

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

the class ClusterAccessor method getClusterConfig.

@GET
@Path("{clusterId}/configs")
public Response getClusterConfig(@PathParam("clusterId") String clusterId) {
    ConfigAccessor accessor = getConfigAccessor();
    ClusterConfig config = null;
    try {
        config = accessor.getClusterConfig(clusterId);
    } catch (HelixException ex) {
        // cluster not found.
        _logger.info("Failed to get cluster config for cluster " + clusterId + ", cluster not found, Exception: " + ex);
    } catch (Exception ex) {
        _logger.error("Failed to get cluster config for cluster " + clusterId + " Exception: " + ex);
        return serverError(ex);
    }
    if (config == null) {
        return notFound();
    }
    return JSONRepresentation(config.getRecord());
}
Also used : HelixException(org.apache.helix.HelixException) ConfigAccessor(org.apache.helix.ConfigAccessor) HelixException(org.apache.helix.HelixException) IOException(java.io.IOException) ClusterConfig(org.apache.helix.model.ClusterConfig) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 9 with ClusterConfig

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

the class TestP2PStateTransitionMessages method testP2PMessageEnabled.

@Test
public void testP2PMessageEnabled() throws Exception {
    preSetup();
    ClusterConfig clusterConfig = new ClusterConfig(_clusterName);
    clusterConfig.enableP2PMessage(true);
    setClusterConfig(clusterConfig);
    testP2PMessage(clusterConfig, true);
}
Also used : ClusterConfig(org.apache.helix.model.ClusterConfig) Test(org.testng.annotations.Test) BaseStageTest(org.apache.helix.controller.stages.BaseStageTest)

Example 10 with ClusterConfig

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

the class MockHelixAdmin method createZKPaths.

private void createZKPaths(String clusterName) {
    String path;
    // IDEAL STATE
    _baseDataAccessor.create(PropertyPathBuilder.idealState(clusterName), new ZNRecord(clusterName), 0);
    // CONFIGURATIONS
    path = PropertyPathBuilder.clusterConfig(clusterName);
    _baseDataAccessor.create(path, new ClusterConfig(clusterName).getRecord(), 0);
    path = PropertyPathBuilder.instanceConfig(clusterName);
    _baseDataAccessor.create(path, new ZNRecord(clusterName), 0);
    path = PropertyPathBuilder.resourceConfig(clusterName);
    _baseDataAccessor.create(path, new ZNRecord(clusterName), 0);
    // PROPERTY STORE
    path = PropertyPathBuilder.propertyStore(clusterName);
    _baseDataAccessor.create(path, new ZNRecord(clusterName), 0);
    // LIVE INSTANCES
    _baseDataAccessor.create(PropertyPathBuilder.liveInstance(clusterName), new ZNRecord(clusterName), 0);
    // MEMBER INSTANCES
    _baseDataAccessor.create(PropertyPathBuilder.instance(clusterName), new ZNRecord(clusterName), 0);
    // External view
    _baseDataAccessor.create(PropertyPathBuilder.externalView(clusterName), new ZNRecord(clusterName), 0);
    // State model definition
    _baseDataAccessor.create(PropertyPathBuilder.stateModelDef(clusterName), new ZNRecord(clusterName), 0);
    // controller
    _baseDataAccessor.create(PropertyPathBuilder.controller(clusterName), new ZNRecord(clusterName), 0);
    path = PropertyPathBuilder.controllerHistory(clusterName);
    final ZNRecord emptyHistory = new ZNRecord(PropertyType.HISTORY.toString());
    final List<String> emptyList = new ArrayList<String>();
    emptyHistory.setListField(clusterName, emptyList);
    _baseDataAccessor.create(path, emptyHistory, 0);
    path = PropertyPathBuilder.controllerMessage(clusterName);
    _baseDataAccessor.create(path, new ZNRecord(clusterName), 0);
    path = PropertyPathBuilder.controllerStatusUpdate(clusterName);
    _baseDataAccessor.create(path, new ZNRecord(clusterName), 0);
    path = PropertyPathBuilder.controllerError(clusterName);
    _baseDataAccessor.create(path, new ZNRecord(clusterName), 0);
}
Also used : ArrayList(java.util.ArrayList) ZNRecord(org.apache.helix.ZNRecord) 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