Examples of HelixAdmin


Examples of org.apache.helix.HelixAdmin

    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();
View Full Code Here

Examples of org.apache.helix.HelixAdmin

    try {
      ConstraintType constraintType = ConstraintType.valueOf(constraintTypeStr);
      ZkClient zkClient =
          (ZkClient) getContext().getAttributes().get(RestAdminApplication.ZKCLIENT);
      // ClusterSetup setupTool = new ClusterSetup(zkClient);
      HelixAdmin admin = new ZKHelixAdmin(zkClient); // setupTool.getClusterManagementTool();

      ZNRecord record = admin.getConstraints(clusterName, constraintType).getRecord();
      if (constraintId == null) {
        // get all message constraints
        representation =
            new StringRepresentation(ClusterRepresentationUtil.ZNRecordToJson(record),
                MediaType.APPLICATION_JSON);
View Full Code Here

Examples of org.apache.helix.HelixAdmin

    final String TAG = "tag";
    final String URL_BASE =
        "http://localhost:" + ADMIN_PORT + "/clusters/" + clusterName + "/resourceGroups";

    _gSetupTool.addCluster(clusterName, true);
    HelixAdmin admin = _gSetupTool.getClusterManagementTool();

    // Add a tagged resource
    IdealState taggedResource = new IdealState("taggedResource");
    taggedResource.setInstanceGroupTag(TAG);
    taggedResource.setStateModelDefRef("OnlineOffline");
    admin.addResource(clusterName, taggedResource.getId(), taggedResource);

    // Add an untagged resource
    IdealState untaggedResource = new IdealState("untaggedResource");
    untaggedResource.setStateModelDefRef("OnlineOffline");
    admin.addResource(clusterName, untaggedResource.getId(), untaggedResource);

    // Now make a REST call for all resources
    Reference resourceRef = new Reference(URL_BASE);
    Request request = new Request(Method.GET, resourceRef);
    Response response = _gClient.handle(request);
View Full Code Here

Examples of org.apache.helix.HelixAdmin

    };
    final String URL_BASE =
        "http://localhost:" + ADMIN_PORT + "/clusters/" + clusterName + "/instances";

    _gSetupTool.addCluster(clusterName, true);
    HelixAdmin admin = _gSetupTool.getClusterManagementTool();

    // Add 4 participants, each with differint tag characteristics
    InstanceConfig instance1 = new InstanceConfig("localhost_1");
    instance1.addTag(TAGS[0]);
    admin.addInstance(clusterName, instance1);
    InstanceConfig instance2 = new InstanceConfig("localhost_2");
    instance2.addTag(TAGS[1]);
    admin.addInstance(clusterName, instance2);
    InstanceConfig instance3 = new InstanceConfig("localhost_3");
    instance3.addTag(TAGS[0]);
    instance3.addTag(TAGS[1]);
    admin.addInstance(clusterName, instance3);
    InstanceConfig instance4 = new InstanceConfig("localhost_4");
    admin.addInstance(clusterName, instance4);

    // Now make a REST call for all resources
    Reference resourceRef = new Reference(URL_BASE);
    Request request = new Request(Method.GET, resourceRef);
    Response response = _gClient.handle(request);
View Full Code Here

Examples of org.apache.helix.HelixAdmin

    StringRepresentation representation = null;
    // String clusterName = getValue("clusterName");

    ZkClient zkClient = (ZkClient) getContext().getAttributes().get(RestAdminApplication.ZKCLIENT);
    ClusterSetup setupTool = new ClusterSetup(zkClient);
    HelixAdmin admin = setupTool.getClusterManagementTool();
    ZNRecord record = new ZNRecord(scopeProperty + " Config");

    HelixConfigScope scope = new HelixConfigScopeBuilder(scopeProperty, keys).build();
    // List<String> configKeys = admin.getConfigKeys(scopeProperty, clusterName, keys);
    List<String> configKeys = admin.getConfigKeys(scope);
    record.setListField(scopeProperty.toString(), configKeys);

    representation =
        new StringRepresentation(ClusterRepresentationUtil.ZNRecordToJson(record),
            MediaType.APPLICATION_JSON);
View Full Code Here

Examples of org.apache.helix.HelixAdmin

    StringRepresentation representation = null;
    // String clusterName = getValue("clusterName");

    ZkClient zkClient = (ZkClient) getContext().getAttributes().get(RestAdminApplication.ZKCLIENT);
    ClusterSetup setupTool = new ClusterSetup(zkClient);
    HelixAdmin admin = setupTool.getClusterManagementTool();
    ZNRecord record = new ZNRecord(scopeProperty + " Config");

    HelixConfigScope scope = new HelixConfigScopeBuilder(scopeProperty, keys).build();
    List<String> configKeys = admin.getConfigKeys(scope);
    Map<String, String> configs = admin.getConfig(scope, configKeys);
    record.setSimpleFields(configs);

    representation =
        new StringRepresentation(ClusterRepresentationUtil.ZNRecordToJson(record),
            MediaType.APPLICATION_JSON);
View Full Code Here

Examples of org.apache.helix.HelixAdmin

  void disablePartition() {
    String instanceName = _manager.getInstanceName();
    String resourceName = _message.getResourceName();
    String partitionName = _message.getPartitionName();
    String clusterName = _manager.getClusterName();
    HelixAdmin admin = _manager.getClusterManagmentTool();
    admin.enablePartition(false, clusterName, instanceName, resourceName,
        Arrays.asList(partitionName));
    logger.info("error in transit from ERROR to " + _message.getToState() + " for partition: "
        + partitionName + ". disable it on " + instanceName);

  }
View Full Code Here

Examples of org.apache.helix.HelixAdmin

    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(ZK_ADDR,
            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(ZK_ADDR,
View Full Code Here

Examples of org.apache.helix.HelixAdmin

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

    // 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.setStateModelDefRef("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
    MockParticipantManager[] participants = new MockParticipantManager[n];
    for (int i = 0; i < n; i++) {
      String instanceName = "localhost_" + (12918 + i);
View Full Code Here

Examples of org.apache.helix.HelixAdmin

        3, // replicas
        "MasterSlave", true); // do rebalance

    // setup message constraint
    // "MESSAGE_TYPE=STATE_TRANSITION,TRANSITION=OFFLINE-SLAVE,INSTANCE=.*,CONSTRAINT_VALUE=1";
    HelixAdmin admin = new ZKHelixAdmin(_gZkClient);
    ConstraintItemBuilder builder = new ConstraintItemBuilder();
    builder.addConstraintAttribute("MESSAGE_TYPE", "STATE_TRANSITION")
        .addConstraintAttribute("INSTANCE", ".*").addConstraintAttribute("CONSTRAINT_VALUE", "1");

    // Map<String, String> constraints = new TreeMap<String, String>();
    // constraints.put("MESSAGE_TYPE", "STATE_TRANSITION");
    // // constraints.put("TRANSITION", "OFFLINE-SLAVE");
    // constraints.put("CONSTRAINT_VALUE", "1");
    // constraints.put("INSTANCE", ".*");
    admin.setConstraint(clusterName, ConstraintType.MESSAGE_CONSTRAINT, "constraint1",
        builder.build());

    final ZKHelixDataAccessor accessor =
        new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(_gZkClient));

View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.