Search in sources :

Example 6 with CustomModeISBuilder

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

the class TestEnableCompression method testEnableCompressionResource.

@Test()
public void testEnableCompressionResource() throws Exception {
    // Logger.getRootLogger().setLevel(Level.INFO);
    String className = TestHelper.getTestClassName();
    String methodName = TestHelper.getTestMethodName();
    String clusterName = className + "_" + methodName;
    System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));
    MockParticipantManager[] participants = new MockParticipantManager[5];
    // ClusterSetup setupTool = new ClusterSetup(ZK_ADDR);
    int numNodes = 10;
    // participant port
    TestHelper.setupCluster(// participant port
    clusterName, // participant port
    ZK_ADDR, // participant port
    12918, // participant name prefix
    "localhost", // resource name prefix
    "TestDB", // no resources, will be added later
    0, // partitions per resource
    0, // number of nodes
    numNodes, // replicas
    0, "OnlineOffline", // dont rebalance
    false);
    List<String> instancesInCluster = _gSetupTool.getClusterManagementTool().getInstancesInCluster(clusterName);
    String resourceName = "TestResource";
    CustomModeISBuilder customModeISBuilder = new CustomModeISBuilder(resourceName);
    int numPartitions = 10000;
    int numReplica = 3;
    customModeISBuilder.setNumPartitions(numPartitions);
    customModeISBuilder.setNumReplica(numReplica);
    customModeISBuilder.setStateModel("OnlineOffline");
    for (int p = 0; p < numPartitions; p++) {
        String partitionName = resourceName + "_" + p;
        customModeISBuilder.add(partitionName);
        for (int r = 0; r < numReplica; r++) {
            String instanceName = instancesInCluster.get((p % numNodes + r) % numNodes);
            customModeISBuilder.assignInstanceAndState(partitionName, instanceName, "ONLINE");
        }
    }
    IdealState idealstate = customModeISBuilder.build();
    idealstate.getRecord().setBooleanField("enableCompression", true);
    _gSetupTool.getClusterManagementTool().addResource(clusterName, resourceName, idealstate);
    ZkClient zkClient = new ZkClient(ZK_ADDR, 60 * 1000, 60 * 1000, new BytesPushThroughSerializer());
    zkClient.waitUntilConnected(10, TimeUnit.SECONDS);
    ClusterControllerManager controller = new ClusterControllerManager(ZK_ADDR, clusterName, "controller_0");
    controller.syncStart();
    // start participants
    for (int i = 0; i < 5; i++) {
        String instanceName = "localhost_" + (12918 + i);
        participants[i] = new MockParticipantManager(ZK_ADDR, clusterName, instanceName);
        participants[i].syncStart();
    }
    boolean result = ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(ZK_ADDR, clusterName), 120000);
    Assert.assertTrue(result);
    List<String> compressedPaths = new ArrayList<String>();
    findCompressedZNodes(zkClient, "/", compressedPaths);
    System.out.println("compressed paths:" + compressedPaths);
    // ONLY IDEALSTATE and EXTERNAL VIEW must be compressed
    Assert.assertEquals(compressedPaths.size(), 2);
    String idealstatePath = PropertyPathBuilder.idealState(clusterName, resourceName);
    String externalViewPath = PropertyPathBuilder.externalView(clusterName, resourceName);
    Assert.assertTrue(compressedPaths.contains(idealstatePath));
    Assert.assertTrue(compressedPaths.contains(externalViewPath));
    // clean up
    controller.syncStop();
    for (int i = 0; i < 5; i++) {
        participants[i].syncStop();
    }
    System.out.println("END " + clusterName + " at " + new Date(System.currentTimeMillis()));
}
Also used : CustomModeISBuilder(org.apache.helix.model.builder.CustomModeISBuilder) ZkClient(org.apache.helix.manager.zk.ZkClient) MockParticipantManager(org.apache.helix.integration.manager.MockParticipantManager) BytesPushThroughSerializer(org.I0Itec.zkclient.serialize.BytesPushThroughSerializer) ArrayList(java.util.ArrayList) BestPossAndExtViewZkVerifier(org.apache.helix.tools.ClusterStateVerifier.BestPossAndExtViewZkVerifier) Date(java.util.Date) IdealState(org.apache.helix.model.IdealState) ClusterControllerManager(org.apache.helix.integration.manager.ClusterControllerManager) Test(org.testng.annotations.Test)

Example 7 with CustomModeISBuilder

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

the class TaskDriver method buildWorkflowIdealState.

private IdealState buildWorkflowIdealState(String workflow) {
    CustomModeISBuilder IsBuilder = new CustomModeISBuilder(workflow);
    IsBuilder.setRebalancerMode(IdealState.RebalanceMode.TASK).setNumReplica(1).setNumPartitions(1).setStateModel(TaskConstants.STATE_MODEL_NAME).disableExternalView();
    IdealState is = IsBuilder.build();
    is.getRecord().setListField(workflow, new ArrayList<String>());
    is.getRecord().setMapField(workflow, new HashMap<String, String>());
    is.setRebalancerClassName(WorkflowRebalancer.class.getName());
    return is;
}
Also used : CustomModeISBuilder(org.apache.helix.model.builder.CustomModeISBuilder) IdealState(org.apache.helix.model.IdealState)

Example 8 with CustomModeISBuilder

use of org.apache.helix.model.builder.CustomModeISBuilder 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)

Aggregations

CustomModeISBuilder (org.apache.helix.model.builder.CustomModeISBuilder)8 IdealState (org.apache.helix.model.IdealState)7 Date (java.util.Date)2 HelixDataAccessor (org.apache.helix.HelixDataAccessor)2 PropertyKey (org.apache.helix.PropertyKey)2 ZNRecord (org.apache.helix.ZNRecord)2 ClusterControllerManager (org.apache.helix.integration.manager.ClusterControllerManager)2 MockParticipantManager (org.apache.helix.integration.manager.MockParticipantManager)2 ZkClient (org.apache.helix.manager.zk.ZkClient)2 Test (org.testng.annotations.Test)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Set (java.util.Set)1 BytesPushThroughSerializer (org.I0Itec.zkclient.serialize.BytesPushThroughSerializer)1 HelixAdmin (org.apache.helix.HelixAdmin)1 HelixProperty (org.apache.helix.HelixProperty)1 ZKHelixAdmin (org.apache.helix.manager.zk.ZKHelixAdmin)1 ZKHelixDataAccessor (org.apache.helix.manager.zk.ZKHelixDataAccessor)1 ZNRecordSerializer (org.apache.helix.manager.zk.ZNRecordSerializer)1