Package org.apache.helix

Examples of org.apache.helix.HelixAdmin


    expectStateModelMap.put(PartitionId.from("TestDB0_2"), "SLAVE");
    expectStateModelMap.put(PartitionId.from("TestDB0_3"), "MASTER");
    checkStateModelMap(fty, expectStateModelMap);

    // drop resourcePartitionId
    HelixAdmin admin = new ZKHelixAdmin(_zkclient);
    admin.dropResource(clusterName, "TestDB0");

    result =
        ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(_zkaddr,
            clusterName));
    Assert.assertTrue(result);
View Full Code Here


    expectStateModelMap.put(PartitionId.from("TestDB0_2"), "SLAVE");
    expectStateModelMap.put(PartitionId.from("TestDB0_3"), "MASTER");
    checkStateModelMap(fty, expectStateModelMap);

    // drop resource
    HelixAdmin admin = new ZKHelixAdmin(_zkclient);
    admin.dropResource(clusterName, "TestDB0");

    result =
        ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(_zkaddr,
            clusterName));
    Assert.assertTrue(result);
View Full Code Here

    MockController controller =
        new MockController(_zkaddr, clusterName, "controller");
    controller.syncStart();

    // get an admin and accessor
    HelixAdmin helixAdmin = new ZKHelixAdmin(_zkclient);
    HelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, _baseAccessor);
    PropertyKey.Builder keyBuilder = accessor.keyBuilder();

    // do the test
    try {
      Thread.sleep(1000);
      // ensure that the external view coalesces
      boolean result =
          ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(_zkaddr,
              clusterName));
      Assert.assertTrue(result);
      ExternalView stableExternalView =
          accessor.getProperty(keyBuilder.externalView(RESOURCE_NAME));
      for (int i = 0; i < NUM_PARTICIPANTS; i++) {
        // disable the controller, bounce the node, re-enable the controller, verify assignments
        // remained the same
        helixAdmin.enableCluster(clusterName, false);
        participants[i].disconnect();
        Thread.sleep(1000);
        participants[i] = createParticipant(clusterName, participants[i].getInstanceName());
        participants[i].connect();
        Thread.sleep(1000);
        helixAdmin.enableCluster(clusterName, true);
        Thread.sleep(1000);
        result =
            ClusterStateVerifier.verifyByZkCallback(new MatchingExternalViewVerifier(
                stableExternalView, clusterName));
        Assert.assertTrue(result);
View Full Code Here

  void disablePartition() {
    String instanceName = _manager.getInstanceName();
    ResourceId resourceId = _message.getResourceId();
    PartitionId partitionId = _message.getPartitionId();
    String clusterName = _manager.getClusterName();
    HelixAdmin admin = _manager.getClusterManagmentTool();
    admin.enablePartition(false, clusterName, instanceName, resourceId.stringify(),
        Arrays.asList(partitionId.stringify()));
    logger.info("error in transit from ERROR to " + _message.getTypedToState() + " for partition: "
        + partitionId + ". disable it on " + instanceName);

  }
View Full Code Here

    constraintItemBuilder
        .addConstraintAttribute(ConstraintAttribute.MESSAGE_TYPE.toString(), "STATE_TRANSITION")
        .addConstraintAttribute(ConstraintAttribute.PARTITION.toString(), ".*")
        .addConstraintAttribute(ConstraintAttribute.CONSTRAINT_VALUE.toString(), "1");

    HelixAdmin admin = new ZKHelixAdmin(_zkclient);
    admin.setConstraint(clusterName, ConstraintType.MESSAGE_CONSTRAINT, "constraint1",
        constraintItemBuilder.build());

    MockController controller =
        new MockController(_zkaddr, clusterName, "controller");
    controller.syncStart();
View Full Code Here

    if (totalWait >= CHECK_TIMEOUT) {
      Assert.fail("No leader was ever elected!");
    }
    String leaderId = leader.getId();
    String standbyId = (leaderId.equals("controller_0")) ? "controller_1" : "controller_0";
    HelixAdmin admin = _setupTool.getClusterManagementTool();
    admin.enableInstance(controllerCluster, leaderId, false);

    // Stop a participant to make sure that the leader election worked
    Thread.sleep(500);
    participants[0].syncStop();
    Thread.sleep(500);
    result =
        ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(_zkaddr,
            clusterName));
    Assert.assertTrue(result);

    // Disable the original standby (leaving 0 active controllers) and kill another participant
    admin.enableInstance(controllerCluster, standbyId, false);
    Thread.sleep(500);
    participants[1].syncStop();

    // Also change the ideal state
    IdealState idealState = admin.getResourceIdealState(clusterName, "TestDB0");
    idealState.setMaxPartitionsPerInstance(1);
    admin.setResourceIdealState(clusterName, "TestDB0", idealState);
    Thread.sleep(500);

    // Also disable an instance in the main cluster
    admin.enableInstance(clusterName, "localhost_12920", false);

    // Re-enable the original leader
    admin.enableInstance(controllerCluster, leaderId, true);

    // Now check that both the ideal state and the live instances are adhered to by the rebalance
    Thread.sleep(500);
    result =
        ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(_zkaddr,
View Full Code Here

// Helix-50: integration test for generate message based on state priority
public class TestInvalidAutoIdealState extends ZkTestBase {
  // TODO Disable this test, need refactor it for testing message generation based on state priority
  // @Test
  void testInvalidReplica2() throws Exception {
    HelixAdmin admin = new ZKHelixAdmin(_zkaddr);

    // create cluster
    String className = TestHelper.getTestClassName();
    String methodName = TestHelper.getTestMethodName();
    String clusterName = className + "_" + methodName;
    String db = "TestDB";

    System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));

    // System.out.println("Creating cluster: " + clusterName);
    admin.addCluster(clusterName, true);

    // add MasterSlave state mode definition
    admin.addStateModelDef(clusterName, "MasterSlave", new StateModelDefinition(
        StateModelConfigGenerator.generateConfigForMasterSlave()));

    // Add nodes to the cluster
    int n = 3;
    System.out.println("Adding " + n + " participants to the cluster");
    for (int i = 0; i < n; i++) {
      int port = 12918 + i;
      InstanceConfig instanceConfig = new InstanceConfig("localhost_" + port);
      instanceConfig.setHostName("localhost");
      instanceConfig.setPort("" + port);
      instanceConfig.setInstanceEnabled(true);
      admin.addInstance(clusterName, instanceConfig);
      // System.out.println("\t Added participant: " + instanceConfig.getInstanceName());
    }

    // construct ideal-state manually
    IdealState idealState = new IdealState(db);
    idealState.setRebalanceMode(RebalanceMode.SEMI_AUTO);
    idealState.setNumPartitions(2);
    idealState.setReplicas("" + 2); // should be 3
    idealState.setStateModelDefId(StateModelDefId.from("MasterSlave"));
    idealState.getRecord().setListField("TestDB_0",
        Arrays.asList("localhost_12918", "localhost_12919", "localhost_12920"));
    idealState.getRecord().setListField("TestDB_1",
        Arrays.asList("localhost_12919", "localhost_12918", "localhost_12920"));

    admin.setResourceIdealState(clusterName, "TestDB", idealState);

    // start participants
    MockParticipant[] participants = new MockParticipant[n];
    for (int i = 0; i < n; i++) {
      String instanceName = "localhost_" + (12918 + i);
View Full Code Here

          }
        });

    String resourceName = "test-resource";
    LOG.info("Ideal state assignment");
    HelixAdmin helixAdmin = participant.getClusterManagmentTool();
    helixAdmin.addResource(clusterName, resourceName, 1, "OnlineOffline",
        IdealState.RebalanceMode.CUSTOMIZED.toString());

    IdealState idealState = helixAdmin.getResourceIdealState(clusterName, resourceName);
    idealState.setReplicas("1");
    idealState.setStateModelFactoryId(StateModelFactoryId.from("test"));
    idealState.setPartitionState(PartitionId.from(ResourceId.from(resourceName), "0"),
        ParticipantId.from(instanceId), State.from("ONLINE"));

    LOG.info("Shutdown ZK server");
    TestHelper.stopZkServer(zkServerRef.get());
    Executors.newSingleThreadScheduledExecutor().schedule(new Runnable() {

      @Override
      public void run() {
        try {
          LOG.info("Restart ZK server");
          // zkServer.set(TestUtils.startZookeeper(zkDir, zkPort));
          zkServerRef.set(TestHelper.startZkServer(zkAddr, null, false));
        } catch (Exception e) {
          LOG.error(e.getMessage(), e);
        }
      }
    }, 2L, TimeUnit.SECONDS);

    // future.get();

    LOG.info("Before update ideal state");
    helixAdmin.setResourceIdealState(clusterName, resourceName, idealState);
    LOG.info("After update ideal state");

    LOG.info("Wait for OFFLINE->ONLINE state transition");
    try {
      Assert.assertTrue(latch.await(10, TimeUnit.SECONDS));
View Full Code Here

        NUM_REPLICAS, // replicas
        "OnlineOffline", RebalanceMode.FULL_AUTO, // use FULL_AUTO mode to test node tagging
        true); // do rebalance

    // Tag the resource
    final HelixAdmin helixAdmin = new ZKHelixAdmin(_zkclient);
    IdealState idealState = helixAdmin.getResourceIdealState(clusterName, RESOURCE_NAME);
    idealState.setInstanceGroupTag(TAG);
    helixAdmin.setResourceIdealState(clusterName, RESOURCE_NAME, idealState);

    // Get a data accessor
    final HelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, _baseAccessor);
    final PropertyKey.Builder keyBuilder = accessor.keyBuilder();

    // Tag the participants
    for (int i = 0; i < NUM_PARTICIPANTS; i++) {
      final String instanceName = "localhost_" + (12918 + i);
      helixAdmin.addInstanceTag(clusterName, instanceName, TAG);
    }

    // Start controller
    MockController controller =
        new MockController(_zkaddr, clusterName, "controller");
    controller.syncStart();

    // Start participants
    MockParticipant[] participants = new MockParticipant[NUM_PARTICIPANTS];
    for (int i = 0; i < NUM_PARTICIPANTS; i++) {
      final String instanceName = "localhost_" + (12918 + i);

      participants[i] = new MockParticipant(_zkaddr, clusterName, instanceName);
      participants[i].syncStart();
    }

    // Verify that there are NUM_PARTITIONS partitions in the external view, each having
    // NUM_REPLICAS replicas, where all assigned replicas are to tagged nodes, and they are all
    // ONLINE.
    Verifier v = new Verifier() {
      @Override
      public boolean verify() throws Exception {
        ExternalView externalView =
            HelixTestUtil.pollForProperty(ExternalView.class, accessor,
                keyBuilder.externalView(RESOURCE_NAME), true);
        if (externalView == null) {
          return false;
        }
        Set<String> taggedInstances =
            Sets.newHashSet(helixAdmin.getInstancesInClusterWithTag(clusterName, TAG));
        Set<String> partitionSet = externalView.getPartitionSet();
        if (partitionSet.size() != NUM_PARTITIONS) {
          return false;
        }
        for (String partitionName : partitionSet) {
          Map<String, String> stateMap = externalView.getStateMap(partitionName);
          if (stateMap.size() != NUM_REPLICAS) {
            return false;
          }
          for (String participantName : stateMap.keySet()) {
            if (!taggedInstances.contains(participantName)) {
              return false;
            }
            String state = stateMap.get(participantName);
            if (!state.equalsIgnoreCase("ONLINE")) {
              return false;
            }
          }
        }
        return true;
      }
    };

    // Run the verifier for both nodes tagged
    boolean initialResult = TestHelper.verify(v, 10 * 1000);
    Assert.assertTrue(initialResult);

    // Untag a node
    helixAdmin.removeInstanceTag(clusterName, "localhost_12918", TAG);

    // Verify again
    boolean finalResult = TestHelper.verify(v, 10 * 1000);
    Assert.assertTrue(finalResult);

View Full Code Here

        NUM_REPLICAS, // replicas
        "MasterSlave", RebalanceMode.FULL_AUTO, // use FULL_AUTO mode to test node tagging
        true); // do rebalance

    // tag the resource
    HelixAdmin helixAdmin = new ZKHelixAdmin(_zkaddr);
    IdealState idealState = helixAdmin.getResourceIdealState(clusterName, RESOURCE_NAME);
    idealState.setInstanceGroupTag(TAG);
    helixAdmin.setResourceIdealState(clusterName, RESOURCE_NAME, idealState);

    // start controller
    MockController controller =
        new MockController(_zkaddr, clusterName, "controller");
    controller.syncStart();
View Full Code Here

TOP

Related Classes of org.apache.helix.HelixAdmin

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.