Skip to content

Commit c5b269f

Browse files
committed
JCBC-2198, KCBC-192, SCBC-490: Followup
Motivation ---------- Analytics server added a stable 'prod' field that is resistant to potential branding changes. Modifications ------------- When inspecting cluster type, use the stable 'prod' field instead of 'prodName'. Simplify by removing ClusterType in favor of using a primitive string; now that we can do exact string matches, there's less need for a dedicated type. Change-Id: I1d2c435e03f58879bc0590e0bf1ebb241969c0f7 Reviewed-on: https://review.couchbase.org/c/couchbase-jvm-clients/+/230781 Reviewed-by: Michael Reiche <michael.reiche@couchbase.com> Tested-by: Build Bot <build@couchbase.com>
1 parent 5b2a761 commit c5b269f

File tree

4 files changed

+26
-87
lines changed

4 files changed

+26
-87
lines changed

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

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@
2929
public class ClusterIdentifier {
3030
private final String clusterUuid;
3131
private final String clusterName;
32-
private final ClusterType clusterType;
32+
private final String product;
3333

34-
ClusterIdentifier(String clusterUuid, String clusterName, ClusterType product) {
34+
ClusterIdentifier(String clusterUuid, String clusterName, String product) {
3535
this.clusterUuid = requireNonNull(clusterUuid);
3636
this.clusterName = requireNonNull(clusterName);
37-
this.clusterType = requireNonNull(product);
37+
this.product = requireNonNull(product);
3838
}
3939

4040
public static @Nullable ClusterIdentifier parse(ObjectNode config) {
@@ -44,9 +44,10 @@ public class ClusterIdentifier {
4444
return null;
4545
}
4646

47-
JsonNode prodName = config.path("prodName"); // field added in Couchbase Server 8.0.
48-
ClusterType type = ClusterType.of(prodName.textValue());
49-
return new ClusterIdentifier(clusterUuid.asText(), clusterName.asText(), type);
47+
// Field "prod" added in Couchbase Server 8.0 (value = "server") / Enterprise Analytics 1.0 (value = "analytics").
48+
// Assume anything that doesn't set it is an older version of Couchbase Server.
49+
String prod = config.path("prod").asText("server");
50+
return new ClusterIdentifier(clusterUuid.asText(), clusterName.asText(), prod);
5051
}
5152

5253
public String clusterUuid() {
@@ -57,8 +58,8 @@ public String clusterName() {
5758
return clusterName;
5859
}
5960

60-
public ClusterType clusterType() {
61-
return clusterType;
61+
public String product() {
62+
return product;
6263
}
6364

6465
@Override
@@ -67,20 +68,20 @@ public boolean equals(Object o) {
6768
ClusterIdentifier that = (ClusterIdentifier) o;
6869
return Objects.equals(clusterUuid, that.clusterUuid)
6970
&& Objects.equals(clusterName, that.clusterName)
70-
&& Objects.equals(clusterType, that.clusterType);
71+
&& Objects.equals(product, that.product);
7172
}
7273

7374
@Override
7475
public int hashCode() {
75-
return Objects.hash(clusterUuid, clusterName, clusterType);
76+
return Objects.hash(clusterUuid, clusterName, product);
7677
}
7778

7879
@Override
7980
public String toString() {
8081
return "ClusterIdent{" +
8182
"clusterUuid='" + clusterUuid + '\'' +
8283
", clusterName='" + redactMeta(clusterName) + '\'' +
83-
", clusterType='" + clusterType + '\'' +
84+
", product='" + product + '\'' +
8485
'}';
8586
}
8687
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public final class ClusterTopologyBuilder {
4444
private NetworkResolution networkResolution = NetworkResolution.DEFAULT;
4545
private String clusterName = "fake-cluster";
4646
private String clusterUuid = "fake-cluster-uuid";
47-
private ClusterType clusterType = ClusterType.COUCHBASE_SERVER;
47+
private String product = "server";
4848
private Set<ClusterCapability> capabilities = EnumSet.allOf(ClusterCapability.class);
4949
private final List<HostAndServicePorts> nodes = new ArrayList<>();
5050

@@ -55,7 +55,7 @@ public ClusterTopology build() {
5555
private ClusterTopology buildWithOrWithoutBucket(@Nullable BucketTopology bucket) {
5656
return ClusterTopology.of(
5757
revision,
58-
new ClusterIdentifier(clusterUuid, clusterName, clusterType),
58+
new ClusterIdentifier(clusterUuid, clusterName, product),
5959
nodes,
6060
capabilities,
6161
networkResolution,

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

Lines changed: 0 additions & 63 deletions
This file was deleted.

‎java-client/src/main/java/com/couchbase/client/java/analytics/AnalyticsAccessor.java‎

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@
2222
import com.couchbase.client.core.error.CouchbaseException;
2323
import com.couchbase.client.core.msg.analytics.AnalyticsRequest;
2424
import com.couchbase.client.core.msg.analytics.AnalyticsResponse;
25-
import com.couchbase.client.core.topology.ClusterType;
25+
import com.couchbase.client.core.topology.ClusterIdentifier;
2626
import com.couchbase.client.java.codec.JsonSerializer;
27+
import org.jspecify.annotations.Nullable;
2728
import reactor.core.publisher.Mono;
2829

2930
import java.time.Duration;
@@ -85,17 +86,17 @@ private static Mono<Void> requireCouchbaseServer(Core core, Duration timeout) {
8586

8687
return core.waitForClusterTopology(timeout)
8788
.mapNotNull(clusterTopology -> {
88-
ClusterType type = ClusterType.from(clusterTopology.id());
89-
if (type.isCouchbaseServer()) {
90-
return null; // success! complete the empty mono.
89+
if (isEnterpriseAnalytics(clusterTopology.id())) {
90+
throw new CouchbaseException(
91+
"This SDK is for Couchbase Server (operational) clusters, but the remote cluster is an Enterprise Analytics cluster." +
92+
" Please use the Enterprise Analytics SDK to access this cluster."
93+
);
9194
}
92-
93-
String message = "This SDK is for Couchbase Server (operational) clusters, but the remote cluster type is '" + type + "'.";
94-
if (type.name().startsWith("Enterprise Analytics")) {
95-
message += " Please use the Enterprise Analytics SDK to access this cluster.";
96-
}
97-
98-
throw new CouchbaseException(message);
95+
return null; // success! complete the empty mono.
9996
});
10097
}
98+
99+
private static boolean isEnterpriseAnalytics(@Nullable ClusterIdentifier clusterId) {
100+
return clusterId != null && "analytics".equals(clusterId.product());
101+
}
101102
}

0 commit comments

Comments
 (0)