use of org.apache.helix.model.LiveInstance in project helix by apache.
the class ZkUnitTestBase method setupLiveInstances.
protected void setupLiveInstances(String clusterName, int[] liveInstances) {
ZKHelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(_gZkClient));
Builder keyBuilder = accessor.keyBuilder();
for (int i = 0; i < liveInstances.length; i++) {
String instance = "localhost_" + liveInstances[i];
LiveInstance liveInstance = new LiveInstance(instance);
liveInstance.setSessionId("session_" + liveInstances[i]);
liveInstance.setHelixVersion("0.0.0");
accessor.setProperty(keyBuilder.liveInstance(instance), liveInstance);
}
}
use of org.apache.helix.model.LiveInstance in project helix by apache.
the class BaseStageTest method setupLiveInstances.
protected List<String> setupLiveInstances(int numLiveInstances) {
List<String> instances = new ArrayList<>();
for (int i = 0; i < numLiveInstances; i++) {
LiveInstance liveInstance = new LiveInstance(HOSTNAME_PREFIX + i);
liveInstance.setSessionId(SESSION_PREFIX + i);
Builder keyBuilder = accessor.keyBuilder();
accessor.setProperty(keyBuilder.liveInstance(HOSTNAME_PREFIX + i), liveInstance);
instances.add(liveInstance.getInstanceName());
}
return instances;
}
use of org.apache.helix.model.LiveInstance in project helix by apache.
the class TestResourceComputationStage method testMultipleResourcesWithSomeDropped.
@Test
public void testMultipleResourcesWithSomeDropped() throws Exception {
int nodes = 5;
List<String> instances = new ArrayList<String>();
for (int i = 0; i < nodes; i++) {
instances.add("localhost_" + i);
}
String[] resources = new String[] { "testResource1", "testResource2" };
List<IdealState> idealStates = new ArrayList<IdealState>();
for (int i = 0; i < resources.length; i++) {
int partitions = 10;
int replicas = 1;
String resourceName = resources[i];
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);
idealStates.add(idealState);
}
// ADD A LIVE INSTANCE WITH A CURRENT STATE THAT CONTAINS RESOURCE WHICH NO
// LONGER EXISTS IN IDEALSTATE
String instanceName = "localhost_" + 3;
LiveInstance liveInstance = new LiveInstance(instanceName);
String sessionId = UUID.randomUUID().toString();
liveInstance.setSessionId(sessionId);
HelixDataAccessor accessor = manager.getHelixDataAccessor();
Builder keyBuilder = accessor.keyBuilder();
accessor.setProperty(keyBuilder.liveInstance(instanceName), liveInstance);
String oldResource = "testResourceOld";
CurrentState currentState = new CurrentState(oldResource);
currentState.setState("testResourceOld_0", "OFFLINE");
currentState.setState("testResourceOld_1", "SLAVE");
currentState.setState("testResourceOld_2", "MASTER");
currentState.setStateModelDefRef("MasterSlave");
accessor.setProperty(keyBuilder.currentState(instanceName, sessionId, oldResource), currentState);
ResourceComputationStage stage = new ResourceComputationStage();
runStage(event, new ReadClusterDataStage());
runStage(event, stage);
Map<String, Resource> resourceMap = event.getAttribute(AttributeName.RESOURCES.name());
// +1 because it will have one for current state
AssertJUnit.assertEquals(resources.length + 1, 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());
}
// Test the data derived from CurrentState
AssertJUnit.assertTrue(resourceMap.containsKey(oldResource));
AssertJUnit.assertEquals(resourceMap.get(oldResource).getResourceName(), oldResource);
AssertJUnit.assertEquals(resourceMap.get(oldResource).getStateModelDefRef(), currentState.getStateModelDefRef());
AssertJUnit.assertEquals(resourceMap.get(oldResource).getPartitions().size(), currentState.getPartitionStateMap().size());
AssertJUnit.assertNotNull(resourceMap.get(oldResource).getPartition("testResourceOld_0"));
AssertJUnit.assertNotNull(resourceMap.get(oldResource).getPartition("testResourceOld_1"));
AssertJUnit.assertNotNull(resourceMap.get(oldResource).getPartition("testResourceOld_2"));
}
use of org.apache.helix.model.LiveInstance in project helix by apache.
the class TestStandAloneCMMain method testStandAloneCMMain.
@Test()
public void testStandAloneCMMain() throws Exception {
logger.info("RUN testStandAloneCMMain() at " + new Date(System.currentTimeMillis()));
ClusterControllerManager newController = null;
for (int i = 1; i <= 2; i++) {
String controllerName = "controller_" + i;
newController = new ClusterControllerManager(ZK_ADDR, CLUSTER_NAME, controllerName);
newController.syncStart();
}
// stopCurrentLeader(_zkClient, CLUSTER_NAME, _startCMResultMap);
_controller.syncStop();
final HelixDataAccessor accessor = new ZKHelixDataAccessor(CLUSTER_NAME, new ZkBaseDataAccessor<ZNRecord>(_gZkClient));
final PropertyKey.Builder keyBuilder = accessor.keyBuilder();
final String newControllerName = newController.getInstanceName();
TestHelper.verify(new Verifier() {
@Override
public boolean verify() throws Exception {
LiveInstance leader = accessor.getProperty(keyBuilder.controllerLeader());
if (leader == null) {
return false;
}
return leader.getInstanceName().equals(newControllerName);
}
}, 30 * 1000);
boolean result = ClusterStateVerifier.verifyByPolling(new ClusterStateVerifier.BestPossAndExtViewZkVerifier(ZK_ADDR, CLUSTER_NAME));
Assert.assertTrue(result);
logger.info("STOP testStandAloneCMMain() at " + new Date(System.currentTimeMillis()));
}
use of org.apache.helix.model.LiveInstance in project helix by apache.
the class ZkIntegrationTestBase method getCurrentLeader.
protected String getCurrentLeader(ZkClient zkClient, String clusterName) {
ZKHelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(zkClient));
Builder keyBuilder = accessor.keyBuilder();
LiveInstance leader = accessor.getProperty(keyBuilder.controllerLeader());
if (leader == null) {
return null;
}
return leader.getInstanceName();
}
Aggregations