Search in sources :

Example 16 with Resource

use of org.apache.helix.model.Resource in project helix by apache.

the class TestResourceValidationStage method testNoSpec.

@Test
public void testNoSpec() throws Exception {
    MockAccessor accessor = new MockAccessor();
    accessor.setProperty(accessor.keyBuilder().clusterConfig(), new ClusterConfig("TestCluster"));
    // create an ideal state and no spec
    String masterSlaveCustomResource = "masterSlaveCustomResource";
    createIS(accessor, masterSlaveCustomResource, "MasterSlave", RebalanceMode.CUSTOMIZED);
    // add some state models
    addStateModels(accessor);
    // refresh the cache
    ClusterEvent event = new ClusterEvent(ClusterEventType.Unknown);
    ClusterDataCache cache = new ClusterDataCache();
    cache.refresh(accessor);
    event.addAttribute(AttributeName.ClusterDataCache.name(), cache);
    // run resource computation
    new ResourceComputationStage().process(event);
    Map<String, Resource> resourceMap = event.getAttribute(AttributeName.RESOURCES.name());
    Assert.assertTrue(resourceMap.containsKey(masterSlaveCustomResource));
    // run resource validation
    new ResourceValidationStage().process(event);
    Map<String, Resource> finalResourceMap = event.getAttribute(AttributeName.RESOURCES.name());
    Assert.assertTrue(finalResourceMap.containsKey(masterSlaveCustomResource));
}
Also used : MockAccessor(org.apache.helix.MockAccessor) Resource(org.apache.helix.model.Resource) ClusterConfig(org.apache.helix.model.ClusterConfig) Test(org.testng.annotations.Test)

Example 17 with Resource

use of org.apache.helix.model.Resource in project helix by apache.

the class BaseStageTest method getResourceMap.

protected Map<String, Resource> getResourceMap(String[] resources, int partitions, String stateModel) {
    Map<String, Resource> resourceMap = new HashMap<String, Resource>();
    for (String r : resources) {
        Resource testResource = new Resource(r);
        testResource.setStateModelDefRef(stateModel);
        for (int i = 0; i < partitions; i++) {
            testResource.addPartition(r + "_" + i);
        }
        resourceMap.put(r, testResource);
    }
    return resourceMap;
}
Also used : HashMap(java.util.HashMap) Resource(org.apache.helix.model.Resource)

Example 18 with Resource

use of org.apache.helix.model.Resource in project helix by apache.

the class TestBestPossibleCalcStageCompatibility method testSemiAutoModeCompatibility.

@Test
public void testSemiAutoModeCompatibility() {
    System.out.println("START TestBestPossibleStateCalcStage at " + new Date(System.currentTimeMillis()));
    String[] resources = new String[] { "testResourceName" };
    setupIdealStateDeprecated(5, resources, 10, 1, IdealStateModeProperty.AUTO);
    setupLiveInstances(5);
    setupStateModel();
    Map<String, Resource> resourceMap = getResourceMap();
    CurrentStateOutput currentStateOutput = new CurrentStateOutput();
    event.addAttribute(AttributeName.RESOURCES.name(), resourceMap);
    event.addAttribute(AttributeName.RESOURCES_TO_REBALANCE.name(), resourceMap);
    event.addAttribute(AttributeName.CURRENT_STATE.name(), currentStateOutput);
    ReadClusterDataStage stage1 = new ReadClusterDataStage();
    runStage(event, stage1);
    BestPossibleStateCalcStage stage2 = new BestPossibleStateCalcStage();
    runStage(event, stage2);
    BestPossibleStateOutput output = event.getAttribute(AttributeName.BEST_POSSIBLE_STATE.name());
    for (int p = 0; p < 5; p++) {
        Partition resource = new Partition("testResourceName_" + p);
        AssertJUnit.assertEquals("MASTER", output.getInstanceStateMap("testResourceName", resource).get("localhost_" + (p + 1) % 5));
    }
    System.out.println("END TestBestPossibleStateCalcStage at " + new Date(System.currentTimeMillis()));
}
Also used : Partition(org.apache.helix.model.Partition) Resource(org.apache.helix.model.Resource) Date(java.util.Date) Test(org.testng.annotations.Test)

Example 19 with Resource

use of org.apache.helix.model.Resource in project helix by apache.

the class TestBestPossibleCalcStageCompatibility method testCustomModeCompatibility.

@Test
public void testCustomModeCompatibility() {
    System.out.println("START TestBestPossibleStateCalcStage at " + new Date(System.currentTimeMillis()));
    String[] resources = new String[] { "testResourceName" };
    setupIdealStateDeprecated(5, resources, 10, 1, IdealStateModeProperty.CUSTOMIZED);
    setupLiveInstances(5);
    setupStateModel();
    Map<String, Resource> resourceMap = getResourceMap();
    CurrentStateOutput currentStateOutput = new CurrentStateOutput();
    event.addAttribute(AttributeName.RESOURCES.name(), resourceMap);
    event.addAttribute(AttributeName.RESOURCES_TO_REBALANCE.name(), resourceMap);
    event.addAttribute(AttributeName.CURRENT_STATE.name(), currentStateOutput);
    ReadClusterDataStage stage1 = new ReadClusterDataStage();
    runStage(event, stage1);
    BestPossibleStateCalcStage stage2 = new BestPossibleStateCalcStage();
    runStage(event, stage2);
    BestPossibleStateOutput output = event.getAttribute(AttributeName.BEST_POSSIBLE_STATE.name());
    for (int p = 0; p < 5; p++) {
        Partition resource = new Partition("testResourceName_" + p);
        AssertJUnit.assertNull(output.getInstanceStateMap("testResourceName", resource).get("localhost_" + (p + 1) % 5));
    }
    System.out.println("END TestBestPossibleStateCalcStage at " + new Date(System.currentTimeMillis()));
}
Also used : Partition(org.apache.helix.model.Partition) Resource(org.apache.helix.model.Resource) Date(java.util.Date) Test(org.testng.annotations.Test)

Example 20 with Resource

use of org.apache.helix.model.Resource in project helix by apache.

the class TestBestPossibleStateCalcStage method testSimple.

@Test
public void testSimple() {
    System.out.println("START TestBestPossibleStateCalcStage at " + new Date(System.currentTimeMillis()));
    // List<IdealState> idealStates = new ArrayList<IdealState>();
    String[] resources = new String[] { "testResourceName" };
    int numPartition = 5;
    int numReplica = 1;
    setupIdealState(5, resources, numPartition, numReplica, RebalanceMode.SEMI_AUTO, BuiltInStateModelDefinitions.MasterSlave.name());
    setupLiveInstances(5);
    setupStateModel();
    Map<String, Resource> resourceMap = getResourceMap(resources, numPartition, BuiltInStateModelDefinitions.MasterSlave.name());
    CurrentStateOutput currentStateOutput = new CurrentStateOutput();
    event.addAttribute(AttributeName.RESOURCES.name(), resourceMap);
    event.addAttribute(AttributeName.RESOURCES_TO_REBALANCE.name(), resourceMap);
    event.addAttribute(AttributeName.CURRENT_STATE.name(), currentStateOutput);
    ReadClusterDataStage stage1 = new ReadClusterDataStage();
    runStage(event, stage1);
    BestPossibleStateCalcStage stage2 = new BestPossibleStateCalcStage();
    runStage(event, stage2);
    BestPossibleStateOutput output = event.getAttribute(AttributeName.BEST_POSSIBLE_STATE.name());
    for (int p = 0; p < 5; p++) {
        Partition resource = new Partition("testResourceName_" + p);
        AssertJUnit.assertEquals("MASTER", output.getInstanceStateMap("testResourceName", resource).get("localhost_" + (p + 1) % 5));
    }
    System.out.println("END TestBestPossibleStateCalcStage at " + new Date(System.currentTimeMillis()));
}
Also used : Partition(org.apache.helix.model.Partition) Resource(org.apache.helix.model.Resource) Date(java.util.Date) Test(org.testng.annotations.Test)

Aggregations

Resource (org.apache.helix.model.Resource)35 Partition (org.apache.helix.model.Partition)16 Test (org.testng.annotations.Test)15 HashMap (java.util.HashMap)9 IdealState (org.apache.helix.model.IdealState)9 Message (org.apache.helix.model.Message)9 ArrayList (java.util.ArrayList)7 StageException (org.apache.helix.controller.pipeline.StageException)7 ClusterConfig (org.apache.helix.model.ClusterConfig)7 Date (java.util.Date)6 LiveInstance (org.apache.helix.model.LiveInstance)6 HelixDataAccessor (org.apache.helix.HelixDataAccessor)5 CurrentState (org.apache.helix.model.CurrentState)5 StateModelDefinition (org.apache.helix.model.StateModelDefinition)5 Map (java.util.Map)4 HelixManager (org.apache.helix.HelixManager)4 ZNRecord (org.apache.helix.ZNRecord)4 ClusterDataCache (org.apache.helix.controller.stages.ClusterDataCache)4 CurrentStateOutput (org.apache.helix.controller.stages.CurrentStateOutput)4 List (java.util.List)3