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, ClusterConfig clusterConfig, ResourceConfig resourceConfig) {
Map<String, Resource> resourceMap = new HashMap<String, Resource>();
for (String r : resources) {
Resource testResource = new Resource(r, clusterConfig, resourceConfig);
testResource.setStateModelDefRef(stateModel);
for (int i = 0; i < partitions; i++) {
testResource.addPartition(r + "_" + i);
}
resourceMap.put(r, testResource);
}
return resourceMap;
}
use of org.apache.helix.model.Resource in project helix by apache.
the class BaseStageTest method getResourceMap.
protected Map<String, Resource> getResourceMap() {
Map<String, Resource> resourceMap = new HashMap<String, Resource>();
Resource testResource = new Resource("testResourceName");
testResource.setStateModelDefRef("MasterSlave");
testResource.addPartition("testResourceName_0");
testResource.addPartition("testResourceName_1");
testResource.addPartition("testResourceName_2");
testResource.addPartition("testResourceName_3");
testResource.addPartition("testResourceName_4");
resourceMap.put("testResourceName", testResource);
return resourceMap;
}
use of org.apache.helix.model.Resource in project helix by apache.
the class TestResourceComputationStage method testSimple.
/**
* Case where we have one resource in IdealState
* @throws Exception
*/
@Test
public void testSimple() throws Exception {
int nodes = 5;
List<String> instances = new ArrayList<String>();
for (int i = 0; i < nodes; i++) {
instances.add("localhost_" + i);
}
int partitions = 10;
int replicas = 1;
String resourceName = "testResource";
ZNRecord record = DefaultIdealStateCalculator.calculateIdealState(instances, partitions, replicas, resourceName, "MASTER", "SLAVE");
IdealState idealState = new IdealState(record);
idealState.setStateModelDefRef("MasterSlave");
HelixDataAccessor accessor = manager.getHelixDataAccessor();
Builder keyBuilder = accessor.keyBuilder();
accessor.setProperty(keyBuilder.idealStates(resourceName), idealState);
ResourceComputationStage stage = new ResourceComputationStage();
runStage(event, new ReadClusterDataStage());
runStage(event, stage);
Map<String, Resource> resource = event.getAttribute(AttributeName.RESOURCES_TO_REBALANCE.name());
AssertJUnit.assertEquals(1, resource.size());
AssertJUnit.assertEquals(resource.keySet().iterator().next(), resourceName);
AssertJUnit.assertEquals(resource.values().iterator().next().getResourceName(), resourceName);
AssertJUnit.assertEquals(resource.values().iterator().next().getStateModelDefRef(), idealState.getStateModelDefRef());
AssertJUnit.assertEquals(resource.values().iterator().next().getPartitions().size(), partitions);
}
use of org.apache.helix.model.Resource in project helix by apache.
the class TestResourceComputationStage method testMultipleResources.
@Test
public void testMultipleResources() throws Exception {
// List<IdealState> idealStates = new ArrayList<IdealState>();
String[] resources = new String[] { "testResource1", "testResource2" };
List<IdealState> idealStates = setupIdealState(5, resources, 10, 1, RebalanceMode.SEMI_AUTO);
ResourceComputationStage stage = new ResourceComputationStage();
runStage(event, new ReadClusterDataStage());
runStage(event, stage);
Map<String, Resource> resourceMap = event.getAttribute(AttributeName.RESOURCES_TO_REBALANCE.name());
AssertJUnit.assertEquals(resources.length, resourceMap.size());
for (int i = 0; i < resources.length; i++) {
String resourceName = resources[i];
IdealState idealState = idealStates.get(i);
AssertJUnit.assertTrue(resourceMap.containsKey(resourceName));
AssertJUnit.assertEquals(resourceMap.get(resourceName).getResourceName(), resourceName);
AssertJUnit.assertEquals(resourceMap.get(resourceName).getStateModelDefRef(), idealState.getStateModelDefRef());
AssertJUnit.assertEquals(resourceMap.get(resourceName).getPartitions().size(), idealState.getNumPartitions());
}
}
use of org.apache.helix.model.Resource in project helix by apache.
the class TestResourceValidationStage method testMissingStateModel.
@Test
public void testMissingStateModel() throws Exception {
MockAccessor accessor = new MockAccessor();
accessor.setProperty(accessor.keyBuilder().clusterConfig(), new ClusterConfig("TestCluster"));
// create an ideal state and no spec
String masterSlaveCustomResource = "masterSlaveCustomResource";
String leaderStandbyCustomResource = "leaderStandbyCustomResource";
createIS(accessor, masterSlaveCustomResource, "MasterSlave", RebalanceMode.CUSTOMIZED);
createIS(accessor, leaderStandbyCustomResource, "LeaderStandby", RebalanceMode.CUSTOMIZED);
// add some state models (but not leader standby)
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));
Assert.assertTrue(resourceMap.containsKey(leaderStandbyCustomResource));
// run resource validation
new ResourceValidationStage().process(event);
Map<String, Resource> finalResourceMap = event.getAttribute(AttributeName.RESOURCES.name());
Assert.assertTrue(finalResourceMap.containsKey(masterSlaveCustomResource));
Assert.assertFalse(finalResourceMap.containsKey(leaderStandbyCustomResource));
}
Aggregations