/** * Get a single map config. * * @param configKey * @return configuration value map, or NULL if not exist. */ public Map<String, String> getMapConfig(String configKey) { return getRecord().getMapField(configKey); }
public ResourceConfig build() { // TODO: Reenable the validation in the future when ResourceConfig is ready. // validate(); return new ResourceConfig(_resourceId, _monitorDisabled, _numPartitions, _stateModelDefRef, _stateModelFactoryName, _numReplica, _minActiveReplica, _maxPartitionsPerInstance, _instanceGroupTag, _helixEnabled, _resourceGroupName, _resourceType, _groupRoutingEnabled, _externalViewDisabled, _rebalanceConfig, _stateTransitionTimeoutConfig, _preferenceLists, _mapFields, _p2pMessageEnabled); } }
resourceConfig.getRebalanceConfig().getRebalanceMode(); if (rebalanceMode.equals(RebalanceConfig.RebalanceMode.FULL_AUTO)) { throw new HelixException( "Resources that in FULL_AUTO mode are not supported: " + resourceConfig .getResourceName()); Map<String, Map<String, String>> preferredMapping = new HashMap<>(); if (existingAssignment != null) { PartitionStateMap partitionStateMap = existingAssignment.getPartitionStateMap(resourceConfig.getResourceName()); getStateModelDef(resourceConfig.getStateModelDefRef()); constraintBasedStrategy.init(resourceConfig.getResourceName(), new ArrayList<>(resourceConfig.getPreferenceLists().keySet()), stateModelDefinition .getStateCountMap(_instanceConfigMap.size(), Integer.parseInt(resourceConfig.getNumReplica())), Integer.MAX_VALUE); Map<String, Map<String, String>> stateMap = znRecord.getMapFields(); PartitionStateMap newStateMap = new PartitionStateMap(resourceConfig.getResourceName()); for (String partition : stateMap.keySet()) { newStateMap.setState(new Partition(partition), stateMap.get(partition)); resultAssignment.setState(resourceConfig.getResourceName(), newStateMap);
private void removePartitionFromUserDefinedList(String db, List<String> userDefinedPartitions) { ResourceConfig resourceConfig = _configAccessor.getResourceConfig(CLUSTER_NAME, db); Map<String, List<String>> lists = resourceConfig.getPreferenceLists(); lists.remove(userDefinedPartitions.get(0)); resourceConfig.setPreferenceLists(lists); userDefinedPartitions.remove(0); _configAccessor.setResourceConfig(CLUSTER_NAME, db, resourceConfig); }
userDefinedPreferenceList = resourceConfig.getPreferenceLists(); if (!userDefinedPreferenceList.isEmpty()) { LOG.info("Using user defined preference list for partitions: " + userDefinedPreferenceList
private Map<String, ResourceConfig> refreshResourceConfigs(HelixDataAccessor accessor) { Map<String, ResourceConfig> refreshedResourceConfigs = Maps.newHashMap(); long startTime = System.currentTimeMillis(); PropertyKey.Builder keyBuilder = accessor.keyBuilder(); Set<PropertyKey> currentResourceConfigKeys = new HashSet<>(); for (String resourceConfig : accessor.getChildNames(keyBuilder.resourceConfigs())) { currentResourceConfigKeys.add(keyBuilder.resourceConfig(resourceConfig)); } Set<PropertyKey> cachedKeys = new HashSet<>(); Map<PropertyKey, ResourceConfig> cachedResourceConfigMap = Maps.newHashMap(); for (String resourceConfig : _resourceConfigMap.keySet()) { cachedKeys.add(keyBuilder.resourceConfig(resourceConfig)); cachedResourceConfigMap.put(keyBuilder.resourceConfig(resourceConfig), _resourceConfigMap.get(resourceConfig)); } cachedKeys.retainAll(currentResourceConfigKeys); Set<PropertyKey> reloadKeys = new HashSet<>(currentResourceConfigKeys); reloadKeys.removeAll(cachedKeys); Map<PropertyKey, ResourceConfig> updatedMap = refreshProperties(accessor, new LinkedList<>(reloadKeys), new ArrayList<>(cachedKeys), cachedResourceConfigMap); for (ResourceConfig resourceConfig : updatedMap.values()) { refreshedResourceConfigs.put(resourceConfig.getResourceName(), resourceConfig); } long endTime = System.currentTimeMillis(); LogUtil.logInfo(LOG, getEventId(), "Refresh " + refreshedResourceConfigs.size() + " resource configs for cluster " + _clusterName + ", took " + (endTime - startTime) + " ms"); return refreshedResourceConfigs; }
resourceConfig.getRebalanceConfig().getRebalanceMode(); if (rebalanceMode.equals(RebalanceConfig.RebalanceMode.FULL_AUTO)) { throw new HelixException( "Resources that in FULL_AUTO mode are not supported: " + resourceConfig .getResourceName()); Map<String, Map<String, String>> preferredMapping = new HashMap<>(); if (existingAssignment != null) { PartitionStateMap partitionStateMap = existingAssignment.getPartitionStateMap(resourceConfig.getResourceName()); getStateModelDef(resourceConfig.getStateModelDefRef()); constraintBasedStrategy.init(resourceConfig.getResourceName(), new ArrayList<>(resourceConfig.getPreferenceLists().keySet()), stateModelDefinition .getStateCountMap(_instanceConfigMap.size(), Integer.parseInt(resourceConfig.getNumReplica())), Integer.MAX_VALUE); Map<String, Map<String, String>> stateMap = znRecord.getMapFields(); PartitionStateMap newStateMap = new PartitionStateMap(resourceConfig.getResourceName()); for (String partition : stateMap.keySet()) { newStateMap.setState(new Partition(partition), stateMap.get(partition)); resultAssignment.setState(resourceConfig.getResourceName(), newStateMap);
private void removePartitionFromUserDefinedList(String db, List<String> userDefinedPartitions) { ResourceConfig resourceConfig = _configAccessor.getResourceConfig(CLUSTER_NAME, db); Map<String, List<String>> lists = resourceConfig.getPreferenceLists(); lists.remove(userDefinedPartitions.get(0)); resourceConfig.setPreferenceLists(lists); userDefinedPartitions.remove(0); _configAccessor.setResourceConfig(CLUSTER_NAME, db, resourceConfig); //TODO: Touch IS, remove this once Helix controller is listening on resource config changes. RebalanceScheduler.invokeRebalance(_dataAccessor, db); }
userDefinedPreferenceList = resourceConfig.getPreferenceLists(); if (!userDefinedPreferenceList.isEmpty()) { LOG.info("Using user defined preference list for partitions: " + userDefinedPreferenceList
/** * Determine whether the given config key is in the simple config * @param configKey The key to check whether exists * @return True if exists, otherwise false */ public boolean simpleConfigContains(String configKey) { return getRecord().getSimpleFields().containsKey(configKey); }
public ResourceConfig build() { // TODO: Reenable the validation in the future when ResourceConfig is ready. // validate(); return new ResourceConfig(_resourceId, _monitorDisabled, _numPartitions, _stateModelDefRef, _stateModelFactoryName, _numReplica, _minActiveReplica, _maxPartitionsPerInstance, _instanceGroupTag, _helixEnabled, _resourceGroupName, _resourceType, _groupRoutingEnabled, _externalViewDisabled, _rebalanceConfig, _stateTransitionTimeoutConfig, _preferenceLists, _mapFields, _p2pMessageEnabled); } }
/** * Put a set of simple configs. * * @param configsMap */ public void putSimpleConfigs(Map<String, String> configsMap) { getRecord().getSimpleFields().putAll(configsMap); }
/** * Get resource config for given resource in given cluster. * * @param clusterName * @param resourceName * * @return */ public ResourceConfig getResourceConfig(String clusterName, String resourceName) { HelixConfigScope scope = new HelixConfigScopeBuilder(ConfigScopeProperty.RESOURCE).forCluster(clusterName) .forResource(resourceName).build(); ZNRecord record = getConfigZnRecord(scope); if (record == null) { LOG.warn("No config found at " + scope.getZkPath()); return null; } return new ResourceConfig(record); }
@Override public int hashCode() { return getId().hashCode(); }
/** * Put a single simple config value. * * @param configKey * @param configVal */ public void putSimpleConfig(String configKey, String configVal) { getRecord().getSimpleFields().put(configKey, configVal); }
/** * Get resource config for given resource in given cluster. * * @param clusterName * @param resourceName * * @return */ public ResourceConfig getResourceConfig(String clusterName, String resourceName) { HelixConfigScope scope = new HelixConfigScopeBuilder(ConfigScopeProperty.RESOURCE).forCluster(clusterName) .forResource(resourceName).build(); ZNRecord record = getConfigZnRecord(scope); if (record == null) { LOG.warn("No config found at " + scope.getZkPath()); return null; } return new ResourceConfig(record); }
@Override public int hashCode() { return getId().hashCode(); }
/** * Get a single map config. * * @param configKey * @return configuration value map, or NULL if not exist. */ public Map<String, String> getMapConfig(String configKey) { return getRecord().getMapField(configKey); }