Java Code Examples for org.apache.helix.model.IdealState#getInstanceGroupTag()
The following examples show how to use
org.apache.helix.model.IdealState#getInstanceGroupTag() .
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: ZKHelixAdmin.java From helix with Apache License 2.0 | 6 votes |
@Override public List<String> getResourcesInClusterWithTag(String clusterName, String tag) { List<String> resourcesWithTag = new ArrayList<String>(); HelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(_zkClient)); PropertyKey.Builder keyBuilder = accessor.keyBuilder(); for (String resourceName : getResourcesInCluster(clusterName)) { IdealState is = accessor.getProperty(keyBuilder.idealStates(resourceName)); if (is != null && is.getInstanceGroupTag() != null && is.getInstanceGroupTag().equals(tag)) { resourcesWithTag.add(resourceName); } } return resourcesWithTag; }
Example 2
Source File: TestWagedRebalance.java From helix with Apache License 2.0 | 6 votes |
/** * Validate each partition is different instances and with necessary tagged instances. */ private void validateIsolation(IdealState is, ExternalView ev, int expectedReplica) { String tag = is.getInstanceGroupTag(); for (String partition : is.getPartitionSet()) { Map<String, String> assignmentMap = ev.getRecord().getMapField(partition); Set<String> instancesInEV = assignmentMap.keySet(); Assert.assertEquals(instancesInEV.size(), expectedReplica); for (String instance : instancesInEV) { if (tag != null) { InstanceConfig config = _gSetupTool.getClusterManagementTool().getInstanceConfig(CLUSTER_NAME, instance); Assert.assertTrue(config.containsTag(tag)); } } } }
Example 3
Source File: TestWagedRebalanceFaultZone.java From helix with Apache License 2.0 | 6 votes |
/** * Validate instances for each partition is on different zone and with necessary tagged instances. */ private void validateZoneAndTagIsolation(IdealState is, ExternalView ev, int expectedReplica) { String tag = is.getInstanceGroupTag(); for (String partition : is.getPartitionSet()) { Set<String> assignedZones = new HashSet<String>(); Map<String, String> assignmentMap = ev.getRecord().getMapField(partition); Set<String> instancesInEV = assignmentMap.keySet(); // TODO: preference List is not persisted in IS. // Assert.assertEquals(instancesInEV, instancesInIs); for (String instance : instancesInEV) { assignedZones.add(_nodeToZoneMap.get(instance)); if (tag != null) { InstanceConfig config = _gSetupTool.getClusterManagementTool().getInstanceConfig(CLUSTER_NAME, instance); Assert.assertTrue(config.containsTag(tag)); } } Assert.assertEquals(assignedZones.size(), expectedReplica); } }
Example 4
Source File: TestCrushAutoRebalance.java From helix with Apache License 2.0 | 6 votes |
/** * Validate instances for each partition is on different zone and with necessary tagged instances. */ private void validateZoneAndTagIsolation(IdealState is, ExternalView ev, int expectedReplica) { String tag = is.getInstanceGroupTag(); for (String partition : is.getPartitionSet()) { Set<String> assignedZones = new HashSet<String>(); Map<String, String> assignmentMap = ev.getRecord().getMapField(partition); Set<String> instancesInEV = assignmentMap.keySet(); // TODO: preference List is not persisted in IS. // Assert.assertEquals(instancesInEV, instancesInIs); for (String instance : instancesInEV) { assignedZones.add(_nodeToZoneMap.get(instance)); if (tag != null) { InstanceConfig config = _gSetupTool.getClusterManagementTool().getInstanceConfig(CLUSTER_NAME, instance); Assert.assertTrue(config.containsTag(tag)); } } Assert.assertEquals(assignedZones.size(), expectedReplica); } }
Example 5
Source File: TestCrushAutoRebalanceNonRack.java From helix with Apache License 2.0 | 6 votes |
/** * Validate each partition is different instances and with necessary tagged instances. */ private void validateIsolation(IdealState is, ExternalView ev, int expectedReplica) { String tag = is.getInstanceGroupTag(); for (String partition : is.getPartitionSet()) { Map<String, String> assignmentMap = ev.getRecord().getMapField(partition); Set<String> instancesInEV = assignmentMap.keySet(); Assert.assertEquals(instancesInEV.size(), expectedReplica); for (String instance : instancesInEV) { if (tag != null) { InstanceConfig config = _gSetupTool.getClusterManagementTool().getInstanceConfig(CLUSTER_NAME, instance); Assert.assertTrue(config.containsTag(tag)); } } } }
Example 6
Source File: AutoRebalancer.java From helix with Apache License 2.0 | 4 votes |
@Override public IdealState computeNewIdealState(String resourceName, IdealState currentIdealState, CurrentStateOutput currentStateOutput, ResourceControllerDataProvider clusterData) { IdealState cachedIdealState = getCachedIdealState(resourceName, clusterData); if (cachedIdealState != null) { LOG.debug("Use cached IdealState for " + resourceName); return cachedIdealState; } LOG.info("Computing IdealState for " + resourceName); List<String> partitions = getStablePartitionList(clusterData, currentIdealState); String stateModelName = currentIdealState.getStateModelDefRef(); StateModelDefinition stateModelDef = clusterData.getStateModelDef(stateModelName); if (stateModelDef == null) { LOG.error("State Model Definition null for resource: " + resourceName); throw new HelixException("State Model Definition null for resource: " + resourceName); } Map<String, LiveInstance> liveInstance = clusterData.getLiveInstances(); int replicas = currentIdealState.getReplicaCount(liveInstance.size()); LinkedHashMap<String, Integer> stateCountMap = stateModelDef .getStateCountMap(liveInstance.size(), replicas); List<String> liveNodes = new ArrayList<>(liveInstance.keySet()); List<String> allNodes = new ArrayList<>(clusterData.getAllInstances()); allNodes.removeAll(clusterData.getDisabledInstances()); liveNodes.retainAll(allNodes); Map<String, Map<String, String>> currentMapping = currentMapping(currentStateOutput, resourceName, partitions, stateCountMap); // If there are nodes tagged with resource name, use only those nodes Set<String> taggedNodes = new HashSet<String>(); Set<String> taggedLiveNodes = new HashSet<String>(); if (currentIdealState.getInstanceGroupTag() != null) { for (String instanceName : allNodes) { if (clusterData.getInstanceConfigMap().get(instanceName) .containsTag(currentIdealState.getInstanceGroupTag())) { taggedNodes.add(instanceName); if (liveInstance.containsKey(instanceName)) { taggedLiveNodes.add(instanceName); } } } if (!taggedLiveNodes.isEmpty()) { // live nodes exist that have this tag if (LOG.isInfoEnabled()) { LOG.info("found the following participants with tag " + currentIdealState.getInstanceGroupTag() + " for " + resourceName + ": " + taggedLiveNodes); } } else if (taggedNodes.isEmpty()) { // no live nodes and no configured nodes have this tag LOG.warn("Resource " + resourceName + " has tag " + currentIdealState.getInstanceGroupTag() + " but no configured participants have this tag"); } else { // configured nodes have this tag, but no live nodes have this tag LOG.warn("Resource " + resourceName + " has tag " + currentIdealState.getInstanceGroupTag() + " but no live participants have this tag"); } allNodes = new ArrayList<>(taggedNodes); liveNodes = new ArrayList<>(taggedLiveNodes); } // sort node lists to ensure consistent preferred assignments Collections.sort(allNodes); Collections.sort(liveNodes); int maxPartition = currentIdealState.getMaxPartitionsPerInstance(); _rebalanceStrategy = getRebalanceStrategy(currentIdealState.getRebalanceStrategy(), partitions, resourceName, stateCountMap, maxPartition); ZNRecord newMapping = _rebalanceStrategy .computePartitionAssignment(allNodes, liveNodes, currentMapping, clusterData); if (LOG.isDebugEnabled()) { LOG.debug("currentMapping: " + currentMapping); LOG.debug("stateCountMap: " + stateCountMap); LOG.debug("liveNodes: " + liveNodes); LOG.debug("allNodes: " + allNodes); LOG.debug("maxPartition: " + maxPartition); LOG.debug("newMapping: " + newMapping); } IdealState newIdealState = new IdealState(resourceName); newIdealState.getRecord().setSimpleFields(currentIdealState.getRecord().getSimpleFields()); newIdealState.setRebalanceMode(RebalanceMode.FULL_AUTO); newIdealState.getRecord().setListFields(newMapping.getListFields()); return newIdealState; }