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

The following examples show how to use org.apache.helix.model.InstanceConfig#getTags() . 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: PinotHelixResourceManager.java    From incubator-pinot with Apache License 2.0 5 votes vote down vote up
public Set<String> getAllBrokerTenantNames() {
  Set<String> tenantSet = new HashSet<>();
  List<InstanceConfig> instanceConfigs = getAllHelixInstanceConfigs();
  for (InstanceConfig instanceConfig : instanceConfigs) {
    for (String tag : instanceConfig.getTags()) {
      if (TagNameUtils.isBrokerTag(tag)) {
        tenantSet.add(TagNameUtils.getTenantFromTag(tag));
      }
    }
  }
  return tenantSet;
}
 
Example 2
Source File: PinotHelixResourceManager.java    From incubator-pinot with Apache License 2.0 5 votes vote down vote up
public Set<String> getAllServerTenantNames() {
  Set<String> tenantSet = new HashSet<>();
  List<InstanceConfig> instanceConfigs = getAllHelixInstanceConfigs();
  for (InstanceConfig instanceConfig : instanceConfigs) {
    for (String tag : instanceConfig.getTags()) {
      if (TagNameUtils.isServerTag(tag)) {
        tenantSet.add(TagNameUtils.getTenantFromTag(tag));
      }
    }
  }
  return tenantSet;
}
 
Example 3
Source File: HelixBrokerStarter.java    From incubator-pinot with Apache License 2.0 5 votes vote down vote up
private void addInstanceTagIfNeeded() {
  InstanceConfig instanceConfig =
      _helixDataAccessor.getProperty(_helixDataAccessor.keyBuilder().instanceConfig(_brokerId));
  List<String> instanceTags = instanceConfig.getTags();
  if (instanceTags == null || instanceTags.isEmpty()) {
    if (ZKMetadataProvider.getClusterTenantIsolationEnabled(_propertyStore)) {
      _helixAdmin.addInstanceTag(_clusterName, _brokerId, TagNameUtils.getBrokerTagForTenant(null));
    } else {
      _helixAdmin.addInstanceTag(_clusterName, _brokerId, Helix.UNTAGGED_BROKER_INSTANCE);
    }
  }
}
 
Example 4
Source File: InstancesResource.java    From helix with Apache License 2.0 4 votes vote down vote up
StringRepresentation getInstancesRepresentation(String clusterName)
    throws JsonGenerationException, JsonMappingException, IOException {
  ZkClient zkClient = (ZkClient) getContext().getAttributes().get(RestAdminApplication.ZKCLIENT);

  HelixDataAccessor accessor =
      ClusterRepresentationUtil.getClusterDataAccessor(zkClient, clusterName);
  Map<String, LiveInstance> liveInstancesMap =
      accessor.getChildValuesMap(accessor.keyBuilder().liveInstances());
  Map<String, InstanceConfig> instanceConfigsMap =
      accessor.getChildValuesMap(accessor.keyBuilder().instanceConfigs());

  Map<String, List<String>> tagInstanceLists = new TreeMap<String, List<String>>();

  for (String instanceName : instanceConfigsMap.keySet()) {
    boolean isAlive = liveInstancesMap.containsKey(instanceName);
    instanceConfigsMap.get(instanceName).getRecord().setSimpleField("Alive", isAlive + "");
    InstanceConfig config = instanceConfigsMap.get(instanceName);
    for (String tag : config.getTags()) {
      if (!tagInstanceLists.containsKey(tag)) {
        tagInstanceLists.put(tag, new LinkedList<String>());
      }
      if (!tagInstanceLists.get(tag).contains(instanceName)) {
        tagInstanceLists.get(tag).add(instanceName);
      }
    }
  }

  // Wrap raw data into an object, then serialize it
  List<ZNRecord> recordList = Lists.newArrayList();
  for (InstanceConfig instanceConfig : instanceConfigsMap.values()) {
    recordList.add(instanceConfig.getRecord());
  }
  ListInstancesWrapper wrapper = new ListInstancesWrapper();
  wrapper.instanceInfo = recordList;
  wrapper.tagInfo = tagInstanceLists;
  StringRepresentation representation =
      new StringRepresentation(ClusterRepresentationUtil.ObjectToJson(wrapper),
          MediaType.APPLICATION_JSON);

  return representation;
}
 
Example 5
Source File: PinotHelixResourceManager.java    From incubator-pinot with Apache License 2.0 4 votes vote down vote up
private List<String> getTagsForInstance(String instanceName) {
  InstanceConfig config = _helixDataAccessor.getProperty(_keyBuilder.instanceConfig(instanceName));
  return config.getTags();
}
 
Example 6
Source File: HelixServerStarter.java    From incubator-pinot with Apache License 2.0 4 votes vote down vote up
private void updateInstanceConfigIfNeeded(String host, int port) {
  InstanceConfig instanceConfig = _helixAdmin.getInstanceConfig(_helixClusterName, _instanceId);
  boolean needToUpdateInstanceConfig = false;

  // Add default instance tags if not exist
  List<String> instanceTags = instanceConfig.getTags();
  if (instanceTags == null || instanceTags.size() == 0) {
    if (ZKMetadataProvider.getClusterTenantIsolationEnabled(_helixManager.getHelixPropertyStore())) {
      instanceConfig.addTag(TagNameUtils.getOfflineTagForTenant(null));
      instanceConfig.addTag(TagNameUtils.getRealtimeTagForTenant(null));
    } else {
      instanceConfig.addTag(UNTAGGED_SERVER_INSTANCE);
    }
    needToUpdateInstanceConfig = true;
  }

  // Update host and port if needed
  if (!host.equals(instanceConfig.getHostName())) {
    instanceConfig.setHostName(host);
    needToUpdateInstanceConfig = true;
  }
  String portStr = Integer.toString(port);
  if (!portStr.equals(instanceConfig.getPort())) {
    instanceConfig.setPort(portStr);
    needToUpdateInstanceConfig = true;
  }

  if (needToUpdateInstanceConfig) {
    LOGGER.info("Updating instance config for instance: {} with instance tags: {}, host: {}, port: {}", _instanceId,
        instanceTags, host, port);
  } else {
    LOGGER.info("Instance config for instance: {} has instance tags: {}, host: {}, port: {}, no need to update",
        _instanceId, instanceTags, host, port);
    return;
  }

  // NOTE: Use HelixDataAccessor.setProperty() instead of HelixAdmin.setInstanceConfig() because the latter explicitly
  // forbids instance host/port modification
  HelixDataAccessor helixDataAccessor = _helixManager.getHelixDataAccessor();
  Preconditions.checkState(
      helixDataAccessor.setProperty(helixDataAccessor.keyBuilder().instanceConfig(_instanceId), instanceConfig),
      "Failed to update instance config");
}