Search in sources :

Example 46 with ZNRecordSerializer

use of org.apache.helix.manager.zk.ZNRecordSerializer in project helix by apache.

the class TestClusterSetup method testSetGetRemoveParticipantConfig.

@Test()
public void testSetGetRemoveParticipantConfig() throws Exception {
    String className = TestHelper.getTestClassName();
    String methodName = TestHelper.getTestMethodName();
    String clusterName = className + "_" + methodName;
    System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));
    _clusterSetup.addCluster(clusterName, true);
    _clusterSetup.addInstanceToCluster(clusterName, "localhost_0");
    // test set/get/remove instance configs
    String scopeArgs = clusterName + ",localhost_0";
    String keyValueMap = "key1=value1,key2=value2";
    String keys = "key1,key2";
    ClusterSetup.processCommandLineArgs(new String[] { "--zkSvr", ZK_ADDR, "--setConfig", ConfigScopeProperty.PARTICIPANT.toString(), scopeArgs, keyValueMap });
    // getConfig returns json-formatted key-value pairs
    String valuesStr = _clusterSetup.getConfig(ConfigScopeProperty.PARTICIPANT, scopeArgs, keys);
    ZNRecordSerializer serializer = new ZNRecordSerializer();
    ZNRecord record = (ZNRecord) serializer.deserialize(valuesStr.getBytes());
    Assert.assertEquals(record.getSimpleField("key1"), "value1");
    Assert.assertEquals(record.getSimpleField("key2"), "value2");
    ClusterSetup.processCommandLineArgs(new String[] { "--zkSvr", ZK_ADDR, "--removeConfig", ConfigScopeProperty.PARTICIPANT.toString(), scopeArgs, keys });
    valuesStr = _clusterSetup.getConfig(ConfigScopeProperty.PARTICIPANT, scopeArgs, keys);
    record = (ZNRecord) serializer.deserialize(valuesStr.getBytes());
    Assert.assertNull(record.getSimpleField("key1"));
    Assert.assertNull(record.getSimpleField("key2"));
    System.out.println("END " + clusterName + " at " + new Date(System.currentTimeMillis()));
}
Also used : Date(java.util.Date) ZNRecord(org.apache.helix.ZNRecord) ZNRecordSerializer(org.apache.helix.manager.zk.ZNRecordSerializer) Test(org.testng.annotations.Test)

Example 47 with ZNRecordSerializer

use of org.apache.helix.manager.zk.ZNRecordSerializer in project helix by apache.

the class SetupCluster method main.

public static void main(String[] args) {
    if (args.length < 2) {
        System.err.println("USAGE: java SetupCluster zookeeperAddress(e.g. localhost:2181) numberOfNodes");
        System.exit(1);
    }
    final String zkAddr = args[0];
    final int numNodes = Integer.parseInt(args[1]);
    final String clusterName = DEFAULT_CLUSTER_NAME;
    ZkClient zkclient = null;
    try {
        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 state model definition
        StateModelConfigGenerator generator = new StateModelConfigGenerator();
        admin.addStateModelDef(clusterName, DEFAULT_STATE_MODEL, new StateModelDefinition(generator.generateConfigForOnlineOffline()));
        // addNodes
        for (int i = 0; i < numNodes; i++) {
            String port = "" + (12001 + i);
            String serverId = "localhost_" + port;
            InstanceConfig config = new InstanceConfig(serverId);
            config.setHostName("localhost");
            config.setPort(port);
            config.setInstanceEnabled(true);
            admin.addInstance(clusterName, config);
        }
        // add resource "repository" which has 1 partition
        String resourceName = DEFAULT_RESOURCE_NAME;
        admin.addResource(clusterName, resourceName, DEFAULT_PARTITION_NUMBER, DEFAULT_STATE_MODEL, RebalanceMode.SEMI_AUTO.toString());
        admin.rebalance(clusterName, resourceName, 1);
    } finally {
        if (zkclient != null) {
            zkclient.close();
        }
    }
}
Also used : ZkClient(org.apache.helix.manager.zk.ZkClient) ZKHelixAdmin(org.apache.helix.manager.zk.ZKHelixAdmin) InstanceConfig(org.apache.helix.model.InstanceConfig) StateModelDefinition(org.apache.helix.model.StateModelDefinition) StateModelConfigGenerator(org.apache.helix.tools.StateModelConfigGenerator) ZNRecordSerializer(org.apache.helix.manager.zk.ZNRecordSerializer)

Example 48 with ZNRecordSerializer

use of org.apache.helix.manager.zk.ZNRecordSerializer in project helix by apache.

the class Consumer method main.

public static void main(String[] args) throws Exception {
    if (args.length < 3) {
        System.err.println("USAGE: java Consumer zookeeperAddress (e.g. localhost:2181) consumerId (0-2), rabbitmqServer (e.g. localhost)");
        System.exit(1);
    }
    final String zkAddr = args[0];
    final String clusterName = SetupConsumerCluster.DEFAULT_CLUSTER_NAME;
    final String consumerId = args[1];
    final String mqServer = args[2];
    ZkClient zkclient = null;
    try {
        // add node to cluster if not already added
        zkclient = new ZkClient(zkAddr, ZkClient.DEFAULT_SESSION_TIMEOUT, ZkClient.DEFAULT_CONNECTION_TIMEOUT, new ZNRecordSerializer());
        ZKHelixAdmin admin = new ZKHelixAdmin(zkclient);
        List<String> nodes = admin.getInstancesInCluster(clusterName);
        if (!nodes.contains("consumer_" + consumerId)) {
            InstanceConfig config = new InstanceConfig("consumer_" + consumerId);
            config.setHostName("localhost");
            config.setInstanceEnabled(true);
            admin.addInstance(clusterName, config);
        }
        // start consumer
        final Consumer consumer = new Consumer(zkAddr, clusterName, "consumer_" + consumerId, mqServer);
        Runtime.getRuntime().addShutdownHook(new Thread() {

            @Override
            public void run() {
                System.out.println("Shutting down consumer_" + consumerId);
                consumer.disconnect();
            }
        });
        consumer.connect();
    } finally {
        if (zkclient != null) {
            zkclient.close();
        }
    }
}
Also used : ZkClient(org.apache.helix.manager.zk.ZkClient) ZKHelixAdmin(org.apache.helix.manager.zk.ZKHelixAdmin) InstanceConfig(org.apache.helix.model.InstanceConfig) ZNRecordSerializer(org.apache.helix.manager.zk.ZNRecordSerializer)

Example 49 with ZNRecordSerializer

use of org.apache.helix.manager.zk.ZNRecordSerializer in project helix by apache.

the class SetupConsumerCluster method main.

public static void main(String[] args) {
    if (args.length < 1) {
        System.err.println("USAGE: java SetupConsumerCluster zookeeperAddress (e.g. localhost:2181)");
        System.exit(1);
    }
    final String zkAddr = args[0];
    final String clusterName = DEFAULT_CLUSTER_NAME;
    ZkClient zkclient = null;
    try {
        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 state model definition
        admin.addStateModelDef(clusterName, DEFAULT_STATE_MODEL, new StateModelDefinition(StateModelConfigGenerator.generateConfigForOnlineOffline()));
        // add resource "topic" which has 6 partitions
        String resourceName = DEFAULT_RESOURCE_NAME;
        admin.addResource(clusterName, resourceName, DEFAULT_PARTITION_NUMBER, DEFAULT_STATE_MODEL, RebalanceMode.FULL_AUTO.toString());
        admin.rebalance(clusterName, resourceName, 1);
    } finally {
        if (zkclient != null) {
            zkclient.close();
        }
    }
}
Also used : ZkClient(org.apache.helix.manager.zk.ZkClient) ZKHelixAdmin(org.apache.helix.manager.zk.ZKHelixAdmin) StateModelDefinition(org.apache.helix.model.StateModelDefinition) ZNRecordSerializer(org.apache.helix.manager.zk.ZNRecordSerializer)

Example 50 with ZNRecordSerializer

use of org.apache.helix.manager.zk.ZNRecordSerializer in project helix by apache.

the class AdminTestBase method beforeSuite.

@BeforeSuite
public void beforeSuite() throws Exception {
    // TODO: use logging.properties file to config java.util.logging.Logger levels
    java.util.logging.Logger topJavaLogger = java.util.logging.Logger.getLogger("");
    topJavaLogger.setLevel(Level.WARNING);
    // start zk
    _zkServer = TestHelper.startZkServer(ZK_ADDR);
    AssertJUnit.assertTrue(_zkServer != null);
    ZKClientPool.reset();
    _gZkClient = new ZkClient(ZK_ADDR, ZkClient.DEFAULT_CONNECTION_TIMEOUT, ZkClient.DEFAULT_SESSION_TIMEOUT, new ZNRecordSerializer());
    _gSetupTool = new ClusterSetup(_gZkClient);
    // start admin
    _adminThread = new AdminThread(ZK_ADDR, ADMIN_PORT);
    _adminThread.start();
    // create a client
    _gClient = new Client(Protocol.HTTP);
    // wait for the web service to start
    Thread.sleep(100);
}
Also used : ZkClient(org.apache.helix.manager.zk.ZkClient) AdminThread(org.apache.helix.webapp.AdminTestHelper.AdminThread) ClusterSetup(org.apache.helix.tools.ClusterSetup) ZkClient(org.apache.helix.manager.zk.ZkClient) Client(org.restlet.Client) ZNRecordSerializer(org.apache.helix.manager.zk.ZNRecordSerializer) BeforeSuite(org.testng.annotations.BeforeSuite)

Aggregations

ZNRecordSerializer (org.apache.helix.manager.zk.ZNRecordSerializer)59 ZkClient (org.apache.helix.manager.zk.ZkClient)39 ZNRecord (org.apache.helix.ZNRecord)23 ZKHelixAdmin (org.apache.helix.manager.zk.ZKHelixAdmin)12 Test (org.testng.annotations.Test)11 IdealState (org.apache.helix.model.IdealState)10 ZKHelixDataAccessor (org.apache.helix.manager.zk.ZKHelixDataAccessor)9 Date (java.util.Date)7 InstanceConfig (org.apache.helix.model.InstanceConfig)7 ClusterSetup (org.apache.helix.tools.ClusterSetup)7 Builder (org.apache.helix.PropertyKey.Builder)6 StateModelDefinition (org.apache.helix.model.StateModelDefinition)6 HelixDataAccessor (org.apache.helix.HelixDataAccessor)5 ExternalView (org.apache.helix.model.ExternalView)5 PropertyKey (org.apache.helix.PropertyKey)4 BeforeClass (org.testng.annotations.BeforeClass)4 BeforeSuite (org.testng.annotations.BeforeSuite)4 File (java.io.File)3 IOException (java.io.IOException)3 InputStream (java.io.InputStream)3