Java Code Examples for org.apache.helix.tools.ClusterSetup#dropResourceFromCluster()

The following examples show how to use org.apache.helix.tools.ClusterSetup#dropResourceFromCluster() . 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: ResourceGroupResource.java    From helix with Apache License 2.0 6 votes vote down vote up
@Override
public Representation delete() {
  try {
    String clusterName =
        ResourceUtil.getAttributeFromRequest(getRequest(), ResourceUtil.RequestKey.CLUSTER_NAME);
    String resourceName =
        ResourceUtil.getAttributeFromRequest(getRequest(), ResourceUtil.RequestKey.RESOURCE_NAME);
    ZkClient zkclient =
        ResourceUtil.getAttributeFromCtx(getContext(), ResourceUtil.ContextKey.ZKCLIENT);

    ClusterSetup setupTool = new ClusterSetup(zkclient);
    setupTool.dropResourceFromCluster(clusterName, resourceName);
    getResponse().setStatus(Status.SUCCESS_OK);
  } catch (Exception e) {
    getResponse().setEntity(ClusterRepresentationUtil.getErrorAsJsonStringFromException(e),
        MediaType.APPLICATION_JSON);
    getResponse().setStatus(Status.SUCCESS_OK);
    LOG.error("", e);
  }
  return null;
}
 
Example 2
Source File: TestCustomIdealState.java    From helix with Apache License 2.0 5 votes vote down vote up
@Test()
public void testDrop() throws Exception {
  int numResources = 2;
  int numPartitionsPerResource = 50;
  int numInstance = 5;
  int replica = 3;

  String uniqClusterName = "TestCustomIS_" + "rg" + numResources + "_p" + numPartitionsPerResource
      + "_n" + numInstance + "_r" + replica + "_drop";

  System.out.println("START " + uniqClusterName + " at " + new Date(System.currentTimeMillis()));
  TestDriver.setupClusterWithoutRebalance(uniqClusterName, ZK_ADDR, numResources,
      numPartitionsPerResource, numInstance, replica);

  for (int i = 0; i < numInstance; i++) {
    TestDriver.startDummyParticipant(uniqClusterName, i);
  }
  TestDriver.startController(uniqClusterName);
  TestDriver.setIdealState(uniqClusterName, 2000, 50);
  TestDriver.verifyCluster(uniqClusterName, 3000, 50 * 1000);

  // drop resource group
  ClusterSetup setup = new ClusterSetup(ZK_ADDR);
  setup.dropResourceFromCluster(uniqClusterName, "TestDB0");

  TestHelper.verifyWithTimeout("verifyEmptyCurStateAndExtView", 30 * 1000, uniqClusterName,
      "TestDB0", TestHelper.setOf("localhost_12918", "localhost_12919",
          "localhost_12920", "localhost_12921", "localhost_12922"),
      ZK_ADDR);

  TestDriver.stopCluster(uniqClusterName);
  deleteCluster(uniqClusterName);
  System.out.println("STOP " + uniqClusterName + " at " + new Date(System.currentTimeMillis()));
}
 
Example 3
Source File: TestDropResourceMetricsReset.java    From helix with Apache License 2.0 4 votes vote down vote up
@Test
public void testBasic() throws Exception {
  final int NUM_PARTICIPANTS = 4;
  final int NUM_PARTITIONS = 64;
  final int NUM_REPLICAS = 1;
  final String RESOURCE_NAME = "BasicDB0";

  String methodName = TestHelper.getTestMethodName();
  String clusterName = _className + "_" + methodName;

  ParticipantMonitorListener listener =
      new ParticipantMonitorListener("ClusterStatus", clusterName, RESOURCE_NAME);

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

  // Start participants and controller
  ClusterSetup setupTool = new ClusterSetup(_gZkClient);
  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();
  }
  ClusterControllerManager controller =
      new ClusterControllerManager(ZK_ADDR, clusterName, "controller_0");
  controller.syncStart();

  // Verify that the bean was created
  boolean noTimeout = _registerLatch.await(30000, TimeUnit.MILLISECONDS);
  Assert.assertTrue(noTimeout);

  // Drop the resource
  setupTool.dropResourceFromCluster(clusterName, RESOURCE_NAME);

  // Verify that the bean was removed
  noTimeout = _unregisterLatch.await(30000, TimeUnit.MILLISECONDS);
  Assert.assertTrue(noTimeout);

  // Clean up
  listener.disconnect();
  controller.syncStop();
  for (MockParticipantManager participant : participants) {
    participant.syncStop();
  }
  TestHelper.dropCluster(clusterName, _gZkClient);
}
 
Example 4
Source File: TestDropResourceMetricsReset.java    From helix with Apache License 2.0 4 votes vote down vote up
@Test (dependsOnMethods = "testBasic")
public void testDropWithNoCurrentState() throws Exception {
  final int NUM_PARTICIPANTS = 1;
  final int NUM_PARTITIONS = 1;
  final int NUM_REPLICAS = 1;
  final String RESOURCE_NAME = "TestDB0";

  String methodName = TestHelper.getTestMethodName();
  String clusterName = _className + "_" + methodName;

  ParticipantMonitorListener listener =
      new ParticipantMonitorListener("ClusterStatus", clusterName, RESOURCE_NAME);

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

  // Start participants and controller
  ClusterSetup setupTool = new ClusterSetup(_gZkClient);
  MockParticipantManager participant =
      new MockParticipantManager(ZK_ADDR, clusterName, "localhost_12918");
  participant.syncStart();
  ClusterControllerManager controller =
      new ClusterControllerManager(ZK_ADDR, clusterName, "controller_0");
  controller.syncStart();

  // Verify that the bean was created
  boolean noTimeout = _registerLatch.await(30000, TimeUnit.MILLISECONDS);
  Assert.assertTrue(noTimeout);

  // stop the participant, so the resource does not exist in any current states.
  participant.syncStop();

  // Drop the resource
  setupTool.dropResourceFromCluster(clusterName, RESOURCE_NAME);

  // Verify that the bean was removed
  noTimeout = _unregisterLatch.await(30000, TimeUnit.MILLISECONDS);
  Assert.assertTrue(noTimeout);

  // Clean up
  listener.disconnect();
  controller.syncStop();

  TestHelper.dropCluster(clusterName, _gZkClient);
}