Search in sources :

Example 1 with AdminRow

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;
    });
}
Also used : DriverChannel(com.datastax.oss.driver.internal.core.channel.DriverChannel) InetSocketAddress(java.net.InetSocketAddress) ArrayList(java.util.ArrayList) Error(com.datastax.oss.protocol.internal.response.Error) EndPoint(com.datastax.oss.driver.api.core.metadata.EndPoint) AdminResult(com.datastax.oss.driver.internal.core.adminrequest.AdminResult) CompletableFuture(java.util.concurrent.CompletableFuture) UnexpectedResponseException(com.datastax.oss.driver.internal.core.adminrequest.UnexpectedResponseException) AdminRow(com.datastax.oss.driver.internal.core.adminrequest.AdminRow)

Example 2 with AdminRow

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();
        }
    }
}
Also used : AdminRow(com.datastax.oss.driver.internal.core.adminrequest.AdminRow)

Example 3 with AdminRow

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;
}
Also used : AdminRow(com.datastax.oss.driver.internal.core.adminrequest.AdminRow)

Example 4 with AdminRow

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;
}
Also used : ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) AdminRow(com.datastax.oss.driver.internal.core.adminrequest.AdminRow) ByteBuffer(java.nio.ByteBuffer)

Example 5 with AdminRow

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;
}
Also used : AdminRow(com.datastax.oss.driver.internal.core.adminrequest.AdminRow)

Aggregations

AdminRow (com.datastax.oss.driver.internal.core.adminrequest.AdminRow)43 Test (org.junit.Test)12 CqlIdentifier (com.datastax.oss.driver.api.core.CqlIdentifier)7 Optional (java.util.Optional)6 ImmutableMap (com.datastax.oss.driver.shaded.guava.common.collect.ImmutableMap)5 UnknownHostException (java.net.UnknownHostException)3 UUID (java.util.UUID)3 ClusteringOrder (com.datastax.oss.driver.api.core.metadata.schema.ClusteringOrder)2 ColumnMetadata (com.datastax.oss.driver.api.core.metadata.schema.ColumnMetadata)2 IndexMetadata (com.datastax.oss.driver.api.core.metadata.schema.IndexMetadata)2 KeyspaceMetadata (com.datastax.oss.driver.api.core.metadata.schema.KeyspaceMetadata)2 TableMetadata (com.datastax.oss.driver.api.core.metadata.schema.TableMetadata)2 DataType (com.datastax.oss.driver.api.core.type.DataType)2 SchemaRefresh (com.datastax.oss.driver.internal.core.metadata.schema.refresh.SchemaRefresh)2 ImmutableList (com.datastax.oss.driver.shaded.guava.common.collect.ImmutableList)2 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)2 InetSocketAddress (java.net.InetSocketAddress)2 DseColumnMetadata (com.datastax.dse.driver.api.core.metadata.schema.DseColumnMetadata)1 DseIndexMetadata (com.datastax.dse.driver.api.core.metadata.schema.DseIndexMetadata)1 DseKeyspaceMetadata (com.datastax.dse.driver.api.core.metadata.schema.DseKeyspaceMetadata)1