Getting information about services in a cluster

I find myself in need of managing many different CouchBase clusters for which I need to, sometimes, allow users to make Analytics queries. Not all of these clusters have an analytics node, so I would like to be able to report to users if they are looking at an Analytics-able cluster beforehand. How can I proceed to obtain this information using Java SDK?

I was guessing something in

https://docs.couchbase.com/sdk-api/couchbase-java-client/com/couchbase/client/java/cluster/ClusterInfo.html

…or in…

https://docs.couchbase.com/sdk-api/couchbase-core-io-1.7.9/com/couchbase/client/core/message/internal/DiagnosticsReport.html

would provide this information, but I haven’t been able to find it out by myself. Also, it seems there’s little information about this topic on the Internet.

This seems a surprising omission from the SDK, but I found a way to get the information. Services such as analytics (a.k.a., “cbas”) run on the nodes, so you need to iterate over the nodes in the cluster. There may be a better way to do this, but this is what I found (as someone with limited experience with the Java SDK):

    Cluster cluster = CouchbaseCluster.create(env);
    cluster.authenticate("Administrator", "password");
    JsonObject rawInfo = cluster.clusterManager().info().raw();
    JsonArray nodes = rawInfo.getArray("nodes");
    nodes.forEach(node->{
    	((JsonObject)node).getArray("services").forEach(service->{
    		if ("cbas".equals(service))
    			System.out.printf("Analytics is running!");
    	});
    });
1 Like

This is exactly what I was looking for. I am going to give it a try right now and will come back with my results. Thank you!

EDIT: This works like a charm. Thank you again!