use of org.apache.helix.spectator.RoutingTableProvider in project helix by apache.
the class TestResourceGroupEndtoEnd method beforeClass.
@BeforeClass
public void beforeClass() throws Exception {
_admin = new ZKHelixAdmin(_gZkClient);
// setup storage cluster
_gSetupTool.addCluster(CLUSTER_NAME, true);
List<String> instanceGroupTags = new ArrayList<String>();
for (int i = 0; i < INSTANCE_GROUP_NR; i++) {
String groupTag = "cluster_" + i;
addInstanceGroup(CLUSTER_NAME, groupTag, GROUP_NODE_NR);
instanceGroupTags.add(groupTag);
}
for (String tag : instanceGroupTags) {
List<String> instances = _admin.getInstancesInClusterWithTag(CLUSTER_NAME, tag);
IdealState idealState = createIdealState(TEST_DB, tag, instances, PARTITIONS, _replica, IdealState.RebalanceMode.CUSTOMIZED.toString(), BuiltInStateModelDefinitions.OnlineOffline.name());
_gSetupTool.addResourceToCluster(CLUSTER_NAME, idealState.getResourceName(), idealState);
}
// start dummy participants
int i = 0;
for (String group : instanceGroupTags) {
List<String> instances = _admin.getInstancesInClusterWithTag(CLUSTER_NAME, group);
for (String instance : instances) {
_participants[i] = new TestParticipantManager(ZK_ADDR, CLUSTER_NAME, TEST_DB, group, instance);
_participants[i].syncStart();
i++;
}
}
// start controller
String controllerName = CONTROLLER_PREFIX + "_0";
_controller = new ClusterControllerManager(ZK_ADDR, CLUSTER_NAME, controllerName);
_controller.syncStart();
boolean result = ClusterStateVerifier.verifyByZkCallback(new ClusterStateVerifier.BestPossAndExtViewZkVerifier(ZK_ADDR, CLUSTER_NAME));
Assert.assertTrue(result);
// start speculator
_routingTableProvider = new RoutingTableProvider();
_spectator = HelixManagerFactory.getZKHelixManager(CLUSTER_NAME, "spectator", InstanceType.SPECTATOR, ZK_ADDR);
_spectator.connect();
_spectator.addExternalViewChangeListener(_routingTableProvider);
Thread.sleep(1000);
}
use of org.apache.helix.spectator.RoutingTableProvider in project helix by apache.
the class TestRoutingTableProvider method beforeClass.
@BeforeClass
public void beforeClass() throws Exception {
System.out.println("START " + getShortClassName() + " at " + new Date(System.currentTimeMillis()));
// setup storage cluster
_gSetupTool.addCluster(CLUSTER_NAME, true);
for (int i = 0; i < PARTICIPANT_NUMBER; i++) {
String instance = PARTICIPANT_PREFIX + "_" + (PARTICIPANT_START_PORT + i);
_gSetupTool.addInstanceToCluster(CLUSTER_NAME, instance);
_instances.add(instance);
}
// start dummy participants
for (int i = 0; i < PARTICIPANT_NUMBER; i++) {
MockParticipantManager participant = new MockParticipantManager(ZK_ADDR, CLUSTER_NAME, _instances.get(i));
participant.syncStart();
_participants.add(participant);
}
createDBInSemiAuto(_gSetupTool, CLUSTER_NAME, TEST_DB, _instances, STATE_MODEL, PARTITION_NUMBER, REPLICA_NUMBER);
// start controller
String controllerName = CONTROLLER_PREFIX + "_0";
_controller = new ClusterControllerManager(ZK_ADDR, CLUSTER_NAME, controllerName);
_controller.syncStart();
// start speculator
_routingTableProvider = new RoutingTableProvider();
_spectator = HelixManagerFactory.getZKHelixManager(CLUSTER_NAME, "spectator", InstanceType.SPECTATOR, ZK_ADDR);
_spectator.connect();
_spectator.addExternalViewChangeListener(_routingTableProvider);
_spectator.addLiveInstanceChangeListener(_routingTableProvider);
_spectator.addInstanceConfigChangeListener(_routingTableProvider);
_routingTableProvider2 = new RoutingTableProvider(_spectator);
_clusterVerifier = new BestPossibleExternalViewVerifier.Builder(CLUSTER_NAME).setZkClient(_gZkClient).build();
Assert.assertTrue(_clusterVerifier.verify());
}
use of org.apache.helix.spectator.RoutingTableProvider in project helix by apache.
the class TestRoutingTableProviderFromCurrentStates method testRoutingTableWithCurrentStates.
@Test
public void testRoutingTableWithCurrentStates() throws InterruptedException {
RoutingTableProvider routingTableEV = new RoutingTableProvider(_manager, PropertyType.EXTERNALVIEW);
RoutingTableProvider routingTableCurrentStates = new RoutingTableProvider(_manager, PropertyType.CURRENTSTATES);
String db1 = "TestDB-1";
_setupTool.addResourceToCluster(CLUSTER_NAME, db1, NUM_PARTITIONS, "MasterSlave", IdealState.RebalanceMode.FULL_AUTO.name());
_setupTool.rebalanceStorageCluster(CLUSTER_NAME, db1, NUM_REPLICAS);
Thread.sleep(200);
HelixClusterVerifier clusterVerifier = new BestPossibleExternalViewVerifier.Builder(CLUSTER_NAME).setZkAddr(ZK_ADDR).build();
Assert.assertTrue(clusterVerifier.verify());
IdealState idealState1 = _setupTool.getClusterManagementTool().getResourceIdealState(CLUSTER_NAME, db1);
validate(idealState1, routingTableEV, routingTableCurrentStates);
// add new DB
String db2 = "TestDB-2";
_setupTool.addResourceToCluster(CLUSTER_NAME, db2, NUM_PARTITIONS, "MasterSlave", IdealState.RebalanceMode.FULL_AUTO.name());
_setupTool.rebalanceStorageCluster(CLUSTER_NAME, db2, NUM_REPLICAS);
Thread.sleep(200);
Assert.assertTrue(clusterVerifier.verify());
IdealState idealState2 = _setupTool.getClusterManagementTool().getResourceIdealState(CLUSTER_NAME, db2);
validate(idealState2, routingTableEV, routingTableCurrentStates);
// shutdown an instance
_participants[0].syncStop();
Thread.sleep(200);
Assert.assertTrue(clusterVerifier.verify());
validate(idealState1, routingTableEV, routingTableCurrentStates);
validate(idealState2, routingTableEV, routingTableCurrentStates);
}
use of org.apache.helix.spectator.RoutingTableProvider in project helix by apache.
the class TestRoutingTableProviderFromTargetEV method testExternalViewDoesNotExist.
@Test
public void testExternalViewDoesNotExist() {
String resourceName = WorkflowGenerator.DEFAULT_TGT_DB + 1;
RoutingTableProvider externalViewProvider = new RoutingTableProvider(_manager, PropertyType.EXTERNALVIEW);
Assert.assertEquals(externalViewProvider.getInstancesForResource(resourceName, "SLAVE").size(), 0);
}
use of org.apache.helix.spectator.RoutingTableProvider in project helix by apache.
the class TestRoutingTableProviderFromTargetEV method testExternalViewDiffFromTargetExternalView.
@Test(dependsOnMethods = "testTargetExternalViewWithoutEnable")
public void testExternalViewDiffFromTargetExternalView() throws InterruptedException {
ClusterConfig clusterConfig = _configAccessor.getClusterConfig(CLUSTER_NAME);
clusterConfig.enableTargetExternalView(true);
clusterConfig.setPersistBestPossibleAssignment(true);
_configAccessor.setClusterConfig(CLUSTER_NAME, clusterConfig);
Thread.sleep(2000);
RoutingTableProvider externalViewProvider = new RoutingTableProvider(_manager, PropertyType.EXTERNALVIEW);
RoutingTableProvider targetExternalViewProvider = new RoutingTableProvider(_manager, PropertyType.TARGETEXTERNALVIEW);
// ExternalView should not contain any MASTERS
// TargetExternalView should contain MASTERS same as the partition number
Set<InstanceConfig> externalViewMasters = externalViewProvider.getInstancesForResource(WorkflowGenerator.DEFAULT_TGT_DB, "MASTER");
Assert.assertEquals(externalViewMasters.size(), 0);
Set<InstanceConfig> targetExternalViewMasters = targetExternalViewProvider.getInstancesForResource(WorkflowGenerator.DEFAULT_TGT_DB, "MASTER");
Assert.assertEquals(targetExternalViewMasters.size(), NUM_NODES);
// TargetExternalView MASTERS mapping should exactly match IdealState MASTERS mapping
Map<String, Map<String, String>> stateMap = _setupTool.getClusterManagementTool().getResourceIdealState(CLUSTER_NAME, WorkflowGenerator.DEFAULT_TGT_DB).getRecord().getMapFields();
Set<String> idealMasters = new HashSet<>();
Set<String> targetMasters = new HashSet<>();
for (Map<String, String> instanceMap : stateMap.values()) {
for (String instance : instanceMap.keySet()) {
if (instanceMap.get(instance).equals("MASTER")) {
idealMasters.add(instance);
}
}
}
for (InstanceConfig instanceConfig : targetExternalViewMasters) {
targetMasters.add(instanceConfig.getInstanceName());
}
Assert.assertTrue(idealMasters.equals(targetMasters));
}
Aggregations