Search in sources :

Example 21 with AdminRow

use of com.datastax.oss.driver.internal.core.adminrequest.AdminRow in project java-driver by datastax.

the class SchemaAgreementChecker method extractSchemaVersions.

private Set<UUID> extractSchemaVersions(AdminResult controlNodeResult, AdminResult peersResult) {
    // Gather the versions of all the nodes that are UP
    ImmutableSet.Builder<UUID> schemaVersions = ImmutableSet.builder();
    // Control node (implicitly UP, we've just queried it)
    Iterator<AdminRow> iterator = controlNodeResult.iterator();
    if (iterator.hasNext()) {
        AdminRow localRow = iterator.next();
        UUID schemaVersion = localRow.getUuid("schema_version");
        if (schemaVersion == null) {
            LOG.warn("[{}] Missing schema_version for control node {}, " + "excluding from schema agreement check", logPrefix, channel.getEndPoint());
        } else {
            schemaVersions.add(schemaVersion);
        }
    } else {
        LOG.warn("[{}] Missing system.local row for control node {}, " + "excluding from schema agreement check", logPrefix, channel.getEndPoint());
    }
    Map<UUID, Node> nodes = context.getMetadataManager().getMetadata().getNodes();
    for (AdminRow peerRow : peersResult) {
        if (isPeerValid(peerRow, nodes)) {
            UUID schemaVersion = Objects.requireNonNull(peerRow.getUuid("schema_version"));
            schemaVersions.add(schemaVersion);
        }
    }
    return schemaVersions.build();
}
Also used : ImmutableSet(com.datastax.oss.driver.shaded.guava.common.collect.ImmutableSet) Node(com.datastax.oss.driver.api.core.metadata.Node) UUID(java.util.UUID) AdminRow(com.datastax.oss.driver.internal.core.adminrequest.AdminRow)

Example 22 with AdminRow

use of com.datastax.oss.driver.internal.core.adminrequest.AdminRow in project java-driver by datastax.

the class DefaultTopologyMonitorTest method mockPeersV2Row.

private AdminRow mockPeersV2Row(int i, UUID hostId) {
    try {
        AdminRow row = mock(AdminRow.class);
        when(row.isNull("host_id")).thenReturn(hostId == null);
        when(row.getUuid("host_id")).thenReturn(hostId);
        when(row.getInetAddress("peer")).thenReturn(InetAddress.getByName("127.0.0." + i));
        when(row.getInteger("peer_port")).thenReturn(7000 + i);
        when(row.isNull("data_center")).thenReturn(false);
        when(row.getString("data_center")).thenReturn("dc" + i);
        when(row.isNull("rack")).thenReturn(false);
        when(row.getString("rack")).thenReturn("rack" + i);
        when(row.getString("release_version")).thenReturn("release_version" + i);
        when(row.isNull("native_address")).thenReturn(false);
        when(row.getInetAddress("native_address")).thenReturn(InetAddress.getByName("127.0.0." + i));
        when(row.isNull("native_port")).thenReturn(false);
        when(row.getInteger("native_port")).thenReturn(9042);
        when(row.isNull("tokens")).thenReturn(false);
        when(row.getSetOfString("tokens")).thenReturn(ImmutableSet.of("token" + i));
        when(row.contains("peer")).thenReturn(true);
        when(row.contains("peer_port")).thenReturn(true);
        when(row.contains("native_port")).thenReturn(true);
        when(row.isNull("rpc_address")).thenReturn(true);
        return row;
    } catch (UnknownHostException e) {
        fail("unexpected", e);
        return null;
    }
}
Also used : UnknownHostException(java.net.UnknownHostException) AdminRow(com.datastax.oss.driver.internal.core.adminrequest.AdminRow)

Example 23 with AdminRow

use of com.datastax.oss.driver.internal.core.adminrequest.AdminRow in project java-driver by datastax.

the class DefaultTopologyMonitorTest method should_refresh_node_from_peers_if_broadcast_address_is_not_present.

@Test
public void should_refresh_node_from_peers_if_broadcast_address_is_not_present() {
    // Given
    topologyMonitor.isSchemaV2 = false;
    node2.broadcastAddress = null;
    AdminRow peer3 = mockPeersRow(3, UUID.randomUUID());
    AdminRow peer2 = mockPeersRow(2, node2.getHostId());
    topologyMonitor.stubQueries(new StubbedQuery("SELECT * FROM system.peers", mockResult(peer3, peer2)));
    // When
    CompletionStage<Optional<NodeInfo>> futureInfo = topologyMonitor.refreshNode(node2);
    // Then
    assertThatStage(futureInfo).isSuccess(maybeInfo -> {
        assertThat(maybeInfo.isPresent()).isTrue();
        NodeInfo info = maybeInfo.get();
        assertThat(info.getDatacenter()).isEqualTo("dc2");
    });
    // The rpc_address in each row should have been tried, only the last row should have been
    // converted
    verify(peer3).getUuid("host_id");
    verify(peer3, never()).getString(anyString());
    verify(peer2, times(2)).getUuid("host_id");
    verify(peer2).getString("data_center");
}
Also used : Optional(java.util.Optional) AdminRow(com.datastax.oss.driver.internal.core.adminrequest.AdminRow) Test(org.junit.Test)

Example 24 with AdminRow

use of com.datastax.oss.driver.internal.core.adminrequest.AdminRow in project java-driver by datastax.

the class PeerRowValidatorTest method should_succeed_for_valid_peer_v1.

@Test
public void should_succeed_for_valid_peer_v1() {
    AdminRow peerRow = mock(AdminRow.class);
    when(peerRow.isNull("host_id")).thenReturn(false);
    when(peerRow.isNull("rpc_address")).thenReturn(false);
    when(peerRow.isNull("native_address")).thenReturn(true);
    when(peerRow.isNull("native_port")).thenReturn(true);
    when(peerRow.isNull("data_center")).thenReturn(false);
    when(peerRow.isNull("rack")).thenReturn(false);
    when(peerRow.isNull("tokens")).thenReturn(false);
    when(peerRow.isNull("schema_version")).thenReturn(false);
    assertThat(PeerRowValidator.isValid(peerRow)).isTrue();
}
Also used : AdminRow(com.datastax.oss.driver.internal.core.adminrequest.AdminRow) Test(org.junit.Test)

Example 25 with AdminRow

use of com.datastax.oss.driver.internal.core.adminrequest.AdminRow in project java-driver by datastax.

the class PeerRowValidatorTest method should_succeed_for_valid_peer_v2.

@Test
public void should_succeed_for_valid_peer_v2() {
    AdminRow peerRow = mock(AdminRow.class);
    when(peerRow.isNull("host_id")).thenReturn(false);
    when(peerRow.isNull("rpc_address")).thenReturn(true);
    when(peerRow.isNull("native_address")).thenReturn(false);
    when(peerRow.isNull("native_port")).thenReturn(false);
    when(peerRow.isNull("data_center")).thenReturn(false);
    when(peerRow.isNull("rack")).thenReturn(false);
    when(peerRow.isNull("tokens")).thenReturn(false);
    when(peerRow.isNull("schema_version")).thenReturn(false);
    assertThat(PeerRowValidator.isValid(peerRow)).isTrue();
}
Also used : AdminRow(com.datastax.oss.driver.internal.core.adminrequest.AdminRow) Test(org.junit.Test)

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