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

The following examples show how to use org.apache.helix.HelixAdmin#enableResource() . 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: TestZkHelixAdmin.java    From helix with Apache License 2.0 6 votes vote down vote up
@Test
public void testDisableResource() {
  String className = TestHelper.getTestClassName();
  String methodName = TestHelper.getTestMethodName();
  String clusterName = className + "_" + methodName;
  System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));
  HelixAdmin admin = new ZKHelixAdmin(_gZkClient);
  admin.addCluster(clusterName, true);
  Assert.assertTrue(ZKUtil.isClusterSetup(clusterName, _gZkClient), "Cluster should be setup");
  String resourceName = "TestDB";
  admin.addStateModelDef(clusterName, "MasterSlave",
      new StateModelDefinition(StateModelConfigGenerator.generateConfigForMasterSlave()));
  admin.addResource(clusterName, resourceName, 4, "MasterSlave");
  admin.enableResource(clusterName, resourceName, false);
  BaseDataAccessor<ZNRecord> baseAccessor = new ZkBaseDataAccessor<>(_gZkClient);
  HelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, baseAccessor);
  PropertyKey.Builder keyBuilder = accessor.keyBuilder();
  IdealState idealState = accessor.getProperty(keyBuilder.idealStates(resourceName));
  Assert.assertFalse(idealState.isEnabled());
  admin.enableResource(clusterName, resourceName, true);
  idealState = accessor.getProperty(keyBuilder.idealStates(resourceName));
  Assert.assertTrue(idealState.isEnabled());

  admin.dropCluster(clusterName);
  System.out.println("END " + clusterName + " at " + new Date(System.currentTimeMillis()));
}
 
Example 2
Source File: TestBucketizedResource.java    From helix with Apache License 2.0 4 votes vote down vote up
@Test
public void testBounceDisableAndDrop() throws Exception {
  String className = TestHelper.getTestClassName();
  String methodName = TestHelper.getTestMethodName();
  String clusterName = className + "_" + methodName;
  String dbName = "TestDB0";
  List<String> instanceNames =
      Arrays.asList("localhost_0", "localhost_1", "localhost_2", "localhost_3", "localhost_4");
  int n = instanceNames.size();

  ZKHelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, _baseAccessor);
  PropertyKey.Builder keyBuilder = accessor.keyBuilder();

  setupCluster(clusterName, instanceNames, dbName, 3, 10, 2);

  // start controller
  ClusterControllerManager controller = new ClusterControllerManager(ZK_ADDR, clusterName);
  controller.syncStart();

  // start participants
  MockParticipantManager[] participants = new MockParticipantManager[n];
  for (int i = 0; i < n; i++) {
    participants[i] = new MockParticipantManager(ZK_ADDR, clusterName, instanceNames.get(i));
    participants[i].syncStart();
  }

  ZkHelixClusterVerifier _clusterVerifier =
      new BestPossibleExternalViewVerifier.Builder(clusterName).setZkAddr(ZK_ADDR).build();
  Assert.assertTrue(_clusterVerifier.verifyByPolling());

  // bounce
  participants[0].syncStop();
  participants[0] = new MockParticipantManager(ZK_ADDR, clusterName, instanceNames.get(0));
  participants[0].syncStart();

  Assert.assertTrue(_clusterVerifier.verifyByPolling());

  // make sure participants[0]'s current state is bucketzied correctly during carryover
  String path =
      keyBuilder.currentState(instanceNames.get(0), participants[0].getSessionId(), dbName)
          .getPath();
  ZNRecord record = _baseAccessor.get(path, null, 0);
  Assert.assertTrue(record.getMapFields().size() == 0);

  // disable the bucketize resource
  HelixAdmin admin = new ZKHelixAdmin(_gZkClient);
  admin.enableResource(clusterName, dbName, false);

  Assert.assertTrue(_clusterVerifier.verifyByPolling());

  // drop the bucketize resource
  _gSetupTool.dropResourceFromCluster(clusterName, dbName);

  Assert.assertTrue(_clusterVerifier.verifyByPolling());

  // make sure external-view is cleaned up
  final String evPath = keyBuilder.externalView(dbName).getPath();

  TestHelper.verify(new TestHelper.Verifier() {
      @Override
      public boolean verify() {
        return !_baseAccessor.exists(evPath, 0);
      }
    }, 3000);

  boolean result = _baseAccessor.exists(evPath, 0);
  Assert.assertFalse(result);

  // clean up
  controller.syncStop();
  for (MockParticipantManager participant : participants) {
    participant.syncStop();
  }
  deleteCluster(clusterName);
}
 
Example 3
Source File: TestDisableResource.java    From helix with Apache License 2.0 4 votes vote down vote up
private void enableResource(String clusterName, boolean enabled) {
  HelixAdmin admin = new ZKHelixAdmin(_gZkClient);
  admin.enableResource(clusterName, "TestDB0", enabled);
}
 
Example 4
Source File: HelixVcrPopulateTool.java    From ambry with Apache License 2.0 2 votes vote down vote up
/**
 * Enable or disable a resource in dest cluster.
 * @param destZkString the cluster's zk string
 * @param destClusterName the cluster's name
 * @param resourceName the resource to enable/disable
 * @param enable enable the resource if true
 */
static void controlResource(String destZkString, String destClusterName, String resourceName, boolean enable) {
  HelixZkClient destZkClient = getHelixZkClient(destZkString);
  HelixAdmin destAdmin = new ZKHelixAdmin(destZkClient);
  destAdmin.enableResource(destClusterName, resourceName, enable);
}