use of org.apache.helix.HelixDataAccessor in project helix by apache.
the class GenericHelixController method onControllerChange.
@Override
public void onControllerChange(NotificationContext changeContext) {
logger.info("START: GenericClusterController.onControllerChange() for cluster " + _clusterName);
_cache.requireFullRefresh();
_taskCache.requireFullRefresh();
boolean controllerIsLeader;
if (changeContext != null && changeContext.getType() == Type.FINALIZE) {
logger.info("GenericClusterController.onControllerChange() FINALIZE for cluster " + _clusterName);
controllerIsLeader = false;
} else {
// double check if this controller is the leader
controllerIsLeader = changeContext.getManager().isLeader();
}
HelixManager manager = changeContext.getManager();
if (controllerIsLeader) {
HelixDataAccessor accessor = manager.getHelixDataAccessor();
Builder keyBuilder = accessor.keyBuilder();
PauseSignal pauseSignal = accessor.getProperty(keyBuilder.pause());
MaintenanceSignal maintenanceSignal = accessor.getProperty(keyBuilder.maintenance());
_paused = updateControllerState(changeContext, pauseSignal, _paused);
_inMaintenanceMode = updateControllerState(changeContext, maintenanceSignal, _inMaintenanceMode);
enableClusterStatusMonitor(true);
_clusterStatusMonitor.setEnabled(!_paused);
_clusterStatusMonitor.setPaused(_paused);
_clusterStatusMonitor.setMaintenance(_inMaintenanceMode);
} else {
enableClusterStatusMonitor(false);
}
logger.info("END: GenericClusterController.onControllerChange() for cluster " + _clusterName);
}
use of org.apache.helix.HelixDataAccessor in project helix by apache.
the class IntegrationTest method printStatus.
private static void printStatus(final HelixManager manager) {
System.out.println("CLUSTER STATUS");
HelixDataAccessor helixDataAccessor = manager.getHelixDataAccessor();
Builder keyBuilder = helixDataAccessor.keyBuilder();
System.out.println("External View \n" + helixDataAccessor.getProperty(keyBuilder.externalView("repository")));
}
use of org.apache.helix.HelixDataAccessor in project helix by apache.
the class ServiceDiscovery method refreshCache.
private void refreshCache() {
Builder propertyKeyBuilder = new PropertyKey.Builder(cluster);
HelixDataAccessor helixDataAccessor = admin.getHelixDataAccessor();
List<LiveInstance> liveInstances = helixDataAccessor.getChildValues(propertyKeyBuilder.liveInstances());
refreshCache(liveInstances);
}
use of org.apache.helix.HelixDataAccessor in project helix by apache.
the class TestHelixAdminScenariosRest method testInstanceOperations.
@Test
public void testInstanceOperations() throws Exception {
final String clusterName = "clusterTestInstanceOperations";
// setup cluster
addCluster(clusterName);
addInstancesToCluster(clusterName, "localhost:123", 6, null);
addResource(clusterName, "db_11", 8);
rebalanceResource(clusterName, "db_11");
ClusterControllerManager controller = new ClusterControllerManager(ZK_ADDR, clusterName, "controller_9900");
controller.syncStart();
// start mock nodes
Map<String, MockParticipantManager> participants = new HashMap<String, MockParticipantManager>();
for (int i = 0; i < 6; i++) {
String instanceName = "localhost_123" + i;
MockParticipantManager participant = new MockParticipantManager(ZK_ADDR, clusterName, instanceName);
participant.syncStart();
participants.put(instanceName, participant);
}
HelixDataAccessor accessor;
// drop node should fail as not disabled
String instanceUrl = getInstanceUrl(clusterName, "localhost_1232");
deleteUrl(instanceUrl, true);
// disabled node
String response = assertSuccessPostOperation(instanceUrl, enableInstanceCmd(false), false);
Assert.assertTrue(response.contains("false"));
// Cannot drop / swap
deleteUrl(instanceUrl, true);
String instancesUrl = getClusterUrl(clusterName) + "/instances";
response = assertSuccessPostOperation(instancesUrl, swapInstanceCmd("localhost_1232", "localhost_12320"), true);
// disconnect the node
participants.get("localhost_1232").syncStop();
// add new node then swap instance
response = assertSuccessPostOperation(instancesUrl, addInstanceCmd("localhost_12320"), false);
Assert.assertTrue(response.contains("localhost_12320"));
// swap instance. The instance get swapped out should not exist anymore
response = assertSuccessPostOperation(instancesUrl, swapInstanceCmd("localhost_1232", "localhost_12320"), false);
Assert.assertTrue(response.contains("localhost_12320"));
Assert.assertFalse(response.contains("localhost_1232\""));
accessor = participants.get("localhost_1231").getHelixDataAccessor();
String path = accessor.keyBuilder().instanceConfig("localhost_1232").getPath();
Assert.assertFalse(_gZkClient.exists(path));
MockParticipantManager newParticipant = new MockParticipantManager(ZK_ADDR, clusterName, "localhost_12320");
newParticipant.syncStart();
participants.put("localhost_12320", newParticipant);
boolean verifyResult = ClusterStateVerifier.verifyByZkCallback(new MasterNbInExtViewVerifier(ZK_ADDR, clusterName));
Assert.assertTrue(verifyResult);
// clean up
controller.syncStop();
for (MockParticipantManager participant : participants.values()) {
participant.syncStop();
}
}
use of org.apache.helix.HelixDataAccessor in project helix by apache.
the class TestHelixAdminScenariosRest method testStartCluster.
@Test
public void testStartCluster() throws Exception {
final String clusterName = "clusterTestStartCluster";
final String controllerClusterName = "controllerClusterTestStartCluster";
Map<String, MockParticipantManager> participants = new HashMap<String, MockParticipantManager>();
Map<String, ClusterDistributedController> distControllers = new HashMap<String, ClusterDistributedController>();
// setup cluster
addCluster(clusterName);
addInstancesToCluster(clusterName, "localhost:123", 6, null);
addResource(clusterName, "db_11", 8);
rebalanceResource(clusterName, "db_11");
addCluster(controllerClusterName);
addInstancesToCluster(controllerClusterName, "controller_900", 2, null);
// start mock nodes
for (int i = 0; i < 6; i++) {
String instanceName = "localhost_123" + i;
MockParticipantManager participant = new MockParticipantManager(ZK_ADDR, clusterName, instanceName);
participant.syncStart();
participants.put(instanceName, participant);
}
// start controller nodes
for (int i = 0; i < 2; i++) {
String controllerName = "controller_900" + i;
ClusterDistributedController distController = new ClusterDistributedController(ZK_ADDR, controllerClusterName, controllerName);
distController.syncStart();
distControllers.put(controllerName, distController);
}
Thread.sleep(100);
// activate clusters
// wrong grand clustername
String clusterUrl = getClusterUrl(clusterName);
assertSuccessPostOperation(clusterUrl, activateClusterCmd("nonExistCluster", true), true);
// wrong cluster name
clusterUrl = getClusterUrl("nonExistCluster");
assertSuccessPostOperation(clusterUrl, activateClusterCmd(controllerClusterName, true), true);
clusterUrl = getClusterUrl(clusterName);
assertSuccessPostOperation(clusterUrl, activateClusterCmd(controllerClusterName, true), false);
Thread.sleep(500);
deleteUrl(clusterUrl, true);
// verify leader node
HelixDataAccessor accessor = distControllers.get("controller_9001").getHelixDataAccessor();
LiveInstance controllerLeader = accessor.getProperty(accessor.keyBuilder().controllerLeader());
Assert.assertTrue(controllerLeader.getInstanceName().startsWith("controller_900"));
accessor = participants.get("localhost_1232").getHelixDataAccessor();
LiveInstance leader = accessor.getProperty(accessor.keyBuilder().controllerLeader());
for (int i = 0; i < 5; i++) {
if (leader != null) {
break;
}
Thread.sleep(1000);
leader = accessor.getProperty(accessor.keyBuilder().controllerLeader());
}
Assert.assertTrue(leader.getInstanceName().startsWith("controller_900"));
boolean verifyResult = ClusterStateVerifier.verifyByZkCallback(new MasterNbInExtViewVerifier(ZK_ADDR, clusterName));
Assert.assertTrue(verifyResult);
verifyResult = ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(ZK_ADDR, clusterName));
Assert.assertTrue(verifyResult);
Thread.sleep(1000);
// clean up
for (ClusterDistributedController controller : distControllers.values()) {
controller.syncStop();
}
for (MockParticipantManager participant : participants.values()) {
participant.syncStop();
}
}
Aggregations