use of com.datastax.oss.driver.api.core.metadata.EndPoint in project java-driver by datastax.
the class CloudConfigFactory method getEndPoints.
@NonNull
protected List<EndPoint> getEndPoints(@NonNull JsonNode proxyMetadata, @NonNull InetSocketAddress sniProxyAddress) {
JsonNode contactInfo = getContactInfo(proxyMetadata);
if (contactInfo.has("contact_points")) {
List<EndPoint> endPoints = new ArrayList<>();
JsonNode hostIdsJson = contactInfo.get("contact_points");
for (int i = 0; i < hostIdsJson.size(); i++) {
endPoints.add(new SniEndPoint(sniProxyAddress, hostIdsJson.get(i).asText()));
}
return endPoints;
} else {
throw new IllegalStateException("Invalid proxy metadata: missing field contact_points");
}
}
use of com.datastax.oss.driver.api.core.metadata.EndPoint in project java-driver by datastax.
the class DefaultTopologyMonitor method refreshNode.
@Override
public CompletionStage<Optional<NodeInfo>> refreshNode(Node node) {
if (closeFuture.isDone()) {
return CompletableFutures.failedFuture(new IllegalStateException("closed"));
}
LOG.debug("[{}] Refreshing info for {}", logPrefix, node);
DriverChannel channel = controlConnection.channel();
EndPoint localEndPoint = channel.getEndPoint();
if (node.getEndPoint().equals(channel.getEndPoint())) {
// refreshNode is called for nodes that just came up. If the control node just came up, it
// means the control connection just reconnected, which means we did a full node refresh. So
// we don't need to process this call.
LOG.debug("[{}] Ignoring refresh of control node", logPrefix);
return CompletableFuture.completedFuture(Optional.empty());
} else if (node.getBroadcastAddress().isPresent()) {
CompletionStage<AdminResult> query;
if (isSchemaV2) {
query = query(channel, "SELECT * FROM " + getPeerTableName() + " WHERE peer = :address and peer_port = :port", ImmutableMap.of("address", node.getBroadcastAddress().get().getAddress(), "port", node.getBroadcastAddress().get().getPort()));
} else {
query = query(channel, "SELECT * FROM " + getPeerTableName() + " WHERE peer = :address", ImmutableMap.of("address", node.getBroadcastAddress().get().getAddress()));
}
return query.thenApply(result -> firstPeerRowAsNodeInfo(result, localEndPoint));
} else {
return query(channel, "SELECT * FROM " + getPeerTableName()).thenApply(result -> findInPeers(result, node.getHostId(), localEndPoint));
}
}
use of com.datastax.oss.driver.api.core.metadata.EndPoint in project java-driver by datastax.
the class DefaultTopologyMonitor method getNewNodeInfo.
@Override
public CompletionStage<Optional<NodeInfo>> getNewNodeInfo(InetSocketAddress broadcastRpcAddress) {
if (closeFuture.isDone()) {
return CompletableFutures.failedFuture(new IllegalStateException("closed"));
}
LOG.debug("[{}] Fetching info for new node {}", logPrefix, broadcastRpcAddress);
DriverChannel channel = controlConnection.channel();
EndPoint localEndPoint = channel.getEndPoint();
return query(channel, "SELECT * FROM " + getPeerTableName()).thenApply(result -> findInPeers(result, broadcastRpcAddress, localEndPoint));
}
use of com.datastax.oss.driver.api.core.metadata.EndPoint in project java-driver by datastax.
the class InitialNodeListRefresh method compute.
@Override
public Result compute(DefaultMetadata oldMetadata, boolean tokenMapEnabled, InternalDriverContext context) {
String logPrefix = context.getSessionName();
TokenFactoryRegistry tokenFactoryRegistry = context.getTokenFactoryRegistry();
// metadata is empty.
assert oldMetadata == DefaultMetadata.EMPTY;
TokenFactory tokenFactory = null;
Map<UUID, DefaultNode> newNodes = new HashMap<>();
for (NodeInfo nodeInfo : nodeInfos) {
UUID hostId = nodeInfo.getHostId();
if (newNodes.containsKey(hostId)) {
LOG.warn("[{}] Found duplicate entries with host_id {} in system.peers, " + "keeping only the first one", logPrefix, hostId);
} else {
EndPoint endPoint = nodeInfo.getEndPoint();
DefaultNode node = findIn(contactPoints, endPoint);
if (node == null) {
node = new DefaultNode(endPoint, context);
LOG.debug("[{}] Adding new node {}", logPrefix, node);
} else {
LOG.debug("[{}] Copying contact point {}", logPrefix, node);
}
if (tokenMapEnabled && tokenFactory == null && nodeInfo.getPartitioner() != null) {
tokenFactory = tokenFactoryRegistry.tokenFactoryFor(nodeInfo.getPartitioner());
}
copyInfos(nodeInfo, node, context);
newNodes.put(hostId, node);
}
}
ImmutableList.Builder<Object> eventsBuilder = ImmutableList.builder();
for (DefaultNode newNode : newNodes.values()) {
if (findIn(contactPoints, newNode.getEndPoint()) == null) {
eventsBuilder.add(NodeStateEvent.added(newNode));
}
}
for (DefaultNode contactPoint : contactPoints) {
if (findIn(newNodes.values(), contactPoint.getEndPoint()) == null) {
eventsBuilder.add(NodeStateEvent.removed(contactPoint));
}
}
return new Result(oldMetadata.withNodes(ImmutableMap.copyOf(newNodes), tokenMapEnabled, true, tokenFactory, context), eventsBuilder.build());
}
use of com.datastax.oss.driver.api.core.metadata.EndPoint in project java-driver by datastax.
the class MetadataManager method addContactPoints.
public void addContactPoints(Set<EndPoint> providedContactPoints) {
// Convert the EndPoints to Nodes, but we can't put them into the Metadata yet, because we
// don't know their host_id. So store them in a volatile field instead, they will get copied
// during the first node refresh.
ImmutableSet.Builder<DefaultNode> contactPointsBuilder = ImmutableSet.builder();
if (providedContactPoints == null || providedContactPoints.isEmpty()) {
LOG.info("[{}] No contact points provided, defaulting to {}", logPrefix, DEFAULT_CONTACT_POINT);
this.wasImplicitContactPoint = true;
contactPointsBuilder.add(new DefaultNode(DEFAULT_CONTACT_POINT, context));
} else {
for (EndPoint endPoint : providedContactPoints) {
contactPointsBuilder.add(new DefaultNode(endPoint, context));
}
}
this.contactPoints = contactPointsBuilder.build();
LOG.debug("[{}] Adding initial contact points {}", logPrefix, contactPoints);
}
Aggregations