use of com.datastax.oss.driver.shaded.guava.common.collect.ImmutableSet in project java-driver by datastax.
the class DefaultTopologyMonitor method nodeInfoBuilder.
/**
* Creates a {@link DefaultNodeInfo.Builder} instance from the given row.
*
* @param broadcastRpcAddress this is a parameter only because we already have it when we come
* from {@link #findInPeers(AdminResult, InetSocketAddress, EndPoint)}. Callers that don't
* already have it can use {@link #getBroadcastRpcAddress}. For the control host, this can be
* null; if this node is a peer however, this cannot be null, since we use that address to
* create the node's endpoint. Callers can use {@link #isPeerValid(AdminRow)} to check that
* before calling this method.
* @param localEndPoint the control node endpoint that was used to query the node's system tables.
* This is a parameter because it would be racy to call {@code
* controlConnection.channel().getEndPoint()} from within this method, as the control
* connection may have changed its channel since. So this parameter must be provided by the
* caller.
*/
@NonNull
protected DefaultNodeInfo.Builder nodeInfoBuilder(@NonNull AdminRow row, @Nullable InetSocketAddress broadcastRpcAddress, @NonNull EndPoint localEndPoint) {
EndPoint endPoint = buildNodeEndPoint(row, broadcastRpcAddress, localEndPoint);
// in system.local
InetAddress broadcastInetAddress = row.getInetAddress("broadcast_address");
if (broadcastInetAddress == null) {
// in system.peers or system.peers_v2
broadcastInetAddress = row.getInetAddress("peer");
}
Integer broadcastPort = 0;
if (row.contains("broadcast_port")) {
// system.local for Cassandra >= 4.0
broadcastPort = row.getInteger("broadcast_port");
} else if (row.contains("peer_port")) {
// system.peers_v2
broadcastPort = row.getInteger("peer_port");
}
InetSocketAddress broadcastAddress = null;
if (broadcastInetAddress != null && broadcastPort != null) {
broadcastAddress = new InetSocketAddress(broadcastInetAddress, broadcastPort);
}
// in system.local only, and only for Cassandra versions >= 2.0.17, 2.1.8, 2.2.0 rc2;
// not present in system.peers nor system.peers_v2
InetAddress listenInetAddress = row.getInetAddress("listen_address");
// in system.local only, and only for Cassandra >= 4.0
Integer listenPort = 0;
if (row.contains("listen_port")) {
listenPort = row.getInteger("listen_port");
}
InetSocketAddress listenAddress = null;
if (listenInetAddress != null && listenPort != null) {
listenAddress = new InetSocketAddress(listenInetAddress, listenPort);
}
DefaultNodeInfo.Builder builder = DefaultNodeInfo.builder().withEndPoint(endPoint).withBroadcastRpcAddress(broadcastRpcAddress).withBroadcastAddress(broadcastAddress).withListenAddress(listenAddress).withDatacenter(row.getString("data_center")).withRack(row.getString("rack")).withCassandraVersion(row.getString("release_version")).withTokens(row.getSetOfString("tokens")).withPartitioner(row.getString("partitioner")).withHostId(Objects.requireNonNull(row.getUuid("host_id"))).withSchemaVersion(row.getUuid("schema_version"));
// Handle DSE-specific columns, if present
String rawVersion = row.getString("dse_version");
if (rawVersion != null) {
builder.withExtra(DseNodeProperties.DSE_VERSION, Version.parse(rawVersion));
}
ImmutableSet.Builder<String> workloadsBuilder = ImmutableSet.builder();
// DSE 5.0
Boolean legacyGraph = row.getBoolean("graph");
if (legacyGraph != null && legacyGraph) {
workloadsBuilder.add("Graph");
}
// DSE 5.0 (other than graph)
String legacyWorkload = row.getString("workload");
if (legacyWorkload != null) {
workloadsBuilder.add(legacyWorkload);
}
// DSE 5.1+
Set<String> modernWorkloads = row.getSetOfString("workloads");
if (modernWorkloads != null) {
workloadsBuilder.addAll(modernWorkloads);
}
ImmutableSet<String> workloads = workloadsBuilder.build();
if (!workloads.isEmpty()) {
builder.withExtra(DseNodeProperties.DSE_WORKLOADS, workloads);
}
// Note: withExtra discards null values
builder.withExtra(DseNodeProperties.SERVER_ID, row.getString("server_id")).withExtra(DseNodeProperties.NATIVE_TRANSPORT_PORT, row.getInteger("native_transport_port")).withExtra(DseNodeProperties.NATIVE_TRANSPORT_PORT_SSL, row.getInteger("native_transport_port_ssl")).withExtra(DseNodeProperties.STORAGE_PORT, row.getInteger("storage_port")).withExtra(DseNodeProperties.STORAGE_PORT_SSL, row.getInteger("storage_port_ssl")).withExtra(DseNodeProperties.JMX_PORT, row.getInteger("jmx_port"));
return builder;
}
Aggregations