Package org.apache.helix.model.builder

Examples of org.apache.helix.model.builder.HelixConfigScopeBuilder


  public void joinCluster() {
    // Read cluster config and see if instance can auto join the cluster
    boolean autoJoin = false;
    try {
      HelixConfigScope scope =
          new HelixConfigScopeBuilder(ConfigScopeProperty.CLUSTER).forCluster(
              _manager.getClusterName()).build();
      autoJoin =
          Boolean.parseBoolean(_configAccessor.get(scope,
              ZKHelixManager.ALLOW_PARTICIPANT_AUTO_JOIN));
      LOG.info("instance: " + _instanceName + " auto-joining " + _clusterName + " is " + autoJoin);
View Full Code Here


    ZkClient client = new ZkClient(zkAddr,
                                   ZkClient.DEFAULT_SESSION_TIMEOUT,
                                   ZkClient.DEFAULT_CONNECTION_TIMEOUT,
                                   new ZNRecordSerializer());

    HelixConfigScope scope = new HelixConfigScopeBuilder(ConfigScopeProperty.CLUSTER)
                                    .forCluster(clusterName)
                                    .build();
    ConfigAccessor configAccessor = new ConfigAccessor(client);
   
    // run foo_test.py during S->M
View Full Code Here

    String pidFileKey = buildKey(fromState, toState, CommandAttribute.PID_FILE);
    List<String> cmdConfigKeys = Arrays.asList(cmdKey, workingDirKey, timeoutKey, pidFileKey);
   
    // read command from resource-scope configures
    if (cmd == null) {
      HelixConfigScope resourceScope = new HelixConfigScopeBuilder(ConfigScopeProperty.RESOURCE)
                                          .forCluster(clusterName)
                                          .forResource(message.getResourceName())
                                          .build();
      Map<String, String> cmdKeyValueMap = manager.getConfigAccessor().get(resourceScope, cmdConfigKeys);
      if (cmdKeyValueMap != null) {
        cmd = cmdKeyValueMap.get(cmdKey);
        workingDir = cmdKeyValueMap.get(workingDirKey);
        timeout = cmdKeyValueMap.get(timeoutKey);
        pidFile = cmdKeyValueMap.get(pidFileKey);
      }
    }
   
    // if resource-scope doesn't contain command, fall back to cluster-scope configures
    if (cmd == null) {
      HelixConfigScope clusterScope = new HelixConfigScopeBuilder(ConfigScopeProperty.CLUSTER)
                                          .forCluster(clusterName)
                                          .build();
      Map<String, String> cmdKeyValueMap = manager.getConfigAccessor().get(clusterScope, cmdConfigKeys);
     
      if (cmdKeyValueMap != null) {
View Full Code Here

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

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

  private static void addConfiguration(ClusterSetup setup, String baseDir,
      String clusterName, String instanceName) throws IOException
  {
    Map<String, String> properties = new HashMap<String, String>();
    HelixConfigScopeBuilder builder = new HelixConfigScopeBuilder(ConfigScopeProperty.PARTICIPANT);
    HelixConfigScope instanceScope = builder.forCluster(clusterName)
        .forParticipant(instanceName).build();
    properties.put("change_log_dir", baseDir + instanceName + "/translog");
    properties.put("file_store_dir", baseDir + instanceName + "/filestore");
    properties.put("check_point_dir", baseDir + instanceName + "/checkpoint");
    setup.getClusterManagementTool().setConfig(instanceScope, properties);
View Full Code Here

      NotificationContext context) throws Exception {
    LOG.debug(_workerId + " becomes ONLINE from OFFLINE for "
        + _partition);
    ConfigAccessor clusterConfig = context.getManager().getConfigAccessor();
    HelixManager manager = context.getManager();
    HelixConfigScope clusterScope = new HelixConfigScopeBuilder(ConfigScopeProperty.CLUSTER)
                                        .forCluster(manager.getClusterName())
                                        .build();
    String json = clusterConfig.get(clusterScope, message.getResourceName());
    Dag.Node node = Dag.Node.fromJson(json);
    Set<String> parentIds = node.getParentIds();
View Full Code Here

    submitDag(dag);
  }

  public void submitDag(Dag dag) throws Exception {
    ConfigAccessor clusterConfig = new ConfigAccessor(_zkclient);
    HelixConfigScope clusterScope = new HelixConfigScopeBuilder(ConfigScopeProperty.CLUSTER)
                                      .forCluster(_clusterName)
                                      .build();
    for (String id : dag.getNodeIds()) {
      Dag.Node node = dag.getNode(id);
      clusterConfig.set(clusterScope, node.getId(), node.toJson());
View Full Code Here

  @Test
  public void testAlertActionDisableNode() throws InterruptedException
  {
    // ConfigScope scope = new ConfigScopeBuilder().forCluster(CLUSTER_NAME).build();
    HelixConfigScope scope = new HelixConfigScopeBuilder(ConfigScopeProperty.CLUSTER).forCluster(CLUSTER_NAME).build();
    Map<String, String> properties = new HashMap<String, String>();
    properties.put("healthChange.enabled", "true");
    _setupTool.getClusterManagementTool().setConfig(scope, properties);

    String alertStr1 = "EXP(decay(1.0)(localhost_*.TestStat@DB=db1.TestMetric1))CMP(GREATER)CON(20)ACTION(DISABLE_INSTANCE)";
    String alertStr2 = "EXP(decay(1.0)(localhost_*.TestStat@DB=db1.TestMetric2))CMP(GREATER)CON(120)ACTION(DISABLE_INSTANCE)";
    String alertStr3 = "EXP(decay(1.0)(localhost_*.TestStat@DB=TestDB;Partition=*.TestMetric2))CMP(GREATER)CON(160)ACTION(DISABLE_PARTITION)";

    _setupTool.getClusterManagementTool().addAlert(CLUSTER_NAME, alertStr1);
    _setupTool.getClusterManagementTool().addAlert(CLUSTER_NAME, alertStr2);
    _setupTool.getClusterManagementTool().addAlert(CLUSTER_NAME, alertStr3);

    int[] metrics1 = {10, 15, 22, 12, 16};
    int[] metrics2 = {22, 115, 22, 163,16};
    int[] metrics3 = {0, 0, 0, 0, 0};
    setHealthData(metrics1, metrics2);

    String controllerName = CONTROLLER_PREFIX + "_0";
    HelixManager manager = _startCMResultMap.get(controllerName)._manager;

    HealthStatsAggregationTask task = new HealthStatsAggregationTask(_startCMResultMap.get(controllerName)._manager);
    task.run();
    Thread.sleep(4000);
    HelixDataAccessor helixDataAccessor = manager.getHelixDataAccessor();
    Builder keyBuilder = helixDataAccessor.keyBuilder();

    boolean result =
        ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(ZK_ADDR,
                                                                                 CLUSTER_NAME));
    Assert.assertTrue(result);

    Builder kb = manager.getHelixDataAccessor().keyBuilder();
    ExternalView externalView = manager.getHelixDataAccessor().getProperty(kb.externalView("TestDB"));
    // Test the DISABLE_INSTANCE alerts
    String participant1 = "localhost_" + (START_PORT + 3);
    String participant2 = "localhost_" + (START_PORT + 2);
    ConfigAccessor configAccessor = manager.getConfigAccessor();
    // scope = new ConfigScopeBuilder().forCluster(manager.getClusterName()).forParticipant(participant1).build();
    scope = new HelixConfigScopeBuilder(ConfigScopeProperty.PARTICIPANT)
                  .forCluster(manager.getClusterName())
                  .forParticipant(participant1)
                  .build();
    String isEnabled = configAccessor.get(scope, "HELIX_ENABLED");
    Assert.assertFalse(Boolean.parseBoolean(isEnabled));

    // scope = new ConfigScopeBuilder().forCluster(manager.getClusterName()).forParticipant(participant2).build();
    scope = new HelixConfigScopeBuilder(ConfigScopeProperty.PARTICIPANT)
                  .forCluster(manager.getClusterName())
                  .forParticipant(participant2)
                  .build();
    isEnabled = configAccessor.get(scope, "HELIX_ENABLED");
    Assert.assertFalse(Boolean.parseBoolean(isEnabled));

    for(String partitionName : externalView.getRecord().getMapFields().keySet())
    {
      for(String hostName :  externalView.getRecord().getMapField(partitionName).keySet())
      {
        if(hostName.equals(participant1) || hostName.equals(participant2))
        {
          Assert.assertEquals(externalView.getRecord().getMapField(partitionName).get(hostName), "OFFLINE");
        }
      }
    }

    // enable the disabled instances
    setHealthData(metrics3, metrics3);
    task.run();
    Thread.sleep(1000);

    manager.getClusterManagmentTool().enableInstance(manager.getClusterName(), participant2, true);
    manager.getClusterManagmentTool().enableInstance(manager.getClusterName(), participant1, true);

    result =
        ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(ZK_ADDR,
                                                                                 CLUSTER_NAME));
    Assert.assertTrue(result);

    // Test the DISABLE_PARTITION case
    int[] metrics4 = {22, 115, 22, 16,163};
    setHealthData2(metrics4);
    task.run();

    // scope = new ConfigScopeBuilder().forCluster(manager.getClusterName()).forParticipant(participant1).build();
    scope = new HelixConfigScopeBuilder(ConfigScopeProperty.PARTICIPANT)
                .forCluster(manager.getClusterName())
                .forParticipant(participant1)
                .build();
    isEnabled = configAccessor.get(scope, "HELIX_ENABLED");
    Assert.assertTrue(Boolean.parseBoolean(isEnabled));

    // scope = new ConfigScopeBuilder().forCluster(manager.getClusterName()).forParticipant(participant2).build();
    scope = new HelixConfigScopeBuilder(ConfigScopeProperty.PARTICIPANT)
                .forCluster(manager.getClusterName())
                .forParticipant(participant2)
                .build();
    isEnabled = configAccessor.get(scope, "HELIX_ENABLED");
    Assert.assertTrue(Boolean.parseBoolean(isEnabled));
View Full Code Here

   
    _setupTool.getClusterManagementTool().addAlert(CLUSTER_NAME, _alertStr1);
    _setupTool.getClusterManagementTool().addAlert(CLUSTER_NAME, _alertStr2);
   
    // ConfigScope scope = new ConfigScopeBuilder().forCluster(CLUSTER_NAME).build();
    HelixConfigScope scope = new HelixConfigScopeBuilder(ConfigScopeProperty.CLUSTER)
                                        .forCluster(CLUSTER_NAME)
                                        .build();
    Map<String, String> properties = new HashMap<String, String>();
    properties.put("healthChange.enabled", "false");
    _setupTool.getClusterManagementTool().setConfig(scope, properties);
View Full Code Here

TOP

Related Classes of org.apache.helix.model.builder.HelixConfigScopeBuilder

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.