From d67e6e60fc920143472836e292cda3634ddbe6e0 Mon Sep 17 00:00:00 2001 From: Amnon Heiman Date: Tue, 29 Sep 2015 09:28:59 +0300 Subject: [PATCH] EndPointSnitchInfo: Support null as host name In origin an undocumented feature (bug?) is that passing null as a host name for getRack and getDatacenter returns the rack or datacenter according to the loopbck address. This follow the same behaviour, so when the host is null, the function will not fail but will call the API with the local loopback address Signed-off-by: Amnon Heiman Signed-off-by: Pekka Enberg --- .../org/apache/cassandra/locator/EndpointSnitchInfo.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/main/java/org/apache/cassandra/locator/EndpointSnitchInfo.java b/src/main/java/org/apache/cassandra/locator/EndpointSnitchInfo.java index 1639bbc..b34250e 100644 --- a/src/main/java/org/apache/cassandra/locator/EndpointSnitchInfo.java +++ b/src/main/java/org/apache/cassandra/locator/EndpointSnitchInfo.java @@ -18,6 +18,7 @@ package org.apache.cassandra.locator; import java.lang.management.ManagementFactory; +import java.net.InetAddress; import java.net.UnknownHostException; import javax.management.MBeanServer; @@ -63,6 +64,9 @@ public class EndpointSnitchInfo implements EndpointSnitchInfoMBean { public String getRack(String host) throws UnknownHostException { log("getRack(String host) throws UnknownHostException"); MultivaluedMap queryParams = new MultivaluedMapImpl(); + if (host == null) { + host = InetAddress.getLoopbackAddress().getHostAddress(); + } queryParams.add("host", host); return c.getStringValue("/snitch/rack", queryParams); } @@ -77,6 +81,9 @@ public class EndpointSnitchInfo implements EndpointSnitchInfoMBean { public String getDatacenter(String host) throws UnknownHostException { log(" getDatacenter(String host) throws UnknownHostException"); MultivaluedMap queryParams = new MultivaluedMapImpl(); + if (host == null) { + host = InetAddress.getLoopbackAddress().getHostAddress(); + } queryParams.add("host", host); return c.getStringValue("/snitch/datacenter", queryParams); }