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();
}
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;
}
}
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");
}
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();
}
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();
}
Aggregations