Package org.apache.helix

Examples of org.apache.helix.ConfigAccessor


  private static Logger logger = Logger.getLogger(ZKHelixAdmin.class);

  public ZKHelixAdmin(ZkClient zkClient) {
    _zkClient = zkClient;
    _configAccessor = new ConfigAccessor(zkClient);
  }
View Full Code Here


  public ZKHelixAdmin(String zkAddress) {
    int timeOutInSec = Integer.parseInt(System.getProperty(CONNECTION_TIMEOUT, "30"));
    _zkClient = new ZkClient(zkAddress, timeOutInSec * 1000);
    _zkClient.setZkSerializer(new ZNRecordSerializer());
    _zkClient.waitUntilConnected(timeOutInSec, TimeUnit.SECONDS);
    _configAccessor = new ConfigAccessor(_zkClient);
  }
View Full Code Here

  }

  void checkResourceConfig(String resourceName, HelixManager manager) {
    if (!_resourceThreadpoolSizeMap.containsKey(resourceName)) {
      int threadpoolSize = -1;
      ConfigAccessor configAccessor = manager.getConfigAccessor();
      if (configAccessor != null) {
        HelixConfigScope scope =
            new HelixConfigScopeBuilder(ConfigScopeProperty.RESOURCE)
                .forCluster(manager.getClusterName()).forResource(resourceName).build();

        String threadpoolSizeStr = configAccessor.get(scope, MAX_THREADS);
        try {
          if (threadpoolSizeStr != null) {
            threadpoolSize = Integer.parseInt(threadpoolSizeStr);
          }
        } catch (Exception e) {
View Full Code Here

                                   new ZNRecordSerializer());

    HelixConfigScope scope = new HelixConfigScopeBuilder(ConfigScopeProperty.CLUSTER)
                                    .forCluster(clusterName)
                                    .build();
    ConfigAccessor configAccessor = new ConfigAccessor(client);
   
    // run foo_test.py during S->M
    String workingDir = ScriptTestHelper.getPrefix() + ScriptTestHelper.INTEGRATION_SCRIPT_DIR;
    String pidFile = ScriptTestHelper.getPrefix() + ScriptTestHelper.INTEGRATION_LOG_DIR + "/default/foo_{PARTITION_NAME}_pid.txt";
   
    // System.out.println("workingDir: " + workingDir);
   
    // the pid file path for the first partition
    // delete it if exists
    String pidFileFirstPartition = ScriptTestHelper.getPrefix() + ScriptTestHelper.INTEGRATION_LOG_DIR + "/default/foo_TestDB0_0_pid.txt";
    File file = new File(pidFileFirstPartition);
    if (file.exists()) {
      file.delete();
    }
   
   
    CommandConfig.Builder builder = new CommandConfig.Builder();
    CommandConfig cmdConfig = builder.setTransition("SLAVE", "MASTER")
                                     .setCommand("dds_driver.py -c foo_test -o start")
                                     .setCommandWorkingDir(workingDir)
                                     .setCommandTimeout("0")
                                     .setPidFile(pidFile)
                                     .build();
    configAccessor.set(scope, cmdConfig.toKeyValueMap());
   
    // nop for O->S, M->S, and S->O
    builder = new CommandConfig.Builder();
    cmdConfig = builder.setTransition("OFFLINE", "SLAVE")
                                     .setCommand(CommandAttribute.NOP.getName())
                                     .build();
    configAccessor.set(scope, cmdConfig.toKeyValueMap());

    builder = new CommandConfig.Builder();
    cmdConfig = builder.setTransition("MASTER", "SLAVE")
                                     .setCommand(CommandAttribute.NOP.getName())
                                     .build();
    configAccessor.set(scope, cmdConfig.toKeyValueMap());
   
    builder = new CommandConfig.Builder();
    cmdConfig = builder.setTransition("SLAVE", "OFFLINE")
                                     .setCommand(CommandAttribute.NOP.getName())
                                     .build();
    configAccessor.set(scope, cmdConfig.toKeyValueMap());
   
    builder = new CommandConfig.Builder();
    cmdConfig = builder.setTransition("OFFLINE", "DROPPED")
                                     .setCommand(CommandAttribute.NOP.getName())
                                     .build();
    configAccessor.set(scope, cmdConfig.toKeyValueMap());


    // start controller
    ClusterController controller =
        new ClusterController(clusterName, "controller_0", zkAddr);
View Full Code Here

  @Transition(to = "ONLINE", from = "OFFLINE")
  public void onBecomeOnlineFromOffline(Message message,
      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();
    String resourceName = message.getResourceName();
    int numPartitions = node.getNumPartitions();
    Task task = _taskFactory.createTask(resourceName, parentIds, manager, _taskResultStore);
View Full Code Here

    Dag dag = Dag.fromJson(dagJson);
    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());
      _admin.addResource(_clusterName, node.getId(),
          node.getNumPartitions(), DEFAULT_STATE_MODEL,
          IdealStateModeProperty.AUTO_REBALANCE.toString());

    }
View Full Code Here

  }

  protected void enableHealthCheck(String clusterName)
  {
    ConfigScope scope = new ConfigScopeBuilder().forCluster(clusterName).build();
    new ConfigAccessor(_gZkClient).set(scope, "healthChange" + ".enabled", "" + true);
  }
View Full Code Here

    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));

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

  public void TestThreadPoolSizeConfig()
  {
    String instanceName = PARTICIPANT_PREFIX + "_" + (START_PORT + 0);
    HelixManager manager = _startCMResultMap.get(instanceName)._manager;
   
    ConfigAccessor accessor = manager.getConfigAccessor();
    ConfigScope scope =
        new ConfigScopeBuilder().forCluster(manager.getClusterName()).forParticipant(instanceName).build();
    accessor.set(scope, "TestMsg."+ HelixTaskExecutor.MAX_THREADS, ""+12);
   
    scope =
        new ConfigScopeBuilder().forCluster(manager.getClusterName()).build();
    accessor.set(scope, "TestMsg."+ HelixTaskExecutor.MAX_THREADS, ""+8);
   
    for (int i = 0; i < NODE_NR; i++)
    {
      instanceName = PARTICIPANT_PREFIX + "_" + (START_PORT + i);
     
View Full Code Here

  @Test
  public void TestThreadPoolSizeConfig()
  {
    String instanceName = PARTICIPANT_PREFIX + "_" + (START_PORT + 0);
    HelixManager manager = _startCMResultMap.get(instanceName)._manager;
    ConfigAccessor accessor = manager.getConfigAccessor();
    ConfigScope scope =
        new ConfigScopeBuilder().forCluster(manager.getClusterName()).forResource("NextDB").build();
    accessor.set(scope, HelixTaskExecutor.MAX_THREADS, ""+12);
   
    _setupTool.addResourceToCluster(CLUSTER_NAME, "NextDB", 64, STATE_MODEL);
    _setupTool.rebalanceStorageCluster(CLUSTER_NAME, "NextDB", 3);
   
    boolean result = ClusterStateVerifier.verifyByPolling(
View Full Code Here

TOP

Related Classes of org.apache.helix.ConfigAccessor

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.