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 <amnon@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
This commit is contained in:
Amnon Heiman 2015-09-29 09:28:59 +03:00 committed by Pekka Enberg
parent f035be4435
commit d67e6e60fc

View File

@ -18,6 +18,7 @@
package org.apache.cassandra.locator; package org.apache.cassandra.locator;
import java.lang.management.ManagementFactory; import java.lang.management.ManagementFactory;
import java.net.InetAddress;
import java.net.UnknownHostException; import java.net.UnknownHostException;
import javax.management.MBeanServer; import javax.management.MBeanServer;
@ -63,6 +64,9 @@ public class EndpointSnitchInfo implements EndpointSnitchInfoMBean {
public String getRack(String host) throws UnknownHostException { public String getRack(String host) throws UnknownHostException {
log("getRack(String host) throws UnknownHostException"); log("getRack(String host) throws UnknownHostException");
MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl(); MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
if (host == null) {
host = InetAddress.getLoopbackAddress().getHostAddress();
}
queryParams.add("host", host); queryParams.add("host", host);
return c.getStringValue("/snitch/rack", queryParams); return c.getStringValue("/snitch/rack", queryParams);
} }
@ -77,6 +81,9 @@ public class EndpointSnitchInfo implements EndpointSnitchInfoMBean {
public String getDatacenter(String host) throws UnknownHostException { public String getDatacenter(String host) throws UnknownHostException {
log(" getDatacenter(String host) throws UnknownHostException"); log(" getDatacenter(String host) throws UnknownHostException");
MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl(); MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
if (host == null) {
host = InetAddress.getLoopbackAddress().getHostAddress();
}
queryParams.add("host", host); queryParams.add("host", host);
return c.getStringValue("/snitch/datacenter", queryParams); return c.getStringValue("/snitch/datacenter", queryParams);
} }