Merge branch "Adding the gossiper MBean implementation"
From Amnon.
This commit is contained in:
commit
dbe22715a8
@ -10,6 +10,7 @@ import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.json.Json;
|
||||
import javax.json.JsonArray;
|
||||
import javax.json.JsonObject;
|
||||
@ -17,6 +18,7 @@ import javax.json.JsonReader;
|
||||
import javax.json.JsonReaderFactory;
|
||||
import javax.json.JsonString;
|
||||
import javax.management.openmbean.TabularData;
|
||||
import javax.ws.rs.core.MultivaluedMap;
|
||||
import javax.ws.rs.core.UriBuilder;
|
||||
|
||||
import com.sun.jersey.api.client.Client;
|
||||
@ -43,6 +45,22 @@ public class APIClient {
|
||||
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) {
|
||||
if (string != "") {
|
||||
return get(string).get(String.class);
|
||||
@ -150,7 +168,7 @@ public class APIClient {
|
||||
String key = "";
|
||||
long val = -1;
|
||||
while (it.hasNext()) {
|
||||
String k = (String) it.next();
|
||||
String k = it.next();
|
||||
System.out.println(k);
|
||||
if (obj.get(k) instanceof JsonString) {
|
||||
key = obj.getString(k);
|
||||
|
@ -25,10 +25,13 @@ package org.apache.cassandra.gms;
|
||||
|
||||
import java.lang.management.ManagementFactory;
|
||||
import java.net.UnknownHostException;
|
||||
|
||||
import javax.management.MBeanServer;
|
||||
import javax.management.ObjectName;
|
||||
import javax.ws.rs.core.MultivaluedMap;
|
||||
|
||||
import com.cloudius.urchin.api.APIClient;
|
||||
import com.sun.jersey.core.util.MultivaluedMapImpl;
|
||||
|
||||
/**
|
||||
* 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();
|
||||
|
||||
public void log(String str) {
|
||||
System.out.println(str);
|
||||
logger.info(str);
|
||||
}
|
||||
|
||||
@ -77,22 +79,26 @@ public class Gossiper implements GossiperMBean {
|
||||
|
||||
public long 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)
|
||||
throws UnknownHostException {
|
||||
log(" getCurrentGenerationNumber(String address) throws UnknownHostException");
|
||||
return c.getIntValue("");
|
||||
return c.getIntValue("gossiper/generation_number/" + address);
|
||||
}
|
||||
|
||||
public void 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 {
|
||||
log(" assassinateEndpoint(String address) throws UnknownHostException");
|
||||
c.post("gossiper/assassinate/" + address, null);
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user