use of com.datastax.oss.driver.internal.core.adminrequest.UnexpectedResponseException in project java-driver by datastax.
the class DefaultTopologyMonitor method refreshNodeList.
@Override
public CompletionStage<Iterable<NodeInfo>> refreshNodeList() {
if (closeFuture.isDone()) {
return CompletableFutures.failedFuture(new IllegalStateException("closed"));
}
LOG.debug("[{}] Refreshing node list", logPrefix);
DriverChannel channel = controlConnection.channel();
EndPoint localEndPoint = channel.getEndPoint();
savePort(channel);
CompletionStage<AdminResult> localQuery = query(channel, "SELECT * FROM system.local");
CompletionStage<AdminResult> peersV2Query = query(channel, "SELECT * FROM system.peers_v2");
CompletableFuture<AdminResult> peersQuery = new CompletableFuture<>();
peersV2Query.whenComplete((r, t) -> {
if (t != null) {
// If system.peers_v2 does not exist, downgrade to system.peers
if (t instanceof UnexpectedResponseException && ((UnexpectedResponseException) t).message instanceof Error) {
Error error = (Error) ((UnexpectedResponseException) t).message;
if (error.code == ProtocolConstants.ErrorCode.INVALID || // 6.0.2 with search enabled)
(error.code == ProtocolConstants.ErrorCode.SERVER_ERROR && error.message.contains("Unknown keyspace/cf pair (system.peers_v2)"))) {
// We should not attempt this query in the future.
this.isSchemaV2 = false;
CompletableFutures.completeFrom(query(channel, "SELECT * FROM system.peers"), peersQuery);
return;
}
}
peersQuery.completeExceptionally(t);
} else {
peersQuery.complete(r);
}
});
return localQuery.thenCombine(peersQuery, (controlNodeResult, peersResult) -> {
List<NodeInfo> nodeInfos = new ArrayList<>();
AdminRow localRow = controlNodeResult.iterator().next();
InetSocketAddress localBroadcastRpcAddress = getBroadcastRpcAddress(localRow, localEndPoint);
nodeInfos.add(nodeInfoBuilder(localRow, localBroadcastRpcAddress, localEndPoint).build());
for (AdminRow peerRow : peersResult) {
if (isPeerValid(peerRow)) {
InetSocketAddress peerBroadcastRpcAddress = getBroadcastRpcAddress(peerRow, localEndPoint);
if (peerBroadcastRpcAddress != null) {
NodeInfo nodeInfo = nodeInfoBuilder(peerRow, peerBroadcastRpcAddress, localEndPoint).build();
nodeInfos.add(nodeInfo);
}
}
}
return nodeInfos;
});
}
Aggregations