sarankk commented on code in PR #189:
URL: https://github.com/apache/cassandra-sidecar/pull/189#discussion_r1970671361


##########
server/src/main/java/org/apache/cassandra/sidecar/utils/SidecarClientProvider.java:
##########
@@ -0,0 +1,166 @@
+/*
+ * 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.cassandra.sidecar.utils;
+
+import java.util.ArrayList;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.inject.Inject;
+import com.google.inject.Provider;
+import com.google.inject.Singleton;
+import io.vertx.core.Promise;
+import io.vertx.core.Vertx;
+import io.vertx.core.http.HttpClient;
+import io.vertx.core.net.JksOptions;
+import io.vertx.core.net.OpenSSLEngineOptions;
+import io.vertx.ext.web.client.WebClient;
+import io.vertx.ext.web.client.WebClientOptions;
+import org.apache.cassandra.sidecar.client.HttpClientConfig;
+import org.apache.cassandra.sidecar.client.SidecarClient;
+import org.apache.cassandra.sidecar.client.SidecarClientConfig;
+import org.apache.cassandra.sidecar.client.SidecarClientConfigImpl;
+import org.apache.cassandra.sidecar.client.SidecarClientVertxRequestExecutor;
+import org.apache.cassandra.sidecar.client.SimpleSidecarInstancesProvider;
+import org.apache.cassandra.sidecar.client.VertxHttpClient;
+import org.apache.cassandra.sidecar.client.retry.ExponentialBackoffRetryPolicy;
+import org.apache.cassandra.sidecar.client.retry.RetryPolicy;
+import org.apache.cassandra.sidecar.common.client.SidecarInstance;
+import org.apache.cassandra.sidecar.common.client.SidecarInstanceImpl;
+import org.apache.cassandra.sidecar.common.server.utils.SidecarVersionProvider;
+import org.apache.cassandra.sidecar.config.SidecarClientConfiguration;
+import org.apache.cassandra.sidecar.config.SidecarConfiguration;
+
+/**
+ * Provider class for retrieving the singleton {@link SidecarClient} instance
+ */
+@Singleton
+public class SidecarClientProvider implements Provider<SidecarClient>
+{
+    private static final Logger LOGGER = 
LoggerFactory.getLogger(SidecarClientProvider.class);
+    private final Vertx vertx;
+    private final SidecarClientConfiguration clientConfig;
+    private final SidecarVersionProvider sidecarVersionProvider;
+    private final SidecarClient client;
+
+    @Inject
+    public SidecarClientProvider(Vertx vertx,
+                                 SidecarConfiguration sidecarConfiguration,
+                                 SidecarVersionProvider sidecarVersionProvider)
+    {
+        this.vertx = vertx;
+        this.clientConfig = sidecarConfiguration.sidecarClientConfiguration();
+        this.sidecarVersionProvider = sidecarVersionProvider;
+        this.client = initializeSidecarClient();
+    }
+
+    @Override
+    public SidecarClient get()
+    {
+        return client;
+    }
+
+    public void close(Promise<Void> completion)
+    {
+        LOGGER.info("Closing Sidecar Client...");
+        try
+        {
+            client.close();
+            Thread.sleep(100);
+            completion.complete();
+        }
+        catch (Throwable throwable)
+        {
+            completion.fail(throwable);
+        }
+    }
+
+    private SidecarClient initializeSidecarClient()
+    {
+        WebClientOptions webClientOptions = webClientOptions();
+        HttpClient httpClient = vertx.createHttpClient(webClientOptions);
+        WebClient webClient = WebClient.wrap(httpClient, webClientOptions);
+
+        HttpClientConfig httpClientConfig = new HttpClientConfig.Builder<>()
+                                            .ssl(webClientOptions().isSsl())
+                                            
.timeoutMillis(clientConfig.requestTimeout().toMillis())
+                                            
.idleTimeoutMillis(clientConfig.requestIdleTimeout().toIntMillis())
+                                            .userAgent("cassandra-sidecar/" + 
sidecarVersionProvider.sidecarVersion())
+                                            .build();
+
+        VertxHttpClient vertxHttpClient = new VertxHttpClient(vertx, 
webClient, httpClientConfig);

Review Comment:
   If we add missing settings in `HttpClientConfig` we dont have to create 
`WebClient` separately, we can directly call `VertxHttpClient vertxHttpClient = 
new VertxHttpClient(vertx, httpClientConfig)` 



##########
server/src/main/java/org/apache/cassandra/sidecar/utils/SidecarClientProvider.java:
##########
@@ -0,0 +1,166 @@
+/*
+ * 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.cassandra.sidecar.utils;
+
+import java.util.ArrayList;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.inject.Inject;
+import com.google.inject.Provider;
+import com.google.inject.Singleton;
+import io.vertx.core.Promise;
+import io.vertx.core.Vertx;
+import io.vertx.core.http.HttpClient;
+import io.vertx.core.net.JksOptions;
+import io.vertx.core.net.OpenSSLEngineOptions;
+import io.vertx.ext.web.client.WebClient;
+import io.vertx.ext.web.client.WebClientOptions;
+import org.apache.cassandra.sidecar.client.HttpClientConfig;
+import org.apache.cassandra.sidecar.client.SidecarClient;
+import org.apache.cassandra.sidecar.client.SidecarClientConfig;
+import org.apache.cassandra.sidecar.client.SidecarClientConfigImpl;
+import org.apache.cassandra.sidecar.client.SidecarClientVertxRequestExecutor;
+import org.apache.cassandra.sidecar.client.SimpleSidecarInstancesProvider;
+import org.apache.cassandra.sidecar.client.VertxHttpClient;
+import org.apache.cassandra.sidecar.client.retry.ExponentialBackoffRetryPolicy;
+import org.apache.cassandra.sidecar.client.retry.RetryPolicy;
+import org.apache.cassandra.sidecar.common.client.SidecarInstance;
+import org.apache.cassandra.sidecar.common.client.SidecarInstanceImpl;
+import org.apache.cassandra.sidecar.common.server.utils.SidecarVersionProvider;
+import org.apache.cassandra.sidecar.config.SidecarClientConfiguration;
+import org.apache.cassandra.sidecar.config.SidecarConfiguration;
+
+/**
+ * Provider class for retrieving the singleton {@link SidecarClient} instance
+ */
+@Singleton
+public class SidecarClientProvider implements Provider<SidecarClient>
+{
+    private static final Logger LOGGER = 
LoggerFactory.getLogger(SidecarClientProvider.class);
+    private final Vertx vertx;
+    private final SidecarClientConfiguration clientConfig;
+    private final SidecarVersionProvider sidecarVersionProvider;
+    private final SidecarClient client;
+
+    @Inject
+    public SidecarClientProvider(Vertx vertx,
+                                 SidecarConfiguration sidecarConfiguration,
+                                 SidecarVersionProvider sidecarVersionProvider)
+    {
+        this.vertx = vertx;
+        this.clientConfig = sidecarConfiguration.sidecarClientConfiguration();
+        this.sidecarVersionProvider = sidecarVersionProvider;
+        this.client = initializeSidecarClient();
+    }
+
+    @Override
+    public SidecarClient get()
+    {
+        return client;
+    }
+
+    public void close(Promise<Void> completion)
+    {
+        LOGGER.info("Closing Sidecar Client...");
+        try
+        {
+            client.close();
+            Thread.sleep(100);
+            completion.complete();
+        }
+        catch (Throwable throwable)
+        {
+            completion.fail(throwable);
+        }
+    }
+
+    private SidecarClient initializeSidecarClient()
+    {
+        WebClientOptions webClientOptions = webClientOptions();
+        HttpClient httpClient = vertx.createHttpClient(webClientOptions);
+        WebClient webClient = WebClient.wrap(httpClient, webClientOptions);
+
+        HttpClientConfig httpClientConfig = new HttpClientConfig.Builder<>()
+                                            .ssl(webClientOptions().isSsl())
+                                            
.timeoutMillis(clientConfig.requestTimeout().toMillis())
+                                            
.idleTimeoutMillis(clientConfig.requestIdleTimeout().toIntMillis())
+                                            .userAgent("cassandra-sidecar/" + 
sidecarVersionProvider.sidecarVersion())
+                                            .build();
+
+        VertxHttpClient vertxHttpClient = new VertxHttpClient(vertx, 
webClient, httpClientConfig);
+        RetryPolicy defaultRetryPolicy = new 
ExponentialBackoffRetryPolicy(clientConfig.maxRetries(),
+                                                                           
clientConfig.retryDelay().toMillis(),
+                                                                           
clientConfig.retryDelay().toMillis());
+        SidecarClientVertxRequestExecutor requestExecutor = new 
SidecarClientVertxRequestExecutor(vertxHttpClient);
+        SidecarInstance instance = new 
SidecarInstanceImpl(webClientOptions.getDefaultHost(), 
webClientOptions.getDefaultPort());
+        ArrayList<SidecarInstance> instances = new ArrayList<>();
+        instances.add(instance);
+        SimpleSidecarInstancesProvider instancesProvider = new 
SimpleSidecarInstancesProvider(instances);
+
+        SidecarClientConfig config = SidecarClientConfigImpl.builder()
+                                                            
.retryDelayMillis(clientConfig.retryDelay().toMillis())
+                                                            
.maxRetryDelayMillis(clientConfig.maxRetryDelay().toMillis())
+                                                            
.maxRetries(clientConfig.maxRetries())
+                                                            .build();
+
+        return new SidecarClient(instancesProvider,
+                                 requestExecutor,
+                                 config,
+                                 defaultRetryPolicy);
+    }
+
+    private WebClientOptions webClientOptions()
+    {
+        WebClientOptions options = new WebClientOptions();
+        options.getPoolOptions()
+               
.setCleanerPeriod(clientConfig.connectionPoolCleanerPeriod().toIntMillis())

Review Comment:
   We should add these client settings to `HttpClientConfig`, that way we dont 
have to create `WebClientOptions separately`, also `VertxHttpClient` takes care 
of setting ssl config, we can use it



##########
server/src/main/java/org/apache/cassandra/sidecar/utils/SidecarClientProvider.java:
##########
@@ -0,0 +1,166 @@
+/*
+ * 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.cassandra.sidecar.utils;
+
+import java.util.ArrayList;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.inject.Inject;
+import com.google.inject.Provider;
+import com.google.inject.Singleton;
+import io.vertx.core.Promise;
+import io.vertx.core.Vertx;
+import io.vertx.core.http.HttpClient;
+import io.vertx.core.net.JksOptions;
+import io.vertx.core.net.OpenSSLEngineOptions;
+import io.vertx.ext.web.client.WebClient;
+import io.vertx.ext.web.client.WebClientOptions;
+import org.apache.cassandra.sidecar.client.HttpClientConfig;
+import org.apache.cassandra.sidecar.client.SidecarClient;
+import org.apache.cassandra.sidecar.client.SidecarClientConfig;
+import org.apache.cassandra.sidecar.client.SidecarClientConfigImpl;
+import org.apache.cassandra.sidecar.client.SidecarClientVertxRequestExecutor;
+import org.apache.cassandra.sidecar.client.SimpleSidecarInstancesProvider;
+import org.apache.cassandra.sidecar.client.VertxHttpClient;
+import org.apache.cassandra.sidecar.client.retry.ExponentialBackoffRetryPolicy;
+import org.apache.cassandra.sidecar.client.retry.RetryPolicy;
+import org.apache.cassandra.sidecar.common.client.SidecarInstance;
+import org.apache.cassandra.sidecar.common.client.SidecarInstanceImpl;
+import org.apache.cassandra.sidecar.common.server.utils.SidecarVersionProvider;
+import org.apache.cassandra.sidecar.config.SidecarClientConfiguration;
+import org.apache.cassandra.sidecar.config.SidecarConfiguration;
+
+/**
+ * Provider class for retrieving the singleton {@link SidecarClient} instance
+ */
+@Singleton
+public class SidecarClientProvider implements Provider<SidecarClient>
+{
+    private static final Logger LOGGER = 
LoggerFactory.getLogger(SidecarClientProvider.class);
+    private final Vertx vertx;
+    private final SidecarClientConfiguration clientConfig;
+    private final SidecarVersionProvider sidecarVersionProvider;
+    private final SidecarClient client;
+
+    @Inject
+    public SidecarClientProvider(Vertx vertx,
+                                 SidecarConfiguration sidecarConfiguration,
+                                 SidecarVersionProvider sidecarVersionProvider)
+    {
+        this.vertx = vertx;
+        this.clientConfig = sidecarConfiguration.sidecarClientConfiguration();
+        this.sidecarVersionProvider = sidecarVersionProvider;
+        this.client = initializeSidecarClient();
+    }
+
+    @Override
+    public SidecarClient get()
+    {
+        return client;
+    }
+
+    public void close(Promise<Void> completion)
+    {
+        LOGGER.info("Closing Sidecar Client...");
+        try
+        {
+            client.close();
+            Thread.sleep(100);
+            completion.complete();
+        }
+        catch (Throwable throwable)
+        {
+            completion.fail(throwable);
+        }
+    }
+
+    private SidecarClient initializeSidecarClient()
+    {
+        WebClientOptions webClientOptions = webClientOptions();
+        HttpClient httpClient = vertx.createHttpClient(webClientOptions);
+        WebClient webClient = WebClient.wrap(httpClient, webClientOptions);
+
+        HttpClientConfig httpClientConfig = new HttpClientConfig.Builder<>()
+                                            .ssl(webClientOptions().isSsl())
+                                            
.timeoutMillis(clientConfig.requestTimeout().toMillis())
+                                            
.idleTimeoutMillis(clientConfig.requestIdleTimeout().toIntMillis())
+                                            .userAgent("cassandra-sidecar/" + 
sidecarVersionProvider.sidecarVersion())
+                                            .build();
+
+        VertxHttpClient vertxHttpClient = new VertxHttpClient(vertx, 
webClient, httpClientConfig);
+        RetryPolicy defaultRetryPolicy = new 
ExponentialBackoffRetryPolicy(clientConfig.maxRetries(),
+                                                                           
clientConfig.retryDelay().toMillis(),
+                                                                           
clientConfig.retryDelay().toMillis());
+        SidecarClientVertxRequestExecutor requestExecutor = new 
SidecarClientVertxRequestExecutor(vertxHttpClient);
+        SidecarInstance instance = new 
SidecarInstanceImpl(webClientOptions.getDefaultHost(), 
webClientOptions.getDefaultPort());
+        ArrayList<SidecarInstance> instances = new ArrayList<>();
+        instances.add(instance);

Review Comment:
   We seem to create `SidecarClient` with random host and port and call 
`peerhealth` with actual instance we want to check health for. Should we 
instead create `SidecarClient` with instance of interest and directly call 
`sidecarHealth` ? this way we dont need `peerHealth` method and need to pass 
default host and port. We can maintain `Map<SidecarInstance, SidecarClient>` to 
get `Sidecarclient` specific for an instance
   



##########
server/src/main/java/org/apache/cassandra/sidecar/utils/SidecarClientProvider.java:
##########
@@ -0,0 +1,166 @@
+/*
+ * 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.cassandra.sidecar.utils;
+
+import java.util.ArrayList;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.inject.Inject;
+import com.google.inject.Provider;
+import com.google.inject.Singleton;
+import io.vertx.core.Promise;
+import io.vertx.core.Vertx;
+import io.vertx.core.http.HttpClient;
+import io.vertx.core.net.JksOptions;
+import io.vertx.core.net.OpenSSLEngineOptions;
+import io.vertx.ext.web.client.WebClient;
+import io.vertx.ext.web.client.WebClientOptions;
+import org.apache.cassandra.sidecar.client.HttpClientConfig;
+import org.apache.cassandra.sidecar.client.SidecarClient;
+import org.apache.cassandra.sidecar.client.SidecarClientConfig;
+import org.apache.cassandra.sidecar.client.SidecarClientConfigImpl;
+import org.apache.cassandra.sidecar.client.SidecarClientVertxRequestExecutor;
+import org.apache.cassandra.sidecar.client.SimpleSidecarInstancesProvider;
+import org.apache.cassandra.sidecar.client.VertxHttpClient;
+import org.apache.cassandra.sidecar.client.retry.ExponentialBackoffRetryPolicy;
+import org.apache.cassandra.sidecar.client.retry.RetryPolicy;
+import org.apache.cassandra.sidecar.common.client.SidecarInstance;
+import org.apache.cassandra.sidecar.common.client.SidecarInstanceImpl;
+import org.apache.cassandra.sidecar.common.server.utils.SidecarVersionProvider;
+import org.apache.cassandra.sidecar.config.SidecarClientConfiguration;
+import org.apache.cassandra.sidecar.config.SidecarConfiguration;
+
+/**
+ * Provider class for retrieving the singleton {@link SidecarClient} instance
+ */
+@Singleton
+public class SidecarClientProvider implements Provider<SidecarClient>
+{
+    private static final Logger LOGGER = 
LoggerFactory.getLogger(SidecarClientProvider.class);
+    private final Vertx vertx;
+    private final SidecarClientConfiguration clientConfig;
+    private final SidecarVersionProvider sidecarVersionProvider;
+    private final SidecarClient client;
+
+    @Inject
+    public SidecarClientProvider(Vertx vertx,
+                                 SidecarConfiguration sidecarConfiguration,
+                                 SidecarVersionProvider sidecarVersionProvider)
+    {
+        this.vertx = vertx;
+        this.clientConfig = sidecarConfiguration.sidecarClientConfiguration();
+        this.sidecarVersionProvider = sidecarVersionProvider;
+        this.client = initializeSidecarClient();
+    }
+
+    @Override
+    public SidecarClient get()
+    {
+        return client;
+    }
+
+    public void close(Promise<Void> completion)
+    {
+        LOGGER.info("Closing Sidecar Client...");
+        try
+        {
+            client.close();
+            Thread.sleep(100);
+            completion.complete();
+        }
+        catch (Throwable throwable)
+        {
+            completion.fail(throwable);
+        }
+    }
+
+    private SidecarClient initializeSidecarClient()
+    {
+        WebClientOptions webClientOptions = webClientOptions();
+        HttpClient httpClient = vertx.createHttpClient(webClientOptions);
+        WebClient webClient = WebClient.wrap(httpClient, webClientOptions);
+
+        HttpClientConfig httpClientConfig = new HttpClientConfig.Builder<>()
+                                            .ssl(webClientOptions().isSsl())
+                                            
.timeoutMillis(clientConfig.requestTimeout().toMillis())
+                                            
.idleTimeoutMillis(clientConfig.requestIdleTimeout().toIntMillis())
+                                            .userAgent("cassandra-sidecar/" + 
sidecarVersionProvider.sidecarVersion())
+                                            .build();
+
+        VertxHttpClient vertxHttpClient = new VertxHttpClient(vertx, 
webClient, httpClientConfig);
+        RetryPolicy defaultRetryPolicy = new 
ExponentialBackoffRetryPolicy(clientConfig.maxRetries(),
+                                                                           
clientConfig.retryDelay().toMillis(),
+                                                                           
clientConfig.retryDelay().toMillis());
+        SidecarClientVertxRequestExecutor requestExecutor = new 
SidecarClientVertxRequestExecutor(vertxHttpClient);
+        SidecarInstance instance = new 
SidecarInstanceImpl(webClientOptions.getDefaultHost(), 
webClientOptions.getDefaultPort());

Review Comment:
   Since we are not setting default host and port, should we avoid getting 
those values?



##########
server/src/main/java/org/apache/cassandra/sidecar/coordination/SidecarPeerProvider.java:
##########
@@ -0,0 +1,34 @@
+/*
+ * 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.cassandra.sidecar.coordination;
+
+import java.util.Set;
+
+import org.apache.cassandra.sidecar.common.client.SidecarInstance;
+
+/**
+ * Provides a set of Sidecar peers to monitor and failover when they go DOWN
+ */
+public interface SidecarPeerProvider
+{
+    /**
+     * @return a set of Sidecar peers to monitor

Review Comment:
   Nit: shall we have `@return a set of Sidecar peers`



##########
server/src/main/java/org/apache/cassandra/sidecar/utils/SidecarClientProvider.java:
##########
@@ -0,0 +1,166 @@
+/*
+ * 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.cassandra.sidecar.utils;
+
+import java.util.ArrayList;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.inject.Inject;
+import com.google.inject.Provider;
+import com.google.inject.Singleton;
+import io.vertx.core.Promise;
+import io.vertx.core.Vertx;
+import io.vertx.core.http.HttpClient;
+import io.vertx.core.net.JksOptions;
+import io.vertx.core.net.OpenSSLEngineOptions;
+import io.vertx.ext.web.client.WebClient;
+import io.vertx.ext.web.client.WebClientOptions;
+import org.apache.cassandra.sidecar.client.HttpClientConfig;
+import org.apache.cassandra.sidecar.client.SidecarClient;
+import org.apache.cassandra.sidecar.client.SidecarClientConfig;
+import org.apache.cassandra.sidecar.client.SidecarClientConfigImpl;
+import org.apache.cassandra.sidecar.client.SidecarClientVertxRequestExecutor;
+import org.apache.cassandra.sidecar.client.SimpleSidecarInstancesProvider;
+import org.apache.cassandra.sidecar.client.VertxHttpClient;
+import org.apache.cassandra.sidecar.client.retry.ExponentialBackoffRetryPolicy;
+import org.apache.cassandra.sidecar.client.retry.RetryPolicy;
+import org.apache.cassandra.sidecar.common.client.SidecarInstance;
+import org.apache.cassandra.sidecar.common.client.SidecarInstanceImpl;
+import org.apache.cassandra.sidecar.common.server.utils.SidecarVersionProvider;
+import org.apache.cassandra.sidecar.config.SidecarClientConfiguration;
+import org.apache.cassandra.sidecar.config.SidecarConfiguration;
+
+/**
+ * Provider class for retrieving the singleton {@link SidecarClient} instance
+ */
+@Singleton
+public class SidecarClientProvider implements Provider<SidecarClient>
+{
+    private static final Logger LOGGER = 
LoggerFactory.getLogger(SidecarClientProvider.class);
+    private final Vertx vertx;
+    private final SidecarClientConfiguration clientConfig;
+    private final SidecarVersionProvider sidecarVersionProvider;
+    private final SidecarClient client;
+
+    @Inject
+    public SidecarClientProvider(Vertx vertx,
+                                 SidecarConfiguration sidecarConfiguration,
+                                 SidecarVersionProvider sidecarVersionProvider)
+    {
+        this.vertx = vertx;
+        this.clientConfig = sidecarConfiguration.sidecarClientConfiguration();
+        this.sidecarVersionProvider = sidecarVersionProvider;
+        this.client = initializeSidecarClient();
+    }
+
+    @Override
+    public SidecarClient get()
+    {
+        return client;
+    }
+
+    public void close(Promise<Void> completion)
+    {
+        LOGGER.info("Closing Sidecar Client...");
+        try
+        {
+            client.close();
+            Thread.sleep(100);
+            completion.complete();
+        }
+        catch (Throwable throwable)
+        {
+            completion.fail(throwable);
+        }
+    }
+
+    private SidecarClient initializeSidecarClient()
+    {
+        WebClientOptions webClientOptions = webClientOptions();
+        HttpClient httpClient = vertx.createHttpClient(webClientOptions);
+        WebClient webClient = WebClient.wrap(httpClient, webClientOptions);

Review Comment:
   `WebClient webClient = WebClient.create(vertx, webClientOptions)` we can do 
this in place of wrapping `HttpClient` 



##########
server/src/main/java/org/apache/cassandra/sidecar/server/Server.java:
##########
@@ -189,6 +197,7 @@ public Future<CompositeFuture> close()
         });
 
         return Future.all(closingFutures)
+

Review Comment:
   Nit: extra line



##########
server/src/main/java/org/apache/cassandra/sidecar/coordination/SidecarPeerProvider.java:
##########
@@ -0,0 +1,34 @@
+/*
+ * 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.cassandra.sidecar.coordination;
+
+import java.util.Set;
+
+import org.apache.cassandra.sidecar.common.client.SidecarInstance;
+
+/**
+ * Provides a set of Sidecar peers to monitor and failover when they go DOWN

Review Comment:
   Since `SidecarPeerProvider` can be used for other tasks other than health 
monitor, should we have `Provides a set of peers of current Sidecar` in comment?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: pr-unsubscr...@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscr...@cassandra.apache.org
For additional commands, e-mail: pr-h...@cassandra.apache.org

Reply via email to