Skip to content

Commit 7681fd4

Browse files
committed
JVMCBC-1680 Retain raw JSON when parsing cluster topology
Motivation ---------- FIT proxy wants to know all TLS + non-TLS service ports, etc. Modifications ------------- Add ClusterTopology.json(), which returns the raw JSON the topology was parsed from, or an empty node if the topology was synthetic (created by a test). Change-Id: I8611fc34016ea3a8cfc785725ce4846da1ef746f Reviewed-on: https://review.couchbase.org/c/couchbase-jvm-clients/+/232811 Tested-by: Build Bot <[email protected]> Reviewed-by: Graham Pople <[email protected]>
1 parent a1a4787 commit 7681fd4

File tree

4 files changed

+21
-1
lines changed

4 files changed

+21
-1
lines changed

core-io/src/main/java/com/couchbase/client/core/topology/ClusterTopology.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import com.couchbase.client.core.annotation.SinceCouchbase;
2020
import com.couchbase.client.core.annotation.Stability;
21+
import com.couchbase.client.core.deps.com.fasterxml.jackson.databind.node.ObjectNode;
2122
import com.couchbase.client.core.env.NetworkResolution;
2223
import org.jspecify.annotations.Nullable;
2324

@@ -38,8 +39,10 @@ public class ClusterTopology {
3839
private final Set<ClusterCapability> capabilities;
3940
private final List<HostAndServicePorts> nodes;
4041
private final @Nullable ClusterIdentifier clusterIdent;
42+
private final ObjectNode json;
4143

4244
public static ClusterTopology of(
45+
ObjectNode json,
4346
TopologyRevision revision,
4447
@Nullable ClusterIdentifier clusterIdent,
4548
List<HostAndServicePorts> nodes,
@@ -50,6 +53,7 @@ public static ClusterTopology of(
5053
) {
5154
if (bucket != null) {
5255
return new ClusterTopologyWithBucket(
56+
json,
5357
revision,
5458
nodes,
5559
capabilities,
@@ -61,6 +65,7 @@ public static ClusterTopology of(
6165
}
6266

6367
return new ClusterTopology(
68+
json,
6469
revision,
6570
nodes,
6671
capabilities,
@@ -71,6 +76,7 @@ public static ClusterTopology of(
7176
}
7277

7378
protected ClusterTopology(
79+
ObjectNode json,
7480
TopologyRevision revision,
7581
List<HostAndServicePorts> nodes,
7682
Set<ClusterCapability> capabilities,
@@ -82,6 +88,7 @@ protected ClusterTopology(
8288
throw new IllegalArgumentException("Must resolve 'auto' network before creating config.");
8389
}
8490

91+
this.json = requireNonNull(json);
8592
this.revision = requireNonNull(revision);
8693
this.nodes = listCopyOf(nodes);
8794
this.capabilities = unmodifiableSet(newEnumSet(ClusterCapability.class, capabilities));
@@ -90,6 +97,10 @@ protected ClusterTopology(
9097
this.clusterIdent = clusterIdent;
9198
}
9299

100+
public ObjectNode json() {
101+
return json;
102+
}
103+
93104
public TopologyRevision revision() {
94105
return revision;
95106
}

core-io/src/main/java/com/couchbase/client/core/topology/ClusterTopologyBuilder.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package com.couchbase.client.core.topology;
1818

1919
import com.couchbase.client.core.annotation.Stability;
20+
import com.couchbase.client.core.deps.com.fasterxml.jackson.databind.node.JsonNodeFactory;
2021
import com.couchbase.client.core.env.NetworkResolution;
2122
import com.couchbase.client.core.service.ServiceType;
2223
import com.couchbase.client.core.util.HostAndPort;
@@ -54,6 +55,7 @@ public ClusterTopology build() {
5455

5556
private ClusterTopology buildWithOrWithoutBucket(@Nullable BucketTopology bucket) {
5657
return ClusterTopology.of(
58+
JsonNodeFactory.instance.objectNode(),
5759
revision,
5860
new ClusterIdentifier(clusterUuid, clusterName, product),
5961
nodes,

core-io/src/main/java/com/couchbase/client/core/topology/ClusterTopologyParser.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ public static ClusterTopology parse(
6464
throw new IllegalArgumentException("Invalid originHost. Expected a hostname, IPv4 address, or IPv6 address (without square brackets), but got: " + originHost);
6565
}
6666

67+
if (clusterConfig.isEmpty()) {
68+
throw new CouchbaseException("Cluster topology JSON is an empty node. Server returned invalid topology, or maybe this was a doomed attempt to re-parse a synthetic topology.");
69+
}
70+
6771
ArrayNode nodesExt = (ArrayNode) clusterConfig.get("nodesExt");
6872
if (nodesExt == null) {
6973
throw new CouchbaseException("Couchbase Server version is too old for this SDK; missing 'nodesExt' field.");
@@ -132,6 +136,7 @@ resolvedNetwork, redactSystem(it)
132136
ClusterIdentifier clusterIdent = ClusterIdentifier.parse(clusterConfig);
133137

134138
return ClusterTopology.of(
139+
clusterConfig,
135140
TopologyRevision.parse(clusterConfig),
136141
clusterIdent,
137142
resolvedNodes,

core-io/src/main/java/com/couchbase/client/core/topology/ClusterTopologyWithBucket.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package com.couchbase.client.core.topology;
1818

1919
import com.couchbase.client.core.annotation.Stability;
20+
import com.couchbase.client.core.deps.com.fasterxml.jackson.databind.node.ObjectNode;
2021
import com.couchbase.client.core.env.NetworkResolution;
2122
import org.jspecify.annotations.Nullable;
2223

@@ -36,6 +37,7 @@ public class ClusterTopologyWithBucket extends ClusterTopology {
3637
private final BucketTopology bucket;
3738

3839
ClusterTopologyWithBucket(
40+
ObjectNode json,
3941
TopologyRevision revision,
4042
List<HostAndServicePorts> nodes,
4143
Set<ClusterCapability> capabilities,
@@ -44,7 +46,7 @@ public class ClusterTopologyWithBucket extends ClusterTopology {
4446
BucketTopology bucket,
4547
@Nullable ClusterIdentifier clusterIdent
4648
) {
47-
super(revision, nodes, capabilities, network, portSelector, clusterIdent);
49+
super(json, revision, nodes, capabilities, network, portSelector, clusterIdent);
4850
this.bucket = requireNonNull(bucket);
4951
}
5052

0 commit comments

Comments
 (0)