Package org.apache.helix.manager.zk

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


    opts.addOption("zkAddress", true, "Zookeeper address");
    opts.addOption("participantClass", true, "Participant service class");
    try {
      CommandLine cliParser = new GnuParser().parse(opts, args);
      String zkAddress = cliParser.getOptionValue("zkAddress");
      final HelixConnection connection = new ZkHelixConnection(zkAddress);
      connection.connect();
      ClusterId clusterId = ClusterId.from(cliParser.getOptionValue("cluster"));
      ParticipantId participantId = ParticipantId.from(cliParser.getOptionValue("participantId"));
      String participantClass = cliParser.getOptionValue("participantClass");
      @SuppressWarnings("unchecked")
      Class<? extends AbstractParticipantService> clazz =
          (Class<? extends AbstractParticipantService>) Class.forName(participantClass);
      final AbstractParticipantService containerParticipant =
          clazz.getConstructor(HelixConnection.class, ClusterId.class, ParticipantId.class)
              .newInstance(connection, clusterId, participantId);
      containerParticipant.startAsync();
      containerParticipant.awaitRunning(60, TimeUnit.SECONDS);
      containerParticipant
          .getParticipant()
          .getMessagingService()
          .registerMessageHandlerFactory(MessageType.SHUTDOWN.toString(),
              new ShutdownMessageHandlerFactory(containerParticipant, connection));
      Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
        @Override
        public void run() {
          LOG.info("Received a shutdown signal. Stopping participant");
          containerParticipant.stopAsync();
          containerParticipant.awaitTerminated();
          connection.disconnect();
        }
      }) {

      });
      Thread.currentThread().join();
View Full Code Here


        NUM_PARTICIPANTS, // number of nodes
        NUM_REPLICAS, // replicas
        "OnlineOffline", RebalanceMode.CUSTOMIZED, true); // do rebalance

    // Connect
    HelixConnection connection = new ZkHelixConnection(_zkaddr);
    connection.connect();

    // Start some participants
    HelixParticipant[] participants = new HelixParticipant[NUM_PARTICIPANTS];
    for (int i = 0; i < NUM_PARTICIPANTS; i++) {
      participants[i] =
          connection.createParticipant(ClusterId.from(clusterName),
              ParticipantId.from("localhost_" + (12918 + i)));
      participants[i].getStateMachineEngine().registerStateModelFactory(
          StateModelDefId.from("OnlineOffline"), new TestHelixConnection.MockStateModelFactory());
      participants[i].start();
    }

    // Start the controller
    HelixController controller =
        connection.createController(ClusterId.from(clusterName), ControllerId.from("controller"));
    controller.start();
    Thread.sleep(500);

    // Verify balanced cluster
    boolean result =
        ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(_zkaddr,
            clusterName));
    Assert.assertTrue(result);

    // Drop a partition from the first participant
    HelixAdmin admin = connection.createClusterManagementTool();
    IdealState idealState = admin.getResourceIdealState(clusterName, RESOURCE_NAME);
    Map<ParticipantId, State> participantStateMap =
        idealState.getParticipantStateMap(PartitionId.from(RESOURCE_NAME + "_0"));
    participantStateMap.remove(ParticipantId.from("localhost_12918"));
    idealState.setParticipantStateMap(PartitionId.from(RESOURCE_NAME + "_0"), participantStateMap);
View Full Code Here

        NUM_PARTICIPANTS, // number of nodes
        NUM_REPLICAS, // replicas
        "OnlineOffline", RebalanceMode.CUSTOMIZED, true); // do rebalance

    // Connect
    HelixConnection connection = new ZkHelixConnection(_zkaddr);
    connection.connect();

    // Create a couple controllers
    HelixController[] controllers = new HelixController[NUM_CONTROLLERS];
    for (int i = 0; i < NUM_CONTROLLERS; i++) {
      controllers[i] =
          connection.createController(ClusterId.from(clusterName),
              ControllerId.from("controller_" + i));
      controllers[i].start();
    }
    Thread.sleep(1000);

    // Now verify that exactly one is leader
    int leaderCount = 0;
    for (HelixController controller : controllers) {
      HelixManager adaptor = new ZKHelixManager(controller);
      boolean result = ZkHelixLeaderElection.tryUpdateController(adaptor);
      if (result) {
        leaderCount++;
      }
    }
    Assert.assertEquals(leaderCount, 1);

    // Clean up
    for (HelixController controller : controllers) {
      controller.stop();
    }
    HelixAdmin admin = connection.createClusterManagementTool();
    admin.dropCluster(clusterName);
    System.out.println("END " + clusterName + " at " + new Date(System.currentTimeMillis()));
  }
View Full Code Here

        Transition.from(State.from("RELEASED"), State.from("LOCKED")), 1);

    ClusterConfig cluster = clusterBuilder.build();

    // set up a connection to work with ZooKeeper-persisted data
    HelixConnection connection = new ZkHelixConnection(args[0]);
    connection.connect();

    // create the cluster
    createCluster(cluster, connection);

    // update the resource
    updateResource(resource, clusterId, connection);

    // update the participant
    updateParticipant(participant, clusterId, connection);

    // start the controller
    ControllerId controllerId = ControllerId.from("exampleController");
    HelixController helixController = connection.createController(clusterId, controllerId);
    helixController.start();

    // start the specified participant
    HelixParticipant helixParticipant = connection.createParticipant(clusterId, participant.getId());
    helixParticipant.getStateMachineEngine().registerStateModelFactory(lockUnlock.getStateModelDefId(),
        new LockUnlockFactory());
    helixParticipant.start();

    // start another participant via auto join
    HelixParticipant autoJoinParticipant =
        connection.createParticipant(clusterId, ParticipantId.from("localhost_12120"));
    autoJoinParticipant.getStateMachineEngine().registerStateModelFactory(lockUnlock.getStateModelDefId(),
        new LockUnlockFactory());
    autoJoinParticipant.start();

    Thread.sleep(5000);
    printExternalView(connection, clusterId, resource.getId());

    // stop the participants
    helixParticipant.stop();
    autoJoinParticipant.stop();

    // stop the controller
    helixController.stop();

    // drop the cluster
    dropCluster(clusterId, connection);
    connection.disconnect();
  }
View Full Code Here

  private static Logger LOG = Logger.getLogger(UpdateProvisionerConfig.class);
  private static String updateContainerCount = "updateContainerCount";
  private HelixConnection _connection;

  public UpdateProvisionerConfig(String zkAddress) {
    _connection = new ZkHelixConnection(zkAddress);
    _connection.connect();
  }
View Full Code Here

  private static Logger LOG = Logger.getLogger(ContainerAdmin.class);
  private static String stopContainer = "stopContainer";
  private HelixConnection _connection;

  public ContainerAdmin(String zkAddress) {
    _connection = new ZkHelixConnection(zkAddress);
    _connection.connect();
  }
View Full Code Here

    State offline = State.from("OFFLINE");
    State dropped = State.from("DROPPED");
    StateModelDefId stateModelDefId = StateModelDefId.from("MasterSlave");

    // create connection
    HelixConnection connection = new ZkHelixConnection(_zkaddr);
    connection.connect();

    // setup cluster
    ClusterAccessor clusterAccessor = connection.createClusterAccessor(clusterId);
    clusterAccessor.dropCluster();

    StateModelDefinition stateModelDef =
        new StateModelDefinition.Builder(stateModelDefId).addState(master, 1).addState(slave, 2)
            .addState(offline, 3).addState(dropped).addTransition(offline, slave, 3)
            .addTransition(slave, offline, 4).addTransition(slave, master, 2)
            .addTransition(master, slave, 1).addTransition(offline, dropped).initialState(offline)
            .upperBound(master, 1).dynamicUpperBound(slave, "R").build();
    PartitionId partition0 = PartitionId.from(resourceId, "0");
    AutoModeISBuilder idealStateBuilder = new AutoModeISBuilder(resourceId).add(partition0);
    idealStateBuilder.setNumReplica(1).setStateModelDefId(stateModelDefId);
    idealStateBuilder.assignPreferenceList(partition0, participantId);
    IdealState idealState = idealStateBuilder.build();
    clusterAccessor.createCluster(new ClusterConfig.Builder(clusterId).addStateModelDefinition(
        stateModelDef).build());
    clusterAccessor.addResource(new ResourceConfig.Builder(resourceId).idealState(idealState)
        .build());
    clusterAccessor.addParticipant(new ParticipantConfig.Builder(participantId).build());

    // start controller
    HelixController controller = connection.createController(clusterId, controllerId);
    controller.start();

    // start participant
    HelixParticipant participant = connection.createParticipant(clusterId, participantId);
    participant.getStateMachineEngine().registerStateModelFactory(
        StateModelDefId.from("MasterSlave"), new MockStateModelFactory());

    participant.start();
    Thread.sleep(1000);

    // verify
    final HelixDataAccessor accessor = connection.createDataAccessor(clusterId);
    final PropertyKey.Builder keyBuilder = accessor.keyBuilder();
    boolean success = TestHelper.verify(new TestHelper.Verifier() {

      @Override
      public boolean verify() throws Exception {
        ExternalView externalView = accessor.getProperty(keyBuilder.externalView("testDB"));
        Map<ParticipantId, State> stateMap = externalView.getStateMap(PartitionId.from("testDB_0"));

        if (stateMap == null || !stateMap.containsKey(participantId)) {
          return false;
        }

        return stateMap.get(participantId).equals(State.from("MASTER"));
      }
    }, 10 * 1000);

    Assert.assertTrue(success);

    // clean up
    controller.stop();
    participant.stop();
    connection.disconnect();

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

  }

  public static void main(String[] args) throws InterruptedException {
    AppStatusReportGenerator generator = new AppStatusReportGenerator();

    ZkHelixConnection connection = new ZkHelixConnection("localhost:2181");
    connection.connect();
    while (true) {
      String generateReport = generator.generateReport(connection, ClusterId.from("testApp1"));
      System.out.println(generateReport);
      Thread.sleep(10000);
      connection.createClusterManagementTool().addCluster("testApp1");
    }
    // connection.disconnect();
  }
View Full Code Here

            if (ind > -1) {
              hostName = report.getHost().substring(ind + 1);
            } else {
              hostName = report.getHost();
            }
            connection = new ZkHelixConnection(hostName + ":2181");

            try {
              connection.connect();
            } catch (Exception e) {
              LOG.warn("AppMaster started but not yet initialized");
View Full Code Here

            if (ind > -1) {
              hostName = report.getHost().substring(ind + 1);
            } else {
              hostName = report.getHost();
            }
            connection = new ZkHelixConnection(hostName + ":2181");

            try {
              connection.connect();
            } catch (Exception e) {
              LOG.warn("AppMaster started but not yet initialized");
View Full Code Here

TOP

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

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.