Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.druid.k8s.discovery;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.collect.ImmutableMap;
import com.google.inject.Inject;
import org.apache.druid.discovery.DiscoveryDruidNode;
import org.apache.druid.discovery.DruidNodeAnnouncer;
import org.apache.druid.discovery.NodeRole;
import org.apache.druid.guice.annotations.Json;
import org.apache.druid.java.util.common.RE;
import org.apache.druid.java.util.common.RetryUtils;
import org.apache.druid.java.util.common.StringUtils;
import org.apache.druid.java.util.common.logger.Logger;
import org.apache.druid.server.DruidNode;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
* Announcement creates following in the pod def...
*
* Labels -
* druidDiscoveryAnnouncement- = true
* druidDiscoveryAnnouncement-id-hash = hashEncodeStringForLabelValue(host:port)
* druidDiscoveryAnnouncement-cluster-identifier =
*
* Annotation -
* druidNodeInfo- = json_serialize(DiscoveryDruidNode)
*
* Note that, a node can have multiple roles e.g. coordinator can take up overlord's role as well.
*/
public class K8sDruidNodeAnnouncer implements DruidNodeAnnouncer
{
private static final Logger LOGGER = new Logger(K8sDruidNodeAnnouncer.class);
private static String POD_LABELS_PATH_PREFIX = "/metadata/labels";
private static String POD_ANNOTATIONS_PATH_PREFIX = "/metadata/annotations";
private static final String OP_ADD = "add";
private static final String OP_REMOVE = "remove";
public static final String ANNOUNCEMENT_DONE = "true";
private final ObjectMapper jsonMapper;
private final K8sDiscoveryConfig discoveryConfig;
private final PodInfo podInfo;
private final K8sApiClient k8sApiClient;
@Inject
public K8sDruidNodeAnnouncer(
PodInfo podInfo,
K8sDiscoveryConfig discoveryConfig,
K8sApiClient k8sApiClient,
@Json ObjectMapper jsonMapper
)
{
this.discoveryConfig = discoveryConfig;
this.podInfo = podInfo;
this.k8sApiClient = k8sApiClient;
this.jsonMapper = jsonMapper;
}
@Override
public void announce(DiscoveryDruidNode discoveryDruidNode)
{
LOGGER.info("Announcing DiscoveryDruidNode[%s]", discoveryDruidNode);
String roleAnnouncementLabel = getRoleAnnouncementLabel(discoveryDruidNode.getNodeRole());
String idAnnouncementLabel = getIdHashAnnouncementLabel();
String clusterIdentifierAnnouncementLabel = getClusterIdentifierAnnouncementLabel();
String infoAnnotation = getInfoAnnotation(discoveryDruidNode.getNodeRole());
try {
List