frankgh commented on code in PR #74:
URL: https://github.com/apache/cassandra-sidecar/pull/74#discussion_r1387023523
##########
adapters/base/src/main/java/org/apache/cassandra/sidecar/adapters/base/CassandraAdapter.java:
##########
@@ -90,20 +99,43 @@ public Metadata metadata()
@Nullable
public NodeSettings nodeSettings()
{
- Session activeSession = session.localCql();
- if (activeSession == null)
- {
- return null;
- }
+ ResultSet rs = executeLocal("select release_version, partitioner from
system.local");
+ if (rs == null) return null;
- Row oneResult = activeSession.execute("select release_version,
partitioner from system.local")
- .one();
+ Row oneResult = rs.one();
return new NodeSettings(oneResult.getString("release_version"),
oneResult.getString("partitioner"),
sidecarVersion);
}
+ @Override
+ public ResultSet executeLocal(Statement statement)
+ {
+ Session activeSession = cqlSessionProvider.get();
+ Metadata metadata = metadata();
+ // Both of the above log about lack of session/metadata, so no need to
log again
+ if (activeSession == null || metadata == null)
+ {
+ return null;
+ }
+
+ Host host = DriverExtensions.getHost(metadata,
localNativeTransportAddress);
+ if (host == null)
+ {
+ LOGGER.debug("Could not find host in metadata for address {}",
localNativeTransportAddress);
+ return null;
+ }
+ statement.setConsistencyLevel(ConsistencyLevel.ONE);
+ statement.setHost(host);
+ return activeSession.execute(statement);
+ }
+
+ public InetSocketAddress localNativeTransportPort()
Review Comment:
NIT
```suggestion
@Override
public InetSocketAddress localNativeTransportPort()
```
##########
src/main/java/org/apache/cassandra/sidecar/server/MainModule.java:
##########
@@ -107,6 +113,55 @@ public MainModule(Path confPath)
this.confPath = confPath;
}
+ /**
+ * Builds the {@link InstanceMetadata} from the {@link
InstanceConfiguration},
+ * a provided {@code versionProvider}, and {@code
healthCheckFrequencyMillis}.
+ *
+ * @param vertx the vertx instance
+ * @param cassandraInstance the cassandra instance configuration
+ * @param versionProvider a Cassandra version provider
+ * @param sidecarVersion the version of the Sidecar from the current
binary
+ * @param jmxConfiguration the configuration for the JMX Client
+ * @param session the CQL Session provider
+ * @return the build instance metadata object
+ */
+ private static InstanceMetadata buildInstanceMetadata(Vertx vertx,
Review Comment:
can we keep private methods at the bottom of the class?
##########
common/src/main/java/com/datastax/driver/core/DriverExtensions.java:
##########
@@ -0,0 +1,67 @@
+/*
+ * 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 com.datastax.driver.core;
+
+import java.net.InetSocketAddress;
+
+/**
+ * A collection of methods that require access to package-private members in
the datastax driver.
+ */
+public class DriverExtensions
+{
+ /**
+ * Check if a host has active connections
+ *
+ * @param host the host to check
+ * @return true if the host has active connections, false otherwise
+ */
+ public static boolean hasActiveConnections(Host host)
Review Comment:
should we annotate with visible for testing, since this is only used for
tests
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]