Search in sources :

Example 1 with FullAutoModeISBuilder

use of org.apache.helix.model.builder.FullAutoModeISBuilder in project helix by apache.

the class TestBatchMessageModeConfigs method setupResource.

private void setupResource(String dbName) throws InterruptedException {
    IdealState idealState = new FullAutoModeISBuilder(dbName).setStateModel("OnlineOffline").setStateModelFactoryName("TestFactory").setNumPartitions(10).setNumReplica(1).build();
    _setupTool.getClusterManagementTool().addResource(CLUSTER_NAME, dbName, idealState);
}
Also used : FullAutoModeISBuilder(org.apache.helix.model.builder.FullAutoModeISBuilder) IdealState(org.apache.helix.model.IdealState)

Example 2 with FullAutoModeISBuilder

use of org.apache.helix.model.builder.FullAutoModeISBuilder in project helix by apache.

the class TestResourceThreadpoolSize method TestPerStateTransitionTypeThreadPool.

@Test
public void TestPerStateTransitionTypeThreadPool() throws InterruptedException {
    String MASTER_SLAVE = "MasterSlave";
    int customizedPoolSize = 22;
    for (MockParticipantManager participant : _participants) {
        participant.getStateMachineEngine().registerStateModelFactory(MASTER_SLAVE, new TestMasterSlaveStateModelFactory(customizedPoolSize), TEST_FACTORY);
    }
    // add db with customized thread pool
    IdealState idealState = new FullAutoModeISBuilder(WorkflowGenerator.DEFAULT_TGT_DB + "4").setStateModel(MASTER_SLAVE).setStateModelFactoryName(TEST_FACTORY).setNumPartitions(10).setNumReplica(1).build();
    _setupTool.getClusterManagementTool().addResource(CLUSTER_NAME, WorkflowGenerator.DEFAULT_TGT_DB + "4", idealState);
    _setupTool.rebalanceStorageCluster(CLUSTER_NAME, WorkflowGenerator.DEFAULT_TGT_DB + "4", 1);
    Thread.sleep(2000);
    // Verify OFFLINE -> SLAVE and SLAVE -> MASTER have different threadpool size.
    for (int i = 0; i < NODE_NR; i++) {
        DefaultMessagingService svc = (DefaultMessagingService) (_participants[i].getMessagingService());
        HelixTaskExecutor helixExecutor = svc.getExecutor();
        ThreadPoolExecutor executorOfflineToSlave = (ThreadPoolExecutor) (helixExecutor._executorMap.get(MessageType.STATE_TRANSITION + "." + WorkflowGenerator.DEFAULT_TGT_DB + "4" + "." + OFFLINE_TO_SLAVE));
        Assert.assertEquals(customizedPoolSize, executorOfflineToSlave.getMaximumPoolSize());
        ThreadPoolExecutor executorSlaveToMaster = (ThreadPoolExecutor) (helixExecutor._executorMap.get(MessageType.STATE_TRANSITION + "." + WorkflowGenerator.DEFAULT_TGT_DB + "4" + "." + SLAVE_TO_MASTER));
        Assert.assertEquals(customizedPoolSize + 5, executorSlaveToMaster.getMaximumPoolSize());
    }
}
Also used : MockParticipantManager(org.apache.helix.integration.manager.MockParticipantManager) DefaultMessagingService(org.apache.helix.messaging.DefaultMessagingService) FullAutoModeISBuilder(org.apache.helix.model.builder.FullAutoModeISBuilder) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) IdealState(org.apache.helix.model.IdealState) Test(org.testng.annotations.Test)

Example 3 with FullAutoModeISBuilder

use of org.apache.helix.model.builder.FullAutoModeISBuilder in project helix by apache.

the class TestResourceThreadpoolSize method TestCustomizedResourceThreadPool.

@Test
public void TestCustomizedResourceThreadPool() {
    int customizedPoolSize = 7;
    int configuredPoolSize = 9;
    for (MockParticipantManager participant : _participants) {
        participant.getStateMachineEngine().registerStateModelFactory(ONLINE_OFFLINE, new TestOnlineOfflineStateModelFactory(customizedPoolSize, 0), TEST_FACTORY);
    }
    // add db with default thread pool
    _setupTool.addResourceToCluster(CLUSTER_NAME, WorkflowGenerator.DEFAULT_TGT_DB + "1", 64, STATE_MODEL);
    _setupTool.rebalanceStorageCluster(CLUSTER_NAME, WorkflowGenerator.DEFAULT_TGT_DB + "1", 3);
    // add db with customized thread pool
    IdealState idealState = new FullAutoModeISBuilder(WorkflowGenerator.DEFAULT_TGT_DB + "2").setStateModel(ONLINE_OFFLINE).setStateModelFactoryName(TEST_FACTORY).setNumPartitions(10).setNumReplica(1).build();
    _setupTool.getClusterManagementTool().addResource(CLUSTER_NAME, WorkflowGenerator.DEFAULT_TGT_DB + "2", idealState);
    _setupTool.rebalanceStorageCluster(CLUSTER_NAME, WorkflowGenerator.DEFAULT_TGT_DB + "2", 1);
    // add db with configured pool size
    idealState = new FullAutoModeISBuilder(WorkflowGenerator.DEFAULT_TGT_DB + "3").setStateModel(ONLINE_OFFLINE).setStateModelFactoryName(TEST_FACTORY).setNumPartitions(10).setNumReplica(1).build();
    _setupTool.getClusterManagementTool().addResource(CLUSTER_NAME, WorkflowGenerator.DEFAULT_TGT_DB + "3", idealState);
    setResourceThreadPoolSize(WorkflowGenerator.DEFAULT_TGT_DB + "3", configuredPoolSize);
    _setupTool.rebalanceStorageCluster(CLUSTER_NAME, WorkflowGenerator.DEFAULT_TGT_DB + "3", 1);
    boolean result = ClusterStateVerifier.verifyByPolling(new ClusterStateVerifier.BestPossAndExtViewZkVerifier(ZK_ADDR, CLUSTER_NAME));
    Assert.assertTrue(result);
    for (int i = 0; i < NODE_NR; i++) {
        DefaultMessagingService svc = (DefaultMessagingService) (_participants[i].getMessagingService());
        HelixTaskExecutor helixExecutor = svc.getExecutor();
        ThreadPoolExecutor executor = (ThreadPoolExecutor) (helixExecutor._executorMap.get(MessageType.STATE_TRANSITION + "." + WorkflowGenerator.DEFAULT_TGT_DB + "1"));
        Assert.assertNull(executor);
        executor = (ThreadPoolExecutor) (helixExecutor._executorMap.get(MessageType.STATE_TRANSITION + "." + WorkflowGenerator.DEFAULT_TGT_DB + "2"));
        Assert.assertEquals(customizedPoolSize, executor.getMaximumPoolSize());
        executor = (ThreadPoolExecutor) (helixExecutor._executorMap.get(MessageType.STATE_TRANSITION + "." + WorkflowGenerator.DEFAULT_TGT_DB + "3"));
        Assert.assertEquals(configuredPoolSize, executor.getMaximumPoolSize());
    }
}
Also used : MockParticipantManager(org.apache.helix.integration.manager.MockParticipantManager) DefaultMessagingService(org.apache.helix.messaging.DefaultMessagingService) FullAutoModeISBuilder(org.apache.helix.model.builder.FullAutoModeISBuilder) ClusterStateVerifier(org.apache.helix.tools.ClusterStateVerifier) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) IdealState(org.apache.helix.model.IdealState) Test(org.testng.annotations.Test)

Example 4 with FullAutoModeISBuilder

use of org.apache.helix.model.builder.FullAutoModeISBuilder in project helix by apache.

the class TestBatchMessageHandling method testSubMessageFailed.

@Test
public void testSubMessageFailed() throws InterruptedException {
    TestOnlineOfflineStateModel._numOfSuccessBeforeFail = 6;
    // Let one instance handle all the batch messages.
    _participants[0].getStateMachineEngine().registerStateModelFactory("OnlineOffline", new TestOnlineOfflineStateModelFactory(), "TestFactory");
    for (int i = 1; i < _participants.length; i++) {
        _participants[i].syncStop();
    }
    // Add 1 db with batch message enabled. Each db has 10 partitions.
    // So it will have 1 batch message and 10 sub messages.
    String dbName = "TestDBSubMessageFail";
    IdealState idealState = new FullAutoModeISBuilder(dbName).setStateModel("OnlineOffline").setStateModelFactoryName("TestFactory").setNumPartitions(10).setNumReplica(1).build();
    idealState.setBatchMessageMode(true);
    _setupTool.getClusterManagementTool().addResource(CLUSTER_NAME, dbName, idealState);
    _setupTool.rebalanceStorageCluster(CLUSTER_NAME, dbName, 1);
    Thread.sleep(1000L);
    int numOfOnlines = 0;
    int numOfErrors = 0;
    ExternalView externalView = _setupTool.getClusterManagementTool().getResourceExternalView(CLUSTER_NAME, dbName);
    for (String partition : externalView.getPartitionSet()) {
        if (externalView.getStateMap(partition).values().contains("ONLINE")) {
            numOfOnlines++;
        }
        if (externalView.getStateMap(partition).values().contains("ERROR")) {
            numOfErrors++;
        }
    }
    Assert.assertEquals(numOfErrors, 4);
    Assert.assertEquals(numOfOnlines, 6);
}
Also used : ExternalView(org.apache.helix.model.ExternalView) FullAutoModeISBuilder(org.apache.helix.model.builder.FullAutoModeISBuilder) IdealState(org.apache.helix.model.IdealState) Test(org.testng.annotations.Test)

Example 5 with FullAutoModeISBuilder

use of org.apache.helix.model.builder.FullAutoModeISBuilder in project helix by apache.

the class TestResourceAccessor method testAddResources.

@Test(dependsOnMethods = "testGetResource")
public void testAddResources() throws IOException {
    System.out.println("Start test :" + TestHelper.getTestMethodName());
    String newResourceName = "newResource";
    IdealState idealState = new IdealState(newResourceName);
    idealState.getRecord().getSimpleFields().putAll(_gSetupTool.getClusterManagementTool().getResourceIdealState(CLUSTER_NAME, RESOURCE_NAME).getRecord().getSimpleFields());
    // Add resource by IdealState
    Entity entity = Entity.entity(OBJECT_MAPPER.writeValueAsString(idealState.getRecord()), MediaType.APPLICATION_JSON_TYPE);
    put("clusters/" + CLUSTER_NAME + "/resources/" + newResourceName, null, entity, Response.Status.OK.getStatusCode());
    Assert.assertEquals(idealState, _gSetupTool.getClusterManagementTool().getResourceIdealState(CLUSTER_NAME, newResourceName));
    // Add resource by query param
    entity = Entity.entity("", MediaType.APPLICATION_JSON_TYPE);
    put("clusters/" + CLUSTER_NAME + "/resources/" + newResourceName + "0", ImmutableMap.of("numPartitions", "4", "stateModelRef", "OnlineOffline", "rebalancerMode", "FULL_AUTO"), entity, Response.Status.OK.getStatusCode());
    IdealState queryIdealState = new FullAutoModeISBuilder(newResourceName + 0).setNumPartitions(4).setStateModel("OnlineOffline").setRebalancerMode(IdealState.RebalanceMode.FULL_AUTO).setRebalanceStrategy("DEFAULT").build();
    Assert.assertEquals(queryIdealState, _gSetupTool.getClusterManagementTool().getResourceIdealState(CLUSTER_NAME, newResourceName + "0"));
}
Also used : Entity(javax.ws.rs.client.Entity) FullAutoModeISBuilder(org.apache.helix.model.builder.FullAutoModeISBuilder) IdealState(org.apache.helix.model.IdealState) Test(org.testng.annotations.Test)

Aggregations

IdealState (org.apache.helix.model.IdealState)7 FullAutoModeISBuilder (org.apache.helix.model.builder.FullAutoModeISBuilder)7 Test (org.testng.annotations.Test)5 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)3 DefaultMessagingService (org.apache.helix.messaging.DefaultMessagingService)3 MockParticipantManager (org.apache.helix.integration.manager.MockParticipantManager)2 Entity (javax.ws.rs.client.Entity)1 ZKHelixAdmin (org.apache.helix.manager.zk.ZKHelixAdmin)1 ZNRecordSerializer (org.apache.helix.manager.zk.ZNRecordSerializer)1 ZkClient (org.apache.helix.manager.zk.ZkClient)1 ExternalView (org.apache.helix.model.ExternalView)1 RebalanceMode (org.apache.helix.model.IdealState.RebalanceMode)1 InstanceConfig (org.apache.helix.model.InstanceConfig)1 StateModelDefinition (org.apache.helix.model.StateModelDefinition)1 CustomModeISBuilder (org.apache.helix.model.builder.CustomModeISBuilder)1 HelixConfigScopeBuilder (org.apache.helix.model.builder.HelixConfigScopeBuilder)1 SemiAutoModeISBuilder (org.apache.helix.model.builder.SemiAutoModeISBuilder)1 ClusterStateVerifier (org.apache.helix.tools.ClusterStateVerifier)1 BestPossibleExternalViewVerifier (org.apache.helix.tools.ClusterVerifiers.BestPossibleExternalViewVerifier)1