Return-Path: X-Original-To: apmail-helix-commits-archive@minotaur.apache.org Delivered-To: apmail-helix-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id B7117D666 for ; Wed, 21 Nov 2012 21:33:05 +0000 (UTC) Received: (qmail 3280 invoked by uid 500); 21 Nov 2012 21:33:05 -0000 Delivered-To: apmail-helix-commits-archive@helix.apache.org Received: (qmail 3256 invoked by uid 500); 21 Nov 2012 21:33:05 -0000 Mailing-List: contact commits-help@helix.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@helix.incubator.apache.org Delivered-To: mailing list commits@helix.incubator.apache.org Received: (qmail 3248 invoked by uid 99); 21 Nov 2012 21:33:05 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 21 Nov 2012 21:33:05 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 21 Nov 2012 21:33:01 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 57FA82388CA2; Wed, 21 Nov 2012 21:31:37 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1412308 [30/42] - in /incubator/helix/site-content: ./ apidocs/assets/ apidocs/reference/ apidocs/reference/org/apache/helix/ apidocs/reference/org/apache/helix/alerts/ apidocs/reference/org/apache/helix/controller/ apidocs/reference/org/a... Date: Wed, 21 Nov 2012 21:30:26 -0000 To: commits@helix.incubator.apache.org From: olamy@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20121121213137.57FA82388CA2@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Modified: incubator/helix/site-content/xref-test/org/apache/helix/tools/TestHelixAdminScenariosRest.html URL: http://svn.apache.org/viewvc/incubator/helix/site-content/xref-test/org/apache/helix/tools/TestHelixAdminScenariosRest.html?rev=1412308&r1=1412307&r2=1412308&view=diff ============================================================================== --- incubator/helix/site-content/xref-test/org/apache/helix/tools/TestHelixAdminScenariosRest.html (original) +++ incubator/helix/site-content/xref-test/org/apache/helix/tools/TestHelixAdminScenariosRest.html Wed Nov 21 21:29:07 2012 @@ -640,134 +640,143 @@ 630 631 accessor = _startCMResultMap.get("localhost_1232")._manager.getHelixDataAccessor(); 632 LiveInstance leader = accessor.getProperty(accessor.keyBuilder().controllerLeader()); -633 Assert.assertTrue(leader.getInstanceName().startsWith("controller_900")); -634 -635 boolean verifyResult = -636 ClusterStateVerifier.verifyByZkCallback(new MasterNbInExtViewVerifier(ZK_ADDR, -637 "clusterTest1")); -638 Assert.assertTrue(verifyResult); -639 -640 verifyResult = -641 ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(ZK_ADDR, -642 "clusterTest1")); -643 Assert.assertTrue(verifyResult); -644 } -645 -646 private void testRebalanceResource() throws Exception -647 { -648 String resourceUrl = getResourceUrl("clusterTest1", "db_11"); -649 Map<String, String> paraMap = new HashMap<String, String>(); -650 paraMap.put(JsonParameters.REPLICAS, "3"); -651 paraMap.put(JsonParameters.MANAGEMENT_COMMAND, ClusterSetup.rebalance); -652 -653 String ISUrl = resourceUrl + "/idealState"; -654 String response = assertSuccessPostOperation(ISUrl, paraMap, false); -655 ZNRecord record = JsonToObject(ZNRecord.class, response); -656 Assert.assertTrue(record.getId().equalsIgnoreCase("db_11")); -657 Assert.assertTrue((((List<String>) (record.getListFields().values().toArray()[0]))).size() == 3); -658 Assert.assertTrue((((Map<String, String>) (record.getMapFields().values().toArray()[0]))).size() == 3); -659 -660 deleteUrl(resourceUrl, false); +633 for(int i = 0; i < 5; i++) +634 { +635 if(leader != null) +636 { +637 break; +638 } +639 Thread.sleep(1000); +640 leader = accessor.getProperty(accessor.keyBuilder().controllerLeader()); +641 } +642 Assert.assertTrue(leader.getInstanceName().startsWith("controller_900")); +643 +644 boolean verifyResult = +645 ClusterStateVerifier.verifyByZkCallback(new MasterNbInExtViewVerifier(ZK_ADDR, +646 "clusterTest1")); +647 Assert.assertTrue(verifyResult); +648 +649 verifyResult = +650 ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(ZK_ADDR, +651 "clusterTest1")); +652 Assert.assertTrue(verifyResult); +653 } +654 +655 private void testRebalanceResource() throws Exception +656 { +657 String resourceUrl = getResourceUrl("clusterTest1", "db_11"); +658 Map<String, String> paraMap = new HashMap<String, String>(); +659 paraMap.put(JsonParameters.REPLICAS, "3"); +660 paraMap.put(JsonParameters.MANAGEMENT_COMMAND, ClusterSetup.rebalance); 661 -662 // re-add and rebalance -663 String reourcesUrl = -664 "http://localhost:" + ADMIN_PORT + "/clusters/clusterTest1/resourceGroups"; -665 response = getUrl(reourcesUrl); -666 Assert.assertFalse(response.contains("db_11")); -667 -668 paraMap = new HashMap<String, String>(); -669 paraMap.put(JsonParameters.RESOURCE_GROUP_NAME, "db_11"); -670 paraMap.put(JsonParameters.STATE_MODEL_DEF_REF, "MasterSlave"); -671 paraMap.put(JsonParameters.PARTITIONS, "48"); -672 paraMap.put(JsonParameters.MANAGEMENT_COMMAND, ClusterSetup.addResource); -673 -674 response = assertSuccessPostOperation(reourcesUrl, paraMap, false); -675 Assert.assertTrue(response.contains("db_11")); +662 String ISUrl = resourceUrl + "/idealState"; +663 String response = assertSuccessPostOperation(ISUrl, paraMap, false); +664 ZNRecord record = JsonToObject(ZNRecord.class, response); +665 Assert.assertTrue(record.getId().equalsIgnoreCase("db_11")); +666 Assert.assertTrue((((List<String>) (record.getListFields().values().toArray()[0]))).size() == 3); +667 Assert.assertTrue((((Map<String, String>) (record.getMapFields().values().toArray()[0]))).size() == 3); +668 +669 deleteUrl(resourceUrl, false); +670 +671 // re-add and rebalance +672 String reourcesUrl = +673 "http://localhost:" + ADMIN_PORT + "/clusters/clusterTest1/resourceGroups"; +674 response = getUrl(reourcesUrl); +675 Assert.assertFalse(response.contains("db_11")); 676 -677 ISUrl = resourceUrl + "/idealState"; -678 paraMap.put(JsonParameters.REPLICAS, "3"); -679 paraMap.put(JsonParameters.MANAGEMENT_COMMAND, ClusterSetup.rebalance); -680 response = assertSuccessPostOperation(ISUrl, paraMap, false); -681 record = JsonToObject(ZNRecord.class, response); -682 Assert.assertTrue(record.getId().equalsIgnoreCase("db_11")); -683 Assert.assertTrue((((List<String>) (record.getListFields().values().toArray()[0]))).size() == 3); -684 Assert.assertTrue((((Map<String, String>) (record.getMapFields().values().toArray()[0]))).size() == 3); +677 paraMap = new HashMap<String, String>(); +678 paraMap.put(JsonParameters.RESOURCE_GROUP_NAME, "db_11"); +679 paraMap.put(JsonParameters.STATE_MODEL_DEF_REF, "MasterSlave"); +680 paraMap.put(JsonParameters.PARTITIONS, "48"); +681 paraMap.put(JsonParameters.MANAGEMENT_COMMAND, ClusterSetup.addResource); +682 +683 response = assertSuccessPostOperation(reourcesUrl, paraMap, false); +684 Assert.assertTrue(response.contains("db_11")); 685 -686 // rebalance with key prefix -687 resourceUrl = getResourceUrl("clusterTest1", "db_22"); -688 ISUrl = resourceUrl + "/idealState"; -689 paraMap.put(JsonParameters.REPLICAS, "2"); -690 paraMap.put(JsonParameters.RESOURCE_KEY_PREFIX, "alias"); -691 paraMap.put(JsonParameters.MANAGEMENT_COMMAND, ClusterSetup.rebalance); -692 response = assertSuccessPostOperation(ISUrl, paraMap, false); -693 record = JsonToObject(ZNRecord.class, response); -694 Assert.assertTrue(record.getId().equalsIgnoreCase("db_22")); -695 Assert.assertTrue((((List<String>) (record.getListFields().values().toArray()[0]))).size() == 2); -696 Assert.assertTrue((((Map<String, String>) (record.getMapFields().values().toArray()[0]))).size() == 2); -697 Assert.assertTrue((((String) (record.getMapFields().keySet().toArray()[0]))).startsWith("alias_")); -698 } -699 -700 private void testAddInstance() throws Exception -701 { -702 String clusterUrl = getClusterUrl("clusterTest1"); -703 Map<String, String> paraMap = new HashMap<String, String>(); -704 paraMap.put(JsonParameters.MANAGEMENT_COMMAND, ClusterSetup.addInstance); -705 String response = null; -706 // Add instances to cluster -707 String instancesUrl = clusterUrl + "/instances"; -708 for (int i = 0; i < 3; i++) -709 { -710 -711 paraMap.put(JsonParameters.INSTANCE_NAME, "localhost:123" + i); -712 response = assertSuccessPostOperation(instancesUrl, paraMap, false); -713 Assert.assertTrue(response.contains(("localhost:123" + i).replace(':', '_'))); -714 } -715 paraMap.remove(JsonParameters.INSTANCE_NAME); -716 paraMap.put(JsonParameters.INSTANCE_NAMES, -717 "localhost:1233;localhost:1234;localhost:1235;localhost:1236"); -718 -719 response = assertSuccessPostOperation(instancesUrl, paraMap, false); -720 for (int i = 3; i <= 6; i++) -721 { -722 Assert.assertTrue(response.contains("localhost_123" + i)); +686 ISUrl = resourceUrl + "/idealState"; +687 paraMap.put(JsonParameters.REPLICAS, "3"); +688 paraMap.put(JsonParameters.MANAGEMENT_COMMAND, ClusterSetup.rebalance); +689 response = assertSuccessPostOperation(ISUrl, paraMap, false); +690 record = JsonToObject(ZNRecord.class, response); +691 Assert.assertTrue(record.getId().equalsIgnoreCase("db_11")); +692 Assert.assertTrue((((List<String>) (record.getListFields().values().toArray()[0]))).size() == 3); +693 Assert.assertTrue((((Map<String, String>) (record.getMapFields().values().toArray()[0]))).size() == 3); +694 +695 // rebalance with key prefix +696 resourceUrl = getResourceUrl("clusterTest1", "db_22"); +697 ISUrl = resourceUrl + "/idealState"; +698 paraMap.put(JsonParameters.REPLICAS, "2"); +699 paraMap.put(JsonParameters.RESOURCE_KEY_PREFIX, "alias"); +700 paraMap.put(JsonParameters.MANAGEMENT_COMMAND, ClusterSetup.rebalance); +701 response = assertSuccessPostOperation(ISUrl, paraMap, false); +702 record = JsonToObject(ZNRecord.class, response); +703 Assert.assertTrue(record.getId().equalsIgnoreCase("db_22")); +704 Assert.assertTrue((((List<String>) (record.getListFields().values().toArray()[0]))).size() == 2); +705 Assert.assertTrue((((Map<String, String>) (record.getMapFields().values().toArray()[0]))).size() == 2); +706 Assert.assertTrue((((String) (record.getMapFields().keySet().toArray()[0]))).startsWith("alias_")); +707 } +708 +709 private void testAddInstance() throws Exception +710 { +711 String clusterUrl = getClusterUrl("clusterTest1"); +712 Map<String, String> paraMap = new HashMap<String, String>(); +713 paraMap.put(JsonParameters.MANAGEMENT_COMMAND, ClusterSetup.addInstance); +714 String response = null; +715 // Add instances to cluster +716 String instancesUrl = clusterUrl + "/instances"; +717 for (int i = 0; i < 3; i++) +718 { +719 +720 paraMap.put(JsonParameters.INSTANCE_NAME, "localhost:123" + i); +721 response = assertSuccessPostOperation(instancesUrl, paraMap, false); +722 Assert.assertTrue(response.contains(("localhost:123" + i).replace(':', '_'))); 723 } -724 -725 // delete one node without disable -726 String instanceUrl = instancesUrl + "/localhost_1236"; -727 deleteUrl(instanceUrl, true); -728 response = getUrl(instancesUrl); -729 Assert.assertTrue(response.contains("localhost_1236")); -730 -731 // delete non-exist node -732 instanceUrl = instancesUrl + "/localhost_12367"; -733 deleteUrl(instanceUrl, true); -734 response = getUrl(instancesUrl); -735 Assert.assertFalse(response.contains("localhost_12367")); -736 -737 // disable node -738 instanceUrl = instancesUrl + "/localhost_1236"; -739 paraMap.put(JsonParameters.MANAGEMENT_COMMAND, ClusterSetup.enableInstance); -740 paraMap.put(JsonParameters.ENABLED, "false"); -741 response = assertSuccessPostOperation(instanceUrl, paraMap, false); -742 Assert.assertTrue(response.contains("false")); -743 -744 deleteUrl(instanceUrl, false); +724 paraMap.remove(JsonParameters.INSTANCE_NAME); +725 paraMap.put(JsonParameters.INSTANCE_NAMES, +726 "localhost:1233;localhost:1234;localhost:1235;localhost:1236"); +727 +728 response = assertSuccessPostOperation(instancesUrl, paraMap, false); +729 for (int i = 3; i <= 6; i++) +730 { +731 Assert.assertTrue(response.contains("localhost_123" + i)); +732 } +733 +734 // delete one node without disable +735 String instanceUrl = instancesUrl + "/localhost_1236"; +736 deleteUrl(instanceUrl, true); +737 response = getUrl(instancesUrl); +738 Assert.assertTrue(response.contains("localhost_1236")); +739 +740 // delete non-exist node +741 instanceUrl = instancesUrl + "/localhost_12367"; +742 deleteUrl(instanceUrl, true); +743 response = getUrl(instancesUrl); +744 Assert.assertFalse(response.contains("localhost_12367")); 745 -746 // add node to controller cluster -747 paraMap.remove(JsonParameters.INSTANCE_NAME); -748 paraMap.put(JsonParameters.MANAGEMENT_COMMAND, ClusterSetup.addInstance); -749 paraMap.put(JsonParameters.INSTANCE_NAMES, "controller:9000;controller:9001"); -750 String controllerUrl = getClusterUrl("Klazt3rz") + "/instances"; -751 response = assertSuccessPostOperation(controllerUrl, paraMap, false); -752 Assert.assertTrue(response.contains("controller_9000")); -753 Assert.assertTrue(response.contains("controller_9001")); +746 // disable node +747 instanceUrl = instancesUrl + "/localhost_1236"; +748 paraMap.put(JsonParameters.MANAGEMENT_COMMAND, ClusterSetup.enableInstance); +749 paraMap.put(JsonParameters.ENABLED, "false"); +750 response = assertSuccessPostOperation(instanceUrl, paraMap, false); +751 Assert.assertTrue(response.contains("false")); +752 +753 deleteUrl(instanceUrl, false); 754 -755 // add a dup host -756 paraMap.remove(JsonParameters.INSTANCE_NAMES); -757 paraMap.put(JsonParameters.INSTANCE_NAME, "localhost:1234"); -758 response = assertSuccessPostOperation(instancesUrl, paraMap, true); -759 } -760 } +755 // add node to controller cluster +756 paraMap.remove(JsonParameters.INSTANCE_NAME); +757 paraMap.put(JsonParameters.MANAGEMENT_COMMAND, ClusterSetup.addInstance); +758 paraMap.put(JsonParameters.INSTANCE_NAMES, "controller:9000;controller:9001"); +759 String controllerUrl = getClusterUrl("Klazt3rz") + "/instances"; +760 response = assertSuccessPostOperation(controllerUrl, paraMap, false); +761 Assert.assertTrue(response.contains("controller_9000")); +762 Assert.assertTrue(response.contains("controller_9001")); +763 +764 // add a dup host +765 paraMap.remove(JsonParameters.INSTANCE_NAMES); +766 paraMap.put(JsonParameters.INSTANCE_NAME, "localhost:1234"); +767 response = assertSuccessPostOperation(instancesUrl, paraMap, true); +768 } +769 }
Modified: incubator/helix/site-content/xref-test/org/apache/helix/tools/TestResetPartitionState.html URL: http://svn.apache.org/viewvc/incubator/helix/site-content/xref-test/org/apache/helix/tools/TestResetPartitionState.html?rev=1412308&r1=1412307&r2=1412308&view=diff ============================================================================== --- incubator/helix/site-content/xref-test/org/apache/helix/tools/TestResetPartitionState.html (original) +++ incubator/helix/site-content/xref-test/org/apache/helix/tools/TestResetPartitionState.html Wed Nov 21 21:29:07 2012 @@ -33,198 +33,192 @@ 23 import java.util.HashMap; 24 import java.util.Map; 25 import java.util.Set; -26 -27 import org.apache.helix.NotificationContext; -28 import org.apache.helix.TestHelper; -29 import org.apache.helix.ZNRecord; -30 import org.apache.helix.PropertyKey.Builder; -31 import org.apache.helix.manager.zk.ZKHelixDataAccessor; -32 import org.apache.helix.manager.zk.ZkBaseDataAccessor; -33 import org.apache.helix.mock.controller.ClusterController; -34 import org.apache.helix.mock.participant.MockParticipant; -35 import org.apache.helix.mock.participant.MockParticipant.ErrTransition; -36 import org.apache.helix.model.LiveInstance; -37 import org.apache.helix.model.Message; -38 import org.apache.helix.tools.ClusterSetup; -39 import org.apache.helix.tools.ClusterStateVerifier; -40 import org.apache.helix.webapp.resources.JsonParameters; +26 import java.util.concurrent.atomic.AtomicInteger; +27 +28 import org.apache.helix.NotificationContext; +29 import org.apache.helix.PropertyKey.Builder; +30 import org.apache.helix.TestHelper; +31 import org.apache.helix.ZNRecord; +32 import org.apache.helix.manager.zk.ZKHelixDataAccessor; +33 import org.apache.helix.manager.zk.ZkBaseDataAccessor; +34 import org.apache.helix.mock.controller.ClusterController; +35 import org.apache.helix.mock.participant.MockParticipant; +36 import org.apache.helix.mock.participant.MockParticipant.ErrTransition; +37 import org.apache.helix.model.LiveInstance; +38 import org.apache.helix.model.Message; +39 import org.apache.helix.webapp.resources.JsonParameters; +40 import org.apache.log4j.Logger; 41 import org.testng.Assert; 42 import org.testng.annotations.Test; 43 -44 -45 public class TestResetPartitionState extends AdminTestBase -46 { -47 String getClusterUrl(String cluster) -48 { -49 return "http://localhost:" + ADMIN_PORT + "/clusters" + "/" + cluster; -50 } -51 -52 String getInstanceUrl(String cluster, String instance) -53 { -54 return "http://localhost:" + ADMIN_PORT + "/clusters/" + cluster + "/instances/" + instance; -55 } -56 -57 String getResourceUrl(String cluster, String resourceGroup) -58 { -59 return "http://localhost:" + ADMIN_PORT + "/clusters/" + cluster + "/resourceGroups/" + resourceGroup; -60 } -61 -62 int _errToOfflineInvoked = 0; -63 class ErrTransitionWithResetCnt extends ErrTransition -64 { -65 public ErrTransitionWithResetCnt(Map<String, Set<String>> errPartitions) -66 { -67 super(errPartitions); -68 } -69 -70 @Override -71 public void doTransition(Message message, NotificationContext context) -72 { -73 super.doTransition(message, context); -74 String fromState = message.getFromState(); -75 String toState = message.getToState(); -76 if (fromState.equals("ERROR") && toState.equals("OFFLINE")) -77 { -78 // System.err.println("doReset() invoked"); -79 _errToOfflineInvoked++; -80 } -81 } -82 } -83 -84 @Test() -85 public void testResetPartitionState() throws Exception -86 { -87 String className = TestHelper.getTestClassName(); -88 String methodName = TestHelper.getTestMethodName(); -89 String clusterName = className + "_" + methodName; -90 final int n = 5; -91 -92 System.out.println("START " + clusterName + " at " -93 + new Date(System.currentTimeMillis())); -94 -95 TestHelper.setupCluster(clusterName, ZK_ADDR, 12918, // participant port -96 "localhost", // participant name prefix -97 "TestDB", // resource name prefix -98 1, // resources -99 10, // partitions per resource -100 n, // number of nodes -101 3, // replicas -102 "MasterSlave", -103 true); // do rebalance -104 -105 // start admin thread -106 // AdminThread adminThread = new AdminThread(ZK_ADDR, _port); -107 // adminThread.start(); -108 -109 -110 // start controller -111 ClusterController controller = -112 new ClusterController(clusterName, "controller_0", ZK_ADDR); -113 controller.syncStart(); -114 -115 Map<String, Set<String>> errPartitions = new HashMap<String, Set<String>>() -116 { -117 { -118 put("SLAVE-MASTER", TestHelper.setOf("TestDB0_4")); -119 put("OFFLINE-SLAVE", TestHelper.setOf("TestDB0_8")); -120 } -121 }; -122 -123 // start mock participants -124 MockParticipant[] participants = new MockParticipant[n]; -125 for (int i = 0; i < n; i++) -126 { -127 String instanceName = "localhost_" + (12918 + i); -128 -129 if (i == 0) -130 { -131 participants[i] = -132 new MockParticipant(clusterName, -133 instanceName, -134 ZK_ADDR, -135 new ErrTransition(errPartitions)); -136 } -137 else -138 { -139 participants[i] = new MockParticipant(clusterName, instanceName, ZK_ADDR); -140 } -141 participants[i].syncStart(); -142 } -143 -144 // verify cluster -145 Map<String, Map<String, String>> errStateMap = -146 new HashMap<String, Map<String, String>>(); -147 errStateMap.put("TestDB0", new HashMap<String, String>()); -148 errStateMap.get("TestDB0").put("TestDB0_4", "localhost_12918"); -149 errStateMap.get("TestDB0").put("TestDB0_8", "localhost_12918"); -150 boolean result = -151 ClusterStateVerifier.verifyByZkCallback((new ClusterStateVerifier.BestPossAndExtViewZkVerifier(ZK_ADDR, -152 clusterName, -153 errStateMap))); -154 Assert.assertTrue(result, "Cluster verification fails"); -155 -156 -157 // reset a non-exist partition, should throw exception -158 String hostName = "localhost_12918"; -159 String instanceUrl = getInstanceUrl(clusterName, hostName); -160 -161 Map<String, String> paramMap = new HashMap<String, String>(); -162 paramMap.put(JsonParameters.MANAGEMENT_COMMAND, ClusterSetup.resetPartition); -163 paramMap.put(JsonParameters.PARTITION, "TestDB0_nonExist"); -164 paramMap.put(JsonParameters.RESOURCE, "TestDB0"); -165 System.out.println("IGNORABLE exception: test reset non-exist partition"); -166 TestHelixAdminScenariosRest.assertSuccessPostOperation(instanceUrl, paramMap, true); -167 -168 -169 // reset one error partition -170 errPartitions.clear(); // remove("SLAVE-MASTER"); -171 participants[0].setTransition(new ErrTransitionWithResetCnt(errPartitions)); -172 clearStatusUpdate(clusterName, "localhost_12918", "TestDB0", "TestDB0_4"); -173 _errToOfflineInvoked = 0; -174 -175 paramMap.put(JsonParameters.PARTITION, "TestDB0_4 TestDB0_8"); -176 TestHelixAdminScenariosRest.assertSuccessPostOperation(instanceUrl, paramMap, false); -177 -178 Thread.sleep(400); // wait reset to be done -179 System.out.println("IGNORABLE exception: test reset non-error partition"); -180 TestHelixAdminScenariosRest.assertSuccessPostOperation(instanceUrl, paramMap, true); -181 -182 result = -183 ClusterStateVerifier.verifyByZkCallback(new ClusterStateVerifier.BestPossAndExtViewZkVerifier(ZK_ADDR, -184 clusterName)); -185 Assert.assertTrue(result); -186 Assert.assertEquals(_errToOfflineInvoked, 2, "reset() should be invoked 2 times"); -187 -188 -189 // clean up -190 // wait for all zk callbacks done -191 Thread.sleep(1000); -192 // adminThread.stop(); -193 controller.syncStop(); -194 for (int i = 0; i < 5; i++) -195 { -196 participants[i].syncStop(); -197 } -198 -199 System.out.println("END " + clusterName + " at " -200 + new Date(System.currentTimeMillis())); -201 } +44 public class TestResetPartitionState extends AdminTestBase { +45 private final static Logger LOG = Logger +46 .getLogger(TestResetPartitionState.class); +47 +48 String getClusterUrl(String cluster) { +49 return "http://localhost:" + ADMIN_PORT + "/clusters" + "/" + cluster; +50 } +51 +52 String getInstanceUrl(String cluster, String instance) { +53 return "http://localhost:" + ADMIN_PORT + "/clusters/" + cluster +54 + "/instances/" + instance; +55 } +56 +57 String getResourceUrl(String cluster, String resourceGroup) { +58 return "http://localhost:" + ADMIN_PORT + "/clusters/" + cluster +59 + "/resourceGroups/" + resourceGroup; +60 } +61 +62 AtomicInteger _errToOfflineInvoked = new AtomicInteger(0); +63 +64 class ErrTransitionWithResetCnt extends ErrTransition { +65 public ErrTransitionWithResetCnt(Map<String, Set<String>> errPartitions) { +66 super(errPartitions); +67 } +68 +69 @Override +70 public void doTransition(Message message, NotificationContext context) { +71 super.doTransition(message, context); +72 String fromState = message.getFromState(); +73 String toState = message.getToState(); +74 if (fromState.equals("ERROR") && toState.equals("OFFLINE")) { +75 // System.err.println("doReset() invoked"); +76 _errToOfflineInvoked.incrementAndGet(); +77 } +78 } +79 } +80 +81 @Test() +82 public void testResetPartitionState() throws Exception { +83 String className = TestHelper.getTestClassName(); +84 String methodName = TestHelper.getTestMethodName(); +85 String clusterName = className + "_" + methodName; +86 final int n = 5; +87 +88 System.out.println("START " + clusterName + " at " +89 + new Date(System.currentTimeMillis())); +90 +91 TestHelper.setupCluster(clusterName, ZK_ADDR, 12918, // participant port +92 "localhost", // participant name prefix +93 "TestDB", // resource name prefix +94 1, // resources +95 10, // partitions per resource +96 n, // number of nodes +97 3, // replicas +98 "MasterSlave", true); // do rebalance +99 +100 // start admin thread +101 // AdminThread adminThread = new AdminThread(ZK_ADDR, _port); +102 // adminThread.start(); +103 +104 // start controller +105 ClusterController controller = new ClusterController(clusterName, +106 "controller_0", ZK_ADDR); +107 controller.syncStart(); +108 +109 Map<String, Set<String>> errPartitions = new HashMap<String, Set<String>>(); +110 errPartitions.put("SLAVE-MASTER", TestHelper.setOf("TestDB0_4")); +111 errPartitions.put("OFFLINE-SLAVE", TestHelper.setOf("TestDB0_8")); +112 +113 // start mock participants +114 MockParticipant[] participants = new MockParticipant[n]; +115 for (int i = 0; i < n; i++) { +116 String instanceName = "localhost_" + (12918 + i); +117 +118 if (i == 0) { +119 participants[i] = new MockParticipant(clusterName, +120 instanceName, ZK_ADDR, new ErrTransition(errPartitions)); +121 } else { +122 participants[i] = new MockParticipant(clusterName, +123 instanceName, ZK_ADDR); +124 } +125 participants[i].syncStart(); +126 } +127 +128 // verify cluster +129 Map<String, Map<String, String>> errStateMap = new HashMap<String, Map<String, String>>(); +130 errStateMap.put("TestDB0", new HashMap<String, String>()); +131 errStateMap.get("TestDB0").put("TestDB0_4", "localhost_12918"); +132 errStateMap.get("TestDB0").put("TestDB0_8", "localhost_12918"); +133 boolean result = ClusterStateVerifier +134 .verifyByZkCallback((new ClusterStateVerifier.BestPossAndExtViewZkVerifier( +135 ZK_ADDR, clusterName, errStateMap))); +136 Assert.assertTrue(result, "Cluster verification fails"); +137 +138 // reset a non-exist partition, should throw exception +139 String hostName = "localhost_12918"; +140 String instanceUrl = getInstanceUrl(clusterName, hostName); +141 +142 Map<String, String> paramMap = new HashMap<String, String>(); +143 paramMap.put(JsonParameters.MANAGEMENT_COMMAND, +144 ClusterSetup.resetPartition); +145 paramMap.put(JsonParameters.PARTITION, "TestDB0_nonExist"); +146 paramMap.put(JsonParameters.RESOURCE, "TestDB0"); +147 LOG.info("IGNORABLE exception: test reset non-exist partition"); +148 TestHelixAdminScenariosRest.assertSuccessPostOperation(instanceUrl, +149 paramMap, true); +150 +151 // reset 2 error partitions +152 errPartitions.clear(); +153 participants[0].setTransition(new ErrTransitionWithResetCnt( +154 errPartitions)); +155 clearStatusUpdate(clusterName, "localhost_12918", "TestDB0", +156 "TestDB0_4"); +157 _errToOfflineInvoked.set(0); +158 +159 paramMap.put(JsonParameters.PARTITION, "TestDB0_4 TestDB0_8"); +160 TestHelixAdminScenariosRest.assertSuccessPostOperation(instanceUrl, +161 paramMap, false); +162 +163 for (int i = 0; i < 10; i++) { +164 Thread.sleep(400); // wait reset to be done +165 LOG.info("IGNORABLE exception: test reset non-error partition"); +166 TestHelixAdminScenariosRest.assertSuccessPostOperation(instanceUrl, +167 paramMap, true); +168 +169 result = ClusterStateVerifier +170 .verifyByZkCallback(new ClusterStateVerifier.BestPossAndExtViewZkVerifier( +171 ZK_ADDR, clusterName)); +172 if (result == true) { +173 break; +174 } +175 } +176 +177 Assert.assertTrue(result); +178 Assert.assertEquals(_errToOfflineInvoked.get(), 2, +179 "reset() should be invoked 2 times"); +180 +181 // clean up +182 // wait for all zk callbacks done +183 Thread.sleep(1000); +184 // adminThread.stop(); +185 controller.syncStop(); +186 for (int i = 0; i < 5; i++) { +187 participants[i].syncStop(); +188 } +189 +190 System.out.println("END " + clusterName + " at " +191 + new Date(System.currentTimeMillis())); +192 } +193 +194 private void clearStatusUpdate(String clusterName, String instance, +195 String resource, String partition) { +196 // clear status update for error partition so verify() will not fail on +197 // old +198 // errors +199 ZKHelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, +200 new ZkBaseDataAccessor<ZNRecord>(_gZkClient)); +201 Builder keyBuilder = accessor.keyBuilder(); 202 -203 private void clearStatusUpdate(String clusterName, String instance, String resource, -204 String partition) -205 { -206 // clear status update for error partition so verify() will not fail on old -207 // errors -208 ZKHelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(_gZkClient)); -209 Builder keyBuilder = accessor.keyBuilder(); -210 -211 LiveInstance liveInstance = accessor.getProperty(keyBuilder.liveInstance(instance)); -212 accessor.removeProperty(keyBuilder.stateTransitionStatus(instance, liveInstance.getSessionId(), resource, partition)); -213 -214 } -215 -216 // TODO: throw exception in reset() -217 } +203 LiveInstance liveInstance = accessor.getProperty(keyBuilder +204 .liveInstance(instance)); +205 accessor.removeProperty(keyBuilder.stateTransitionStatus(instance, +206 liveInstance.getSessionId(), resource, partition)); +207 +208 } +209 +210 // TODO: throw exception in reset() +211 }
Modified: incubator/helix/site-content/xref-test/org/apache/helix/tools/package-frame.html URL: http://svn.apache.org/viewvc/incubator/helix/site-content/xref-test/org/apache/helix/tools/package-frame.html?rev=1412308&r1=1412307&r2=1412308&view=diff ============================================================================== --- incubator/helix/site-content/xref-test/org/apache/helix/tools/package-frame.html (original) +++ incubator/helix/site-content/xref-test/org/apache/helix/tools/package-frame.html Wed Nov 21 21:29:07 2012 @@ -3,7 +3,7 @@ - Helix 0.6-incubating-SNAPSHOT Reference Package org.apache.helix.tools + Apache Helix 0.6-incubating-SNAPSHOT Reference Package org.apache.helix.tools Modified: incubator/helix/site-content/xref-test/org/apache/helix/tools/package-summary.html URL: http://svn.apache.org/viewvc/incubator/helix/site-content/xref-test/org/apache/helix/tools/package-summary.html?rev=1412308&r1=1412307&r2=1412308&view=diff ============================================================================== --- incubator/helix/site-content/xref-test/org/apache/helix/tools/package-summary.html (original) +++ incubator/helix/site-content/xref-test/org/apache/helix/tools/package-summary.html Wed Nov 21 21:29:07 2012 @@ -3,7 +3,7 @@ - Helix 0.6-incubating-SNAPSHOT Reference Package org.apache.helix.tools + Apache Helix 0.6-incubating-SNAPSHOT Reference Package org.apache.helix.tools Modified: incubator/helix/site-content/xref-test/org/apache/helix/util/package-frame.html URL: http://svn.apache.org/viewvc/incubator/helix/site-content/xref-test/org/apache/helix/util/package-frame.html?rev=1412308&r1=1412307&r2=1412308&view=diff ============================================================================== --- incubator/helix/site-content/xref-test/org/apache/helix/util/package-frame.html (original) +++ incubator/helix/site-content/xref-test/org/apache/helix/util/package-frame.html Wed Nov 21 21:29:07 2012 @@ -3,7 +3,7 @@ - Helix 0.6-incubating-SNAPSHOT Reference Package org.apache.helix.util + Apache Helix 0.6-incubating-SNAPSHOT Reference Package org.apache.helix.util Modified: incubator/helix/site-content/xref-test/org/apache/helix/util/package-summary.html URL: http://svn.apache.org/viewvc/incubator/helix/site-content/xref-test/org/apache/helix/util/package-summary.html?rev=1412308&r1=1412307&r2=1412308&view=diff ============================================================================== --- incubator/helix/site-content/xref-test/org/apache/helix/util/package-summary.html (original) +++ incubator/helix/site-content/xref-test/org/apache/helix/util/package-summary.html Wed Nov 21 21:29:07 2012 @@ -3,7 +3,7 @@ - Helix 0.6-incubating-SNAPSHOT Reference Package org.apache.helix.util + Apache Helix 0.6-incubating-SNAPSHOT Reference Package org.apache.helix.util Modified: incubator/helix/site-content/xref-test/org/apache/helix/webapp/package-frame.html URL: http://svn.apache.org/viewvc/incubator/helix/site-content/xref-test/org/apache/helix/webapp/package-frame.html?rev=1412308&r1=1412307&r2=1412308&view=diff ============================================================================== --- incubator/helix/site-content/xref-test/org/apache/helix/webapp/package-frame.html (original) +++ incubator/helix/site-content/xref-test/org/apache/helix/webapp/package-frame.html Wed Nov 21 21:29:07 2012 @@ -3,7 +3,7 @@ - Helix 0.6-incubating-SNAPSHOT Reference Package org.apache.helix.webapp + Apache Helix 0.6-incubating-SNAPSHOT Reference Package org.apache.helix.webapp Modified: incubator/helix/site-content/xref-test/org/apache/helix/webapp/package-summary.html URL: http://svn.apache.org/viewvc/incubator/helix/site-content/xref-test/org/apache/helix/webapp/package-summary.html?rev=1412308&r1=1412307&r2=1412308&view=diff ============================================================================== --- incubator/helix/site-content/xref-test/org/apache/helix/webapp/package-summary.html (original) +++ incubator/helix/site-content/xref-test/org/apache/helix/webapp/package-summary.html Wed Nov 21 21:29:07 2012 @@ -3,7 +3,7 @@ - Helix 0.6-incubating-SNAPSHOT Reference Package org.apache.helix.webapp + Apache Helix 0.6-incubating-SNAPSHOT Reference Package org.apache.helix.webapp Modified: incubator/helix/site-content/xref-test/overview-frame.html URL: http://svn.apache.org/viewvc/incubator/helix/site-content/xref-test/overview-frame.html?rev=1412308&r1=1412307&r2=1412308&view=diff ============================================================================== --- incubator/helix/site-content/xref-test/overview-frame.html (original) +++ incubator/helix/site-content/xref-test/overview-frame.html Wed Nov 21 21:29:07 2012 @@ -3,7 +3,7 @@ - Helix 0.6-incubating-SNAPSHOT Reference + Apache Helix 0.6-incubating-SNAPSHOT Reference Modified: incubator/helix/site-content/xref-test/overview-summary.html URL: http://svn.apache.org/viewvc/incubator/helix/site-content/xref-test/overview-summary.html?rev=1412308&r1=1412307&r2=1412308&view=diff ============================================================================== --- incubator/helix/site-content/xref-test/overview-summary.html (original) +++ incubator/helix/site-content/xref-test/overview-summary.html Wed Nov 21 21:29:07 2012 @@ -3,7 +3,7 @@ - Helix 0.6-incubating-SNAPSHOT Reference + Apache Helix 0.6-incubating-SNAPSHOT Reference @@ -24,7 +24,7 @@ -

Helix 0.6-incubating-SNAPSHOT Reference

+

Apache Helix 0.6-incubating-SNAPSHOT Reference