APIClient: Make API server errors human readable
Make the error messages returned by Scylla API server human readable from 'nodetool'. For example, if an API URL is missing, print out the following error: [penberg@nero scylla-tools-java]$ ./bin/nodetool getcompactionthreshold ks test4 nodetool: Scylla API server HTTP GET to URL 'column_family/minimum_compaction/ks:test4' failed: Not found See 'nodetool help' or 'nodetool help <command>'. instead of the scary-looking error that we now print: [penberg@nero scylla-tools-java]$ ./bin/nodetool getcompactionthreshold ks test4 error: Not found -- StackTrace -- java.lang.RuntimeException: Not found at com.scylladb.jmx.api.APIClient.getException(APIClient.java:116) at com.scylladb.jmx.api.APIClient.getRawValue(APIClient.java:160) at com.scylladb.jmx.api.APIClient.getRawValue(APIClient.java:174) at com.scylladb.jmx.api.APIClient.getIntValue(APIClient.java:216) at com.scylladb.jmx.api.APIClient.getIntValue(APIClient.java:220) at org.apache.cassandra.db.ColumnFamilyStore.getMinimumCompactionThreshold(ColumnFamilyStore.java:475) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at sun.reflect.misc.Trampoline.invoke(MethodUtil.java:71) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) [snip] Message-Id: <1458032300-17704-1-git-send-email-penberg@scylladb.com> (cherry picked from commit c4d8d7087e342085dcff854f4dbcd42db07a5f4d)
This commit is contained in:
parent
02e0598506
commit
9c9d879a48
@ -100,7 +100,7 @@ public class APIClient {
|
|||||||
public Response post(String path, MultivaluedMap<String, String> queryParams) {
|
public Response post(String path, MultivaluedMap<String, String> queryParams) {
|
||||||
Response response = get(path, queryParams).post(Entity.entity(null, MediaType.TEXT_PLAIN));
|
Response response = get(path, queryParams).post(Entity.entity(null, MediaType.TEXT_PLAIN));
|
||||||
if (response.getStatus() != Response.Status.OK.getStatusCode() ) {
|
if (response.getStatus() != Response.Status.OK.getStatusCode() ) {
|
||||||
throw getException(response.readEntity(String.class));
|
throw getException("Scylla API server HTTP POST to URL '" + path + "' failed", response.readEntity(String.class));
|
||||||
}
|
}
|
||||||
return response;
|
return response;
|
||||||
|
|
||||||
@ -110,10 +110,10 @@ public class APIClient {
|
|||||||
post(path, null);
|
post(path, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public RuntimeException getException(String txt) {
|
public IllegalStateException getException(String msg, String json) {
|
||||||
JsonReader reader = factory.createReader(new StringReader(txt));
|
JsonReader reader = factory.createReader(new StringReader(json));
|
||||||
JsonObject res = reader.readObject();
|
JsonObject res = reader.readObject();
|
||||||
return new RuntimeException(res.getString("message"));
|
return new IllegalStateException(msg + ": " + res.getString("message"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public String postGetVal(String path, MultivaluedMap<String, String> queryParams) {
|
public String postGetVal(String path, MultivaluedMap<String, String> queryParams) {
|
||||||
@ -157,7 +157,7 @@ public class APIClient {
|
|||||||
// TBD
|
// TBD
|
||||||
// We are currently not caching errors,
|
// We are currently not caching errors,
|
||||||
// it should be reconsider.
|
// it should be reconsider.
|
||||||
throw getException(response.readEntity(String.class));
|
throw getException("Scylla API server HTTP GET to URL '" + string + "' failed", response.readEntity(String.class));
|
||||||
}
|
}
|
||||||
res = response.readEntity(String.class);
|
res = response.readEntity(String.class);
|
||||||
if (duration > 0) {
|
if (duration > 0) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user