Skip to content

Commit

Permalink
#34 Use a different approach to retrieve datacenter name
Browse files Browse the repository at this point in the history
 - Older version of cassandra do not expose the jmx attribute "datacenter"
   We are suppose to use the method getDatacenter which need to recieve as
   parameter the public ip of the node
  • Loading branch information
Romain GÉRARD committed Nov 15, 2018
1 parent 612633e commit 033ca74
Showing 1 changed file with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.management.*;
import javax.management.MBeanAttributeInfo;
import javax.management.MBeanServerConnection;
import javax.management.ObjectName;
import javax.management.openmbean.CompositeData;
import javax.management.openmbean.CompositeType;
import javax.management.remote.JMXConnector;
Expand All @@ -17,7 +19,6 @@
import java.util.regex.Pattern;
import java.util.stream.Stream;


import static java.util.stream.Collectors.toList;


Expand Down Expand Up @@ -370,7 +371,11 @@ static Optional<NodeInfo> getNodeInfo(MBeanServerConnection beanConn) {
}

try {
datacenterName = beanConn.getAttribute(ObjectName.getInstance("org.apache.cassandra.db:type=EndpointSnitchInfo"), "Datacenter").toString();
String hostID = beanConn.getAttribute(ObjectName.getInstance("org.apache.cassandra.db:type=StorageService"), "LocalHostId").toString();
Map<String, String> hostIdToEndpoint = (Map<String, String>) beanConn.getAttribute(ObjectName.getInstance("org.apache.cassandra.db:type=StorageService"), "HostIdToEndpoint");
Object opParams[] = {hostIdToEndpoint.get(hostID)};
String opSig[] = {String.class.getName()};
datacenterName = beanConn.invoke(ObjectName.getInstance("org.apache.cassandra.db:type=EndpointSnitchInfo"), "getDatacenter", opParams, opSig).toString();
} catch (Exception e) {
logger.error("Cannot retrieve the datacenter name information for the node", e);
return Optional.empty();
Expand Down

0 comments on commit 033ca74

Please sign in to comment.