Java Code Examples for org.apache.helix.HelixAdmin#dropResource()
The following examples show how to use
org.apache.helix.HelixAdmin#dropResource() .
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 | 5 votes |
@Test public void testDropResource() { String className = TestHelper.getTestClassName(); String methodName = TestHelper.getTestMethodName(); String clusterName = className + "_" + methodName; System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis())); HelixAdmin tool = new ZKHelixAdmin(_gZkClient); tool.addCluster(clusterName, true); Assert.assertTrue(ZKUtil.isClusterSetup(clusterName, _gZkClient), "Cluster should be setup"); tool.addStateModelDef(clusterName, "MasterSlave", new StateModelDefinition(StateModelConfigGenerator.generateConfigForMasterSlave())); tool.addResource(clusterName, "test-db", 4, "MasterSlave"); Map<String, String> resourceConfig = new HashMap<>(); resourceConfig.put("key1", "value1"); tool.setConfig(new HelixConfigScopeBuilder(ConfigScopeProperty.RESOURCE).forCluster(clusterName) .forResource("test-db").build(), resourceConfig); PropertyKey.Builder keyBuilder = new PropertyKey.Builder(clusterName); Assert.assertTrue(_gZkClient.exists(keyBuilder.idealStates("test-db").getPath()), "test-db ideal-state should exist"); Assert.assertTrue(_gZkClient.exists(keyBuilder.resourceConfig("test-db").getPath()), "test-db resource config should exist"); tool.dropResource(clusterName, "test-db"); Assert.assertFalse(_gZkClient.exists(keyBuilder.idealStates("test-db").getPath()), "test-db ideal-state should be dropped"); Assert.assertFalse(_gZkClient.exists(keyBuilder.resourceConfig("test-db").getPath()), "test-db resource config should be dropped"); tool.dropCluster(clusterName); System.out.println("END " + clusterName + " at " + new Date(System.currentTimeMillis())); }
Example 2
Source File: ResourceAccessor.java From helix with Apache License 2.0 | 5 votes |
@DELETE @Path("{resourceName}") public Response deleteResource(@PathParam("clusterId") String clusterId, @PathParam("resourceName") String resourceName) { HelixAdmin admin = getHelixAdmin(); try { admin.dropResource(clusterId, resourceName); } catch (Exception e) { _logger.error("Error in deleting a resource: " + resourceName, e); return serverError(); } return OK(); }
Example 3
Source File: TestStateModelLeak.java From helix with Apache License 2.0 | 4 votes |
/** * test drop resource should remove all state models * @throws Exception */ @Test public void testDrop() throws Exception { // Logger.getRootLogger().setLevel(Level.INFO); String className = TestHelper.getTestClassName(); String methodName = TestHelper.getTestMethodName(); String clusterName = className + "_" + methodName; int n = 2; System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis())); TestHelper.setupCluster(clusterName, ZK_ADDR, 12918, // participant port "localhost", // participant name prefix "TestDB", // resource name prefix 1, // resources 4, // partitions per resource n, // number of nodes 2, // replicas "MasterSlave", true); // do rebalance // start controller ClusterControllerManager controller = new ClusterControllerManager(ZK_ADDR, clusterName, "controller"); controller.syncStart(); MockParticipantManager[] participants = new MockParticipantManager[n]; for (int i = 0; i < n; i++) { final String instanceName = "localhost_" + (12918 + i); participants[i] = new MockParticipantManager(ZK_ADDR, clusterName, instanceName); participants[i].syncStart(); } boolean result = ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(ZK_ADDR, clusterName)); Assert.assertTrue(result); // check state-models in state-machine HelixStateMachineEngine stateMachine = (HelixStateMachineEngine) participants[0].getStateMachineEngine(); StateModelFactory<? extends StateModel> fty = stateMachine.getStateModelFactory("MasterSlave"); Map<String, String> expectStateModelMap = new TreeMap<String, String>(); expectStateModelMap.put("TestDB0_0", "SLAVE"); expectStateModelMap.put("TestDB0_1", "MASTER"); expectStateModelMap.put("TestDB0_2", "SLAVE"); expectStateModelMap.put("TestDB0_3", "MASTER"); checkStateModelMap(fty, expectStateModelMap); // drop resource HelixAdmin admin = new ZKHelixAdmin(_gZkClient); admin.dropResource(clusterName, "TestDB0"); result = ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(ZK_ADDR, clusterName)); Assert.assertTrue(result); // check state models have been dropped also Assert.assertTrue(fty.getPartitionSet("TestDB0").isEmpty(), "All state-models should be dropped, but was " + fty.getPartitionSet("TestDB0")); // cleanup controller.syncStop(); for (int i = 0; i < n; i++) { participants[i].syncStop(); } TestHelper.dropCluster(clusterName, _gZkClient); System.out.println("END " + clusterName + " at " + new Date(System.currentTimeMillis())); }
Example 4
Source File: TestStateModelLeak.java From helix with Apache License 2.0 | 4 votes |
/** * test drop resource in error state should remove all state-models * @throws Exception */ @Test public void testDropErrorPartition() throws Exception { // Logger.getRootLogger().setLevel(Level.INFO); String className = TestHelper.getTestClassName(); String methodName = TestHelper.getTestMethodName(); String clusterName = className + "_" + methodName; int n = 2; System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis())); TestHelper.setupCluster(clusterName, ZK_ADDR, 12918, // participant port "localhost", // participant name prefix "TestDB", // resource name prefix 1, // resources 4, // partitions per resource n, // number of nodes 2, // replicas "MasterSlave", true); // do rebalance // start controller ClusterControllerManager controller = new ClusterControllerManager(ZK_ADDR, clusterName, "controller"); controller.syncStart(); MockParticipantManager[] participants = new MockParticipantManager[n]; for (int i = 0; i < n; i++) { final String instanceName = "localhost_" + (12918 + i); participants[i] = new MockParticipantManager(ZK_ADDR, clusterName, instanceName); if (i == 0) { Map<String, Set<String>> errTransitionMap = new HashMap<String, Set<String>>(); Set<String> partitions = new HashSet<String>(); partitions.add("TestDB0_0"); errTransitionMap.put("OFFLINE-SLAVE", partitions); participants[0].setTransition(new ErrTransition(errTransitionMap)); } participants[i].syncStart(); } Map<String, Map<String, String>> errStates = new HashMap<String, Map<String, String>>(); errStates.put("TestDB0", new HashMap<String, String>()); errStates.get("TestDB0").put("TestDB0_0", "localhost_12918"); boolean result = ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(ZK_ADDR, clusterName, errStates)); Assert.assertTrue(result); // check state-models in state-machine HelixStateMachineEngine stateMachine = (HelixStateMachineEngine) participants[0].getStateMachineEngine(); StateModelFactory<? extends StateModel> fty = stateMachine.getStateModelFactory("MasterSlave"); Map<String, String> expectStateModelMap = new TreeMap<String, String>(); expectStateModelMap.put("TestDB0_0", "ERROR"); expectStateModelMap.put("TestDB0_1", "MASTER"); expectStateModelMap.put("TestDB0_2", "SLAVE"); expectStateModelMap.put("TestDB0_3", "MASTER"); checkStateModelMap(fty, expectStateModelMap); // drop resource HelixAdmin admin = new ZKHelixAdmin(_gZkClient); admin.dropResource(clusterName, "TestDB0"); result = ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(ZK_ADDR, clusterName)); Assert.assertTrue(result); // check state models have been dropped also Assert.assertTrue(fty.getPartitionSet("TestDB0").isEmpty(), "All state-models should be dropped, but was " + fty.getPartitionSet("TestDB0")); // cleanup controller.syncStop(); for (int i = 0; i < n; i++) { participants[i].syncStop(); } TestHelper.dropCluster(clusterName, _gZkClient); System.out.println("END " + clusterName + " at " + new Date(System.currentTimeMillis())); }
Example 5
Source File: TestDrop.java From helix with Apache License 2.0 | 4 votes |
@Test public void testBasic() throws Exception { String className = TestHelper.getTestClassName(); String methodName = TestHelper.getTestMethodName(); String clusterName = className + "_" + methodName; final int n = 5; System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis())); MockParticipantManager[] participants = new MockParticipantManager[n]; TestHelper.setupCluster(clusterName, ZK_ADDR, 12918, // participant port "localhost", // participant name prefix "TestDB", // resource name prefix 1, // resources 8, // partitions per resource n, // number of nodes 3, // replicas "MasterSlave", true); // do rebalance // start controller ClusterControllerManager controller = new ClusterControllerManager(ZK_ADDR, clusterName, "controller"); controller.syncStart(); // start participants for (int i = 0; i < n; i++) { String instanceName = "localhost_" + (12918 + i); participants[i] = new MockParticipantManager(ZK_ADDR, clusterName, instanceName); participants[i].syncStart(); } ZkHelixClusterVerifier verifier = new BestPossibleExternalViewVerifier.Builder(clusterName).setZkAddr(ZK_ADDR).build(); Assert.assertTrue(verifier.verifyByPolling()); // Drop TestDB0 HelixAdmin admin = new ZKHelixAdmin(_gZkClient); admin.dropResource(clusterName, "TestDB0"); assertEmptyCSandEV(clusterName, "TestDB0", participants); controller.syncStop(); for (int i = 0; i < n; i++) { participants[i].syncStop(); } deleteCluster(clusterName); System.out.println("END " + clusterName + " at " + new Date(System.currentTimeMillis())); }