Java Code Examples for org.apache.helix.ConfigAccessor#set()

The following examples show how to use org.apache.helix.ConfigAccessor#set() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestResourceThreadpoolSize.java    From helix with Apache License 2.0 5 votes vote down vote up
private void setResourceThreadPoolSize(String resourceName, int threadPoolSize) {
  HelixManager manager = _participants[0];
  ConfigAccessor accessor = manager.getConfigAccessor();
  HelixConfigScope scope =
      new HelixConfigScopeBuilder(HelixConfigScope.ConfigScopeProperty.RESOURCE)
          .forCluster(manager.getClusterName()).forResource(resourceName).build();
  accessor.set(scope, HelixTaskExecutor.MAX_THREADS, "" + threadPoolSize);
}
 
Example 2
Source File: ControllerTest.java    From incubator-pinot with Apache License 2.0 5 votes vote down vote up
protected void startController(ControllerConf config) {
  Preconditions.checkState(_controllerStarter == null);

  _controllerPort = Integer.valueOf(config.getControllerPort());
  _controllerBaseApiUrl = "http://localhost:" + _controllerPort;
  _controllerRequestURLBuilder = ControllerRequestURLBuilder.baseUrl(_controllerBaseApiUrl);
  _controllerDataDir = config.getDataDir();

  _controllerStarter = getControllerStarter(config);
  _controllerStarter.start();
  _helixResourceManager = _controllerStarter.getHelixResourceManager();
  _helixManager = _controllerStarter.getHelixControllerManager();
  _helixDataAccessor = _helixManager.getHelixDataAccessor();
  ConfigAccessor configAccessor = _helixManager.getConfigAccessor();
  // HelixResourceManager is null in Helix only mode, while HelixManager is null in Pinot only mode.
  HelixConfigScope scope =
      new HelixConfigScopeBuilder(HelixConfigScope.ConfigScopeProperty.CLUSTER).forCluster(getHelixClusterName())
          .build();
  switch (_controllerStarter.getControllerMode()) {
    case DUAL:
    case PINOT_ONLY:
      _helixAdmin = _helixResourceManager.getHelixAdmin();
      _propertyStore = _helixResourceManager.getPropertyStore();

      // TODO: Enable periodic rebalance per 10 seconds as a temporary work-around for the Helix issue:
      //       https://github.com/apache/helix/issues/331. Remove this after Helix fixing the issue.
      configAccessor.set(scope, ClusterConfig.ClusterConfigProperty.REBALANCE_TIMER_PERIOD.name(), "10000");
      break;
    case HELIX_ONLY:
      _helixAdmin = _helixManager.getClusterManagmentTool();
      _propertyStore = _helixManager.getHelixPropertyStore();
      break;
  }
  //enable case insensitive pql for test cases.
  configAccessor.set(scope, CommonConstants.Helix.ENABLE_CASE_INSENSITIVE_KEY, Boolean.toString(true));
  //Set hyperloglog log2m value to 12.
  configAccessor.set(scope, CommonConstants.Helix.DEFAULT_HYPERLOGLOG_LOG2M_KEY, Integer.toString(12));
}
 
Example 3
Source File: TestDisableResourceMbean.java    From helix with Apache License 2.0 4 votes vote down vote up
@Test
public void testDisableResourceMonitoring() throws Exception {
  final int NUM_PARTICIPANTS = 2;
  String clusterName = TestHelper.getTestClassName() + "_" + TestHelper.getTestMethodName();
  System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));

  // Set up cluster
  TestHelper.setupCluster(clusterName, ZK_ADDR, 12918, // participant port
      "localhost", // participant name prefix
      "TestDB", // resource name prefix
      3, // resources
      32, // partitions per resource
      4, // number of nodes
      1, // replicas
      "MasterSlave", RebalanceMode.FULL_AUTO, // use FULL_AUTO mode to test node tagging
      true); // do rebalance

  MockParticipantManager[] participants = new MockParticipantManager[NUM_PARTICIPANTS];
  for (int i = 0; i < NUM_PARTICIPANTS; i++) {
    participants[i] =
        new MockParticipantManager(ZK_ADDR, clusterName, "localhost_" + (12918 + i));
    participants[i].syncStart();
  }

  ConfigAccessor configAccessor = new ConfigAccessor(_gZkClient);
  HelixConfigScope resourceScope =
      new HelixConfigScopeBuilder(HelixConfigScope.ConfigScopeProperty.RESOURCE)
          .forCluster(clusterName).forResource("TestDB1").build();
  configAccessor
      .set(resourceScope, ResourceConfig.ResourceConfigProperty.MONITORING_DISABLED.name(),
          "true");

  resourceScope = new HelixConfigScopeBuilder(HelixConfigScope.ConfigScopeProperty.RESOURCE)
      .forCluster(clusterName).forResource("TestDB2").build();
  configAccessor
      .set(resourceScope, ResourceConfig.ResourceConfigProperty.MONITORING_DISABLED.name(),
          "false");

  ClusterControllerManager controller =
      new ClusterControllerManager(ZK_ADDR, clusterName, "controller_0");
  controller.syncStart();

  ZkHelixClusterVerifier clusterVerifier =
      new BestPossibleExternalViewVerifier.Builder(clusterName).setZkClient(_gZkClient).build();
  Assert.assertTrue(clusterVerifier.verifyByPolling());

  // Verify the bean was created for TestDB0, but not for TestDB1.
  pollForMBeanExistance(getMbeanName("TestDB0", clusterName), true);
  pollForMBeanExistance(getMbeanName("TestDB1", clusterName), false);
  pollForMBeanExistance(getMbeanName("TestDB2", clusterName), true);

  controller.syncStop();
  for (MockParticipantManager participant : participants) {
    participant.syncStop();
  }
  TestHelper.dropCluster(clusterName, _gZkClient);
  System.out.println("END " + clusterName + " at " + new Date(System.currentTimeMillis()));
}
 
Example 4
Source File: TestConfigThreadpoolSize.java    From helix with Apache License 2.0 4 votes vote down vote up
@Test
public void TestThreadPoolSizeConfig() {
  String instanceName = PARTICIPANT_PREFIX + "_" + (START_PORT + 0);
  HelixManager manager = _participants[0];

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

    _participants[i].getMessagingService().registerMessageHandlerFactory("TestMsg",
        new TestMessagingHandlerFactory());
    _participants[i].getMessagingService()
        .registerMessageHandlerFactory("TestMsg2", new TestMessagingHandlerFactory2());

  }

  for (int i = 0; i < NODE_NR; i++) {
    instanceName = PARTICIPANT_PREFIX + "_" + (START_PORT + i);

    DefaultMessagingService svc =
        (DefaultMessagingService) (_participants[i]
            .getMessagingService());
    HelixTaskExecutor helixExecutor = svc.getExecutor();
    ThreadPoolExecutor executor =
        (ThreadPoolExecutor) (helixExecutor._executorMap.get("TestMsg"));

    ThreadPoolExecutor executor2 =
        (ThreadPoolExecutor) (helixExecutor._executorMap.get("TestMsg2"));
    if (i != 0) {

      Assert.assertEquals(8, executor.getMaximumPoolSize());
    } else {
      Assert.assertEquals(12, executor.getMaximumPoolSize());
    }
    Assert.assertEquals(HelixTaskExecutor.DEFAULT_PARALLEL_TASKS, executor2.getMaximumPoolSize());
  }
}