Java Code Examples for org.apache.helix.model.IdealState#RebalanceMode
The following examples show how to use
org.apache.helix.model.IdealState#RebalanceMode .
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: ClusterSetup.java From helix with Apache License 2.0 | 6 votes |
/** * Create an IdealState for a resource that belongs to a resource group We use * "resourceGroupName$resourceInstanceTag" as the IdealState znode name to differetiate different * resources from the same resourceGroup. */ public IdealState createIdealStateForResourceGroup(String resourceGroupName, String resourceTag, int numPartition, int replica, String rebalanceMode, String stateModelDefName) { String idealStateId = genIdealStateNameWithResourceTag(resourceGroupName, resourceTag); IdealState idealState = new IdealState(idealStateId); idealState.setNumPartitions(numPartition); idealState.setStateModelDefRef(stateModelDefName); IdealState.RebalanceMode mode = idealState.rebalanceModeFromString(rebalanceMode, IdealState.RebalanceMode.SEMI_AUTO); idealState.setRebalanceMode(mode); idealState.setReplicas("" + replica); idealState.setStateModelFactoryName(HelixConstants.DEFAULT_STATE_MODEL_FACTORY); idealState.setResourceGroupName(resourceGroupName); idealState.setInstanceGroupTag(resourceTag); idealState.enableGroupRouting(true); return idealState; }
Example 2
Source File: PersistAssignmentStage.java From helix with Apache License 2.0 | 4 votes |
private void persistAssignment(final Resource resource, final ResourceControllerDataProvider cache, final ClusterEvent event, final BestPossibleStateOutput bestPossibleAssignment, final ClusterConfig clusterConfig, final HelixDataAccessor accessor, final PropertyKey.Builder keyBuilder) { String resourceId = resource.getResourceName(); if (resource != null) { final IdealState idealState = cache.getIdealState(resourceId); if (idealState == null) { LogUtil.logWarn(LOG, event.getEventId(), "IdealState not found for resource " + resourceId); return; } IdealState.RebalanceMode mode = idealState.getRebalanceMode(); if (!mode.equals(IdealState.RebalanceMode.SEMI_AUTO) && !mode .equals(IdealState.RebalanceMode.FULL_AUTO)) { // do not persist assignment for resource in neither semi or full auto. return; } boolean needPersist = false; if (mode.equals(IdealState.RebalanceMode.FULL_AUTO)) { // persist preference list in ful-auto mode. Map<String, List<String>> newLists = bestPossibleAssignment.getPreferenceLists(resourceId); if (newLists != null && hasPreferenceListChanged(newLists, idealState)) { idealState.setPreferenceLists(newLists); needPersist = true; } } PartitionStateMap partitionStateMap = bestPossibleAssignment.getPartitionStateMap(resourceId); if (clusterConfig.isPersistIntermediateAssignment()) { IntermediateStateOutput intermediateAssignment = event.getAttribute(AttributeName.INTERMEDIATE_STATE.name()); partitionStateMap = intermediateAssignment.getPartitionStateMap(resourceId); } //TODO: temporary solution for Espresso/Dbus backcompatible, should remove this. Map<Partition, Map<String, String>> assignmentToPersist = convertAssignmentPersisted(resource, idealState, partitionStateMap.getStateMap()); if (assignmentToPersist != null && hasInstanceMapChanged(assignmentToPersist, idealState)) { for (Partition partition : assignmentToPersist.keySet()) { Map<String, String> instanceMap = assignmentToPersist.get(partition); idealState.setInstanceStateMap(partition.getPartitionName(), instanceMap); } needPersist = true; } if (needPersist) { // Update instead of set to ensure any intermediate changes that the controller does not update are kept. accessor.updateProperty(keyBuilder.idealStates(resourceId), new DataUpdater<ZNRecord>() { @Override public ZNRecord update(ZNRecord current) { if (current != null) { // Overwrite MapFields and ListFields items with the same key. // Note that default merge will keep old values in the maps or lists unchanged, which is not desired. current.getMapFields().clear(); current.getMapFields().putAll(idealState.getRecord().getMapFields()); current.getListFields().putAll(idealState.getRecord().getListFields()); } return current; } }, idealState); } } }
Example 3
Source File: IdealStateBuilder.java From helix with Apache License 2.0 | 4 votes |
/** * sub-class should implement this to set ideal-state mode * @return */ public IdealStateBuilder setRebalancerMode(IdealState.RebalanceMode rebalancerMode) { this.rebalancerMode = rebalancerMode; return this; }