// Path: src/main/java/eu/luminis/elastic/LoggingFailureListener.java
// public class LoggingFailureListener extends RestClient.FailureListener {
//     private static final Logger logger = LoggerFactory.getLogger(LoggingFailureListener.class);
// 
//     @Override
//     public void onFailure(HttpHost host) {
//         logger.warn("The following host just failed {}:{}", host.getHostName(), host.getPort());
//     }
// }


import eu.luminis.elastic.LoggingFailureListener;
import org.apache.http.Header;
import org.apache.http.HttpHost;
import org.apache.http.message.BasicHeader;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.sniff.Sniffer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import javax.annotation.PreDestroy;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
        Cluster cluster = closeCluster(clusterName);
        clusters.remove(clusterName);
        return cluster;
    }

    /**
     * Returns the names of all registered clusters.
     *
     * @return The names of the registered clusters
     */
    public Set<String> listAvailableClusters() {
        return clusters.keySet();
    }

    @PreDestroy
    protected void tearDown() {
        clusters.keySet().forEach(this::closeCluster);
        clusters.clear();
    }

    private boolean exists(String clusterName) {
        return clusters.get(clusterName) != null;
    }

    private Cluster createCluster(List<String> hosts, boolean enableSniffer) {
        HttpHost[] nodes = hosts.stream().map(HttpHost::create).toArray(HttpHost[]::new);
        Header[] defaultHeaders = new Header[]{new BasicHeader(HEADER_CONTENT_TYPE_KEY, DEFAULT_HEADER_CONTENT_TYPE)};

        RestClient client = RestClient.builder(nodes)
                .setDefaultHeaders(defaultHeaders)
// Path: src/main/java/eu/luminis/elastic/LoggingFailureListener.java
// public class LoggingFailureListener extends RestClient.FailureListener {
//     private static final Logger logger = LoggerFactory.getLogger(LoggingFailureListener.class);
// 
//     @Override
//     public void onFailure(HttpHost host) {
//         logger.warn("The following host just failed {}:{}", host.getHostName(), host.getPort());
//     }
// }


// Path: src/main/java/eu/luminis/elastic/cluster/ClusterManagementService.java
import eu.luminis.elastic.LoggingFailureListener;
import org.apache.http.Header;
import org.apache.http.HttpHost;
import org.apache.http.message.BasicHeader;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.sniff.Sniffer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import javax.annotation.PreDestroy;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

        Cluster cluster = closeCluster(clusterName);
        clusters.remove(clusterName);
        return cluster;
    }

    /**
     * Returns the names of all registered clusters.
     *
     * @return The names of the registered clusters
     */
    public Set<String> listAvailableClusters() {
        return clusters.keySet();
    }

    @PreDestroy
    protected void tearDown() {
        clusters.keySet().forEach(this::closeCluster);
        clusters.clear();
    }

    private boolean exists(String clusterName) {
        return clusters.get(clusterName) != null;
    }

    private Cluster createCluster(List<String> hosts, boolean enableSniffer) {
        HttpHost[] nodes = hosts.stream().map(HttpHost::create).toArray(HttpHost[]::new);
        Header[] defaultHeaders = new Header[]{new BasicHeader(HEADER_CONTENT_TYPE_KEY, DEFAULT_HEADER_CONTENT_TYPE)};

        RestClient client = RestClient.builder(nodes)
                .setDefaultHeaders(defaultHeaders)
                .setFailureListener(new LoggingFailureListener())