@Override public void onLiveInstanceChange(List<LiveInstance> liveInstances, NotificationContext changeContext) { for (LiveInstance liveInstance : liveInstances) { log.info("Live Helix participant instance: " + liveInstance.getInstanceName()); } } }
String instanceId = instance.getInstanceName(); String sessionId = instance.getSessionId();
sessionIdMap.put(liveInstance.getInstanceName(), liveInstance.getSessionId());
private static Set<String> getLiveInstanceName(List<LiveInstance> liveInstances) { Set<String> liveInstanceNames = new HashSet<String>(); for (LiveInstance liveInstance : liveInstances) { liveInstanceNames.add(liveInstance.getInstanceName()); } return liveInstanceNames; }
@Override public void onLiveInstanceChange(List<LiveInstance> liveInstances, NotificationContext changeContext) { for (LiveInstance liveInstance : liveInstances) { LOGGER.info("Live Helix participant instance: " + liveInstance.getInstanceName()); } } }
@Override public void onLiveInstanceChange(List<LiveInstance> liveInstances, NotificationContext changeContext) { for (LiveInstance liveInstance : liveInstances) { log.info("Live Helix participant instance: " + liveInstance.getInstanceName()); } } }
private Set<String> getLiveInstanceName(List<LiveInstance> liveInstances, List<String> excludedInstances) { Set<String> liveInstanceNames = new HashSet<>(); for (LiveInstance liveInstance : liveInstances) { if (!excludedInstances.contains(liveInstance.getInstanceName())) { liveInstanceNames.add(liveInstance.getInstanceName()); } } return liveInstanceNames; }
public AssignableInstance(ClusterConfig clusterConfig, InstanceConfig instanceConfig, LiveInstance liveInstance) { if (clusterConfig == null || instanceConfig == null || liveInstance == null) { throw new IllegalArgumentException(String.format( "ClusterConfig, InstanceConfig, LiveInstance cannot be null! ClusterConfig null: %s, InstanceConfig null: %s, LiveInstance null: %s", clusterConfig == null, instanceConfig == null, liveInstance == null)); } if (!instanceConfig.getInstanceName().equals(liveInstance.getInstanceName())) { throw new IllegalArgumentException( String.format("Instance name from LiveInstance (%s) and InstanceConfig (%s) don't match!", liveInstance.getInstanceName(), instanceConfig.getInstanceName())); } _clusterConfig = clusterConfig; _instanceConfig = instanceConfig; _liveInstance = liveInstance; _currentAssignments = new HashSet<>(); _totalCapacity = new HashMap<>(); _usedCapacity = new HashMap<>(); refreshTotalCapacity(); }
public AssignableInstance(ClusterConfig clusterConfig, InstanceConfig instanceConfig, LiveInstance liveInstance) { if (clusterConfig == null || instanceConfig == null || liveInstance == null) { throw new IllegalArgumentException(String.format( "ClusterConfig, InstanceConfig, LiveInstance cannot be null! ClusterConfig null: %s, InstanceConfig null: %s, LiveInstance null: %s", clusterConfig == null, instanceConfig == null, liveInstance == null)); } if (!instanceConfig.getInstanceName().equals(liveInstance.getInstanceName())) { throw new IllegalArgumentException( String.format("Instance name from LiveInstance (%s) and InstanceConfig (%s) don't match!", liveInstance.getInstanceName(), instanceConfig.getInstanceName())); } _clusterConfig = clusterConfig; _instanceConfig = instanceConfig; _liveInstance = liveInstance; _currentAssignments = new HashSet<>(); _totalCapacity = new HashMap<>(); _usedCapacity = new HashMap<>(); refreshTotalCapacity(); }
@GET @Path("{clusterId}/controller") public Response getClusterController(@PathParam("clusterId") String clusterId) { HelixDataAccessor dataAccessor = getDataAccssor(clusterId); Map<String, Object> controllerInfo = new HashMap<>(); controllerInfo.put(Properties.id.name(), clusterId); LiveInstance leader = dataAccessor.getProperty(dataAccessor.keyBuilder().controllerLeader()); if (leader != null) { controllerInfo.put(ClusterProperties.controller.name(), leader.getInstanceName()); controllerInfo.putAll(leader.getRecord().getSimpleFields()); } else { controllerInfo.put(ClusterProperties.controller.name(), "No Lead Controller!"); } return JSONRepresentation(controllerInfo); }
@Override public boolean isLeader() { if (_instanceType != InstanceType.CONTROLLER && _instanceType != InstanceType.CONTROLLER_PARTICIPANT) { return false; } if (!isConnected()) { return false; } try { LiveInstance leader = _dataAccessor.getProperty(_keyBuilder.controllerLeader()); if (leader != null) { String leaderName = leader.getInstanceName(); String sessionId = leader.getSessionId(); if (leaderName != null && leaderName.equals(_instanceName) && sessionId != null && sessionId.equals(_sessionId)) { return true; } } } catch (Exception e) { // log } return false; }
@Override public boolean verify() throws Exception { LiveInstance leader = accessor.getProperty(keyBuilder.controllerLeader()); if (leader == null) { return false; } return leader.getInstanceName().equals(newControllerName); } }, 30 * 1000);
@Override public boolean verify() { LiveInstance liveInstance = accessor.getProperty(keyBuilder.controllerLeader()); if (liveInstance != null) { // disconnect the current leader manager managerList.remove(liveInstance.getInstanceName()).disconnect(); return true; } else { return false; } } }, 1000));
@Override public boolean verify() { LiveInstance liveInstance = accessor.getProperty(keyBuilder.controllerLeader()); return liveInstance != null && controllerName.equals(liveInstance.getInstanceName()) && manager.getSessionId().equals(liveInstance.getSessionId()); } }, 1000));
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; }
private void verifyP2PDisabled() { ClusterDataCache dataCache = new ClusterDataCache(CLUSTER_NAME); dataCache.refresh(_accessor); Map<String, LiveInstance> liveInstanceMap = dataCache.getLiveInstances(); for (LiveInstance instance : liveInstanceMap.values()) { Map<String, CurrentState> currentStateMap = dataCache.getCurrentState(instance.getInstanceName(), instance.getSessionId()); Assert.assertNotNull(currentStateMap); for (CurrentState currentState : currentStateMap.values()) { for (String partition : currentState.getPartitionStateMap().keySet()) { String state = currentState.getState(partition); if (state.equalsIgnoreCase("MASTER")) { String triggerHost = currentState.getTriggerHost(partition); Assert.assertEquals(triggerHost, _controllerName, state + " of " + partition + " on " + instance.getInstanceName() + " was triggered by " + triggerHost); } } } } }
@Override public void process(ClusterEvent event) throws Exception { _eventId = event.getEventId(); ClusterDataCache cache = event.getAttribute(AttributeName.ClusterDataCache.name()); final Map<String, Resource> resourceMap = event.getAttribute(AttributeName.RESOURCES.name()); if (cache == null || resourceMap == null) { throw new StageException("Missing attributes in event:" + event + ". Requires DataCache|RESOURCE"); } Map<String, LiveInstance> liveInstances = cache.getLiveInstances(); final CurrentStateOutput currentStateOutput = new CurrentStateOutput(); for (LiveInstance instance : liveInstances.values()) { String instanceName = instance.getInstanceName(); String instanceSessionId = instance.getSessionId(); // update pending messages Map<String, Message> messages = cache.getMessages(instanceName); Map<String, Message> relayMessages = cache.getRelayMessages(instanceName); updatePendingMessages(instance, messages.values(), currentStateOutput, relayMessages.values(), resourceMap); // update current states. Map<String, CurrentState> currentStateMap = cache.getCurrentState(instanceName, instanceSessionId); updateCurrentStates(instance, currentStateMap.values(), currentStateOutput, resourceMap); } event.addAttribute(AttributeName.CURRENT_STATE.name(), currentStateOutput); }
private void verifyP2PEnabled(long startTime) { ClusterDataCache dataCache = new ClusterDataCache(CLUSTER_NAME); dataCache.refresh(_accessor); Map<String, LiveInstance> liveInstanceMap = dataCache.getLiveInstances(); for (LiveInstance instance : liveInstanceMap.values()) { Map<String, CurrentState> currentStateMap = dataCache.getCurrentState(instance.getInstanceName(), instance.getSessionId()); Assert.assertNotNull(currentStateMap); for (CurrentState currentState : currentStateMap.values()) { for (String partition : currentState.getPartitionStateMap().keySet()) { String state = currentState.getState(partition); long start = currentState.getStartTime(partition); if (state.equalsIgnoreCase("MASTER") && start > startTime) { String triggerHost = currentState.getTriggerHost(partition); if (!triggerHost.equals(_controllerName)) { p2pTrigged ++; } total ++; } } } } }
protected String getCurrentLeader(HelixZkClient 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(); }
@Override public void process(ClusterEvent event) throws Exception { HelixManager manager = event.getAttribute(AttributeName.helixmanager.name()); ClusterDataCache cache = event.getAttribute(AttributeName.ClusterDataCache.name()); if (manager == null || cache == null) { throw new StageException("Missing attributes in event:" + event + ". Requires HelixManager | DataCache"); } HelixManagerProperties properties = manager.getProperties(); Map<String, LiveInstance> liveInstanceMap = cache.getLiveInstances(); for (LiveInstance liveInstance : liveInstanceMap.values()) { String participantVersion = liveInstance.getHelixVersion(); if (!properties.isParticipantCompatible(participantVersion)) { String errorMsg = "incompatible participant. pipeline will not continue. " + "controller: " + manager.getInstanceName() + ", controllerVersion: " + properties.getVersion() + ", minimumSupportedParticipantVersion: " + properties.getProperty("miminum_supported_version.participant") + ", participant: " + liveInstance.getInstanceName() + ", participantVersion: " + participantVersion; LogUtil.logError(LOG, event.getEventId(), errorMsg); throw new StageException(errorMsg); } } } }