Java Code Examples for org.apache.helix.model.CurrentState#getResourceName()

The following examples show how to use org.apache.helix.model.CurrentState#getResourceName() . 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 vote down vote up
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: CurrentStateComputationStage.java    From helix with Apache License 2.0 4 votes vote down vote up
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);
        }
      }
    }
  }
}