changeset 66:d2bbcfe1c2ae embedded-storage-structure

Reduce endpoints. Embed user input in "obj" field. The endpoints available are: /{namespace}/systems/{systemId} /{namespace}/systems/{systemId}/agents/{agentId} /{namespace}/systems/{systemId}/agents/{agentId}/jvms/{jvmId} The inputs are now embedded: { "obj" { <valid json input> }, "systemId", ... } The input identities are attached outside of the embedded object. This makes it easier to return the input given in a PUT request in subsequent GET/POST requests. The input parameters for Ids accept "all" for GET/POST/DELETE requests but not for PUT requests.
author Jie Kang <jkang@redhat.com>
date Wed, 01 Mar 2017 16:16:25 -0500
parents 30b23482267d
children c630c9bdda93
files server/core/src/main/java/com/redhat/thermostat/server/core/internal/web/handler/http/NamespaceHttpHandler.java server/core/src/main/java/com/redhat/thermostat/server/core/internal/web/handler/storage/StorageHandler.java server/core/src/main/java/com/redhat/thermostat/server/core/internal/web/handler/storage/mongo/MongoStorageHandler.java server/core/src/main/java/com/redhat/thermostat/server/core/internal/web/handler/storage/mongo/filters/MongoRequestFilters.java server/core/src/main/java/com/redhat/thermostat/server/core/internal/web/handler/storage/mongo/response/MongoResponseBuilder.java server/core/src/main/java/com/redhat/thermostat/server/core/internal/web/json/DocumentBuilder.java server/core/src/test/java/com/redhat/thermostat/server/core/GetCoreServerTest.java server/core/src/test/java/com/redhat/thermostat/server/core/MongoCoreServerTest.java server/core/src/test/java/com/redhat/thermostat/server/core/internal/web/handler/storage/mongo/response/MongoResponseBuilderTest.java server/core/src/test/java/com/redhat/thermostat/server/core/internal/web/json/DocumentBuilderTest.java
diffstat 10 files changed, 231 insertions(+), 435 deletions(-) [+]
line wrap: on
line diff
--- a/server/core/src/main/java/com/redhat/thermostat/server/core/internal/web/handler/http/NamespaceHttpHandler.java	Wed Mar 01 12:23:51 2017 -0500
+++ b/server/core/src/main/java/com/redhat/thermostat/server/core/internal/web/handler/http/NamespaceHttpHandler.java	Wed Mar 01 16:16:25 2017 -0500
@@ -24,202 +24,148 @@
     private static final String STREAM_LIMIT = "1";
 
     @GET
-    @Path("systems")
+    @Path("systems/{systemId}")
     @Produces(MediaType.APPLICATION_JSON)
     public void getSystems(@Context SecurityContext context,
                            @Suspended final AsyncResponse asyncResponse,
                            @PathParam("namespace") String namespace,
+                           @PathParam("systemId") String systemId,
                            @QueryParam("offset") @DefaultValue(OFFSET) String offset,
                            @QueryParam("limit") @DefaultValue(LIMIT) String limit,
                            @QueryParam("sort") String sort) {
-        handler.getSystems(context, asyncResponse, namespace, offset, limit, sort);
+        handler.getSystems(context, asyncResponse, namespace, systemId, offset, limit, sort);
     }
 
     @PUT
-    @Path("systems")
+    @Path("systems/{systemId}")
     @Produces(MediaType.APPLICATION_JSON)
     public void putSystems(String body,
                            @Context SecurityContext context,
                            @Suspended final AsyncResponse asyncResponse,
-                           @PathParam("namespace") String namespace) {
-        handler.putSystems(body, context, asyncResponse, namespace);
+                           @PathParam("namespace") String namespace,
+                           @PathParam("systemId") String systemId) {
+        handler.putSystems(body, context, asyncResponse, namespace, systemId);
     }
 
     @POST
-    @Path("systems")
+    @Path("systems/{systemId}")
     @Produces(MediaType.APPLICATION_JSON)
     public void postSystems(String body,
                             @Context SecurityContext context,
                             @Suspended final AsyncResponse asyncResponse,
                             @PathParam("namespace") String namespace,
+                            @PathParam("systemId") String systemId,
                             @QueryParam("offset") @DefaultValue(OFFSET) String offset,
                             @QueryParam("limit") @DefaultValue(LIMIT) String limit,
                             @QueryParam("sort") String sort) {
-        handler.postSystems(body, context, asyncResponse, namespace, offset, limit, sort);
-    }
-
-    @DELETE
-    @Path("systems")
-    @Produces(MediaType.APPLICATION_JSON)
-    public void deleteSystems(String body,
-                              @Context SecurityContext context,
-                              @Suspended final AsyncResponse asyncResponse,
-                              @PathParam("namespace") String namespace) {
-        handler.deleteSystems(body, context, asyncResponse, namespace);
-    }
-
-    @GET
-    @Path("systems/{systemId}")
-    @Produces(MediaType.APPLICATION_JSON)
-    public void getSystem(@Context SecurityContext securityContext,
-                          @Suspended final AsyncResponse asyncResponse,
-                          @PathParam("namespace") String namespace,
-                          @PathParam("systemId") String systemId) {
-        handler.getSystem(securityContext, asyncResponse, namespace, systemId);
-    }
-
-    @PUT
-    @Path("systems/{systemId}")
-    @Produces(MediaType.APPLICATION_JSON)
-    public void putSystem(String body,
-                          @Context SecurityContext context,
-                          @Suspended final AsyncResponse asyncResponse,
-                          @PathParam("namespace") String namespace) {
-        handler.putSystem(body, context, asyncResponse, namespace);
+        handler.postSystems(body, context, asyncResponse, namespace, systemId, offset, limit, sort);
     }
 
     @DELETE
     @Path("systems/{systemId}")
     @Produces(MediaType.APPLICATION_JSON)
-    public void deleteSystem(@Context SecurityContext context,
-                             @Suspended final AsyncResponse asyncResponse,
-                             @PathParam("namespace") String namespace) {
-        handler.deleteSystem(context, asyncResponse, namespace);
+    public void deleteSystems(String body,
+                              @Context SecurityContext context,
+                              @Suspended final AsyncResponse asyncResponse,
+                              @PathParam("namespace") String namespace,
+                              @PathParam("systemId") String systemId) {
+        handler.deleteSystems(body, context, asyncResponse, namespace, systemId);
     }
 
     @GET
-    @Path("systems/{systemId}/agents")
+    @Path("systems/{systemId}/agents/{agentId}")
     @Produces(MediaType.APPLICATION_JSON)
     public void getAgents(@Context SecurityContext securityContext,
                           @Suspended final AsyncResponse asyncResponse,
                           @PathParam("namespace") String namespace,
                           @PathParam("systemId") String systemId,
+                          @PathParam("agentId") String agentId,
                           @QueryParam("offset") @DefaultValue(OFFSET) String offset,
                           @QueryParam("limit") @DefaultValue(LIMIT) String limit,
                           @QueryParam("sort") String sort) {
-        handler.getAgents(securityContext, asyncResponse, namespace, systemId, offset, limit, sort);
+        handler.getAgents(securityContext, asyncResponse, namespace, systemId, agentId, offset, limit, sort);
     }
 
     @GET
-    @Path("stream/systems/{systemId}/agents")
+    @Path("stream/systems/{systemId}/agents/{agentId}")
     @Produces(MediaType.APPLICATION_JSON)
     public ChunkedOutput<String> streamAgents(@Context SecurityContext securityContext,
                                               @PathParam("namespace") String namespace,
                                               @PathParam("systemId") String systemId,
+                                              @PathParam("agentId") String agentId,
                                               @QueryParam("limit") @DefaultValue(STREAM_LIMIT) String limit) {
         return handler.streamAgents(securityContext, namespace, systemId, limit);
     }
 
     @PUT
-    @Path("systems/{systemId}/agents")
+    @Path("systems/{systemId}/agents/{agentId}")
     @Produces(MediaType.APPLICATION_JSON)
     public void putAgents(String body,
                           @Context SecurityContext context,
                           @Suspended final AsyncResponse asyncResponse,
                           @PathParam("namespace") String namespace,
-                          @PathParam("systemId") String systemId) {
-        handler.putAgents(body, context, asyncResponse, namespace, systemId);
+                          @PathParam("systemId") String systemId,
+                          @PathParam("agentId") String agentId) {
+        handler.putAgents(body, context, asyncResponse, namespace, systemId, agentId);
     }
 
     @POST
-    @Path("systems/{systemId}/agents")
+    @Path("systems/{systemId}/agents/{agentId}")
     @Produces(MediaType.APPLICATION_JSON)
     public void postAgents(String body,
                            @Context SecurityContext context,
                            @Suspended final AsyncResponse asyncResponse,
                            @PathParam("namespace") String namespace,
                            @PathParam("systemId") String systemId,
+                           @PathParam("agentId") String agentId,
                            @QueryParam("offset") @DefaultValue(OFFSET) String offset,
                            @QueryParam("limit") @DefaultValue(LIMIT) String limit,
                            @QueryParam("sort") String sort) {
-        handler.postAgents(body, context, asyncResponse, namespace, systemId, offset, limit, sort);
+        handler.postAgents(body, context, asyncResponse, namespace, systemId, agentId, offset, limit, sort);
     }
 
     @DELETE
-    @Path("systems/{systemId}/agents")
+    @Path("systems/{systemId}/agents/{agentId}")
     @Produces(MediaType.APPLICATION_JSON)
     public void deleteAgents(String body,
                              @Context SecurityContext context,
                              @Suspended final AsyncResponse asyncResponse,
                              @PathParam("namespace") String namespace,
-                             @PathParam("systemId") String systemId) {
-        handler.deleteAgents(body, context, asyncResponse, namespace, systemId);
+                             @PathParam("systemId") String systemId,
+                             @PathParam("agentId") String agentId) {
+        handler.deleteAgents(body, context, asyncResponse, namespace, systemId, agentId);
     }
 
     @GET
-    @Path("systems/{systemId}/agents/{agentId}")
-    @Produces(MediaType.APPLICATION_JSON)
-    public void getAgent(@Context SecurityContext securityContext,
-                         @Suspended final AsyncResponse asyncResponse,
-                         @PathParam("namespace") String namespace,
-                         @PathParam("systemId") String systemId,
-                         @PathParam("agentId") String agentId) {
-        handler.getAgent(securityContext, asyncResponse, namespace, systemId, agentId);
-    }
-
-    @PUT
-    @Path("systems/{systemId}/agents/{agentId}")
-    @Produces(MediaType.APPLICATION_JSON)
-    public void putAgent(String body,
-                         @Context SecurityContext context,
-                         @Suspended final AsyncResponse asyncResponse,
-                         @PathParam("namespace") String namespace,
-                         @PathParam("systemId") String systemId,
-                         @PathParam("agentId") String agentId) {
-        handler.putAgent(body, context, asyncResponse, namespace, systemId, agentId);
-    }
-
-    @DELETE
-    @Path("systems/{systemId}/agents/{agentId}")
-    @Produces(MediaType.APPLICATION_JSON)
-    public void deleteAgent(String body,
-                            @Context SecurityContext context,
-                            @Suspended final AsyncResponse asyncResponse,
-                            @PathParam("namespace") String namespace,
-                            @PathParam("systemId") String systemId,
-                            @PathParam("agentId") String agentId) {
-        handler.deleteAgent(body, context, asyncResponse, namespace, systemId, agentId);
-    }
-
-    @GET
-    @Path("systems/{systemId}/agents/{agentId}/jvms")
+    @Path("systems/{systemId}/agents/{agentId}/jvms/{jvmId}")
     @Produces(MediaType.APPLICATION_JSON)
     public void getJvms(@Context SecurityContext securityContext,
                         @Suspended final AsyncResponse asyncResponse,
                         @PathParam("namespace") String namespace,
                         @PathParam("systemId") String systemId,
                         @PathParam("agentId") String agentId,
-                        @PathParam("vmId") String vmId,
+                        @PathParam("jvmId") String jvmId,
                         @QueryParam("offset") @DefaultValue(OFFSET) String offset,
                         @QueryParam("limit") @DefaultValue(LIMIT) String limit,
                         @QueryParam("sort") String sort) {
-        handler.getJvms(securityContext, asyncResponse, namespace, systemId, agentId, vmId, offset, limit, sort);
+        handler.getJvms(securityContext, asyncResponse, namespace, systemId, agentId, jvmId, offset, limit, sort);
     }
 
     @PUT
-    @Path("systems/{systemId}/agents/{agentId}/jvms")
+    @Path("systems/{systemId}/agents/{agentId}/jvms/{jvmId}")
     @Produces(MediaType.APPLICATION_JSON)
     public void putJvms(String body,
                         @Context SecurityContext context,
                         @Suspended final AsyncResponse asyncResponse,
                         @PathParam("namespace") String namespace,
                         @PathParam("systemId") String systemId,
-                        @PathParam("agentId") String agentId) {
-        handler.putJvms(body, context, asyncResponse, namespace, systemId, agentId);
+                        @PathParam("agentId") String agentId,
+                        @PathParam("jvmId") String jvmId) {
+        handler.putJvms(body, context, asyncResponse, namespace, systemId, agentId, jvmId);
     }
 
     @POST
-    @Path("systems/{systemId}/agents/{agentId}/jvms")
+    @Path("systems/{systemId}/agents/{agentId}/jvms/{jvmId}")
     @Produces(MediaType.APPLICATION_JSON)
     public void postJvms(String body,
                          @Context SecurityContext context,
@@ -227,60 +173,24 @@
                          @PathParam("namespace") String namespace,
                          @PathParam("systemId") String systemId,
                          @PathParam("agentId") String agentId,
+                         @PathParam("jvmId") String jvmId,
                          @QueryParam("offset") @DefaultValue(OFFSET) String offset,
                          @QueryParam("limit") @DefaultValue(LIMIT) String limit,
                          @QueryParam("sort") String sort) {
-        handler.postJvms(body, context, asyncResponse, namespace, systemId, agentId, offset, limit, sort);
+        handler.postJvms(body, context, asyncResponse, namespace, systemId, agentId, jvmId, offset, limit, sort);
     }
 
     @DELETE
-    @Path("systems/{systemId}/agents/{agentId}/jvms")
+    @Path("systems/{systemId}/agents/{agentId}/jvms/{jvmId}")
     @Produces(MediaType.APPLICATION_JSON)
     public void deleteJvms(String body,
                            @Context SecurityContext context,
                            @Suspended final AsyncResponse asyncResponse,
                            @PathParam("namespace") String namespace,
                            @PathParam("systemId") String systemId,
-                           @PathParam("agentId") String agentId) {
-        handler.deleteJvms(body, context, asyncResponse, namespace, systemId, agentId);
-    }
-
-    @GET
-    @Path("systems/{systemId}/agents/{agentId}/jvms/{jvmId}")
-    @Produces(MediaType.APPLICATION_JSON)
-    public void getJvm(@Context SecurityContext securityContext,
-                       @Suspended final AsyncResponse asyncResponse,
-                       @PathParam("namespace") String namespace,
-                       @PathParam("systemId") String systemId,
-                       @PathParam("agentId") String agentId,
-                       @PathParam("jvmId") String jvmId) {
-        handler.getJvm(securityContext, asyncResponse, namespace, systemId, agentId, jvmId);
+                           @PathParam("agentId") String agentId,
+                           @PathParam("jvmId") String jvmId) {
+        handler.deleteJvms(body, context, asyncResponse, namespace, systemId, agentId, jvmId);
     }
 
-    @PUT
-    @Path("systems/{systemId}/agents/{agentId}/jvms/{jvmId}")
-    @Produces(MediaType.APPLICATION_JSON)
-    public void putJvm(String body,
-                       @Context SecurityContext context,
-                       @Suspended final AsyncResponse asyncResponse,
-                       @PathParam("namespace") String namespace,
-                       @PathParam("systemId") String systemId,
-                       @PathParam("agentId") String agentId,
-                       @PathParam("jvmId") String jvmId) {
-        handler.putJvm(body, context, asyncResponse, namespace, systemId, agentId, jvmId);
-    }
-
-
-    @DELETE
-    @Path("systems/{systemId}/agents/{agentId}/jvms/{jvmId}")
-    @Produces(MediaType.APPLICATION_JSON)
-    public void deleteJvm(String body,
-                          @Context SecurityContext context,
-                          @Suspended final AsyncResponse asyncResponse,
-                          @PathParam("namespace") String namespace,
-                          @PathParam("systemId") String systemId,
-                          @PathParam("agentId") String agentId,
-                          @PathParam("jvmId") String jvmId) {
-        handler.deleteJvm(body, context, asyncResponse, namespace, systemId, agentId, jvmId);
-    }
 }
--- a/server/core/src/main/java/com/redhat/thermostat/server/core/internal/web/handler/storage/StorageHandler.java	Wed Mar 01 12:23:51 2017 -0500
+++ b/server/core/src/main/java/com/redhat/thermostat/server/core/internal/web/handler/storage/StorageHandler.java	Wed Mar 01 16:16:25 2017 -0500
@@ -42,49 +42,29 @@
 import org.glassfish.jersey.server.ChunkedOutput;
 
 public interface StorageHandler {
-    void getSystems(SecurityContext context, AsyncResponse asyncResponse, String namespace, String offset, String limit, String sort);
-
-    void putSystems(String body, SecurityContext context, AsyncResponse asyncResponse, String namespace);
+    void getSystems(SecurityContext context, AsyncResponse asyncResponse, String namespace, String systemId, String offset, String limit, String sort);
 
-    void postSystems(String body, SecurityContext context, AsyncResponse asyncResponse, String namespace, String offset, String limit, String sort);
+    void putSystems(String body, SecurityContext context, AsyncResponse asyncResponse, String namespace, String systemId);
 
-    void deleteSystems(String body, SecurityContext context, AsyncResponse asyncResponse, String namespace);
-
-    void getSystem(SecurityContext securityContext, AsyncResponse asyncResponse, String namespace, String systemId);
+    void postSystems(String body, SecurityContext context, AsyncResponse asyncResponse, String namespace, String systemId, String offset, String limit, String sort);
 
-    void putSystem(String body, SecurityContext context, AsyncResponse asyncResponse, String namespace);
-
-    void deleteSystem(SecurityContext context, AsyncResponse asyncResponse, String namespace);
-
-    void getAgents(SecurityContext securityContext, AsyncResponse asyncResponse, String namespace, String systemId, String offset, String limit, String sort);
+    void deleteSystems(String body, SecurityContext context, AsyncResponse asyncResponse, String namespace, String systemId);
 
-    void putAgents(String body, SecurityContext context, AsyncResponse asyncResponse, String namespace, String systemId);
-
+    void getAgents(SecurityContext securityContext, AsyncResponse asyncResponse, String namespace, String systemId, String agentId, String offset, String limit, String sort);
 
-    void postAgents(String body, SecurityContext context, AsyncResponse asyncResponse, String namespace, String systemId, String offset, String limit, String sort);
-
+    void putAgents(String body, SecurityContext context, AsyncResponse asyncResponse, String namespace, String systemId, String agentId);
 
-    void deleteAgents(String body, SecurityContext context, AsyncResponse asyncResponse, String namespace, String systemId);
-
-    void getAgent(SecurityContext securityContext, AsyncResponse asyncResponse, String namespace, String systemId, String agentId);
+    void postAgents(String body, SecurityContext context, AsyncResponse asyncResponse, String namespace, String systemId, String agentId, String offset, String limit, String sort);
 
-    void putAgent(String body, SecurityContext context, AsyncResponse asyncResponse, String namespace, String systemId, String agentId);
+    void deleteAgents(String body, SecurityContext context, AsyncResponse asyncResponse, String namespace, String systemId, String agentId);
 
-    void deleteAgent(String body, SecurityContext context, AsyncResponse asyncResponse, String namespace, String systemId, String agentId);
-
-    void getJvms(SecurityContext securityContext, AsyncResponse asyncResponse, String namespace, String systemId, String agentId, String vmId, String offset, String limit, String sort);
+    void getJvms(SecurityContext securityContext, AsyncResponse asyncResponse, String namespace, String systemId, String agentId, String jvmId, String offset, String limit, String sort);
 
-    void putJvms(String body, SecurityContext context, AsyncResponse asyncResponse, String namespace, String systemId, String agentId);
-
-    void postJvms(String body, SecurityContext context, AsyncResponse asyncResponse, String namespace, String systemId, String agentId, String offset, String limit, String sort);
-
-    void deleteJvms(String body, SecurityContext context, AsyncResponse asyncResponse, String namespace, String systemId, String agentId);
+    void putJvms(String body, SecurityContext context, AsyncResponse asyncResponse, String namespace, String systemId, String agentId, String jvmId);
 
-    void getJvm(SecurityContext securityContext, AsyncResponse asyncResponse, String namespace, String systemId, String agentId, String jvmId);
+    void postJvms(String body, SecurityContext context, AsyncResponse asyncResponse, String namespace, String systemId, String agentId, String jvmId, String offset, String limit, String sort);
 
-    void putJvm(String body, SecurityContext context, AsyncResponse asyncResponse, String namespace, String systemId, String agentId, String jvmId);
-
-    void deleteJvm(String body, SecurityContext context, AsyncResponse asyncResponse, String namespace, String systemId, String agentId, String jvmId);
+    void deleteJvms(String body, SecurityContext context, AsyncResponse asyncResponse, String namespace, String systemId, String agentId, String jvmId);
 
     void getNamespaces(SecurityContext context, AsyncResponse asyncResponse, String offset, String limit);
 
--- a/server/core/src/main/java/com/redhat/thermostat/server/core/internal/web/handler/storage/mongo/MongoStorageHandler.java	Wed Mar 01 12:23:51 2017 -0500
+++ b/server/core/src/main/java/com/redhat/thermostat/server/core/internal/web/handler/storage/mongo/MongoStorageHandler.java	Wed Mar 01 16:16:25 2017 -0500
@@ -39,6 +39,7 @@
 import static com.mongodb.client.model.Projections.exclude;
 import static com.mongodb.client.model.Projections.excludeId;
 import static com.mongodb.client.model.Projections.fields;
+import static com.mongodb.client.model.Projections.include;
 
 import java.io.IOException;
 import java.util.ArrayList;
@@ -74,59 +75,50 @@
     private final String jvmCollectionSuffix = "-jvms";
 
     @Override
-    public void getSystems(final SecurityContext context, final AsyncResponse asyncResponse, final String namespace, final String offset, final String limit, final String sort) {
-        if (!isMongoConnected(asyncResponse)) {
-            return;
-        }
-        new Thread(new Runnable() {
-            @Override
-            public void run() {
-                getAll(offset,limit,context,null,null,null,namespace,sort,asyncResponse,systemCollectionSuffix);
-            }
-        }).start();
-    }
-
-    @Override
-    public void putSystems(final String body, final SecurityContext context, final AsyncResponse asyncResponse, final String namespace) {
+    public void getSystems(final SecurityContext context, final AsyncResponse asyncResponse, final String namespace, final String systemId, final String offset, final String limit, final String sort) {
         if (!isMongoConnected(asyncResponse)) {
             return;
         }
         new Thread(new Runnable() {
             @Override
             public void run() {
-                putAll(body, context, namespace, asyncResponse, systemCollectionSuffix);
+                getAll(offset, limit, context, systemId, null, null, namespace, sort, asyncResponse, systemCollectionSuffix);
             }
         }).start();
     }
 
     @Override
-    public void postSystems(final String body, final SecurityContext context, final AsyncResponse asyncResponse, final String namespace, final String offset, final String limit, final String sort) {
+    public void putSystems(final String body, final SecurityContext context, final AsyncResponse asyncResponse, final String namespace, final String systemId) {
+        if (!isMongoConnected(asyncResponse)) {
+            return;
+        }
+        if (systemId.equals("all")) {
+            asyncResponse.resume(Response.status(Response.Status.BAD_REQUEST).build());
+            return;
+        }
+        new Thread(new Runnable() {
+            @Override
+            public void run() {
+                putAll(body, context, systemId, null, null, namespace, asyncResponse, systemCollectionSuffix);
+            }
+        }).start();
+    }
+
+    @Override
+    public void postSystems(final String body, final SecurityContext context, final AsyncResponse asyncResponse, final String namespace, final String systemId, final String offset, final String limit, final String sort) {
         if (!isMongoConnected(asyncResponse)) {
             return;
         }
         new Thread(new Runnable() {
             @Override
             public void run() {
-                postAll(body, offset, limit, context, null, null, null, namespace, sort, asyncResponse, agentCollectionSuffix);
+                postAll(body, offset, limit, context, systemId, null, null, namespace, sort, asyncResponse, agentCollectionSuffix);
             }
         }).start();
     }
 
     @Override
-    public void deleteSystems(String body, SecurityContext context, final AsyncResponse asyncResponse, String namespace) {
-        if (!isMongoConnected(asyncResponse)) {
-            return;
-        }
-        new Thread(new Runnable() {
-            @Override
-            public void run() {
-                asyncResponse.resume(Response.status(Response.Status.NOT_IMPLEMENTED).build());
-            }
-        }).start();
-    }
-
-    @Override
-    public void getSystem(SecurityContext securityContext, final AsyncResponse asyncResponse, String namespace, String systemId) {
+    public void deleteSystems(String body, SecurityContext context, final AsyncResponse asyncResponse, String namespace, String systemId) {
         if (!isMongoConnected(asyncResponse)) {
             return;
         }
@@ -139,33 +131,7 @@
     }
 
     @Override
-    public void putSystem(String body, SecurityContext context, final AsyncResponse asyncResponse, String namespace) {
-        if (!isMongoConnected(asyncResponse)) {
-            return;
-        }
-        new Thread(new Runnable() {
-            @Override
-            public void run() {
-                asyncResponse.resume(Response.status(Response.Status.NOT_IMPLEMENTED).build());
-            }
-        }).start();
-    }
-
-    @Override
-    public void deleteSystem(SecurityContext context, final AsyncResponse asyncResponse, String namespace) {
-        if (!isMongoConnected(asyncResponse)) {
-            return;
-        }
-        new Thread(new Runnable() {
-            @Override
-            public void run() {
-                asyncResponse.resume(Response.status(Response.Status.NOT_IMPLEMENTED).build());
-            }
-        }).start();
-    }
-
-    @Override
-    public void getAgents(final SecurityContext context, final AsyncResponse asyncResponse, final String namespace, final String systemId, final String offset, final String limit, final String sort) {
+    public void getAgents(final SecurityContext context, final AsyncResponse asyncResponse, final String namespace, final String systemId, final String agentId, final String offset, final String limit, final String sort) {
         if (!isMongoConnected(asyncResponse)) {
             return;
         }
@@ -173,40 +139,45 @@
         new Thread(new Runnable() {
             @Override
             public void run() {
-                getAll(offset,limit,context,systemId,null,null,namespace,sort,asyncResponse,agentCollectionSuffix);
+                getAll(offset,limit,context,systemId,agentId,null,namespace,sort,asyncResponse,agentCollectionSuffix);
             }
         }).start();
     }
 
     @Override
-    public void putAgents(final String body, final SecurityContext context, final AsyncResponse asyncResponse, final String namespace, final String systemId) {
+    public void putAgents(final String body, final SecurityContext context, final AsyncResponse asyncResponse, final String namespace, final String systemId, final String agentId) {
         if (!isMongoConnected(asyncResponse)) {
             return;
         }
 
+        if (agentId.equals("all")) {
+            asyncResponse.resume(Response.status(Response.Status.BAD_REQUEST).build());
+            return;
+        }
+
         new Thread(new Runnable() {
             @Override
             public void run() {
-                putAll(body, context, namespace, asyncResponse, agentCollectionSuffix);
+                putAll(body, context, systemId, agentId, null, namespace, asyncResponse, agentCollectionSuffix);
             }
         }).start();
     }
 
     @Override
-    public void postAgents(final String body, final SecurityContext context, final AsyncResponse asyncResponse, final String namespace, final String systemId, final String offset, final String limit, final String sort) {
+    public void postAgents(final String body, final SecurityContext context, final AsyncResponse asyncResponse, final String namespace, final String systemId, final String agentId, final String offset, final String limit, final String sort) {
         if (!isMongoConnected(asyncResponse)) {
             return;
         }
         new Thread(new Runnable() {
             @Override
             public void run() {
-               postAll(body, offset, limit, context, systemId, null, null, namespace, sort, asyncResponse, agentCollectionSuffix);
+               postAll(body, offset, limit, context, systemId, agentId, null, namespace, sort, asyncResponse, agentCollectionSuffix);
             }
         }).start();
     }
 
     @Override
-    public void deleteAgents(String body, SecurityContext context, final AsyncResponse asyncResponse, final String namespace, String systemId) {
+    public void deleteAgents(String body, SecurityContext context, final AsyncResponse asyncResponse, final String namespace, String systemId, String agentId) {
         if (!isMongoConnected(asyncResponse)) {
             return;
         }
@@ -233,124 +204,52 @@
     }
 
     @Override
-    public void getAgent(SecurityContext context, final AsyncResponse asyncResponse, String namespace, String systemId, String agentId) {
-        if (!isMongoConnected(asyncResponse)) {
-            return;
-        }
-        new Thread(new Runnable() {
-            @Override
-            public void run() {
-                asyncResponse.resume(Response.status(Response.Status.NOT_IMPLEMENTED).build());
-            }
-        }).start();
-    }
-
-    @Override
-    public void putAgent(String body, SecurityContext context, final AsyncResponse asyncResponse, String namespace, String systemId, String agentId) {
-        if (!isMongoConnected(asyncResponse)) {
-            return;
-        }
-        new Thread(new Runnable() {
-            @Override
-            public void run() {
-                asyncResponse.resume(Response.status(Response.Status.NOT_IMPLEMENTED).build());
-            }
-        }).start();
-    }
-
-    @Override
-    public void deleteAgent(String body, SecurityContext context, final AsyncResponse asyncResponse, String namespace, String systemId, String agentId) {
-        if (!isMongoConnected(asyncResponse)) {
-            return;
-        }
-        new Thread(new Runnable() {
-            @Override
-            public void run() {
-                asyncResponse.resume(Response.status(Response.Status.NOT_IMPLEMENTED).build());
-            }
-        }).start();
-    }
-
-    @Override
-    public void getJvms(final SecurityContext context, final AsyncResponse asyncResponse, final String namespace, final String systemId, final String agentId, String vmId, final String offset, final String limit, final String sort) {
-        if (!isMongoConnected(asyncResponse)) {
-            return;
-        }
-        new Thread(new Runnable() {
-            @Override
-            public void run() {
-                getAll(offset, limit, context, systemId, agentId, null, namespace, sort, asyncResponse, jvmCollectionSuffix);
-            }
-        }).start();
-    }
-
-    @Override
-    public void putJvms(final String body, final SecurityContext context, final AsyncResponse asyncResponse, final String namespace, String systemId, String agentId) {
+    public void getJvms(final SecurityContext context, final AsyncResponse asyncResponse, final String namespace, final String systemId, final String agentId, final String jvmId, final String offset, final String limit, final String sort) {
         if (!isMongoConnected(asyncResponse)) {
             return;
         }
         new Thread(new Runnable() {
             @Override
             public void run() {
-                putAll(body, context, namespace, asyncResponse, jvmCollectionSuffix);
+                getAll(offset, limit, context, systemId, agentId, jvmId, namespace, sort, asyncResponse, jvmCollectionSuffix);
             }
         }).start();
     }
 
     @Override
-    public void postJvms(final String body, final SecurityContext context, final AsyncResponse asyncResponse, final String namespace, final String systemId, final String agentId, final String offset, final String limit, final String sort) {
+    public void putJvms(final String body, final SecurityContext context, final AsyncResponse asyncResponse, final String namespace, final String systemId, final String agentId, final String jvmId) {
         if (!isMongoConnected(asyncResponse)) {
             return;
         }
+
+        if (jvmId.equals("all")) {
+            asyncResponse.resume(Response.status(Response.Status.BAD_REQUEST).build());
+            return;
+        }
+
         new Thread(new Runnable() {
             @Override
             public void run() {
-                postAll(body, offset, limit, context, systemId, agentId, null, namespace, sort, asyncResponse, agentCollectionSuffix);
+                putAll(body, context, systemId, agentId, jvmId, namespace, asyncResponse, jvmCollectionSuffix);
             }
         }).start();
     }
 
     @Override
-    public void deleteJvms(String body, SecurityContext context, final AsyncResponse asyncResponse, String namespace, String systemId, String agentId) {
+    public void postJvms(final String body, final SecurityContext context, final AsyncResponse asyncResponse, final String namespace, final String systemId, final String agentId, final String jvmId, final String offset, final String limit, final String sort) {
         if (!isMongoConnected(asyncResponse)) {
             return;
         }
         new Thread(new Runnable() {
             @Override
             public void run() {
-                asyncResponse.resume(Response.status(Response.Status.NOT_IMPLEMENTED).build());
+                postAll(body, offset, limit, context, systemId, agentId, jvmId, namespace, sort, asyncResponse, agentCollectionSuffix);
             }
         }).start();
     }
 
     @Override
-    public void getJvm(SecurityContext context, final AsyncResponse asyncResponse, String namespace, String systemId, String agentId, String jvmId) {
-        if (!isMongoConnected(asyncResponse)) {
-            return;
-        }
-        new Thread(new Runnable() {
-            @Override
-            public void run() {
-                asyncResponse.resume(Response.status(Response.Status.NOT_IMPLEMENTED).build());
-            }
-        }).start();
-    }
-
-    @Override
-    public void putJvm(String body, SecurityContext context, final AsyncResponse asyncResponse, String namespace, String systemId, String agentId, String jvmId) {
-        if (!isMongoConnected(asyncResponse)) {
-            return;
-        }
-        new Thread(new Runnable() {
-            @Override
-            public void run() {
-                asyncResponse.resume(Response.status(Response.Status.NOT_IMPLEMENTED).build());
-            }
-        }).start();
-    }
-
-    @Override
-    public void deleteJvm(String body, SecurityContext context, final AsyncResponse asyncResponse, String namespace, String systemId, String agentId, String jvmId) {
+    public void deleteJvms(String body, SecurityContext context, final AsyncResponse asyncResponse, String namespace, String systemId, String agentId, String jvmId) {
         if (!isMongoConnected(asyncResponse)) {
             return;
         }
@@ -454,9 +353,9 @@
             String[] items = sort.split(",");
             for (String item : items) {
                 if (item.charAt(0) == '+') {
-                    sortObject.append(item.substring(1), 1);
+                    sortObject.append("obj." + item.substring(1), 1);
                 } else if (item.charAt(0) == '-') {
-                    sortObject.append(item.substring(1), -1);
+                    sortObject.append("obj." + item.substring(1), -1);
                 }
             }
         }
@@ -475,7 +374,7 @@
             String documents = timedRequest.run(new TimedRequest.TimedRunnable<String>() {
                 @Override
                 public String run() {
-                    FindIterable<Document> documents = ThermostatMongoStorage.getDatabase().getCollection(namespace + collectionSuffix).find(filter).projection(fields(exclude("tags"), excludeId())).sort(createSortObject(sort)).limit(l).skip(o);
+                    FindIterable<Document> documents = ThermostatMongoStorage.getDatabase().getCollection(namespace + collectionSuffix).find(filter).projection(fields(include("obj"), excludeId())).sort(createSortObject(sort)).limit(l).skip(o);
                     return MongoResponseBuilder.buildJsonDocuments(documents);
                 }
             });
@@ -486,13 +385,13 @@
         }
     }
 
-    private void putAll(String body, SecurityContext context, final String namespace, AsyncResponse asyncResponse, final String collectionSuffix) {
+    private void putAll(String body, SecurityContext context, String systemId, String agentId, String jvmId, final String namespace, AsyncResponse asyncResponse, final String collectionSuffix) {
         try {
             BasicDBList inputList = (BasicDBList) JSON.parse(body);
 
             final List<Document> items = new ArrayList<>();
             for (Object item : inputList) {
-                items.add(Document.parse(DocumentBuilder.addTags(item.toString(), context.getUserPrincipal().getName())));
+                items.add(Document.parse(new DocumentBuilder(item.toString()).addTags(context.getUserPrincipal().getName()).addId("systemId", systemId).addId("agentId", agentId).addId("jvmId", jvmId).build()));
             }
 
             TimedRequest<Boolean> timedRequest = new TimedRequest<>();
--- a/server/core/src/main/java/com/redhat/thermostat/server/core/internal/web/handler/storage/mongo/filters/MongoRequestFilters.java	Wed Mar 01 12:23:51 2017 -0500
+++ b/server/core/src/main/java/com/redhat/thermostat/server/core/internal/web/handler/storage/mongo/filters/MongoRequestFilters.java	Wed Mar 01 16:16:25 2017 -0500
@@ -105,7 +105,7 @@
             Pattern p = Pattern.compile("(<=|>=|<|>|=)");
             Matcher m = p.matcher(filter);
             if (m.find()) {
-                String key = filter.substring(0, m.start());
+                String key = "obj." + filter.substring(0, m.start());
                 String comparator = filter.substring(m.start(), m.end());
                 String value = filter.substring(m.end());
                 switch (comparator) {
--- a/server/core/src/main/java/com/redhat/thermostat/server/core/internal/web/handler/storage/mongo/response/MongoResponseBuilder.java	Wed Mar 01 12:23:51 2017 -0500
+++ b/server/core/src/main/java/com/redhat/thermostat/server/core/internal/web/handler/storage/mongo/response/MongoResponseBuilder.java	Wed Mar 01 16:16:25 2017 -0500
@@ -75,7 +75,7 @@
         int i = 0;
         for (Document document : documents) {
             i++;
-            s.append(document.toJson()).append(",");
+            s.append(((Document)document.get("obj")).toJson()).append(",");
         }
 
         if (i != 0) {
--- a/server/core/src/main/java/com/redhat/thermostat/server/core/internal/web/json/DocumentBuilder.java	Wed Mar 01 12:23:51 2017 -0500
+++ b/server/core/src/main/java/com/redhat/thermostat/server/core/internal/web/json/DocumentBuilder.java	Wed Mar 01 16:16:25 2017 -0500
@@ -38,14 +38,22 @@
 
 public class DocumentBuilder {
 
+    private StringBuilder contentBuilder;
+
+    public DocumentBuilder(String content) {
+        contentBuilder = new StringBuilder();
+        contentBuilder.append("{ \"obj\" : ");
+        contentBuilder.append(content);
+        contentBuilder.append("}");
+    }
+
     /**
      * Adds tags to the JSON content
      * {/[ ... }/] -> {/[ ... ,tags:["admin",...]}/]
-     * @param content
      * @param tags
      * @return the JSON string with tags attached
      */
-    public static String addTags(String content, String... tags) {
+    public DocumentBuilder addTags(String... tags) {
         StringBuilder tagBuilder = new StringBuilder();
         tagBuilder.append(",\"tags\":[\"admin\"");
         for (String tag : tags) {
@@ -53,8 +61,27 @@
         }
         tagBuilder.append("]");
 
-        StringBuilder contentBuilder = new StringBuilder(content);
         contentBuilder.insert(contentBuilder.length() - 1, tagBuilder.toString());
+        return this;
+    }
+
+    /**
+     * Add key-value pair to the JSON content
+     * {/[ ... }/] -> {/[ ... ,"key:"admin"}/]
+     *
+     * @param key
+     * @param value
+     * @return the JSON string with key-value pair attached
+     */
+    public DocumentBuilder addId(String key, String value) {
+        if (key != null && value != null) {
+            String kvPair = ",\"" + key + "\":\"" + value + "\"";
+            contentBuilder.insert(contentBuilder.length() - 1, kvPair);
+        }
+        return this;
+    }
+
+    public String build() {
         return contentBuilder.toString();
     }
 }
--- a/server/core/src/test/java/com/redhat/thermostat/server/core/GetCoreServerTest.java	Wed Mar 01 12:23:51 2017 -0500
+++ b/server/core/src/test/java/com/redhat/thermostat/server/core/GetCoreServerTest.java	Wed Mar 01 16:16:25 2017 -0500
@@ -13,13 +13,6 @@
 public class GetCoreServerTest extends AbstractCoreServerTest {
     @Test
     public void testGetSystems() throws InterruptedException, ExecutionException, TimeoutException {
-        String url = baseUrl + "/namespace/systems";
-        ContentResponse response = client.GET(url);
-        assertTrue(response.getStatus() == Response.Status.SERVICE_UNAVAILABLE.getStatusCode());
-    }
-
-    @Test
-    public void testGetSystem() throws InterruptedException, ExecutionException, TimeoutException {
         String url = baseUrl + "/namespace/systems/systemId";
         ContentResponse response = client.GET(url);
         assertTrue(response.getStatus() == Response.Status.SERVICE_UNAVAILABLE.getStatusCode());
@@ -27,13 +20,6 @@
 
     @Test
     public void testGetAgents() throws InterruptedException, ExecutionException, TimeoutException {
-        String url = baseUrl + "/namespace/systems/systemId/agents";
-        ContentResponse response = client.GET(url);
-        assertTrue(response.getStatus() == Response.Status.SERVICE_UNAVAILABLE.getStatusCode());
-    }
-
-    @Test
-    public void testGetAgent() throws InterruptedException, ExecutionException, TimeoutException {
         String url = baseUrl + "/namespace/systems/systemId/agents/agentId";
         ContentResponse response = client.GET(url);
         assertTrue(response.getStatus() == Response.Status.SERVICE_UNAVAILABLE.getStatusCode());
@@ -41,13 +27,6 @@
 
     @Test
     public void testGetJvms() throws InterruptedException, ExecutionException, TimeoutException {
-        String url = baseUrl + "/namespace/systems/systemId/agents/agentId/jvms";
-        ContentResponse response = client.GET(url);
-        assertTrue(response.getStatus() == Response.Status.SERVICE_UNAVAILABLE.getStatusCode());
-    }
-
-    @Test
-    public void testGetJvm() throws InterruptedException, ExecutionException, TimeoutException {
         String url = baseUrl + "/namespace/systems/systemId/agents/agentId/jvms/jvmId";
         ContentResponse response = client.GET(url);
         assertTrue(response.getStatus() == Response.Status.SERVICE_UNAVAILABLE.getStatusCode());
--- a/server/core/src/test/java/com/redhat/thermostat/server/core/MongoCoreServerTest.java	Wed Mar 01 12:23:51 2017 -0500
+++ b/server/core/src/test/java/com/redhat/thermostat/server/core/MongoCoreServerTest.java	Wed Mar 01 16:16:25 2017 -0500
@@ -17,221 +17,222 @@
 
     @Test
     public void testPutGetSystems() throws InterruptedException, ExecutionException, TimeoutException {
-        String url = baseUrl + "/PutGetSystems/systems";
+        String url = baseUrl + "/PutGetSystems/systems/systemId";
 
-        String putInput = "[{\"systemId\":\"a\"},{\"systemId\":\"b\"}]";
+        String putInput = "[{\"systemStuff\":\"a\"},{\"systemStuff\":\"b\"}]";
         ContentResponse putResponse = client.newRequest(url).method(HttpMethod.PUT).content(new StringContentProvider(putInput), "application/json").send();
 
+        assertEquals(Response.Status.OK.getStatusCode(), putResponse.getStatus());
         assertEquals("PUT: true", putResponse.getContentAsString());
-        assertTrue(putResponse.getStatus() == Response.Status.OK.getStatusCode());
 
         ContentResponse getResponse = client.newRequest(url).method(HttpMethod.GET).send();
 
-        assertTrue(getResponse.getContentAsString().matches("\\{\"response\" : \\[\\{ \"systemId\" : \"a\" },\\{ \"systemId\" : \"b\" }],\"time\" : \"[0-9]*\"}"));
-        assertTrue(getResponse.getStatus() == Response.Status.OK.getStatusCode());
+        assertEquals(Response.Status.OK.getStatusCode(), getResponse.getStatus());
+        assertTrue(getResponse.getContentAsString().matches("\\{\"response\" : \\[\\{ \"systemStuff\" : \"a\" },\\{ \"systemStuff\" : \"b\" }],\"time\" : \"[0-9]*\"}"));
     }
 
     @Test
     public void testPutGetAgents() throws InterruptedException, ExecutionException, TimeoutException {
-        String url = baseUrl + "/PutGetAgents/systems/all/agents";
-        String putInput = "[{\"agentId\":\"a\"},{\"agentId\":\"b\"}]";
+        String url = baseUrl + "/PutGetAgents/systems/all/agents/agentId";
+        String putInput = "[{\"agentStuff\":\"a\"},{\"agentStuff\":\"b\"}]";
         ContentResponse putResponse = client.newRequest(url).method(HttpMethod.PUT).content(new StringContentProvider(putInput), "application/json").send();
 
+        assertEquals(Response.Status.OK.getStatusCode(), putResponse.getStatus());
         assertEquals("PUT: true", putResponse.getContentAsString());
-        assertTrue(putResponse.getStatus() == Response.Status.OK.getStatusCode());
 
         ContentResponse getResponse = client.newRequest(url).method(HttpMethod.GET).send();
 
-        assertTrue(getResponse.getContentAsString().matches("\\{\"response\" : \\[\\{ \"agentId\" : \"a\" },\\{ \"agentId\" : \"b\" }],\"time\" : \"[0-9]*\"}"));
-        assertTrue(getResponse.getStatus() == Response.Status.OK.getStatusCode());
+        assertEquals(Response.Status.OK.getStatusCode(), getResponse.getStatus());
+        assertTrue(getResponse.getContentAsString().matches("\\{\"response\" : \\[\\{ \"agentStuff\" : \"a\" },\\{ \"agentStuff\" : \"b\" }],\"time\" : \"[0-9]*\"}"));
     }
 
     @Test
     public void testGetAgentsLimit() throws InterruptedException, ExecutionException, TimeoutException {
-        String url = baseUrl + "/GetAgentsLimit/systems/all/agents";
-        String putInput = "[{\"agentId\":\"a\"},{\"agentId\":\"b\"}]";
+        String url = baseUrl + "/GetAgentsLimit/systems/all/agents/agentId";
+        String putInput = "[{\"agentStuff\":\"a\"},{\"agentStuff\":\"b\"}]";
         ContentResponse putResponse = client.newRequest(url).method(HttpMethod.PUT).content(new StringContentProvider(putInput), "application/json").send();
 
+        assertEquals(Response.Status.OK.getStatusCode(), putResponse.getStatus());
         assertEquals("PUT: true", putResponse.getContentAsString());
-        assertTrue(putResponse.getStatus() == Response.Status.OK.getStatusCode());
 
         ContentResponse getResponse = client.newRequest(url).method(HttpMethod.GET).param("limit", "1").send();
 
-        assertTrue(getResponse.getContentAsString().matches("\\{\"response\" : \\[\\{ \"agentId\" : \"a\" }],\"time\" : \"[0-9]*\"}"));
-        assertTrue(getResponse.getStatus() == Response.Status.OK.getStatusCode());
+        assertEquals(Response.Status.OK.getStatusCode(), getResponse.getStatus());
+        assertTrue(getResponse.getContentAsString().matches("\\{\"response\" : \\[\\{ \"agentStuff\" : \"a\" }],\"time\" : \"[0-9]*\"}"));
     }
 
     @Test
     public void testGetAgentsSort() throws InterruptedException, ExecutionException, TimeoutException {
-        String url = baseUrl + "/GetAgentsSort/systems/all/agents";
-        String putInput = "[{\"agentId\":\"a\"},{\"agentId\":\"b\"}]";
+        String url = baseUrl + "/GetAgentsSort/systems/all/agents/agentId";
+        String putInput = "[{\"agentStuff\":\"a\"},{\"agentStuff\":\"b\"}]";
         ContentResponse putResponse = client.newRequest(url).method(HttpMethod.PUT).content(new StringContentProvider(putInput), "application/json").send();
 
+        assertEquals(Response.Status.OK.getStatusCode(), putResponse.getStatus());
         assertEquals("PUT: true", putResponse.getContentAsString());
-        assertTrue(putResponse.getStatus() == Response.Status.OK.getStatusCode());
 
-        ContentResponse sortDescResponse = client.newRequest(url).method(HttpMethod.GET).param("sort", "-agentId").send();
+        ContentResponse sortDescResponse = client.newRequest(url).method(HttpMethod.GET).param("sort", "-agentStuff").send();
 
-        assertTrue(sortDescResponse.getContentAsString().matches("\\{\"response\" : \\[\\{ \"agentId\" : \"b\" },\\{ \"agentId\" : \"a\" }],\"time\" : \"[0-9]*\"}"));
-        assertTrue(sortDescResponse.getStatus() == Response.Status.OK.getStatusCode());
-
+        assertEquals(Response.Status.OK.getStatusCode(), sortDescResponse.getStatus());
+        assertTrue(sortDescResponse.getContentAsString().matches("\\{\"response\" : \\[\\{ \"agentStuff\" : \"b\" },\\{ \"agentStuff\" : \"a\" }],\"time\" : \"[0-9]*\"}"));
 
-        ContentResponse sortAsceResponse = client.newRequest(url).method(HttpMethod.GET).param("sort", "+agentId").send();
+        ContentResponse sortAsceResponse = client.newRequest(url).method(HttpMethod.GET).param("sort", "+agentStuff").send();
 
-        assertTrue(sortAsceResponse.getContentAsString().matches("\\{\"response\" : \\[\\{ \"agentId\" : \"a\" },\\{ \"agentId\" : \"b\" }],\"time\" : \"[0-9]*\"}"));
-        assertTrue(sortAsceResponse.getStatus() == Response.Status.OK.getStatusCode());
+        assertEquals(Response.Status.OK.getStatusCode(), sortAsceResponse.getStatus());
+        assertTrue(sortAsceResponse.getContentAsString().matches("\\{\"response\" : \\[\\{ \"agentStuff\" : \"a\" },\\{ \"agentStuff\" : \"b\" }],\"time\" : \"[0-9]*\"}"));
     }
 
     @Test
     public void testGetAgentsLimitSort() throws InterruptedException, ExecutionException, TimeoutException {
-        String url = baseUrl + "/GetAgentsSortLimit/systems/all/agents";
-        String putInput = "[{\"agentId\":\"a\"},{\"agentId\":\"b\"}]";
+        String url = baseUrl + "/GetAgentsSortLimit/systems/all/agents/agentId";
+        String putInput = "[{\"agentStuff\":\"a\"},{\"agentStuff\":\"b\"}]";
         ContentResponse putResponse = client.newRequest(url).method(HttpMethod.PUT).content(new StringContentProvider(putInput), "application/json").send();
 
+        assertEquals(Response.Status.OK.getStatusCode(), putResponse.getStatus());
         assertEquals("PUT: true", putResponse.getContentAsString());
-        assertTrue(putResponse.getStatus() == Response.Status.OK.getStatusCode());
 
-        ContentResponse getResponse = client.newRequest(url).method(HttpMethod.GET).param("limit", "1").param("sort", "-agentId").send();
+        ContentResponse getResponse = client.newRequest(url).method(HttpMethod.GET).param("limit", "1").param("sort", "-agentStuff").send();
 
-        assertTrue(getResponse.getContentAsString().matches("\\{\"response\" : \\[\\{ \"agentId\" : \"b\" }],\"time\" : \"[0-9]*\"}"));
-        assertTrue(getResponse.getStatus() == Response.Status.OK.getStatusCode());
+        System.out.println(getResponse.getContentAsString());
+        assertEquals(Response.Status.OK.getStatusCode(), getResponse.getStatus());
+        assertTrue(getResponse.getContentAsString().matches("\\{\"response\" : \\[\\{ \"agentStuff\" : \"b\" }],\"time\" : \"[0-9]*\"}"));
     }
 
     @Test
     public void testEqualQueryPostAgents() throws InterruptedException, ExecutionException, TimeoutException {
-        String url = baseUrl + "/EqualQueryPostAgents/systems/all/agents";
-        String putInput = "[{\"agentId\":\"a\"},{\"agentId\":\"b\"}]";
+        String url = baseUrl + "/EqualQueryPostAgents/systems/all/agents/agentId";
+        String putInput = "[{\"agentStuff\":\"a\"},{\"agentStuff\":\"b\"}]";
         ContentResponse putResponse = client.newRequest(url).method(HttpMethod.PUT).content(new StringContentProvider(putInput), "application/json").send();
 
+        assertEquals(Response.Status.OK.getStatusCode(), putResponse.getStatus());
         assertEquals("PUT: true", putResponse.getContentAsString());
-        assertTrue(putResponse.getStatus() == Response.Status.OK.getStatusCode());
 
-        String postInput = "[\"agentId=a\"]";
+        String postInput = "[\"agentStuff=a\"]";
         ContentResponse postResponse = client.newRequest(url).method(HttpMethod.POST).content(new StringContentProvider(postInput), "application/json").send();
 
-        assertTrue(postResponse.getContentAsString().matches("\\{\"response\" : \\[\\{ \"agentId\" : \"a\" }],\"time\" : \"[0-9]*\"}"));
-        assertTrue(postResponse.getStatus() == Response.Status.OK.getStatusCode());
+        assertEquals(Response.Status.OK.getStatusCode(), postResponse.getStatus());
+        assertTrue(postResponse.getContentAsString().matches("\\{\"response\" : \\[\\{ \"agentStuff\" : \"a\" }],\"time\" : \"[0-9]*\"}"));
     }
 
     @Test
     public void testLessQueryPostAgents() throws InterruptedException, ExecutionException, TimeoutException {
-        String url = baseUrl + "/LessQueryPostAgents/systems/all/agents";
-        String putInput = "[{\"agentId\":\"a\"},{\"agentId\":\"b\"}]";
+        String url = baseUrl + "/LessQueryPostAgents/systems/all/agents/agentId";
+        String putInput = "[{\"agentStuff\":\"a\"},{\"agentStuff\":\"b\"}]";
         ContentResponse putResponse = client.newRequest(url).method(HttpMethod.PUT).content(new StringContentProvider(putInput), "application/json").send();
 
+        assertEquals(Response.Status.OK.getStatusCode(), putResponse.getStatus());
         assertEquals("PUT: true", putResponse.getContentAsString());
-        assertTrue(putResponse.getStatus() == Response.Status.OK.getStatusCode());
 
-        String postInput = "[\"agentId<b\"]";
+        String postInput = "[\"agentStuff<b\"]";
         ContentResponse postResponse = client.newRequest(url).method(HttpMethod.POST).content(new StringContentProvider(postInput), "application/json").send();
 
-        assertTrue(postResponse.getContentAsString().matches("\\{\"response\" : \\[\\{ \"agentId\" : \"a\" }],\"time\" : \"[0-9]*\"}"));
-        assertTrue(postResponse.getStatus() == Response.Status.OK.getStatusCode());
+        assertEquals(Response.Status.OK.getStatusCode(), postResponse.getStatus());
+        assertTrue(postResponse.getContentAsString().matches("\\{\"response\" : \\[\\{ \"agentStuff\" : \"a\" }],\"time\" : \"[0-9]*\"}"));
     }
 
     @Test
     public void testGreaterQueryPostAgents() throws InterruptedException, ExecutionException, TimeoutException {
-        String url = baseUrl + "/GreaterQueryPostAgents/systems/all/agents";
-        String putInput = "[{\"agentId\":\"a\"},{\"agentId\":\"b\"}]";
+        String url = baseUrl + "/GreaterQueryPostAgents/systems/all/agents/agentId";
+        String putInput = "[{\"agentStuff\":\"a\"},{\"agentStuff\":\"b\"}]";
         ContentResponse putResponse = client.newRequest(url).method(HttpMethod.PUT).content(new StringContentProvider(putInput), "application/json").send();
 
+        assertEquals(Response.Status.OK.getStatusCode(), putResponse.getStatus());
         assertEquals("PUT: true", putResponse.getContentAsString());
-        assertTrue(putResponse.getStatus() == Response.Status.OK.getStatusCode());
 
-        String postInput = "[\"agentId>a\"]";
+        String postInput = "[\"agentStuff>a\"]";
         ContentResponse postResponse = client.newRequest(url).method(HttpMethod.POST).content(new StringContentProvider(postInput), "application/json").send();
 
-        assertTrue(postResponse.getContentAsString().matches("\\{\"response\" : \\[\\{ \"agentId\" : \"b\" }],\"time\" : \"[0-9]*\"}"));
-        assertTrue(postResponse.getStatus() == Response.Status.OK.getStatusCode());
+        assertEquals(Response.Status.OK.getStatusCode(), postResponse.getStatus());
+        assertTrue(postResponse.getContentAsString().matches("\\{\"response\" : \\[\\{ \"agentStuff\" : \"b\" }],\"time\" : \"[0-9]*\"}"));
     }
 
     @Test
     public void testLessEqualQueryPostAgents() throws InterruptedException, ExecutionException, TimeoutException {
-        String url = baseUrl + "/LessEqualQueryPostAgents/systems/all/agents";
-        String putInput = "[{\"agentId\":\"a\"},{\"agentId\":\"b\"}]";
+        String url = baseUrl + "/LessEqualQueryPostAgents/systems/all/agents/agentId";
+        String putInput = "[{\"agentStuff\":\"a\"},{\"agentStuff\":\"b\"}]";
         ContentResponse putResponse = client.newRequest(url).method(HttpMethod.PUT).content(new StringContentProvider(putInput), "application/json").send();
 
+        assertEquals(Response.Status.OK.getStatusCode(), putResponse.getStatus());
         assertEquals("PUT: true", putResponse.getContentAsString());
-        assertTrue(putResponse.getStatus() == Response.Status.OK.getStatusCode());
 
-        String postInput = "[\"agentId<=b\"]";
+        String postInput = "[\"agentStuff<=b\"]";
         ContentResponse postResponse = client.newRequest(url).method(HttpMethod.POST).content(new StringContentProvider(postInput), "application/json").send();
 
-        assertTrue(postResponse.getContentAsString().matches("\\{\"response\" : \\[\\{ \"agentId\" : \"a\" },\\{ \"agentId\" : \"b\" }],\"time\" : \"[0-9]*\"}"));
-        assertTrue(postResponse.getStatus() == Response.Status.OK.getStatusCode());
+        assertEquals(Response.Status.OK.getStatusCode(), postResponse.getStatus());
+        assertTrue(postResponse.getContentAsString().matches("\\{\"response\" : \\[\\{ \"agentStuff\" : \"a\" },\\{ \"agentStuff\" : \"b\" }],\"time\" : \"[0-9]*\"}"));
     }
 
     @Test
     public void testGreaterEqualQueryPostAgents() throws InterruptedException, ExecutionException, TimeoutException {
-        String url = baseUrl + "/GreaterEqualQueryPostAgents/systems/all/agents";
-        String putInput = "[{\"agentId\":\"a\"},{\"agentId\":\"b\"}]";
+        String url = baseUrl + "/GreaterEqualQueryPostAgents/systems/all/agents/agentId";
+        String putInput = "[{\"agentStuff\":\"a\"},{\"agentStuff\":\"b\"}]";
         ContentResponse putResponse = client.newRequest(url).method(HttpMethod.PUT).content(new StringContentProvider(putInput), "application/json").send();
 
+        assertEquals(Response.Status.OK.getStatusCode(), putResponse.getStatus());
         assertEquals("PUT: true", putResponse.getContentAsString());
-        assertTrue(putResponse.getStatus() == Response.Status.OK.getStatusCode());
 
-        String postInput = "[\"agentId>=a\"]";
+        String postInput = "[\"agentStuff>=a\"]";
         ContentResponse postResponse = client.newRequest(url).method(HttpMethod.POST).content(new StringContentProvider(postInput), "application/json").send();
 
-        assertTrue(postResponse.getContentAsString().matches("\\{\"response\" : \\[\\{ \"agentId\" : \"a\" },\\{ \"agentId\" : \"b\" }],\"time\" : \"[0-9]*\"}"));
-        assertTrue(postResponse.getStatus() == Response.Status.OK.getStatusCode());
+        assertEquals(Response.Status.OK.getStatusCode(), postResponse.getStatus());
+        assertTrue(postResponse.getContentAsString().matches("\\{\"response\" : \\[\\{ \"agentStuff\" : \"a\" },\\{ \"agentStuff\" : \"b\" }],\"time\" : \"[0-9]*\"}"));
     }
 
 
     @Test
     public void testMultiQueryPostAgents() throws InterruptedException, ExecutionException, TimeoutException {
-        String url = baseUrl + "/MultiQueryPostAgents/systems/all/agents";
-        String putInput = "[{\"agentId\":\"a\", \"item\":\"1\"},{\"agentId\":\"a\", \"item\":\"2\"}]";
+        String url = baseUrl + "/MultiQueryPostAgents/systems/all/agents/agentId";
+        String putInput = "[{\"agentStuff\":\"a\", \"item\":\"1\"},{\"agentStuff\":\"a\", \"item\":\"2\"}]";
         ContentResponse putResponse = client.newRequest(url).method(HttpMethod.PUT).content(new StringContentProvider(putInput), "application/json").send();
 
+        assertEquals(Response.Status.OK.getStatusCode(), putResponse.getStatus());
         assertEquals("PUT: true", putResponse.getContentAsString());
-        assertTrue(putResponse.getStatus() == Response.Status.OK.getStatusCode());
 
-        String postInput = "[\"agentId=a\", \"item<2\"]";
+        String postInput = "[\"agentStuff=a\", \"item<2\"]";
         ContentResponse postResponse = client.newRequest(url).method(HttpMethod.POST).content(new StringContentProvider(postInput), "application/json").send();
 
-        assertTrue(postResponse.getContentAsString().matches("\\{\"response\" : \\[\\{ \"agentId\" : \"a\", \"item\" : \"1\" }],\"time\" : \"[0-9]*\"}"));
-        assertTrue(postResponse.getStatus() == Response.Status.OK.getStatusCode());
+        System.out.println(postResponse.getContentAsString());
+        assertEquals(Response.Status.OK.getStatusCode(), postResponse.getStatus());
+        assertTrue(postResponse.getContentAsString().matches("\\{\"response\" : \\[\\{ \"agentStuff\" : \"a\", \"item\" : \"1\" }],\"time\" : \"[0-9]*\"}"));
     }
 
     @Test
     public void testDeleteAgents() throws InterruptedException, ExecutionException, TimeoutException {
-        String url = baseUrl + "/DeleteAgents/systems/all/agents";
-        String input = "[{\"agentId\":\"a\"},{\"agentId\":\"b\"}]";
+        String url = baseUrl + "/DeleteAgents/systems/all/agents/agentId";
+        String input = "[{\"agentStuff\":\"a\"},{\"agentStuff\":\"b\"}]";
         ContentResponse putResponse = client.newRequest(url).method(HttpMethod.PUT).content(new StringContentProvider(input), "application/json").send();
 
+        assertEquals(Response.Status.OK.getStatusCode(), putResponse.getStatus());
         assertEquals("PUT: true", putResponse.getContentAsString());
-        assertTrue(putResponse.getStatus() == Response.Status.OK.getStatusCode());
 
         ContentResponse getResponse = client.newRequest(url).method(HttpMethod.GET).send();
 
-        assertTrue(getResponse.getContentAsString().matches("\\{\"response\" : \\[\\{ \"agentId\" : \"a\" },\\{ \"agentId\" : \"b\" }],\"time\" : \"[0-9]*\"}"));
-        assertTrue(getResponse.getStatus() == Response.Status.OK.getStatusCode());
+        assertEquals(Response.Status.OK.getStatusCode(), getResponse.getStatus());
+        assertTrue(getResponse.getContentAsString().matches("\\{\"response\" : \\[\\{ \"agentStuff\" : \"a\" },\\{ \"agentStuff\" : \"b\" }],\"time\" : \"[0-9]*\"}"));
 
         ContentResponse deleteResponse = client.newRequest(url).method(HttpMethod.DELETE).send();
 
+        assertEquals(Response.Status.OK.getStatusCode(), deleteResponse.getStatus());
         assertEquals("DELETE: true", deleteResponse.getContentAsString());
-        assertTrue(deleteResponse.getStatus() == Response.Status.OK.getStatusCode());
 
         ContentResponse getAfterResponse = client.newRequest(url).method(HttpMethod.GET).send();
 
+        assertEquals(Response.Status.OK.getStatusCode(), getAfterResponse.getStatus());
         assertTrue(getAfterResponse.getContentAsString().matches("\\{\"response\" : \\[],\"time\" : \"[0-9]*\"}"));
-        assertTrue(getAfterResponse.getStatus() == Response.Status.OK.getStatusCode());
     }
 
     @Test
     public void testPutGetJvms() throws InterruptedException, ExecutionException, TimeoutException {
-        String url = baseUrl + "/PutGetJvms/systems/all/agents/all/jvms";
-        String putInput = "[{\"jvmId\":\"a\"},{\"jvmId\":\"b\"}]";
+        String url = baseUrl + "/PutGetJvms/systems/all/agents/all/jvms/jvmId";
+        String putInput = "[{\"jvmStuff\":\"a\"},{\"jvmStuff\":\"b\"}]";
         ContentResponse putResponse = client.newRequest(url).method(HttpMethod.PUT).content(new StringContentProvider(putInput), "application/json").send();
 
+        assertEquals(Response.Status.OK.getStatusCode(), putResponse.getStatus());
         assertEquals("PUT: true", putResponse.getContentAsString());
-        assertTrue(putResponse.getStatus() == Response.Status.OK.getStatusCode());
 
         ContentResponse getResponse = client.newRequest(url).method(HttpMethod.GET).send();
 
-        assertTrue(getResponse.getContentAsString().matches("\\{\"response\" : \\[\\{ \"jvmId\" : \"a\" },\\{ \"jvmId\" : \"b\" }],\"time\" : \"[0-9]*\"}"));
-        assertTrue(getResponse.getStatus() == Response.Status.OK.getStatusCode());
+        assertEquals(Response.Status.OK.getStatusCode(), getResponse.getStatus());
+        assertTrue(getResponse.getContentAsString().matches("\\{\"response\" : \\[\\{ \"jvmStuff\" : \"a\" },\\{ \"jvmStuff\" : \"b\" }],\"time\" : \"[0-9]*\"}"));
     }
 
 }
--- a/server/core/src/test/java/com/redhat/thermostat/server/core/internal/web/handler/storage/mongo/response/MongoResponseBuilderTest.java	Wed Mar 01 12:23:51 2017 -0500
+++ b/server/core/src/test/java/com/redhat/thermostat/server/core/internal/web/handler/storage/mongo/response/MongoResponseBuilderTest.java	Wed Mar 01 16:16:25 2017 -0500
@@ -34,8 +34,8 @@
 
     @Test
     public void testBuildJsonDocument() {
-        Document d1 = Document.parse("{\"hello\" : \"blob\"}");
-        Document d2 = Document.parse("{\"a\" : {\"blob\" : [\"hi\"]}}");
+        Document d1 = Document.parse("{\"obj\" : {\"hello\" : \"blob\"}}");
+        Document d2 = Document.parse("{\"obj\" : {\"a\" : {\"blob\" : [\"hi\"]}}}");
         final List<Document> list = new ArrayList<>();
         list.add(d1);
         list.add(d2);
--- a/server/core/src/test/java/com/redhat/thermostat/server/core/internal/web/json/DocumentBuilderTest.java	Wed Mar 01 12:23:51 2017 -0500
+++ b/server/core/src/test/java/com/redhat/thermostat/server/core/internal/web/json/DocumentBuilderTest.java	Wed Mar 01 16:16:25 2017 -0500
@@ -10,9 +10,9 @@
         String content = "{\"a\":\"b\"}";
         String[] tags = {"x", "y"};
 
-        String result = DocumentBuilder.addTags(content, tags);
+        String result = new DocumentBuilder(content).addTags(tags).build();
 
-        String expected = "{\"a\":\"b\",\"tags\":[\"admin\",\"x\",\"y\"]}";
+        String expected = "{ \"obj\" : {\"a\":\"b\"},\"tags\":[\"admin\",\"x\",\"y\"]}";
         assertEquals(expected, result);
     }
 
@@ -21,9 +21,9 @@
         String content = "{\"a\":\"b\"}";
         String[] tags = {"x"};
 
-        String result = DocumentBuilder.addTags(content, tags);
+        String result = new DocumentBuilder(content).addTags(tags).build();
 
-        String expected = "{\"a\":\"b\",\"tags\":[\"admin\",\"x\"]}";
+        String expected = "{ \"obj\" : {\"a\":\"b\"},\"tags\":[\"admin\",\"x\"]}";
         assertEquals(expected, result);
     }
 
@@ -31,9 +31,9 @@
     public void testAddZeroTags() {
         String content = "{\"a\":\"b\"}";
 
-        String result = DocumentBuilder.addTags(content);
+        String result = new DocumentBuilder(content).addTags().build();
 
-        String expected = "{\"a\":\"b\",\"tags\":[\"admin\"]}";
+        String expected = "{ \"obj\" : {\"a\":\"b\"},\"tags\":[\"admin\"]}";
         assertEquals(expected, result);
     }
 }