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
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);
JsonObject rawInfo = cluster.clusterManager().info().raw();
JsonArray nodes = rawInfo.getArray("nodes");
System.out.printf("Analytics is running!");
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!