Merge branch "Adding the gossiper MBean implementation"

From Amnon.
This commit is contained in:
Pekka Enberg 2015-06-02 09:19:02 +03:00
commit dbe22715a8
2 changed files with 28 additions and 4 deletions

View File

@ -10,6 +10,7 @@ import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import javax.json.Json; import javax.json.Json;
import javax.json.JsonArray; import javax.json.JsonArray;
import javax.json.JsonObject; import javax.json.JsonObject;
@ -17,6 +18,7 @@ import javax.json.JsonReader;
import javax.json.JsonReaderFactory; import javax.json.JsonReaderFactory;
import javax.json.JsonString; import javax.json.JsonString;
import javax.management.openmbean.TabularData; import javax.management.openmbean.TabularData;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.core.UriBuilder; import javax.ws.rs.core.UriBuilder;
import com.sun.jersey.api.client.Client; import com.sun.jersey.api.client.Client;
@ -43,6 +45,22 @@ public class APIClient {
return service.path(path).accept(MediaType.APPLICATION_JSON); return service.path(path).accept(MediaType.APPLICATION_JSON);
} }
public Builder get(String path, MultivaluedMap<String, String> queryParams) {
ClientConfig config = new DefaultClientConfig();
Client client = Client.create(config);
WebResource service = client.resource(UriBuilder.fromUri(getBaseUrl())
.build());
return service.queryParams(queryParams).path(path).accept(MediaType.APPLICATION_JSON);
}
public void post(String path, MultivaluedMap<String, String> queryParams) {
if (queryParams != null) {
get(path, queryParams).post();
return;
}
get(path).post();
}
public String getStringValue(String string) { public String getStringValue(String string) {
if (string != "") { if (string != "") {
return get(string).get(String.class); return get(string).get(String.class);
@ -150,7 +168,7 @@ public class APIClient {
String key = ""; String key = "";
long val = -1; long val = -1;
while (it.hasNext()) { while (it.hasNext()) {
String k = (String) it.next(); String k = it.next();
System.out.println(k); System.out.println(k);
if (obj.get(k) instanceof JsonString) { if (obj.get(k) instanceof JsonString) {
key = obj.getString(k); key = obj.getString(k);

View File

@ -25,10 +25,13 @@ package org.apache.cassandra.gms;
import java.lang.management.ManagementFactory; import java.lang.management.ManagementFactory;
import java.net.UnknownHostException; import java.net.UnknownHostException;
import javax.management.MBeanServer; import javax.management.MBeanServer;
import javax.management.ObjectName; import javax.management.ObjectName;
import javax.ws.rs.core.MultivaluedMap;
import com.cloudius.urchin.api.APIClient; import com.cloudius.urchin.api.APIClient;
import com.sun.jersey.core.util.MultivaluedMapImpl;
/** /**
* This module is responsible for Gossiping information for the local endpoint. * This module is responsible for Gossiping information for the local endpoint.
@ -54,7 +57,6 @@ public class Gossiper implements GossiperMBean {
private APIClient c = new APIClient(); private APIClient c = new APIClient();
public void log(String str) { public void log(String str) {
System.out.println(str);
logger.info(str); logger.info(str);
} }
@ -77,22 +79,26 @@ public class Gossiper implements GossiperMBean {
public long getEndpointDowntime(String address) throws UnknownHostException { public long getEndpointDowntime(String address) throws UnknownHostException {
log(" getEndpointDowntime(String address) throws UnknownHostException"); log(" getEndpointDowntime(String address) throws UnknownHostException");
return c.getLongValue(""); return c.getLongValue("gossiper/downtime/" + address);
} }
public int getCurrentGenerationNumber(String address) public int getCurrentGenerationNumber(String address)
throws UnknownHostException { throws UnknownHostException {
log(" getCurrentGenerationNumber(String address) throws UnknownHostException"); log(" getCurrentGenerationNumber(String address) throws UnknownHostException");
return c.getIntValue(""); return c.getIntValue("gossiper/generation_number/" + address);
} }
public void unsafeAssassinateEndpoint(String address) public void unsafeAssassinateEndpoint(String address)
throws UnknownHostException { throws UnknownHostException {
log(" unsafeAssassinateEndpoint(String address) throws UnknownHostException"); log(" unsafeAssassinateEndpoint(String address) throws UnknownHostException");
MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
queryParams.add("unsafe", "True");
c.post("gossiper/assassinate/" + address, queryParams);
} }
public void assassinateEndpoint(String address) throws UnknownHostException { public void assassinateEndpoint(String address) throws UnknownHostException {
log(" assassinateEndpoint(String address) throws UnknownHostException"); log(" assassinateEndpoint(String address) throws UnknownHostException");
c.post("gossiper/assassinate/" + address, null);
} }
} }