Examples of ZKHelixAdmin


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

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

    // tag the resource and participants
    HelixAdmin helixAdmin = new ZKHelixAdmin(ZK_ADDR);
    for (String taggedNode : TAGGED_NODES) {
      helixAdmin.addInstanceTag(clusterName, taggedNode, TAG);
    }
    IdealState idealState = helixAdmin.getResourceIdealState(clusterName, RESOURCE_NAME);
    idealState.setInstanceGroupTag(TAG);
    helixAdmin.setResourceIdealState(clusterName, RESOURCE_NAME, idealState);

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

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

// 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.manager.zk.ZKHelixAdmin

        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

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

    StatusPrinter statusPrinter = new StatusPrinter();
    statusPrinter.registerWith(helixController);
  }

  void startAdmin() throws Exception {
    HelixAdmin admin = new ZKHelixAdmin(ZK_ADDR);

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

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

    // ideal-state znrecord
    ZNRecord record = new ZNRecord(resourceName);
    record.setSimpleField("IDEAL_STATE_MODE", "AUTO");
    record.setSimpleField("NUM_PARTITIONS", "1");
    record.setSimpleField("REPLICAS", "2");
    record.setSimpleField("STATE_MODEL_DEF_REF", "MasterSlave");
    record.setListField(resourceName, Arrays.asList("node1", "node2"));

    admin.setResourceIdealState(clusterName, resourceName, new IdealState(record));

    ConstraintItemBuilder builder = new ConstraintItemBuilder();

    // limit one transition message at a time across the entire cluster
    builder.addConstraintAttribute("MESSAGE_TYPE", "STATE_TRANSITION")
    // .addConstraintAttribute("INSTANCE", ".*") // un-comment this line if using instance-level
    // constraint
        .addConstraintAttribute("CONSTRAINT_VALUE", "1");
    admin.setConstraint(clusterName, ClusterConstraints.ConstraintType.MESSAGE_CONSTRAINT,
        "constraint1", builder.build());
  }
View Full Code Here

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

      startProcess(instanceName);
    }

    private static void addInstanceConfig(String instanceName) {
      // add node to cluster if not already added
      ZKHelixAdmin admin = new ZKHelixAdmin(ZK_ADDR);

      InstanceConfig instanceConfig = null;
      try {
        instanceConfig = admin.getInstanceConfig(clusterName, instanceName);
      } catch (Exception e) {
      }
      if (instanceConfig == null) {
        InstanceConfig config = new InstanceConfig(instanceName);
        config.setHostName("localhost");
        config.setInstanceEnabled(true);
        echo("Adding InstanceConfig:" + config);
        admin.addInstance(clusterName, config);
      }
    }
View Full Code Here

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

    HelixManager controllerManager = null;
    Thread[] processArray;
    processArray = new Thread[numInstances];
    try {
      startLocalZookeeper(2199);
      HelixAdmin admin = new ZKHelixAdmin(zkAddress);
      admin.addCluster(clusterName, true);
      StateModelConfigGenerator generator = new StateModelConfigGenerator();
      admin.addStateModelDef(clusterName, "OnlineOffline",
          new StateModelDefinition(generator.generateConfigForOnlineOffline()));
      admin.addResource(clusterName, lockGroupName, numPartitions, "OnlineOffline",
          RebalanceMode.FULL_AUTO.toString());
      admin.rebalance(clusterName, lockGroupName, 1);
      for (int i = 0; i < numInstances; i++) {
        final String instanceName = "localhost_" + (12000 + i);
        processArray[i] = new Thread(new Runnable() {

          @Override
View Full Code Here

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

   * Configure the instance, the configuration of each node is available to
   * other nodes.
   * @param instanceName
   */
  private void configureInstance(String instanceName) {
    ZKHelixAdmin helixAdmin = new ZKHelixAdmin(zkAddress);

    List<String> instancesInCluster = helixAdmin.getInstancesInCluster(clusterName);
    if (instancesInCluster == null || !instancesInCluster.contains(instanceName)) {
      InstanceConfig config = new InstanceConfig(instanceName);
      config.setHostName("localhost");
      config.setPort("12000");
      helixAdmin.addInstance(clusterName, config);
    }
  }
View Full Code Here

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

            ZK_ADDR, CLUSTER_NAME));
    Assert.assertTrue(result);

    TestHelper.verifyState(CLUSTER_NAME, ZK_ADDR, map, "OFFLINE");

    ZKHelixAdmin tool = new ZKHelixAdmin(_gZkClient);
    tool.enablePartition(true, CLUSTER_NAME, "localhost_12919", "TestDB", Arrays.asList("TestDB_9"));

    result =
        ClusterStateVerifier.verifyByPolling(new ClusterStateVerifier.BestPossAndExtViewZkVerifier(
            ZK_ADDR, CLUSTER_NAME));
    Assert.assertTrue(result);
View Full Code Here

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

    // parse the YAML
    Yaml yaml = new Yaml();
    YAMLClusterConfig cfg = yaml.loadAs(input, YAMLClusterConfig.class);

    // create the cluster
    HelixAdmin helixAdmin = new ZKHelixAdmin(_zkAddress);
    if (cfg.clusterName == null) {
      throw new HelixException("Cluster name is required!");
    }
    helixAdmin.addCluster(cfg.clusterName);

    // add each participant
    if (cfg.participants != null) {
      for (ParticipantConfig participant : cfg.participants) {
        helixAdmin.addInstance(cfg.clusterName, getInstanceCfg(participant));
      }
    }

    // add each resource
    if (cfg.resources != null) {
      for (ResourceConfig resource : cfg.resources) {
        if (resource.name == null) {
          throw new HelixException("Resources must be named!");
        }
        if (resource.stateModel == null || resource.stateModel.name == null) {
          throw new HelixException("Resource must specify a named state model!");
        }
        // if states is null, assume using a built-in or already-added state model
        if (resource.stateModel.states != null) {
          StateModelDefinition stateModelDef =
              getStateModelDef(resource.stateModel, resource.constraints);
          helixAdmin.addStateModelDef(cfg.clusterName, resource.stateModel.name, stateModelDef);
        } else {
          StateModelDefinition stateModelDef = null;
          if (resource.stateModel.name.equals("MasterSlave")) {
            stateModelDef =
                new StateModelDefinition(StateModelConfigGenerator.generateConfigForMasterSlave());
          } else if (resource.stateModel.name.equals("OnlineOffline")) {
            stateModelDef =
                new StateModelDefinition(StateModelConfigGenerator.generateConfigForOnlineOffline());
          } else if (resource.stateModel.name.equals("LeaderStandby")) {
            stateModelDef =
                new StateModelDefinition(StateModelConfigGenerator.generateConfigForLeaderStandby());
          }
          if (stateModelDef != null) {
            try {
              helixAdmin.addStateModelDef(cfg.clusterName, resource.stateModel.name, stateModelDef);
            } catch (HelixException e) {
              LOG.warn("State model definition " + resource.stateModel.name
                  + " could not be added.");
            }
          }
        }
        int partitions = 1;
        int replicas = 1;
        if (resource.partitions != null) {
          if (resource.partitions.containsKey("count")) {
            partitions = resource.partitions.get("count");
          }
          if (resource.partitions.containsKey("replicas")) {
            replicas = resource.partitions.get("replicas");
          }
        }

        if (resource.rebalancer == null || !resource.rebalancer.containsKey("mode")) {
          throw new HelixException("Rebalance mode is required!");
        }
        helixAdmin.addResource(cfg.clusterName, resource.name, partitions,
            resource.stateModel.name, resource.rebalancer.get("mode"));
        // user-defined rebalancer
        if (resource.rebalancer.containsKey("class")
            && resource.rebalancer.get("mode").equals(RebalanceMode.USER_DEFINED.toString())) {
          IdealState idealState = helixAdmin.getResourceIdealState(cfg.clusterName, resource.name);
          idealState.setRebalancerClassName(resource.rebalancer.get("class"));
          helixAdmin.setResourceIdealState(cfg.clusterName, resource.name, idealState);
        }
        helixAdmin.rebalance(cfg.clusterName, resource.name, replicas);
      }
    }

    // enable auto join if this option is set
    if (cfg.autoJoinAllowed != null && cfg.autoJoinAllowed) {
      HelixConfigScope scope =
          new HelixConfigScopeBuilder(ConfigScopeProperty.CLUSTER).forCluster(cfg.clusterName)
              .build();
      Map<String, String> properties = new HashMap<String, String>();
      properties.put(ZKHelixManager.ALLOW_PARTICIPANT_AUTO_JOIN, cfg.autoJoinAllowed.toString());
      helixAdmin.setConfig(scope, properties);
    }
    return cfg;
  }
View Full Code Here

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

  @Test
  public void testZkAdminTimeout() {
    boolean exceptionThrown = false;
    try {
      new ZKHelixAdmin("localhost:27999");
    } catch (Exception e) {
      exceptionThrown = true;
    }
    Assert.assertTrue(exceptionThrown);
    System.setProperty(ZKHelixAdmin.CONNECTION_TIMEOUT, "3");
    exceptionThrown = false;
    long time = System.currentTimeMillis();
    try {
      new ZKHelixAdmin("localhost:27999");
    } catch (Exception e) {
      exceptionThrown = true;
    }
    Assert.assertTrue(exceptionThrown);
    Assert.assertTrue(System.currentTimeMillis() - time < 5000);
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.