Skip to content

Commit 24449f2

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]> (cherry picked from commit 7681fd4) Reviewed-on: https://review.couchbase.org/c/couchbase-jvm-clients/+/232864 Reviewed-by: David Nault <[email protected]>
1 parent 86a2cd6 commit 24449f2

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
@@ -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

@@ -37,8 +38,10 @@ public class ClusterTopology {
3738
private final Set<ClusterCapability> capabilities;
3839
private final List<HostAndServicePorts> nodes;
3940
private final @Nullable ClusterIdentifier clusterIdent;
41+
private final ObjectNode json;
4042

4143
public static ClusterTopology of(
44+
ObjectNode json,
4245
TopologyRevision revision,
4346
@Nullable ClusterIdentifier clusterIdent,
4447
List<HostAndServicePorts> nodes,
@@ -49,6 +52,7 @@ public static ClusterTopology of(
4952
) {
5053
if (bucket != null) {
5154
return new ClusterTopologyWithBucket(
55+
json,
5256
revision,
5357
nodes,
5458
capabilities,
@@ -60,6 +64,7 @@ public static ClusterTopology of(
6064
}
6165

6266
return new ClusterTopology(
67+
json,
6368
revision,
6469
nodes,
6570
capabilities,
@@ -70,6 +75,7 @@ public static ClusterTopology of(
7075
}
7176

7277
protected ClusterTopology(
78+
ObjectNode json,
7379
TopologyRevision revision,
7480
List<HostAndServicePorts> nodes,
7581
Set<ClusterCapability> capabilities,
@@ -81,6 +87,7 @@ protected ClusterTopology(
8187
throw new IllegalArgumentException("Must resolve 'auto' network before creating config.");
8288
}
8389

90+
this.json = requireNonNull(json);
8491
this.revision = requireNonNull(revision);
8592
this.nodes = listCopyOf(nodes);
8693
this.capabilities = unmodifiableSet(newEnumSet(ClusterCapability.class, capabilities));
@@ -89,6 +96,10 @@ protected ClusterTopology(
8996
this.clusterIdent = clusterIdent;
9097
}
9198

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

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)