use of org.apache.helix.integration.manager.ClusterControllerManager in project helix by apache.
the class ZkStandAloneCMTestBase method beforeClass.
@BeforeClass
public void beforeClass() throws Exception {
// Logger.getRootLogger().setLevel(Level.INFO);
System.out.println("START " + CLASS_NAME + " at " + new Date(System.currentTimeMillis()));
String namespace = "/" + CLUSTER_NAME;
if (_gZkClient.exists(namespace)) {
_gZkClient.deleteRecursively(namespace);
}
_setupTool = new ClusterSetup(ZK_ADDR);
// setup storage cluster
_setupTool.addCluster(CLUSTER_NAME, true);
_setupTool.addResourceToCluster(CLUSTER_NAME, TEST_DB, _PARTITIONS, STATE_MODEL);
for (int i = 0; i < NODE_NR; i++) {
String storageNodeName = PARTICIPANT_PREFIX + "_" + (START_PORT + i);
_setupTool.addInstanceToCluster(CLUSTER_NAME, storageNodeName);
}
_setupTool.rebalanceStorageCluster(CLUSTER_NAME, TEST_DB, _replica);
// start dummy participants
for (int i = 0; i < NODE_NR; i++) {
String instanceName = PARTICIPANT_PREFIX + "_" + (START_PORT + i);
_participants[i] = new MockParticipantManager(ZK_ADDR, CLUSTER_NAME, instanceName);
_participants[i].syncStart();
}
// start controller
String controllerName = CONTROLLER_PREFIX + "_0";
_controller = new ClusterControllerManager(ZK_ADDR, CLUSTER_NAME, controllerName);
_controller.syncStart();
boolean result = ClusterStateVerifier.verifyByZkCallback(new MasterNbInExtViewVerifier(ZK_ADDR, CLUSTER_NAME));
Assert.assertTrue(result);
result = ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(ZK_ADDR, CLUSTER_NAME));
Assert.assertTrue(result);
// create cluster manager
_manager = HelixManagerFactory.getZKHelixManager(CLUSTER_NAME, "Admin", InstanceType.ADMINISTRATOR, ZK_ADDR);
_manager.connect();
}
use of org.apache.helix.integration.manager.ClusterControllerManager in project helix by apache.
the class TestControllerHistory method testControllerLeaderHistory.
@Test()
public void testControllerLeaderHistory() throws Exception {
HelixManager manager = HelixManagerFactory.getZKHelixManager(CLUSTER_NAME, "admin", InstanceType.ADMINISTRATOR, ZK_ADDR);
manager.connect();
PropertyKey.Builder keyBuilder = new PropertyKey.Builder(CLUSTER_NAME);
PropertyKey propertyKey = keyBuilder.controllerLeaderHistory();
LeaderHistory leaderHistory = manager.getHelixDataAccessor().getProperty(propertyKey);
Assert.assertNotNull(leaderHistory);
List<String> list = leaderHistory.getRecord().getListField("HISTORY");
Assert.assertEquals(list.size(), 1);
for (int i = 0; i <= 12; i++) {
_controller.syncStop();
_controller = new ClusterControllerManager(ZK_ADDR, CLUSTER_NAME, "Controller-" + i);
_controller.syncStart();
}
leaderHistory = manager.getHelixDataAccessor().getProperty(propertyKey);
Assert.assertNotNull(leaderHistory);
list = leaderHistory.getRecord().getListField("HISTORY");
Assert.assertEquals(list.size(), 10);
manager.disconnect();
}
use of org.apache.helix.integration.manager.ClusterControllerManager in project helix by apache.
the class TestControllerLiveLock method test.
@Test
public void test() throws Exception {
String className = TestHelper.getTestClassName();
String methodName = TestHelper.getTestMethodName();
String clusterName = className + "_" + methodName;
int n = 12;
final int p = 256;
BaseDataAccessor<ZNRecord> baseAccessor = new ZkBaseDataAccessor<ZNRecord>(_gZkClient);
final HelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, baseAccessor);
final PropertyKey.Builder keyBuilder = accessor.keyBuilder();
System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));
// participant port
TestHelper.setupCluster(// participant port
clusterName, // participant port
ZK_ADDR, // participant port
12918, // participant name prefix
"localhost", // resource name prefix
"TestDB", // resources
1, // partitions per resource
p, // number of nodes
n, // replicas
1, "LeaderStandby", RebalanceMode.FULL_AUTO, // do rebalance
true);
ClusterControllerManager controller = new ClusterControllerManager(ZK_ADDR, clusterName, "controller_0");
controller.syncStart();
// start participants
Random random = new Random();
MockParticipantManager[] participants = new MockParticipantManager[n];
for (int i = 0; i < n; i++) {
String instanceName = "localhost_" + (12918 + i);
participants[i] = new MockParticipantManager(ZK_ADDR, clusterName, instanceName);
participants[i].syncStart();
Thread.sleep(Math.abs(random.nextInt()) % 500 + 500);
}
boolean result = ClusterStateVerifier.verifyByZkCallback(new ClusterStateVerifier.BestPossAndExtViewZkVerifier(ZK_ADDR, clusterName));
Assert.assertTrue(result);
// make sure all partitions are assigned and no partitions is assigned to STANDBY state
result = TestHelper.verify(new TestHelper.Verifier() {
@Override
public boolean verify() throws Exception {
ExternalView extView = accessor.getProperty(keyBuilder.externalView("TestDB0"));
for (int i = 0; i < p; i++) {
String partition = "TestDB0_" + i;
Map<String, String> map = extView.getRecord().getMapField(partition);
if (map == null || map.size() != 1) {
return false;
}
}
return true;
}
}, 10 * 1000);
if (!result) {
ExternalView extView = accessor.getProperty(keyBuilder.externalView("TestDB0"));
for (int i = 0; i < p; i++) {
String partition = "TestDB0_" + i;
Map<String, String> map = extView.getRecord().getMapField(partition);
if (map == null || map.size() != 1) {
LOG.error(partition + ": " + map);
}
}
}
Assert.assertTrue(result);
// clean up
controller.syncStop();
for (int i = 0; i < n; i++) {
participants[i].syncStop();
}
System.out.println("END " + clusterName + " at " + new Date(System.currentTimeMillis()));
}
use of org.apache.helix.integration.manager.ClusterControllerManager in project helix by apache.
the class TestDrop method testDropSchemataResource.
@Test
public void testDropSchemataResource() throws Exception {
// Logger.getRootLogger().setLevel(Level.INFO);
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];
// participant port
TestHelper.setupCluster(// participant port
clusterName, // participant port
ZK_ADDR, // participant port
12918, // participant name prefix
"localhost", // resource name prefix
"TestDB", // resources
1, // partitions per resource
8, // number of nodes
n, // replicas
3, "MasterSlave", // do rebalance
true);
// start controller
ClusterControllerManager controller = new ClusterControllerManager(ZK_ADDR, clusterName, "controller_0");
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();
}
HelixClusterVerifier verifier = new BestPossibleExternalViewVerifier.Builder(clusterName).setZkAddr(ZK_ADDR).build();
Assert.assertTrue(verifier.verify());
// add schemata resource group
String command = "--zkSvr " + ZK_ADDR + " --addResource " + clusterName + " schemata 1 STORAGE_DEFAULT_SM_SCHEMATA";
ClusterSetup.processCommandLineArgs(command.split("\\s+"));
command = "--zkSvr " + ZK_ADDR + " --rebalance " + clusterName + " schemata " + n;
ClusterSetup.processCommandLineArgs(command.split("\\s+"));
Assert.assertTrue(verifier.verify());
// drop schemata resource group
// System.out.println("Dropping schemata resource group...");
command = "--zkSvr " + ZK_ADDR + " --dropResource " + clusterName + " schemata";
ClusterSetup.processCommandLineArgs(command.split("\\s+"));
Assert.assertTrue(verifier.verify());
Thread.sleep(2000);
assertEmptyCSandEV(clusterName, "schemata", participants);
// clean up
controller.syncStop();
for (int i = 0; i < n; i++) {
participants[i].syncStop();
}
System.out.println("END " + clusterName + " at " + new Date(System.currentTimeMillis()));
}
use of org.apache.helix.integration.manager.ClusterControllerManager in project helix by apache.
the class TestDrop method testDropErrorPartitionCustomIS.
@Test
public void testDropErrorPartitionCustomIS() throws Exception {
// Logger.getRootLogger().setLevel(Level.INFO);
String className = TestHelper.getTestClassName();
String methodName = TestHelper.getTestMethodName();
String clusterName = className + "_" + methodName;
final int n = 2;
System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));
MockParticipantManager[] participants = new MockParticipantManager[n];
// participant port
TestHelper.setupCluster(// participant port
clusterName, // participant port
ZK_ADDR, // participant port
12918, // participant name prefix
"localhost", // resource name prefix
"TestDB", // resources
1, // partitions per resource
2, // number of nodes
n, // replicas
2, "MasterSlave", // do rebalance
false);
// set custom ideal-state
CustomModeISBuilder isBuilder = new CustomModeISBuilder("TestDB0");
isBuilder.setNumPartitions(2);
isBuilder.setNumReplica(2);
isBuilder.setStateModel("MasterSlave");
isBuilder.assignInstanceAndState("TestDB0_0", "localhost_12918", "MASTER");
isBuilder.assignInstanceAndState("TestDB0_0", "localhost_12919", "SLAVE");
isBuilder.assignInstanceAndState("TestDB0_1", "localhost_12919", "MASTER");
isBuilder.assignInstanceAndState("TestDB0_1", "localhost_12918", "SLAVE");
HelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(_gZkClient));
PropertyKey.Builder keyBuilder = accessor.keyBuilder();
accessor.setProperty(keyBuilder.idealStates("TestDB0"), isBuilder.build());
// start controller
ClusterControllerManager controller = new ClusterControllerManager(ZK_ADDR, clusterName, "controller_0");
controller.syncStart();
// start participants
Map<String, Set<String>> errTransitions = new HashMap<String, Set<String>>();
errTransitions.put("SLAVE-MASTER", TestHelper.setOf("TestDB0_0"));
for (int i = 0; i < n; i++) {
String instanceName = "localhost_" + (12918 + i);
if (i == 0) {
participants[i] = new MockParticipantManager(ZK_ADDR, clusterName, instanceName);
participants[i].setTransition(new ErrTransition(errTransitions));
} else {
participants[i] = new MockParticipantManager(ZK_ADDR, clusterName, instanceName);
}
participants[i].syncStart();
}
Map<String, Map<String, String>> errStateMap = new HashMap<String, Map<String, String>>();
errStateMap.put("TestDB0", new HashMap<String, String>());
errStateMap.get("TestDB0").put("TestDB0_0", "localhost_12918");
HelixClusterVerifier verifier = new BestPossibleExternalViewVerifier.Builder(clusterName).setZkAddr(ZK_ADDR).setErrStates(errStateMap).build();
Assert.assertTrue(verifier.verify());
// drop resource containing error partitions should drop the partition successfully
ClusterSetup.processCommandLineArgs(new String[] { "--zkSvr", ZK_ADDR, "--dropResource", clusterName, "TestDB0" });
// make sure TestDB0_0 partition is dropped
verifier = new BestPossibleExternalViewVerifier.Builder(clusterName).setZkAddr(ZK_ADDR).build();
Assert.assertTrue(verifier.verify(), "Should be empty exeternal-view");
assertEmptyCSandEV(clusterName, "TestDB0", participants);
// clean up
controller.syncStop();
for (int i = 0; i < n; i++) {
participants[i].syncStop();
}
System.out.println("END " + clusterName + " at " + new Date(System.currentTimeMillis()));
}
Aggregations