use of com.datastax.oss.driver.internal.core.adminrequest.AdminRow 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;
});
}
use of com.datastax.oss.driver.internal.core.adminrequest.AdminRow in project java-driver by datastax.
the class ReprepareOnUp method gatherServerIds.
private void gatherServerIds(AdminResult rows, Throwable error) {
assert adminExecutor.inEventLoop();
if (serverKnownIds == null) {
serverKnownIds = new HashSet<>();
}
if (error != null) {
LOG.debug("[{}] Error querying system.prepared_statements ({}), proceeding without server ids", logPrefix, error.toString());
gatherPayloadsToReprepare();
} else {
for (AdminRow row : rows) {
serverKnownIds.add(row.getByteBuffer("prepared_id"));
}
if (rows.hasNextPage()) {
LOG.debug("[{}] system.prepared_statements has more pages", logPrefix);
rows.nextPage().whenCompleteAsync(this::gatherServerIds, adminExecutor);
} else {
LOG.debug("[{}] Gathered {} server ids, proceeding", logPrefix, serverKnownIds.size());
gatherPayloadsToReprepare();
}
}
}
use of com.datastax.oss.driver.internal.core.adminrequest.AdminRow in project java-driver by datastax.
the class SchemaParserTestBase method mockLegacyTableRow.
protected static AdminRow mockLegacyTableRow(String keyspace, String name, String comparator) {
AdminRow row = mock(AdminRow.class);
when(row.contains("table_name")).thenReturn(false);
when(row.getString("keyspace_name")).thenReturn(keyspace);
when(row.getString("columnfamily_name")).thenReturn(name);
when(row.getBoolean("is_dense")).thenReturn(false);
when(row.getString("comparator")).thenReturn(comparator);
when(row.isString("caching")).thenReturn(true);
when(row.getString("caching")).thenReturn("{\"keys\":\"ALL\", \"rows_per_partition\":\"NONE\"}");
when(row.getString("compaction_strategy_class")).thenReturn("org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy");
when(row.getString("compaction_strategy_options")).thenReturn("{\"mock_option\":\"1\"}");
return row;
}
use of com.datastax.oss.driver.internal.core.adminrequest.AdminRow in project java-driver by datastax.
the class SchemaParserTestBase method mockAggregateRow.
protected static AdminRow mockAggregateRow(String keyspace, String name, List<String> argumentTypes, String stateFunc, String stateType, String finalFunc, String returnType, Object initCond) {
AdminRow row = mock(AdminRow.class);
when(row.contains("keyspace_name")).thenReturn(true);
when(row.contains("aggregate_name")).thenReturn(true);
when(row.contains("argument_types")).thenReturn(true);
when(row.contains("state_func")).thenReturn(true);
when(row.contains("state_type")).thenReturn(true);
when(row.contains("final_func")).thenReturn(true);
when(row.contains("return_type")).thenReturn(true);
when(row.contains("initcond")).thenReturn(true);
when(row.getString("keyspace_name")).thenReturn(keyspace);
when(row.getString("aggregate_name")).thenReturn(name);
when(row.getListOfString("argument_types")).thenReturn(argumentTypes);
when(row.getString("state_func")).thenReturn(stateFunc);
when(row.getString("state_type")).thenReturn(stateType);
when(row.getString("final_func")).thenReturn(finalFunc);
when(row.getString("return_type")).thenReturn(returnType);
if (initCond instanceof ByteBuffer) {
when(row.isString("initcond")).thenReturn(false);
when(row.getByteBuffer("initcond")).thenReturn(((ByteBuffer) initCond));
} else if (initCond instanceof String) {
when(row.isString("initcond")).thenReturn(true);
when(row.getString("initcond")).thenReturn(((String) initCond));
} else {
fail("Unsupported initcond type" + initCond.getClass());
}
return row;
}
use of com.datastax.oss.driver.internal.core.adminrequest.AdminRow in project java-driver by datastax.
the class SchemaParserTestBase method mockFunctionRow.
protected static AdminRow mockFunctionRow(String keyspace, String name, List<String> argumentNames, List<String> argumentTypes, String body, boolean calledOnNullInput, String language, String returnType) {
AdminRow row = mock(AdminRow.class);
when(row.contains("keyspace_name")).thenReturn(true);
when(row.contains("function_name")).thenReturn(true);
when(row.contains("argument_names")).thenReturn(true);
when(row.contains("argument_types")).thenReturn(true);
when(row.contains("body")).thenReturn(true);
when(row.contains("called_on_null_input")).thenReturn(true);
when(row.contains("language")).thenReturn(true);
when(row.contains("return_type")).thenReturn(true);
when(row.getString("keyspace_name")).thenReturn(keyspace);
when(row.getString("function_name")).thenReturn(name);
when(row.getListOfString("argument_names")).thenReturn(argumentNames);
when(row.getListOfString("argument_types")).thenReturn(argumentTypes);
when(row.getString("body")).thenReturn(body);
when(row.getBoolean("called_on_null_input")).thenReturn(calledOnNullInput);
when(row.getString("language")).thenReturn(language);
when(row.getString("return_type")).thenReturn(returnType);
return row;
}
Aggregations