changeset 201:d6b45fcdc3f9 web-gateway

Fix GET for jvm-memory module. This patch fixes issues with the GET implementation for the jvm-memory module. The mongodb utilities in 'core' are updated to match the document format of Thermostat. The SecurityContext in the GET request is unused for now. The API is updated to have default values for limit and offset query parameters.
author Jie Kang <jkang@redhat.com>
date Thu, 16 Mar 2017 15:35:19 -0400
parents bb4c37beecb1
children c00b964b798b
files core/src/main/java/com/redhat/thermostat/gateway/core/storage/mongodb/filters/MongoSortFilters.java core/src/main/java/com/redhat/thermostat/gateway/core/storage/mongodb/response/MongoResponseBuilder.java distribution/src/config/services.properties services/jvm-gc/pom.xml services/jvm-memory/jvm-memory-swagger.json services/jvm-memory/pom.xml services/jvm-memory/src/gen/java/io/swagger/api/ApiException.java services/jvm-memory/src/gen/java/io/swagger/api/ApiOriginFilter.java services/jvm-memory/src/gen/java/io/swagger/api/ApiResponseMessage.java services/jvm-memory/src/gen/java/io/swagger/api/JvmMemoryApi.java services/jvm-memory/src/gen/java/io/swagger/api/JvmMemoryApiService.java services/jvm-memory/src/gen/java/io/swagger/api/NotFoundException.java services/jvm-memory/src/gen/java/io/swagger/api/StringUtil.java services/jvm-memory/src/gen/java/io/swagger/model/JvmMemoryStats.java services/jvm-memory/src/main/java/io/swagger/api/factories/JvmMemoryApiServiceFactory.java services/jvm-memory/src/main/java/io/swagger/api/impl/JvmMemoryApiServiceImpl.java
diffstat 16 files changed, 45 insertions(+), 28 deletions(-) [+]
line wrap: on
line diff
--- a/core/src/main/java/com/redhat/thermostat/gateway/core/storage/mongodb/filters/MongoSortFilters.java	Thu Mar 16 15:04:01 2017 -0400
+++ b/core/src/main/java/com/redhat/thermostat/gateway/core/storage/mongodb/filters/MongoSortFilters.java	Thu Mar 16 15:35:19 2017 -0400
@@ -12,9 +12,9 @@
             String[] items = sort.split(",");
             for (String item : items) {
                 if (item.charAt(0) == '+') {
-                    sortObject.append("obj." + item.substring(1), 1);
+                    sortObject.append(item.substring(1), 1);
                 } else if (item.charAt(0) == '-') {
-                    sortObject.append("obj." + item.substring(1), -1);
+                    sortObject.append(item.substring(1), -1);
                 }
             }
         }
--- a/core/src/main/java/com/redhat/thermostat/gateway/core/storage/mongodb/response/MongoResponseBuilder.java	Thu Mar 16 15:04:01 2017 -0400
+++ b/core/src/main/java/com/redhat/thermostat/gateway/core/storage/mongodb/response/MongoResponseBuilder.java	Thu Mar 16 15:35:19 2017 -0400
@@ -83,7 +83,7 @@
         documents.forEach(new Block<Document>() {
             @Override
             public void apply(Document document) {
-                s.append(((Document)document.get("obj")).toJson()).append(",");
+                s.append(document.toJson()).append(",");
                 i[0]++;
             }
         });
--- a/distribution/src/config/services.properties	Thu Mar 16 15:04:01 2017 -0400
+++ b/distribution/src/config/services.properties	Thu Mar 16 15:35:19 2017 -0400
@@ -1,1 +1,1 @@
-/jvm-memory = services/jvm-memory/jaxrs-server/target/swagger-jaxrs-server-1.0.0.war
\ No newline at end of file
+/jvm-memory = services/jvm-memory/target/thermostat-web-gateway-jvm-memory-service-1.99.12-SNAPSHOT.war
\ No newline at end of file
--- a/services/jvm-gc/pom.xml	Thu Mar 16 15:04:01 2017 -0400
+++ b/services/jvm-gc/pom.xml	Thu Mar 16 15:35:19 2017 -0400
@@ -154,7 +154,6 @@
         <groupId>javax.validation</groupId>
         <artifactId>validation-api</artifactId>
         <version>1.1.0.Final</version>
-        <scope>provided</scope>
     </dependency>
 
   </dependencies>
--- a/services/jvm-memory/jvm-memory-swagger.json	Thu Mar 16 15:04:01 2017 -0400
+++ b/services/jvm-memory/jvm-memory-swagger.json	Thu Mar 16 15:35:19 2017 -0400
@@ -118,13 +118,15 @@
             "name": "limit",
             "in": "query",
             "description": "Limit of items to return.",
-            "type": "integer"
+            "type": "integer",
+            "default": 100
         },
         "offset": {
             "name": "offset",
             "in": "query",
             "description": "Offset of items to return.",
-            "type": "integer"
+            "type": "integer",
+            "default": 0
         },
         "sort": {
             "name": "sort",
--- a/services/jvm-memory/pom.xml	Thu Mar 16 15:04:01 2017 -0400
+++ b/services/jvm-memory/pom.xml	Thu Mar 16 15:35:19 2017 -0400
@@ -12,7 +12,7 @@
   <packaging>jar</packaging>
 
   <name>Thermostat Web Gateway JVM Memory Service</name>
-  
+
   <build>
     <sourceDirectory>src/main/java</sourceDirectory>
     <plugins>
@@ -20,6 +20,14 @@
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-war-plugin</artifactId>
         <version>2.1.1</version>
+        <executions>
+          <execution>
+            <phase>package</phase>
+            <goals>
+              <goal>war</goal>
+            </goals>
+          </execution>
+        </executions>
       </plugin>
       <plugin>
         <artifactId>maven-failsafe-plugin</artifactId>
@@ -154,13 +162,12 @@
       <version>2.2</version>
     </dependency>
 
-  
+
     <!-- Bean Validation API support -->
     <dependency>
-        <groupId>javax.validation</groupId>
-        <artifactId>validation-api</artifactId>
-	<version>1.1.0.Final</version>
-	<scope>provided</scope>
+      <groupId>javax.validation</groupId>
+      <artifactId>validation-api</artifactId>
+      <version>1.1.0.Final</version>
     </dependency>
 
   </dependencies>
--- a/services/jvm-memory/src/gen/java/io/swagger/api/ApiException.java	Thu Mar 16 15:04:01 2017 -0400
+++ b/services/jvm-memory/src/gen/java/io/swagger/api/ApiException.java	Thu Mar 16 15:35:19 2017 -0400
@@ -1,6 +1,6 @@
 package io.swagger.api;
 
-@javax.annotation.Generated(value = "io.swagger.codegen.languages.JavaJerseyServerCodegen", date = "2017-03-16T18:33:02.984Z")
+@javax.annotation.Generated(value = "io.swagger.codegen.languages.JavaJerseyServerCodegen", date = "2017-03-16T19:29:24.964Z")
 public class ApiException extends Exception{
     private int code;
     public ApiException (int code, String msg) {
--- a/services/jvm-memory/src/gen/java/io/swagger/api/ApiOriginFilter.java	Thu Mar 16 15:04:01 2017 -0400
+++ b/services/jvm-memory/src/gen/java/io/swagger/api/ApiOriginFilter.java	Thu Mar 16 15:35:19 2017 -0400
@@ -5,7 +5,7 @@
 import javax.servlet.*;
 import javax.servlet.http.HttpServletResponse;
 
-@javax.annotation.Generated(value = "io.swagger.codegen.languages.JavaJerseyServerCodegen", date = "2017-03-16T18:33:02.984Z")
+@javax.annotation.Generated(value = "io.swagger.codegen.languages.JavaJerseyServerCodegen", date = "2017-03-16T19:29:24.964Z")
 public class ApiOriginFilter implements javax.servlet.Filter {
     public void doFilter(ServletRequest request, ServletResponse response,
             FilterChain chain) throws IOException, ServletException {
--- a/services/jvm-memory/src/gen/java/io/swagger/api/ApiResponseMessage.java	Thu Mar 16 15:04:01 2017 -0400
+++ b/services/jvm-memory/src/gen/java/io/swagger/api/ApiResponseMessage.java	Thu Mar 16 15:35:19 2017 -0400
@@ -3,7 +3,7 @@
 import javax.xml.bind.annotation.XmlTransient;
 
 @javax.xml.bind.annotation.XmlRootElement
-@javax.annotation.Generated(value = "io.swagger.codegen.languages.JavaJerseyServerCodegen", date = "2017-03-16T18:33:02.984Z")
+@javax.annotation.Generated(value = "io.swagger.codegen.languages.JavaJerseyServerCodegen", date = "2017-03-16T19:29:24.964Z")
 public class ApiResponseMessage {
     public static final int ERROR = 1;
     public static final int WARNING = 2;
--- a/services/jvm-memory/src/gen/java/io/swagger/api/JvmMemoryApi.java	Thu Mar 16 15:04:01 2017 -0400
+++ b/services/jvm-memory/src/gen/java/io/swagger/api/JvmMemoryApi.java	Thu Mar 16 15:35:19 2017 -0400
@@ -27,7 +27,7 @@
 @Consumes({ "application/json" })
 @Produces({ "application/json", "text/html; charset=utf-8" })
 @io.swagger.annotations.Api(description = "the jvm-memory API")
-@javax.annotation.Generated(value = "io.swagger.codegen.languages.JavaJerseyServerCodegen", date = "2017-03-16T18:33:02.984Z")
+@javax.annotation.Generated(value = "io.swagger.codegen.languages.JavaJerseyServerCodegen", date = "2017-03-16T19:29:24.964Z")
 public class JvmMemoryApi  {
    private final JvmMemoryApiService delegate = JvmMemoryApiServiceFactory.getJvmMemoryApi();
 
@@ -50,8 +50,8 @@
     @io.swagger.annotations.ApiOperation(value = "", notes = "Get jvm memory information. Use '*' for the id parameters to specify all systems, agents and/or jvms.", response = JvmMemoryStats.class, tags={  })
     @io.swagger.annotations.ApiResponses(value = { 
         @io.swagger.annotations.ApiResponse(code = 200, message = "OK", response = JvmMemoryStats.class) })
-    public Response jvmMemoryGet(@ApiParam(value = "Limit of items to return.") @QueryParam("limit") Integer limit
-,@ApiParam(value = "Offset of items to return.") @QueryParam("offset") Integer offset
+    public Response jvmMemoryGet(@ApiParam(value = "Limit of items to return.", defaultValue="100") @DefaultValue("100") @QueryParam("limit") Integer limit
+,@ApiParam(value = "Offset of items to return.", defaultValue="0") @DefaultValue("0") @QueryParam("offset") Integer offset
 ,@ApiParam(value = "CSV Sort string") @QueryParam("sort") String sort
 ,@ApiParam(value = "Key, Comparator, Value trios to filter the data") @QueryParam("filters") List<String> filters
 ,@Context SecurityContext securityContext)
--- a/services/jvm-memory/src/gen/java/io/swagger/api/JvmMemoryApiService.java	Thu Mar 16 15:04:01 2017 -0400
+++ b/services/jvm-memory/src/gen/java/io/swagger/api/JvmMemoryApiService.java	Thu Mar 16 15:35:19 2017 -0400
@@ -15,7 +15,7 @@
 import javax.ws.rs.core.Response;
 import javax.ws.rs.core.SecurityContext;
 import javax.validation.constraints.*;
-@javax.annotation.Generated(value = "io.swagger.codegen.languages.JavaJerseyServerCodegen", date = "2017-03-16T18:33:02.984Z")
+@javax.annotation.Generated(value = "io.swagger.codegen.languages.JavaJerseyServerCodegen", date = "2017-03-16T19:29:24.964Z")
 public abstract class JvmMemoryApiService {
     public abstract Response jvmMemoryDelete( List<String> filters,SecurityContext securityContext) throws NotFoundException;
     public abstract Response jvmMemoryGet( Integer limit, Integer offset, String sort, List<String> filters,SecurityContext securityContext) throws NotFoundException;
--- a/services/jvm-memory/src/gen/java/io/swagger/api/NotFoundException.java	Thu Mar 16 15:04:01 2017 -0400
+++ b/services/jvm-memory/src/gen/java/io/swagger/api/NotFoundException.java	Thu Mar 16 15:35:19 2017 -0400
@@ -1,6 +1,6 @@
 package io.swagger.api;
 
-@javax.annotation.Generated(value = "io.swagger.codegen.languages.JavaJerseyServerCodegen", date = "2017-03-16T18:33:02.984Z")
+@javax.annotation.Generated(value = "io.swagger.codegen.languages.JavaJerseyServerCodegen", date = "2017-03-16T19:29:24.964Z")
 public class NotFoundException extends ApiException {
     private int code;
     public NotFoundException (int code, String msg) {
--- a/services/jvm-memory/src/gen/java/io/swagger/api/StringUtil.java	Thu Mar 16 15:04:01 2017 -0400
+++ b/services/jvm-memory/src/gen/java/io/swagger/api/StringUtil.java	Thu Mar 16 15:35:19 2017 -0400
@@ -1,6 +1,6 @@
 package io.swagger.api;
 
-@javax.annotation.Generated(value = "io.swagger.codegen.languages.JavaJerseyServerCodegen", date = "2017-03-16T18:33:02.984Z")
+@javax.annotation.Generated(value = "io.swagger.codegen.languages.JavaJerseyServerCodegen", date = "2017-03-16T19:29:24.964Z")
 public class StringUtil {
   /**
    * Check if the given array contains the given value (with case-insensitive comparison).
--- a/services/jvm-memory/src/gen/java/io/swagger/model/JvmMemoryStats.java	Thu Mar 16 15:04:01 2017 -0400
+++ b/services/jvm-memory/src/gen/java/io/swagger/model/JvmMemoryStats.java	Thu Mar 16 15:35:19 2017 -0400
@@ -19,7 +19,7 @@
 /**
  * JvmMemoryStats
  */
-@javax.annotation.Generated(value = "io.swagger.codegen.languages.JavaJerseyServerCodegen", date = "2017-03-16T18:33:02.984Z")
+@javax.annotation.Generated(value = "io.swagger.codegen.languages.JavaJerseyServerCodegen", date = "2017-03-16T19:29:24.964Z")
 public class JvmMemoryStats   {
 
   @Override
--- a/services/jvm-memory/src/main/java/io/swagger/api/factories/JvmMemoryApiServiceFactory.java	Thu Mar 16 15:04:01 2017 -0400
+++ b/services/jvm-memory/src/main/java/io/swagger/api/factories/JvmMemoryApiServiceFactory.java	Thu Mar 16 15:35:19 2017 -0400
@@ -3,7 +3,7 @@
 import io.swagger.api.JvmMemoryApiService;
 import io.swagger.api.impl.JvmMemoryApiServiceImpl;
 
-@javax.annotation.Generated(value = "io.swagger.codegen.languages.JavaJerseyServerCodegen", date = "2017-03-16T18:33:02.984Z")
+@javax.annotation.Generated(value = "io.swagger.codegen.languages.JavaJerseyServerCodegen", date = "2017-03-16T19:29:24.964Z")
 public class JvmMemoryApiServiceFactory {
     private final static JvmMemoryApiService service = new JvmMemoryApiServiceImpl();
 
--- a/services/jvm-memory/src/main/java/io/swagger/api/impl/JvmMemoryApiServiceImpl.java	Thu Mar 16 15:04:01 2017 -0400
+++ b/services/jvm-memory/src/main/java/io/swagger/api/impl/JvmMemoryApiServiceImpl.java	Thu Mar 16 15:35:19 2017 -0400
@@ -15,10 +15,12 @@
 import io.swagger.model.JvmMemoryStats;
 
 import java.util.Collections;
+import java.util.HashMap;
 import java.util.List;
 import io.swagger.api.NotFoundException;
 
 import java.io.InputStream;
+import java.util.Map;
 
 import org.bson.Document;
 import org.bson.conversions.Bson;
@@ -30,7 +32,14 @@
 @javax.annotation.Generated(value = "io.swagger.codegen.languages.JavaJerseyServerCodegen", date = "2017-03-16T18:33:02.984Z")
 public class JvmMemoryApiServiceImpl extends JvmMemoryApiService {
     static {
-        ThermostatMongoStorage.start(Collections.EMPTY_MAP);
+        Map<String, String> mongoConfig = new HashMap<>();
+        mongoConfig.put("MONGO_URL", "mongodb://127.0.0.1:27518");
+        mongoConfig.put("MONGO_DB", "thermostat");
+        mongoConfig.put("MONGO_USERNAME", "mongodevuser");
+        mongoConfig.put("MONGO_PASSWORD", "mongodevpassword");
+
+
+        ThermostatMongoStorage.start(mongoConfig);
     }
 
     private final String collectionName = "vm-memory-stats";
@@ -42,15 +51,15 @@
     @Override
     public Response jvmMemoryGet( Integer limit,  Integer offset,  String sort,  List<String> filters, SecurityContext securityContext) throws NotFoundException {
 
-        final String userName = securityContext.getUserPrincipal().getName();
-        final Bson filter = MongoRequestFilters.buildFilter(filters, Collections.singletonList(userName));
+//        final String userName = securityContext.getUserPrincipal().getName();
+        final Bson filter = MongoRequestFilters.buildFilter(filters, Collections.EMPTY_LIST);
         final Bson sortObject = MongoSortFilters.createSortObject(sort);
 
         FindIterable<Document> documents = ThermostatMongoStorage.getDatabase().getCollection(collectionName).find(filter).projection(fields(excludeId())).sort(sortObject).limit(limit).skip(offset).batchSize(limit).cursorType(CursorType.NonTailable);
 
         String message = MongoResponseBuilder.buildJsonResponse(MongoResponseBuilder.buildJsonDocuments(documents));
 
-        return Response.ok().entity(new ApiResponseMessage(ApiResponseMessage.OK, "magic!")).build();
+        return Response.ok().entity(new ApiResponseMessage(ApiResponseMessage.OK, message)).build();
     }
     @Override
     public Response jvmMemoryPost(JvmMemoryStats jvmMemoryStats,  List<String> tags, SecurityContext securityContext) throws NotFoundException {