Java Code Examples for org.apache.helix.HelixAdmin#enablePartition()

The following examples show how to use org.apache.helix.HelixAdmin#enablePartition() . 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: HelixStateTransitionHandler.java    From helix with Apache License 2.0 5 votes vote down vote up
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);

}
 
Example 2
Source File: TestZkHelixAdmin.java    From helix with Apache License 2.0 5 votes vote down vote up
@Test
public void testEnableDisablePartitions() {
  String className = TestHelper.getTestClassName();
  String methodName = TestHelper.getTestMethodName();
  String clusterName = className + "_" + methodName;
  String instanceName = "TestInstance";
  String testResourcePrefix = "TestResource";
  System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));
  HelixAdmin admin = new ZKHelixAdmin(_gZkClient);
  admin.addCluster(clusterName, true);
  admin.addInstance(clusterName, new InstanceConfig(instanceName));

  // Test disable instances with resources
  admin.enablePartition(false, clusterName, instanceName, testResourcePrefix + "0",
      Arrays.asList("1", "2"));
  admin.enablePartition(false, clusterName, instanceName, testResourcePrefix + "1",
      Arrays.asList("2", "3", "4"));
  InstanceConfig instanceConfig = admin.getInstanceConfig(clusterName, instanceName);
  Assert.assertEquals(instanceConfig.getDisabledPartitions(testResourcePrefix + "0").size(), 2);
  Assert.assertEquals(instanceConfig.getDisabledPartitions(testResourcePrefix + "1").size(), 3);

  // Test disable partition across resources
  // TODO : Remove this part once setInstanceEnabledForPartition(partition, enabled) is removed
  instanceConfig.setInstanceEnabledForPartition("10", false);
  Assert.assertEquals(instanceConfig.getDisabledPartitions(testResourcePrefix + "0").size(), 3);
  Assert.assertEquals(instanceConfig.getDisabledPartitions(testResourcePrefix + "1").size(), 4);
  admin.dropCluster(clusterName);
}