Java Code Examples for org.apache.helix.model.CurrentState#getPartitionStateMap()
The following examples show how to use
org.apache.helix.model.CurrentState#getPartitionStateMap() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RoutingTable.java From helix with Apache License 2.0 | 5 votes |
private void refresh(Map<String, Map<String, Map<String, CurrentState>>> currentStateMap) { Map<String, InstanceConfig> instanceConfigMap = new HashMap<>(); if (currentStateMap != null && !currentStateMap.isEmpty()) { for (InstanceConfig config : _instanceConfigs) { instanceConfigMap.put(config.getId(), config); } for (LiveInstance liveInstance : _liveInstances) { String instanceName = liveInstance.getInstanceName(); String sessionId = liveInstance.getEphemeralOwner(); InstanceConfig instanceConfig = instanceConfigMap.get(instanceName); if (instanceConfig == null) { logger.warn( "Participant {} is not found with proper configuration information. It might already be removed from the cluster. " + "Skip recording partition assignments that are related to this instance.", instanceName); continue; } Map<String, CurrentState> currentStates = Collections.emptyMap(); if (currentStateMap.containsKey(instanceName) && currentStateMap.get(instanceName).containsKey(sessionId)) { currentStates = currentStateMap.get(instanceName).get(sessionId); } for (CurrentState currentState : currentStates.values()) { String resourceName = currentState.getResourceName(); Map<String, String> stateMap = currentState.getPartitionStateMap(); for (String partitionName : stateMap.keySet()) { String state = stateMap.get(partitionName); addEntry(resourceName, partitionName, state, instanceConfig); } } } } }
Example 2
Source File: ZkTestBase.java From helix with Apache License 2.0 | 5 votes |
@Override public boolean verify() { BaseDataAccessor<ZNRecord> baseAccessor = new ZkBaseDataAccessor<ZNRecord>(_zkClient); HelixDataAccessor accessor = new ZKHelixDataAccessor(_clusterName, baseAccessor); PropertyKey.Builder keyBuilder = accessor.keyBuilder(); ExternalView externalView = accessor.getProperty(keyBuilder.externalView(_resourceName)); // verify external view empty if (externalView != null) { for (String partition : externalView.getPartitionSet()) { Map<String, String> stateMap = externalView.getStateMap(partition); if (stateMap != null && !stateMap.isEmpty()) { LOG.error("External view not empty for " + partition); return false; } } } // verify current state empty List<String> liveParticipants = accessor.getChildNames(keyBuilder.liveInstances()); for (String participant : liveParticipants) { List<String> sessionIds = accessor.getChildNames(keyBuilder.sessions(participant)); for (String sessionId : sessionIds) { CurrentState currentState = accessor.getProperty(keyBuilder.currentState(participant, sessionId, _resourceName)); Map<String, String> partitionStateMap = currentState.getPartitionStateMap(); if (partitionStateMap != null && !partitionStateMap.isEmpty()) { LOG.error("Current state not empty for " + participant); return false; } } } return true; }
Example 3
Source File: CurrentStateComputationStage.java From helix with Apache License 2.0 | 4 votes |
private void updateCurrentStates(LiveInstance instance, Collection<CurrentState> currentStates, CurrentStateOutput currentStateOutput, Map<String, Resource> resourceMap) { String instanceName = instance.getInstanceName(); String instanceSessionId = instance.getEphemeralOwner(); for (CurrentState currentState : currentStates) { if (!instanceSessionId.equals(currentState.getSessionId())) { continue; } String resourceName = currentState.getResourceName(); String stateModelDefName = currentState.getStateModelDefRef(); Resource resource = resourceMap.get(resourceName); if (resource == null) { continue; } if (stateModelDefName != null) { currentStateOutput.setResourceStateModelDef(resourceName, stateModelDefName); } currentStateOutput.setBucketSize(resourceName, currentState.getBucketSize()); Map<String, String> partitionStateMap = currentState.getPartitionStateMap(); for (String partitionName : partitionStateMap.keySet()) { Partition partition = resource.getPartition(partitionName); if (partition != null) { currentStateOutput.setCurrentState(resourceName, partition, instanceName, currentState.getState(partitionName)); currentStateOutput.setEndTime(resourceName, partition, instanceName, currentState.getEndTime(partitionName)); String info = currentState.getInfo(partitionName); // This is to avoid null value entries in the map, and reduce memory usage by avoiding extra empty entries in the map. if (info != null) { currentStateOutput.setInfo(resourceName, partition, instanceName, info); } String requestState = currentState.getRequestedState(partitionName); if (requestState != null) { currentStateOutput .setRequestedState(resourceName, partition, instanceName, requestState); } } } } }
Example 4
Source File: InstanceServiceImpl.java From helix with Apache License 2.0 | 4 votes |
@Override public InstanceInfo getInstanceInfo(String clusterId, String instanceName, List<HealthCheck> healthChecks) { InstanceInfo.Builder instanceInfoBuilder = new InstanceInfo.Builder(instanceName); InstanceConfig instanceConfig = _dataAccessor.getProperty(_dataAccessor.keyBuilder().instanceConfig(instanceName)); LiveInstance liveInstance = _dataAccessor.getProperty(_dataAccessor.keyBuilder().liveInstance(instanceName)); if (instanceConfig != null) { instanceInfoBuilder.instanceConfig(instanceConfig.getRecord()); } else { LOG.warn("Missing instance config for {}", instanceName); } if (liveInstance != null) { instanceInfoBuilder.liveInstance(liveInstance.getRecord()); String sessionId = liveInstance.getEphemeralOwner(); List<String> resourceNames = _dataAccessor .getChildNames(_dataAccessor.keyBuilder().currentStates(instanceName, sessionId)); instanceInfoBuilder.resources(resourceNames); List<String> partitions = new ArrayList<>(); for (String resourceName : resourceNames) { CurrentState currentState = _dataAccessor.getProperty( _dataAccessor.keyBuilder().currentState(instanceName, sessionId, resourceName)); if (currentState != null && currentState.getPartitionStateMap() != null) { partitions.addAll(currentState.getPartitionStateMap().keySet()); } else { LOG.warn( "Current state is either null or partitionStateMap is missing. InstanceName: {}, SessionId: {}, ResourceName: {}", instanceName, sessionId, resourceName); } } instanceInfoBuilder.partitions(partitions); } else { LOG.warn("Missing live instance for {}", instanceName); } try { Map<String, Boolean> healthStatus = getInstanceHealthStatus(clusterId, instanceName, healthChecks); instanceInfoBuilder.healthStatus(healthStatus); } catch (HelixException ex) { LOG.error( "Exception while getting health status. Cluster: {}, Instance: {}, reporting health status as unHealth", clusterId, instanceName, ex); instanceInfoBuilder.healthStatus(false); } return instanceInfoBuilder.build(); }
Example 5
Source File: ServiceStatus.java From incubator-pinot with Apache License 2.0 | 4 votes |
@Override protected Map<String, String> getPartitionStateMap(CurrentState state) { return state.getPartitionStateMap(); }