Java Code Examples for org.apache.helix.HelixAdmin#getStateModelDef()
The following examples show how to use
org.apache.helix.HelixAdmin#getStateModelDef() .
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: HelixSetupUtils.java From incubator-pinot with Apache License 2.0 | 6 votes |
private static void createBrokerResourceIfNeeded(String helixClusterName, HelixAdmin helixAdmin, boolean enableBatchMessageMode) { // Add state model definition if needed String stateModel = PinotHelixBrokerResourceOnlineOfflineStateModelGenerator.PINOT_BROKER_RESOURCE_ONLINE_OFFLINE_STATE_MODEL; StateModelDefinition stateModelDef = helixAdmin.getStateModelDef(helixClusterName, stateModel); if (stateModelDef == null) { LOGGER.info("Adding state model: {}", stateModel); helixAdmin.addStateModelDef(helixClusterName, stateModel, PinotHelixBrokerResourceOnlineOfflineStateModelGenerator.generatePinotStateModelDefinition()); } // Add broker resource if needed if (helixAdmin.getResourceIdealState(helixClusterName, BROKER_RESOURCE_INSTANCE) == null) { LOGGER.info("Adding resource: {}", BROKER_RESOURCE_INSTANCE); IdealState idealState = new CustomModeISBuilder(BROKER_RESOURCE_INSTANCE).setStateModel(stateModel).build(); idealState.setBatchMessageMode(enableBatchMessageMode); helixAdmin.addResource(helixClusterName, BROKER_RESOURCE_INSTANCE, idealState); } }
Example 2
Source File: HelixSetupUtils.java From incubator-pinot with Apache License 2.0 | 5 votes |
private static void addSegmentStateModelDefinitionIfNeeded(String helixClusterName, HelixAdmin helixAdmin, HelixDataAccessor helixDataAccessor, boolean isUpdateStateModel) { String segmentStateModelName = PinotHelixSegmentOnlineOfflineStateModelGenerator.PINOT_SEGMENT_ONLINE_OFFLINE_STATE_MODEL; StateModelDefinition stateModelDefinition = helixAdmin.getStateModelDef(helixClusterName, segmentStateModelName); if (stateModelDefinition == null || isUpdateStateModel) { if (stateModelDefinition == null) { LOGGER.info("Adding state model: {} with CONSUMING state", segmentStateModelName); } else { LOGGER.info("Updating state model: {} to contain CONSUMING state", segmentStateModelName); } helixDataAccessor .createStateModelDef(PinotHelixSegmentOnlineOfflineStateModelGenerator.generatePinotStateModelDefinition()); } }
Example 3
Source File: ResourceAccessor.java From helix with Apache License 2.0 | 4 votes |
private Map<String, String> computePartitionHealth(String clusterId, String resourceName) { HelixAdmin admin = getHelixAdmin(); IdealState idealState = admin.getResourceIdealState(clusterId, resourceName); ExternalView externalView = admin.getResourceExternalView(clusterId, resourceName); StateModelDefinition stateModelDef = admin.getStateModelDef(clusterId, idealState.getStateModelDefRef()); String initialState = stateModelDef.getInitialState(); List<String> statesPriorityList = stateModelDef.getStatesPriorityList(); statesPriorityList = statesPriorityList.subList(0, statesPriorityList.indexOf(initialState)); // Trim // stateList // to // initialState // and // above int minActiveReplicas = idealState.getMinActiveReplicas(); // Start the logic that determines the health status of each partition Map<String, String> partitionHealthResult = new HashMap<>(); Set<String> allPartitionNames = idealState.getPartitionSet(); if (!allPartitionNames.isEmpty()) { for (String partitionName : allPartitionNames) { int replicaCount = idealState.getReplicaCount(idealState.getPreferenceList(partitionName).size()); // Simplify expectedStateCountMap by assuming that all instances are available to reduce // computation load on this REST endpoint LinkedHashMap<String, Integer> expectedStateCountMap = stateModelDef.getStateCountMap(replicaCount, replicaCount); // Extract all states into Collections from ExternalView Map<String, String> stateMapInExternalView = externalView.getStateMap(partitionName); Collection<String> allReplicaStatesInExternalView = (stateMapInExternalView != null && !stateMapInExternalView.isEmpty()) ? stateMapInExternalView.values() : Collections.<String> emptyList(); int numActiveReplicasInExternalView = 0; HealthStatus status = HealthStatus.HEALTHY; // Go through all states that are "active" states (higher priority than InitialState) for (int statePriorityIndex = 0; statePriorityIndex < statesPriorityList .size(); statePriorityIndex++) { String currentState = statesPriorityList.get(statePriorityIndex); int currentStateCountInIdealState = expectedStateCountMap.get(currentState); int currentStateCountInExternalView = Collections.frequency(allReplicaStatesInExternalView, currentState); numActiveReplicasInExternalView += currentStateCountInExternalView; // Top state counts must match, if not, unhealthy if (statePriorityIndex == 0 && currentStateCountInExternalView != currentStateCountInIdealState) { status = HealthStatus.UNHEALTHY; break; } else if (currentStateCountInExternalView < currentStateCountInIdealState) { // For non-top states, if count in ExternalView is less than count in IdealState, // partially healthy status = HealthStatus.PARTIAL_HEALTHY; } } if (numActiveReplicasInExternalView < minActiveReplicas) { // If this partition does not satisfy the number of minimum active replicas, unhealthy status = HealthStatus.UNHEALTHY; } partitionHealthResult.put(partitionName, status.name()); } } return partitionHealthResult; }