com.yahoo.vespa.config.server.application.DefaultClusterReindexingStatusClient Maven / Gradle / Ivy
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.config.server.application;
import com.yahoo.json.Jackson;
import ai.vespa.util.http.hc5.VespaAsyncHttpClientBuilder;
import com.fasterxml.jackson.databind.JsonNode;
import com.yahoo.concurrent.CompletableFutures;
import com.yahoo.concurrent.DaemonThreadFactory;
import com.yahoo.config.model.api.PortInfo;
import com.yahoo.config.model.api.ServiceInfo;
import com.yahoo.vespa.applicationmodel.ClusterId;
import com.yahoo.vespa.config.server.modelfactory.ModelResult;
import org.apache.hc.client5.http.async.methods.SimpleHttpResponse;
import org.apache.hc.client5.http.async.methods.SimpleRequestBuilder;
import org.apache.hc.client5.http.config.RequestConfig;
import org.apache.hc.client5.http.impl.async.CloseableHttpAsyncClient;
import org.apache.hc.core5.concurrent.FutureCallback;
import org.apache.hc.core5.http.HttpStatus;
import org.apache.hc.core5.reactor.IOReactorConfig;
import org.apache.hc.core5.util.Timeout;
import java.io.IOException;
import java.net.URI;
import java.time.Instant;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
import java.util.stream.Collectors;
import static com.yahoo.config.model.api.container.ContainerServiceType.CLUSTERCONTROLLER_CONTAINER;
import static com.yahoo.yolean.Exceptions.throwUnchecked;
import static com.yahoo.yolean.Exceptions.uncheck;
/**
* Retrieves reindexing status from cluster controllers over HTTP
*
* @author bjorncs
*/
public class DefaultClusterReindexingStatusClient implements ClusterReindexingStatusClient {
private final Executor executor =
Executors.newSingleThreadExecutor(new DaemonThreadFactory("cluster-controller-reindexing-client-"));
private final CloseableHttpAsyncClient httpClient = createHttpClient();
public DefaultClusterReindexingStatusClient() {
httpClient.start();
}
@Override
public Map getReindexingStatus(ModelResult application) throws IOException {
Map> clusters = clusterControllerClusters(application);
Map>> futureStatusPerCluster = new HashMap<>();
clusters.forEach((clusterId, clusterNodes) -> {
var parallelRequests = clusterNodes.stream()
.map(this::getReindexingStatus)
.toList();
CompletableFuture