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

The following examples show how to use org.apache.helix.model.InstanceConfig#containsTag() . 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 vote down vote up
@Override
public List<String> getInstancesInClusterWithTag(String clusterName, String tag) {
  String memberInstancesPath = PropertyPathBuilder.instance(clusterName);
  List<String> instances = _zkClient.getChildren(memberInstancesPath);
  List<String> result = new ArrayList<String>();

  HelixDataAccessor accessor =
      new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(_zkClient));
  PropertyKey.Builder keyBuilder = accessor.keyBuilder();

  for (String instanceName : instances) {
    InstanceConfig config = accessor.getProperty(keyBuilder.instanceConfig(instanceName));
    if (config == null) {
      throw new IllegalStateException(String
          .format("Instance %s does not have a config, cluster might be in bad state",
              instanceName));
    }
    if (config.containsTag(tag)) {
      result.add(instanceName);
    }
  }
  return result;
}
 
Example 2
Source File: BaseControllerDataProvider.java    From helix with Apache License 2.0 5 votes vote down vote up
/**
 * Return all the nodes that are tagged with given instance tag.
 * @param instanceTag The instance group tag.
 */
public Set<String> getInstancesWithTag(String instanceTag) {
  Set<String> taggedInstances = new HashSet<>();
  for (String instance : _instanceConfigCache.getPropertyMap().keySet()) {
    InstanceConfig instanceConfig = _instanceConfigCache.getPropertyByName(instance);
    if (instanceConfig != null && instanceConfig.containsTag(instanceTag)) {
      taggedInstances.add(instance);
    }
  }

  return taggedInstances;
}
 
Example 3
Source File: PinotHelixResourceManager.java    From incubator-pinot with Apache License 2.0 5 votes vote down vote up
/**
 * Add instance group tag for controller so that pinot controller can be assigned to lead controller resource.
 */
private void addInstanceGroupTagIfNeeded() {
  InstanceConfig instanceConfig = getHelixInstanceConfig(_instanceId);
  // The instanceConfig can be null when connecting as a participant while running from PerfBenchmarkRunner
  if (instanceConfig != null && !instanceConfig.containsTag(Helix.CONTROLLER_INSTANCE)) {
    LOGGER.info("Controller: {} doesn't contain group tag: {}. Adding one.", _instanceId, Helix.CONTROLLER_INSTANCE);
    instanceConfig.addTag(Helix.CONTROLLER_INSTANCE);
    HelixDataAccessor accessor = _helixZkManager.getHelixDataAccessor();
    accessor.setProperty(accessor.keyBuilder().instanceConfig(_instanceId), instanceConfig);
  }
}
 
Example 4
Source File: HelixHelper.java    From incubator-pinot with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the instances in the cluster with the given tag.
 *
 * TODO: refactor code to use this method over {@link #getInstancesWithTag(HelixManager, String)} if applicable to
 * reuse instance configs in order to reduce ZK accesses
 */
public static List<String> getInstancesWithTag(List<InstanceConfig> instanceConfigs, String tag) {
  List<String> instancesWithTag = new ArrayList<>();
  for (InstanceConfig instanceConfig : instanceConfigs) {
    if (instanceConfig.containsTag(tag)) {
      instancesWithTag.add(instanceConfig.getInstanceName());
    }
  }
  return instancesWithTag;
}
 
Example 5
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;
}