Search in sources :

Example 6 with RoutingTableProvider

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);
}
Also used : ClusterControllerManager(org.apache.helix.integration.manager.ClusterControllerManager) ZKHelixAdmin(org.apache.helix.manager.zk.ZKHelixAdmin) ArrayList(java.util.ArrayList) ClusterStateVerifier(org.apache.helix.tools.ClusterStateVerifier) IdealState(org.apache.helix.model.IdealState) RoutingTableProvider(org.apache.helix.spectator.RoutingTableProvider) BeforeClass(org.testng.annotations.BeforeClass)

Example 7 with RoutingTableProvider

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());
}
Also used : ClusterControllerManager(org.apache.helix.integration.manager.ClusterControllerManager) MockParticipantManager(org.apache.helix.integration.manager.MockParticipantManager) BestPossibleExternalViewVerifier(org.apache.helix.tools.ClusterVerifiers.BestPossibleExternalViewVerifier) Date(java.util.Date) RoutingTableProvider(org.apache.helix.spectator.RoutingTableProvider) BeforeClass(org.testng.annotations.BeforeClass)

Example 8 with RoutingTableProvider

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);
}
Also used : HelixClusterVerifier(org.apache.helix.tools.ClusterVerifiers.HelixClusterVerifier) RoutingTableProvider(org.apache.helix.spectator.RoutingTableProvider) IdealState(org.apache.helix.model.IdealState) Test(org.testng.annotations.Test)

Example 9 with RoutingTableProvider

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);
}
Also used : RoutingTableProvider(org.apache.helix.spectator.RoutingTableProvider) Test(org.testng.annotations.Test)

Example 10 with RoutingTableProvider

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));
}
Also used : InstanceConfig(org.apache.helix.model.InstanceConfig) Map(java.util.Map) RoutingTableProvider(org.apache.helix.spectator.RoutingTableProvider) ClusterConfig(org.apache.helix.model.ClusterConfig) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Aggregations

RoutingTableProvider (org.apache.helix.spectator.RoutingTableProvider)13 Test (org.testng.annotations.Test)11 ArrayList (java.util.ArrayList)6 ExternalView (org.apache.helix.model.ExternalView)6 InstanceConfig (org.apache.helix.model.InstanceConfig)5 IdealState (org.apache.helix.model.IdealState)3 HashSet (java.util.HashSet)2 ClusterControllerManager (org.apache.helix.integration.manager.ClusterControllerManager)2 HelixClusterVerifier (org.apache.helix.tools.ClusterVerifiers.HelixClusterVerifier)2 BeforeClass (org.testng.annotations.BeforeClass)2 Date (java.util.Date)1 Map (java.util.Map)1 Callable (java.util.concurrent.Callable)1 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1 HelixManager (org.apache.helix.HelixManager)1 MockParticipantManager (org.apache.helix.integration.manager.MockParticipantManager)1 ZKHelixAdmin (org.apache.helix.manager.zk.ZKHelixAdmin)1 ClusterConfig (org.apache.helix.model.ClusterConfig)1 RoutingTableSnapshot (org.apache.helix.spectator.RoutingTableSnapshot)1 ClusterStateVerifier (org.apache.helix.tools.ClusterStateVerifier)1