Package org.apache.helix.manager.zk

Examples of org.apache.helix.manager.zk.ZKHelixManager


  public static HelixManager getZKHelixManager(String clusterName,
                                               String instanceName,
                                               InstanceType type,
                                               String zkAddr) throws Exception
  {
    return new ZKHelixManager(clusterName, instanceName, type, zkAddr);
  }
View Full Code Here


    if (_gZkClient.exists("/" + clusterName))
    {
      _gZkClient.deleteRecursive("/" + clusterName);
    }

    ZKHelixManager controller = new ZKHelixManager(clusterName, null,
                                                   InstanceType.CONTROLLER,
                                                   ZK_ADDR);
    try
    {
      controller.connect();
      Assert.fail("Should throw HelixException if initial cluster structure is not setup");
    } catch (HelixException e)
    {
      // OK
    }

    TestHelper.setupEmptyCluster(_gZkClient, clusterName);

    controller.connect();
    AssertJUnit.assertTrue(controller.isConnected());
    controller.connect();
    AssertJUnit.assertTrue(controller.isConnected());

    MockListener listener = new MockListener();
    listener.reset();

    try
    {
      controller.addControllerListener(null);
      Assert.fail("Should throw HelixException");
    } catch (HelixException e)
    {
      // OK
    }

    controller.addControllerListener(listener);
    AssertJUnit.assertTrue(listener.isControllerChangeListenerInvoked);
    controller.removeListener(listener);

    ZkHelixPropertyStore<ZNRecord> store = controller.getHelixPropertyStore();
    ZNRecord record = new ZNRecord("node_1");
    int options = 0;
    store.set("node_1", record, AccessOption.PERSISTENT);
    Stat stat = new Stat();
    record = store.get("node_1",stat, options);
    AssertJUnit.assertEquals("node_1", record.getId());

    controller.getMessagingService();
    controller.getHealthReportCollector();
    controller.getClusterManagmentTool();

    controller.handleNewSession();
    controller.disconnect();
    AssertJUnit.assertFalse(controller.isConnected());

    System.out.println("END " + className + ".testController() at " + new Date(System.currentTimeMillis()));
  }
View Full Code Here

    if (_gZkClient.exists("/" + clusterName))
    {
      _gZkClient.deleteRecursive("/" + clusterName);
    }

    ZKHelixManager admin = new ZKHelixManager(clusterName, null,
                                              InstanceType.ADMINISTRATOR,
                                              ZK_ADDR);

    TestHelper.setupEmptyCluster(_gZkClient, clusterName);

    admin.connect();
    AssertJUnit.assertTrue(admin.isConnected());

    HelixAdmin adminTool = admin.getClusterManagmentTool();
    ConfigScope scope = new ConfigScopeBuilder().forCluster(clusterName)
        .forResource("testResource").forPartition("testPartition").build();
    Map<String, String> properties = new HashMap<String, String>();
    properties.put("pKey1", "pValue1");
    properties.put("pKey2", "pValue2");
    adminTool.setConfig(scope, properties);

    properties = adminTool.getConfig(scope, TestHelper.setOf("pKey1", "pKey2"));
    Assert.assertEquals(properties.size(), 2);
    Assert.assertEquals(properties.get("pKey1"), "pValue1");
    Assert.assertEquals(properties.get("pKey2"), "pValue2");

    admin.disconnect();
    AssertJUnit.assertFalse(admin.isConnected());

    System.out.println("END " + className + ".testAdministrator() at " + new Date(System.currentTimeMillis()));
  }
View Full Code Here

  @Test
  public void testInstanceBounce() throws Exception
  {
    String controllerName = CONTROLLER_PREFIX + "_0";
    StartCMResult controllerResult = _startCMResultMap.get(controllerName);
    ZKHelixManager controller = (ZKHelixManager) controllerResult._manager;
    int handlerSize = controller.getHandlers().size();

    for (int i = 0; i < 2; i++)
    {
      String instanceName = PARTICIPANT_PREFIX + "_" + (START_PORT + i);
      // kill 2 participants
      _startCMResultMap.get(instanceName)._manager.disconnect();
      _startCMResultMap.get(instanceName)._thread.interrupt();
      try
      {
        Thread.sleep(1000);
      }
      catch (InterruptedException e)
      {
        e.printStackTrace();
      }
      // restart the participant
      StartCMResult result = TestHelper.startDummyProcess(ZK_ADDR, CLUSTER_NAME, instanceName);
      _startCMResultMap.put(instanceName, result);
      Thread.sleep(100);
    }
    Thread.sleep(4000);

    boolean result = ClusterStateVerifier.verifyByPolling(
        new ClusterStateVerifier.BestPossAndExtViewZkVerifier(ZK_ADDR, CLUSTER_NAME), 50 * 1000);
    Assert.assertTrue(result);
    // When a new live instance is created, we still add current state listener to it thus number should increase by 2
    for(int j = 0; j < 10; j++)
    {
      if(controller.getHandlers().size() == (handlerSize + 2))
      {
        break;
      }
      Thread.sleep(400);
    }
    Assert.assertEquals( controller.getHandlers().size(), handlerSize + 2);
  }
View Full Code Here

                            5, // number of nodes
                            3, // replicas
                            "MasterSlave",
                            true); // do rebalance

    ZKHelixManager manager =
        new ZKHelixManager(clusterName,
                               "localhost_12918",
                               InstanceType.PARTICIPANT,
                               ZK_ADDR);
    manager.connect();
  
    // Logger.getRootLogger().setLevel(Level.INFO);
    String lastSessionId = manager.getSessionId();
    for (int i = 0; i < 3; i++)
    {
      // System.err.println("curSessionId: " + lastSessionId);
      ZkTestHelper.expireSession(manager._zkClient);

      String sessionId = manager.getSessionId();
      Assert.assertTrue(sessionId.compareTo(lastSessionId) > 0, "Session id should be increased after expiry");
      lastSessionId = sessionId;

      // make sure session id is not 0
      Assert.assertFalse(sessionId.equals("0"),
                         "Hit race condition in zhclient.handleNewSession(). sessionId is not returned yet.");
     
      // TODO: need to test session expiry during handleNewSession()
    }

    // Logger.getRootLogger().setLevel(Level.INFO);
    System.out.println("Disconnecting ...");
    manager.disconnect();
   
    System.out.println("END " + clusterName + " at "
        + new Date(System.currentTimeMillis()));

  }
View Full Code Here

        0, 1, 2, 3, 4, 5
    };
    setupInstances(clusterName, ids);

    // ///////////////////
    ZKHelixManager manager =
        new ZKHelixManager(clusterName, "localhost_0", InstanceType.PARTICIPANT, ZK_ADDR);
    manager.connect();
    HelixDataAccessor accessor = manager.getHelixDataAccessor();

    LiveInstance liveInstance =
        accessor.getProperty(accessor.keyBuilder().liveInstance("localhost_0"));
    Assert.assertTrue(liveInstance.getRecord().getListFields().size() == 0);
    Assert.assertTrue(liveInstance.getRecord().getMapFields().size() == 0);
    Assert.assertTrue(liveInstance.getRecord().getSimpleFields().size() == 3);

    manager = new ZKHelixManager(clusterName, "localhost_1", InstanceType.PARTICIPANT, ZK_ADDR);
    manager.setLiveInstanceInfoProvider(new provider(false));

    manager.connect();
    accessor = manager.getHelixDataAccessor();

    liveInstance = accessor.getProperty(accessor.keyBuilder().liveInstance("localhost_1"));
    Assert.assertTrue(liveInstance.getRecord().getListFields().size() == 1);
    Assert.assertTrue(liveInstance.getRecord().getMapFields().size() == 1);
    Assert.assertTrue(liveInstance.getRecord().getSimpleFields().size() == 4);

    manager = new ZKHelixManager(clusterName, "localhost_2", InstanceType.PARTICIPANT, ZK_ADDR);
    manager.setLiveInstanceInfoProvider(new provider(true));

    manager.connect();
    accessor = manager.getHelixDataAccessor();

    liveInstance = accessor.getProperty(accessor.keyBuilder().liveInstance("localhost_2"));
    Assert.assertTrue(liveInstance.getRecord().getListFields().size() == 1);
    Assert.assertTrue(liveInstance.getRecord().getMapFields().size() == 1);
    Assert.assertTrue(liveInstance.getRecord().getSimpleFields().size() == 5);
View Full Code Here

    // basic test
    if (_gZkClient.exists("/" + clusterName)) {
      _gZkClient.deleteRecursive("/" + clusterName);
    }

    ZKHelixManager admin =
        new ZKHelixManager(clusterName, null, InstanceType.ADMINISTRATOR, ZK_ADDR);

    TestHelper.setupEmptyCluster(_gZkClient, clusterName);

    admin.connect();
    AssertJUnit.assertTrue(admin.isConnected());

    HelixAdmin adminTool = admin.getClusterManagmentTool();
    // ConfigScope scope = new ConfigScopeBuilder().forCluster(clusterName)
    // .forResource("testResource").forPartition("testPartition").build();
    HelixConfigScope scope =
        new HelixConfigScopeBuilder(ConfigScopeProperty.PARTITION).forCluster(clusterName)
            .forResource("testResource").forPartition("testPartition").build();

    Map<String, String> properties = new HashMap<String, String>();
    properties.put("pKey1", "pValue1");
    properties.put("pKey2", "pValue2");
    adminTool.setConfig(scope, properties);

    properties = adminTool.getConfig(scope, Arrays.asList("pKey1", "pKey2"));
    Assert.assertEquals(properties.size(), 2);
    Assert.assertEquals(properties.get("pKey1"), "pValue1");
    Assert.assertEquals(properties.get("pKey2"), "pValue2");

    admin.disconnect();
    AssertJUnit.assertFalse(admin.isConnected());

    System.out.println("END " + className + ".testAdministrator() at "
        + new Date(System.currentTimeMillis()));
  }
View Full Code Here

    // basic test
    if (_gZkClient.exists("/" + clusterName)) {
      _gZkClient.deleteRecursive("/" + clusterName);
    }

    ZKHelixManager controller =
        new ZKHelixManager(clusterName, null, InstanceType.CONTROLLER, ZK_ADDR);

    try {
      controller.connect();
      Assert.fail("Should throw HelixException if initial cluster structure is not setup");
    } catch (HelixException e) {
      // OK
    }

    TestHelper.setupEmptyCluster(_gZkClient, clusterName);

    controller.connect();
    AssertJUnit.assertTrue(controller.isConnected());
    controller.connect();
    AssertJUnit.assertTrue(controller.isConnected());

    MockListener listener = new MockListener();
    listener.reset();

    try {
      controller.addControllerListener(null);
      Assert.fail("Should throw HelixException");
    } catch (HelixException e) {
      // OK
    }

    Builder keyBuilder = new Builder(controller.getClusterName());
    controller.addControllerListener(listener);
    AssertJUnit.assertTrue(listener.isControllerChangeListenerInvoked);
    controller.removeListener(keyBuilder.controller(), listener);

    ZkHelixPropertyStore<ZNRecord> store = controller.getHelixPropertyStore();
    ZNRecord record = new ZNRecord("node_1");
    int options = 0;
    store.set("/node_1", record, AccessOption.PERSISTENT);
    Stat stat = new Stat();
    record = store.get("/node_1", stat, options);
    AssertJUnit.assertEquals("node_1", record.getId());

    controller.getMessagingService();
    controller.getHealthReportCollector();
    controller.getClusterManagmentTool();

    controller.handleNewSession();
    controller.disconnect();
    AssertJUnit.assertFalse(controller.isConnected());

    System.out.println("END " + className + ".testController() at "
        + new Date(System.currentTimeMillis()));
  }
View Full Code Here

    String clusterName = cmd.getOptionValue(cluster);
    String instance = cmd.getOptionValue(instanceName);
    String stateModelName = cmd.getOptionValue(stateModel);

    HelixManager manager =
        new ZKHelixManager(clusterName, instance, InstanceType.PARTICIPANT, zkAddress);

    StateMachineEngine stateMach = manager.getStateMachineEngine();
    stateMach.registerStateModelFactory(stateModelName, new AgentStateModelFactory());

    Runtime.getRuntime().addShutdownHook(new HelixAgentShutdownHook(manager));

    try {
      manager.connect();
      Thread.currentThread().join();
    } catch (Exception e) {
      LOG.error(e);
    } finally {
      if (manager != null && manager.isConnected()) {
        manager.disconnect();
      }
    }
  }
View Full Code Here

   * @param zkAddr
   * @return a HelixManager backed by Zookeeper
   */
  public static HelixManager getZKHelixManager(String clusterName, String instanceName,
      InstanceType type, String zkAddr) {
    return new ZKHelixManager(clusterName, instanceName, type, zkAddr);
  }
View Full Code Here

TOP

Related Classes of org.apache.helix.manager.zk.ZKHelixManager

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.