Search in sources :

Example 6 with FullAutoModeISBuilder

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

the class IdealStateBuilderExample method main.

public static void main(String[] args) {
    if (args.length < 3) {
        System.err.println("USAGE: java IdealStateBuilderExample zkAddress clusterName idealStateMode" + " (FULL_AUTO, SEMI_AUTO, CUSTOMIZED, or USER_DEFINED)");
        System.exit(1);
    }
    final String zkAddr = args[0];
    final String clusterName = args[1];
    RebalanceMode idealStateMode = RebalanceMode.valueOf(args[2].toUpperCase());
    ZkClient zkclient = new ZkClient(zkAddr, ZkClient.DEFAULT_SESSION_TIMEOUT, ZkClient.DEFAULT_CONNECTION_TIMEOUT, new ZNRecordSerializer());
    ZKHelixAdmin admin = new ZKHelixAdmin(zkclient);
    // add cluster
    admin.addCluster(clusterName, true);
    // add MasterSlave state model definition
    admin.addStateModelDef(clusterName, "MasterSlave", new StateModelDefinition(StateModelConfigGenerator.generateConfigForMasterSlave()));
    // add 2 participants: "localhost:{12918, 12919}"
    int n = 2;
    for (int i = 0; i < n; i++) {
        int port = 12918 + i;
        InstanceConfig config = new InstanceConfig("localhost_" + port);
        config.setHostName("localhost");
        config.setPort(Integer.toString(port));
        config.setInstanceEnabled(true);
        admin.addInstance(clusterName, config);
    }
    // add ideal-state according to ideal-state-mode
    String resourceName = "TestDB";
    IdealState idealState = null;
    switch(idealStateMode) {
        case SEMI_AUTO:
            {
                SemiAutoModeISBuilder builder = new SemiAutoModeISBuilder(resourceName);
                builder.setStateModel("MasterSlave").setNumPartitions(2).setNumReplica(2);
                builder.assignPreferenceList(buildPartitionName(resourceName, 0), "localhost_12918", "localhost_12919").assignPreferenceList(buildPartitionName(resourceName, 1), "localhost_12919", "localhost_12918");
                idealState = builder.build();
                break;
            }
        case FULL_AUTO:
            {
                FullAutoModeISBuilder builder = new FullAutoModeISBuilder(resourceName);
                builder.setStateModel("MasterSlave").setNumPartitions(2).setNumReplica(2).setMaxPartitionsPerNode(2);
                builder.add(buildPartitionName(resourceName, 0)).add(buildPartitionName(resourceName, 1));
                idealState = builder.build();
                break;
            }
        case CUSTOMIZED:
            {
                CustomModeISBuilder builder = new CustomModeISBuilder(resourceName);
                builder.setStateModel("MasterSlave").setNumPartitions(2).setNumReplica(2);
                builder.assignInstanceAndState(buildPartitionName(resourceName, 0), "localhost_12918", "MASTER").assignInstanceAndState(buildPartitionName(resourceName, 0), "localhost_12919", "SLAVE").assignInstanceAndState(buildPartitionName(resourceName, 1), "localhost_12918", "SLAVE").assignInstanceAndState(buildPartitionName(resourceName, 1), "localhost_12919", "MASTER");
                idealState = builder.build();
                break;
            }
        default:
            break;
    }
    admin.addResource(clusterName, resourceName, idealState);
    // start helix controller
    new Thread(new Runnable() {

        @Override
        public void run() {
            try {
                HelixControllerMain.main(new String[] { "--zkSvr", zkAddr, "--cluster", clusterName });
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    }).start();
    // start dummy participants
    for (int i = 0; i < n; i++) {
        int port = 12918 + i;
        final String instanceName = "localhost_" + port;
        new Thread(new Runnable() {

            @Override
            public void run() {
                DummyParticipant.main(new String[] { zkAddr, clusterName, instanceName });
            }
        }).start();
    }
}
Also used : ZkClient(org.apache.helix.manager.zk.ZkClient) CustomModeISBuilder(org.apache.helix.model.builder.CustomModeISBuilder) SemiAutoModeISBuilder(org.apache.helix.model.builder.SemiAutoModeISBuilder) FullAutoModeISBuilder(org.apache.helix.model.builder.FullAutoModeISBuilder) IdealState(org.apache.helix.model.IdealState) ZKHelixAdmin(org.apache.helix.manager.zk.ZKHelixAdmin) InstanceConfig(org.apache.helix.model.InstanceConfig) StateModelDefinition(org.apache.helix.model.StateModelDefinition) RebalanceMode(org.apache.helix.model.IdealState.RebalanceMode) ZNRecordSerializer(org.apache.helix.manager.zk.ZNRecordSerializer)

Example 7 with FullAutoModeISBuilder

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

the class TestResourceThreadpoolSize method testBatchMessageThreadPoolSize.

@Test
public void testBatchMessageThreadPoolSize() throws InterruptedException {
    int customizedPoolSize = 5;
    _participants[0].getStateMachineEngine().registerStateModelFactory("OnlineOffline", new TestOnlineOfflineStateModelFactory(customizedPoolSize, 2000), "TestFactory");
    for (int i = 1; i < _participants.length; i++) {
        _participants[i].syncStop();
    }
    Thread.sleep(2000L);
    // Add 10 dbs with batch message enabled. Each db has 10 partitions.
    // So it will have 10 batch messages and each batch message has 10 sub messages.
    int numberOfDbs = 10;
    for (int i = 0; i < numberOfDbs; i++) {
        String dbName = "TestDBABatch" + i;
        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(2000L);
    DefaultMessagingService svc = (DefaultMessagingService) (_participants[0].getMessagingService());
    HelixTaskExecutor helixExecutor = svc.getExecutor();
    ThreadPoolExecutor executor = (ThreadPoolExecutor) (helixExecutor._batchMessageExecutorService);
    Assert.assertNotNull(executor);
    Assert.assertTrue(executor.getPoolSize() >= numberOfDbs);
    BestPossibleExternalViewVerifier verifier = new BestPossibleExternalViewVerifier.Builder(CLUSTER_NAME).setZkAddr(ZK_ADDR).build();
    Assert.assertTrue(verifier.verify());
}
Also used : DefaultMessagingService(org.apache.helix.messaging.DefaultMessagingService) HelixConfigScopeBuilder(org.apache.helix.model.builder.HelixConfigScopeBuilder) FullAutoModeISBuilder(org.apache.helix.model.builder.FullAutoModeISBuilder) FullAutoModeISBuilder(org.apache.helix.model.builder.FullAutoModeISBuilder) BestPossibleExternalViewVerifier(org.apache.helix.tools.ClusterVerifiers.BestPossibleExternalViewVerifier) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) 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