Mercurial > hg > thermostat-ng > agent
changeset 2740:3d1c63f2b665
Refactor jvm-memory and jvm-gc endpoints to use path-based query
This series of patches brings the jvm-gc and jvm-memory APIs in line
with the other web services.
Previously, you would GET or PUT
https://host**/jvm-memory/0.0.2?query=jvmId=={jvmId} (properly escaped, of course).
Now, you call
https://host/jvm-memory/0.0.3/systems/{systemId}/jvms/{jvmId}.
In addition, I've added a new endpoint (valid for GET only)
https://host/jvm-memory/0.0.3/jvms/{jvmId}
...which is easier for the web client to call. I didn't implement this for POST, etc.
Reviewed-by: aazores, jkang
Review-thread: http://icedtea.classpath.org/pipermail/thermostat/2017-August/024586.html
author | Simon Tooke <stooke@redhat.com> |
---|---|
date | Fri, 25 Aug 2017 09:55:37 -0400 |
parents | cc16bcb56e60 |
children | c245bf78f9cb |
files | plugins/vm-gc/agent/src/main/java/com/redhat/thermostat/vm/gc/agent/internal/models/VmGcStatDAOImpl.java plugins/vm-gc/agent/src/test/java/com/redhat/thermostat/vm/gc/agent/internal/models/VmGcStatDAOImplTest.java plugins/vm-gc/distribution/configFiles/gateway.properties plugins/vm-memory/agent/src/main/java/com/redhat/thermostat/vm/memory/agent/internal/models/VmMemoryStatDAOImpl.java plugins/vm-memory/agent/src/test/java/com/redhat/thermostat/vm/memory/agent/internal/models/VmMemoryStatDAOImplTest.java plugins/vm-memory/distribution/configFiles/gateway.properties |
diffstat | 6 files changed, 38 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/plugins/vm-gc/agent/src/main/java/com/redhat/thermostat/vm/gc/agent/internal/models/VmGcStatDAOImpl.java Wed Aug 23 13:51:09 2017 +0200 +++ b/plugins/vm-gc/agent/src/main/java/com/redhat/thermostat/vm/gc/agent/internal/models/VmGcStatDAOImpl.java Fri Aug 25 09:55:37 2017 -0400 @@ -43,6 +43,7 @@ import java.util.logging.Level; import java.util.logging.Logger; +import com.redhat.thermostat.common.plugin.SystemID; import org.apache.felix.scr.annotations.Activate; import org.apache.felix.scr.annotations.Component; import org.apache.felix.scr.annotations.Reference; @@ -72,6 +73,9 @@ @Reference private HttpRequestService httpRequestService; + @Reference + private SystemID systemID; + public VmGcStatDAOImpl() { this(new JsonHelper(new VmGcStatTypeAdapter()), new ConfigurationCreator(), null); } @@ -88,6 +92,10 @@ this.gatewayURL = config.getGatewayURL(); } + void bindSystemID(final SystemID id) { + this.systemID = id; + } + protected void bindHttpRequestService(HttpRequestService httpRequestService) { this.httpRequestService = httpRequestService; } @@ -97,11 +105,15 @@ logger.log(Level.INFO, "Unbound HTTP service. Further attempts to store data will fail until bound again."); } + protected URI getPostURI(final String jvmID) { + return gatewayURL.resolve("systems/" + systemID.getSystemID() + "/jvms/" + jvmID); + } + @Override public void putVmGcStat(final VmGcStat stat) { try { String json = jsonHelper.toJson(Arrays.asList(stat)); - httpRequestService.sendHttpRequest(json, gatewayURL, HttpRequestService.Method.POST); + httpRequestService.sendHttpRequest(json, getPostURI(stat.getJvmId()), HttpRequestService.Method.POST); } catch (RequestFailedException | IOException e) { logger.log(Level.WARNING, "Failed to send VmGcStat information to web gateway", e); }
--- a/plugins/vm-gc/agent/src/test/java/com/redhat/thermostat/vm/gc/agent/internal/models/VmGcStatDAOImplTest.java Wed Aug 23 13:51:09 2017 +0200 +++ b/plugins/vm-gc/agent/src/test/java/com/redhat/thermostat/vm/gc/agent/internal/models/VmGcStatDAOImplTest.java Fri Aug 25 09:55:37 2017 -0400 @@ -45,6 +45,7 @@ import java.net.URI; import java.util.Arrays; +import com.redhat.thermostat.common.plugin.SystemID; import org.junit.Before; import org.junit.Test; @@ -93,12 +94,15 @@ @Test public void verifyAddVmGcStat() throws Exception { + SystemID id = mock(SystemID.class); + when(id.getSystemID()).thenReturn("systemid"); + dao.bindSystemID(id); dao.activate(); dao.putVmGcStat(stat); verify(jsonHelper).toJson(eq(Arrays.asList(stat))); - verify(httpRequestService).sendHttpRequest(JSON, GATEWAY_URI, HttpRequestService.Method.POST); + verify(httpRequestService).sendHttpRequest(JSON, GATEWAY_URI.resolve("systems/systemid/jvms/Vm-1"), HttpRequestService.Method.POST); } }
--- a/plugins/vm-gc/distribution/configFiles/gateway.properties Wed Aug 23 13:51:09 2017 +0200 +++ b/plugins/vm-gc/distribution/configFiles/gateway.properties Fri Aug 25 09:55:37 2017 -0400 @@ -1,2 +1,2 @@ # URL to the jvm-gc microservice provided by the Thermostat web gateway -gatewayURL=https://localhost:30000/jvm-gc/0.0.2/ +gatewayURL=https://localhost:30000/jvm-gc/0.0.3
--- a/plugins/vm-memory/agent/src/main/java/com/redhat/thermostat/vm/memory/agent/internal/models/VmMemoryStatDAOImpl.java Wed Aug 23 13:51:09 2017 +0200 +++ b/plugins/vm-memory/agent/src/main/java/com/redhat/thermostat/vm/memory/agent/internal/models/VmMemoryStatDAOImpl.java Fri Aug 25 09:55:37 2017 -0400 @@ -43,6 +43,7 @@ import java.util.logging.Level; import java.util.logging.Logger; +import com.redhat.thermostat.common.plugin.SystemID; import org.apache.felix.scr.annotations.Activate; import org.apache.felix.scr.annotations.Component; import org.apache.felix.scr.annotations.Reference; @@ -73,6 +74,9 @@ @Reference private HttpRequestService httpRequestService; + @Reference + private SystemID systemID; + public VmMemoryStatDAOImpl() { this(new JsonHelper(new VmMemoryStatTypeAdapter()), new ConfigurationCreator(), null); } @@ -89,16 +93,24 @@ this.gatewayURL = config.getGatewayURL(); } + void bindSystemID(final SystemID id) { + this.systemID = id; + } + @Override public void putVmMemoryStat(final VmMemoryStat stat) { try { String json = jsonHelper.toJson(Arrays.asList(stat)); - httpRequestService.sendHttpRequest(json, gatewayURL, HttpRequestService.Method.POST); + httpRequestService.sendHttpRequest(json, getPostURI(stat.getJvmId()), HttpRequestService.Method.POST); } catch (RequestFailedException | IOException e) { logger.log(Level.WARNING, "Failed to send VmMemoryStat to Web Gateway", e); } } + protected URI getPostURI(final String jvmID) { + return gatewayURL.resolve("systems/" + systemID.getSystemID() + "/jvms/" + jvmID); + } + protected Logger getLogger() { return logger; }
--- a/plugins/vm-memory/agent/src/test/java/com/redhat/thermostat/vm/memory/agent/internal/models/VmMemoryStatDAOImplTest.java Wed Aug 23 13:51:09 2017 +0200 +++ b/plugins/vm-memory/agent/src/test/java/com/redhat/thermostat/vm/memory/agent/internal/models/VmMemoryStatDAOImplTest.java Fri Aug 25 09:55:37 2017 -0400 @@ -46,6 +46,7 @@ import java.util.Arrays; import java.util.List; +import com.redhat.thermostat.common.plugin.SystemID; import org.junit.Before; import org.junit.Test; @@ -118,12 +119,15 @@ VmMemoryStatDAOImpl dao = new VmMemoryStatDAOImpl(jsonHelper, creator, source); dao.bindHttpRequestService(httpRequestService); + SystemID id = mock(SystemID.class); + when(id.getSystemID()).thenReturn("systemid"); + dao.bindSystemID(id); dao.activate(); dao.putVmMemoryStat(stat); verify(jsonHelper).toJson(Arrays.asList(stat)); - verify(httpRequestService).sendHttpRequest(JSON, GATEWAY_URI, HttpRequestService.Method.POST); + verify(httpRequestService).sendHttpRequest(JSON, GATEWAY_URI.resolve("systems/systemid/jvms/jvmId"), HttpRequestService.Method.POST); } }
--- a/plugins/vm-memory/distribution/configFiles/gateway.properties Wed Aug 23 13:51:09 2017 +0200 +++ b/plugins/vm-memory/distribution/configFiles/gateway.properties Fri Aug 25 09:55:37 2017 -0400 @@ -1,2 +1,2 @@ # URL to the jvm-memory microservice provided by the Thermostat web gateway -gatewayURL=https://localhost:30000/jvm-memory/0.0.2/ +gatewayURL=https://localhost:30000/jvm-memory/0.0.3