Java Code Examples for org.apache.helix.model.InstanceConfig#getInstanceEnabled()

The following examples show how to use org.apache.helix.model.InstanceConfig#getInstanceEnabled() . 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: BaseControllerDataProvider.java    From helix with Apache License 2.0 6 votes vote down vote up
private void updateDisabledInstances() {
  // Move the calculating disabled instances to refresh
  _disabledInstanceForPartitionMap.clear();
  _disabledInstanceSet.clear();
  for (InstanceConfig config : _instanceConfigCache.getPropertyMap().values()) {
    Map<String, List<String>> disabledPartitionMap = config.getDisabledPartitionsMap();
    if (!config.getInstanceEnabled()) {
      _disabledInstanceSet.add(config.getInstanceName());
    }
    for (String resource : disabledPartitionMap.keySet()) {
      if (!_disabledInstanceForPartitionMap.containsKey(resource)) {
        _disabledInstanceForPartitionMap.put(resource, new HashMap<String, Set<String>>());
      }
      for (String partition : disabledPartitionMap.get(resource)) {
        if (!_disabledInstanceForPartitionMap.get(resource).containsKey(partition)) {
          _disabledInstanceForPartitionMap.get(resource).put(partition, new HashSet<String>());
        }
        _disabledInstanceForPartitionMap.get(resource).get(partition)
            .add(config.getInstanceName());
      }
    }
  }
  if (_clusterConfig != null && _clusterConfig.getDisabledInstances() != null) {
    _disabledInstanceSet.addAll(_clusterConfig.getDisabledInstances().keySet());
  }
}
 
Example 2
Source File: InstanceValidationUtil.java    From helix with Apache License 2.0 6 votes vote down vote up
/**
 * Method to check if the instance is enabled by configuration
 * @param dataAccessor
 * @param instanceName
 * @return
 */
public static boolean isEnabled(HelixDataAccessor dataAccessor, String instanceName) {
  PropertyKey.Builder propertyKeyBuilder = dataAccessor.keyBuilder();
  InstanceConfig instanceConfig = dataAccessor.getProperty(propertyKeyBuilder.instanceConfig(instanceName));
  ClusterConfig clusterConfig = dataAccessor.getProperty(propertyKeyBuilder.clusterConfig());
  // TODO deprecate instance level config checks once migrated the enable status to cluster config only
  if (instanceConfig == null || clusterConfig == null) {
    throw new HelixException("InstanceConfig or ClusterConfig is NULL");
  }

  boolean enabledInInstanceConfig = instanceConfig.getInstanceEnabled();
  Map<String, String> disabledInstances = clusterConfig.getDisabledInstances();
  boolean enabledInClusterConfig =
      disabledInstances == null || !disabledInstances.keySet().contains(instanceName);
  return enabledInClusterConfig && enabledInInstanceConfig;
}
 
Example 3
Source File: DelayedRebalanceUtil.java    From helix with Apache License 2.0 5 votes vote down vote up
/**
 * @return The time when an offline or disabled instance should be treated as inactive.
 * Return -1 if it is inactive now.
 */
private static long getInactiveTime(String instance, Set<String> liveInstances, Long offlineTime,
    long delay, InstanceConfig instanceConfig, ClusterConfig clusterConfig) {
  long inactiveTime = Long.MAX_VALUE;

  // check the time instance went offline.
  if (!liveInstances.contains(instance)) {
    if (offlineTime != null && offlineTime > 0 && offlineTime + delay < inactiveTime) {
      inactiveTime = offlineTime + delay;
    }
  }

  // check the time instance got disabled.
  if (!instanceConfig.getInstanceEnabled() || (clusterConfig.getDisabledInstances() != null
      && clusterConfig.getDisabledInstances().containsKey(instance))) {
    long disabledTime = instanceConfig.getInstanceEnabledTime();
    if (clusterConfig.getDisabledInstances() != null && clusterConfig.getDisabledInstances()
        .containsKey(instance)) {
      // Update batch disable time
      long batchDisableTime = Long.parseLong(clusterConfig.getDisabledInstances().get(instance));
      if (disabledTime == -1 || disabledTime > batchDisableTime) {
        disabledTime = batchDisableTime;
      }
    }
    if (disabledTime > 0 && disabledTime + delay < inactiveTime) {
      inactiveTime = disabledTime + delay;
    }
  }

  if (inactiveTime == Long.MAX_VALUE) {
    return -1;
  }

  return inactiveTime;
}
 
Example 4
Source File: HelixHelper.java    From incubator-pinot with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the enabled instances in the cluster with the given tag.
 *
 * TODO: refactor code to use this method over {@link #getEnabledInstancesWithTag(HelixManager, String)} if applicable
 * to reuse instance configs in order to reduce ZK accesses
 */
public static List<String> getEnabledInstancesWithTag(List<InstanceConfig> instanceConfigs, String tag) {
  List<String> enabledInstancesWithTag = new ArrayList<>();
  for (InstanceConfig instanceConfig : instanceConfigs) {
    if (instanceConfig.getInstanceEnabled() && instanceConfig.containsTag(tag)) {
      enabledInstancesWithTag.add(instanceConfig.getInstanceName());
    }
  }
  return enabledInstancesWithTag;
}
 
Example 5
Source File: Topology.java    From helix with Apache License 2.0 4 votes vote down vote up
private boolean isInstanceEnabled(ClusterConfig clusterConfig, String instanceName,
    InstanceConfig instanceConfig) {
  return (instanceConfig.getInstanceEnabled() && (clusterConfig.getDisabledInstances() == null
      || !clusterConfig.getDisabledInstances().containsKey(instanceName)));
}