Add Swagger Related Configurations 85/13885/3
authorGuangrong Fu <fu.guangrong@zte.com.cn>
Wed, 20 Sep 2017 13:13:40 +0000 (21:13 +0800)
committerGuangrong Fu <fu.guangrong@zte.com.cn>
Thu, 21 Sep 2017 00:36:50 +0000 (08:36 +0800)
Change-Id: Ia6dddca44d18725b6b77afc5c7d5dd0ba73c3542
Issue-ID: HOLMES-54
Signed-off-by: Guangrong Fu <fu.guangrong@zte.com.cn>
rulemgt-standalone/pom.xml
rulemgt/pom.xml
rulemgt/src/main/java/org/onap/holmes/rulemgt/bean/request/RuleDeleteRequest.java
rulemgt/src/main/java/org/onap/holmes/rulemgt/resources/HealthCheck.java
rulemgt/src/main/java/org/onap/holmes/rulemgt/resources/RuleMgtResources.java
rulemgt/src/main/resources/swagger.json [new file with mode: 0644]
rulemgt/src/test/java/org/onap/holmes/rulemgt/resources/RuleMgtResourcesTest.java

index 97cca2a..58d91e9 100644 (file)
                                         <exclude>Dockerfile</exclude>
                                     </excludes>
                                 </resource>
+                                <resource>
+                                    <directory>../rulemgt/src/main/resources</directory>
+                                    <filtering>false</filtering>
+                                </resource>
                             </resources>
                             <overwrite>true</overwrite>
                         </configuration>
                                         <exclude>Dockerfile</exclude>
                                     </excludes>
                                 </resource>
+                                <resource>
+                                    <directory>../rulemgt/src/main/resources</directory>
+                                    <filtering>false</filtering>
+                                </resource>
                             </resources>
                             <overwrite>true</overwrite>
                         </configuration>
index 5aa0b72..013105b 100644 (file)
             <artifactId>guava</artifactId>
             <version>19.0</version>
         </dependency>
-
     </dependencies>
     <build>
         <plugins>
                     </execution>
                 </executions>
             </plugin>
-
         </plugins>
         <resources>
             <resource>
             </resource>
         </resources>
     </build>
+
+    <profiles>
+        <profile>
+            <id>swagger</id>
+            <dependencies>
+                <dependency>
+                    <groupId>io.swagger</groupId>
+                    <artifactId>swagger-jersey2-jaxrs</artifactId>
+                    <version>1.5.0</version>
+                </dependency>
+            </dependencies>
+            <build>
+                <plugins>
+                    <plugin>
+                        <groupId>com.github.kongchen</groupId>
+                        <artifactId>swagger-maven-plugin</artifactId>
+                        <version>3.1.1</version>
+                        <configuration>
+                            <apiSources>
+                                <apiSource>
+                                    <springmvc>false</springmvc>
+                                    <locations>org.onap.holmes.rulemgt.resources</locations>
+                                    <basePath>/api/holmes-rule-mgmt/v1/</basePath>
+                                    <info>
+                                        <title>API Descriptions for Holmes Rule Management</title>
+                                        <version>v1</version>
+                                        <description>
+                                            This page shows all the APIs available in the Holmes rule management module.
+                                        </description>
+                                        <termsOfService>
+                                            http://www.github.com/kongchen/swagger-maven-plugin
+                                        </termsOfService>
+                                        <contact>
+                                            <email>fu.guangrong@zte.com.cn</email>
+                                            <name>Guangrong Fu</name>
+                                        </contact>
+                                        <license>
+                                            <url>http://www.apache.org/licenses/LICENSE-2.0.html</url>
+                                            <name>Apache 2.0</name>
+                                        </license>
+                                    </info>
+                                    <securityDefinitions>
+                                    </securityDefinitions>
+                                    <swaggerDirectory>${basedir}/src/main/resources</swaggerDirectory>
+                                </apiSource>
+                            </apiSources>
+                        </configuration>
+                        <executions>
+                            <execution>
+                                <phase>compile</phase>
+                                <goals>
+                                    <goal>generate</goal>
+                                </goals>
+                            </execution>
+                        </executions>
+                        <dependencies>
+                            <dependency>
+                                <groupId>io.swagger</groupId>
+                                <artifactId>swagger-hibernate-validations</artifactId>
+                                <version>1.5.6</version>
+                            </dependency>
+                        </dependencies>
+                    </plugin>
+                </plugins>
+            </build>
+        </profile>
+    </profiles>
 </project>
index 7cc4fff..57aeafc 100644 (file)
 package org.onap.holmes.rulemgt.bean.request;\r
 \r
 import com.fasterxml.jackson.annotation.JsonProperty;\r
+import lombok.AllArgsConstructor;\r
 import lombok.Getter;\r
+import lombok.NoArgsConstructor;\r
 import lombok.Setter;\r
 \r
 \r
 @Setter\r
 @Getter\r
+@AllArgsConstructor\r
+@NoArgsConstructor\r
 public class RuleDeleteRequest {\r
     @JsonProperty(value = "ruleid")\r
     private String ruleId;\r
index 6613edf..73d1c5b 100644 (file)
@@ -29,7 +29,7 @@ import org.jvnet.hk2.annotations.Service;
 @Service
 @SwaggerDefinition
 @Path("/healthcheck")
-@Api(tags = {"HealthCheck"})
+@Api(tags = {"Health Check"})
 @Produces(MediaType.TEXT_PLAIN)
 @Slf4j
 public class HealthCheck {
index 04578f7..00adc63 100644 (file)
@@ -29,6 +29,7 @@ import javax.ws.rs.GET;
 import javax.ws.rs.POST;\r
 import javax.ws.rs.PUT;\r
 import javax.ws.rs.Path;\r
+import javax.ws.rs.PathParam;\r
 import javax.ws.rs.Produces;\r
 import javax.ws.rs.QueryParam;\r
 import javax.ws.rs.core.Context;\r
@@ -36,13 +37,10 @@ import javax.ws.rs.core.MediaType;
 import lombok.extern.slf4j.Slf4j;\r
 import net.sf.json.JSONObject;\r
 import org.jvnet.hk2.annotations.Service;\r
-import org.onap.holmes.common.api.entity.ServiceRegisterEntity;\r
-import org.onap.holmes.common.config.MicroServiceConfig;\r
 import org.onap.holmes.common.exception.CorrelationException;\r
 import org.onap.holmes.common.utils.ExceptionUtil;\r
 import org.onap.holmes.common.utils.JacksonUtil;\r
 import org.onap.holmes.common.utils.LanguageUtil;\r
-import org.onap.holmes.common.utils.MSBRegisterUtil;\r
 import org.onap.holmes.common.utils.UserUtil;\r
 import org.onap.holmes.rulemgt.bean.request.RuleCreateRequest;\r
 import org.onap.holmes.rulemgt.bean.request.RuleDeleteRequest;\r
@@ -56,7 +54,7 @@ import org.onap.holmes.rulemgt.wrapper.RuleMgtWrapper;
 @Service\r
 @SwaggerDefinition\r
 @Path("/rule")\r
-@Api(tags = {"CorrelationRules"})\r
+@Api(tags = {"Holmes Rule Management"})\r
 @Produces(MediaType.APPLICATION_JSON)\r
 @Slf4j\r
 public class RuleMgtResources {\r
@@ -66,10 +64,13 @@ public class RuleMgtResources {
 \r
     @PUT\r
     @Produces(MediaType.APPLICATION_JSON)\r
-    @ApiOperation(value = "Save the alarm+ rule to the database, and deployed to the engine when the enable to open.", response = RuleAddAndUpdateResponse.class)\r
+    @ApiOperation(value = "Save a rule into the database; deploy it to the Drools engine if it is enabled.",\r
+            response = RuleAddAndUpdateResponse.class)\r
     @Timed\r
     public RuleAddAndUpdateResponse addCorrelationRule(@Context HttpServletRequest request,\r
-            @ApiParam(value = "alarm+ rule create request.<br>[rulename]:<font color=\"red\">required</font><br>[content]:<font color=\"red\">required</font><br>[enabled]:<font color=\"red\">required</font>", required = true) RuleCreateRequest ruleCreateRequest) {\r
+            @ApiParam(value = "The request entity of the HTTP call, which comprises \"rulename\"(required), "\r
+                    + "\"content\"(required), \"enabled\"(required) and \"description\"(optional)", required = true)\r
+                    RuleCreateRequest ruleCreateRequest) {\r
         Locale locale = LanguageUtil.getLocale(request);\r
         RuleAddAndUpdateResponse ruleChangeResponse;\r
         try {\r
@@ -85,10 +86,12 @@ public class RuleMgtResources {
 \r
     @POST\r
     @Produces(MediaType.APPLICATION_JSON)\r
-    @ApiOperation(value = "Update the alarm+ rule and deployed to the engine when the enable to open.", response = RuleAddAndUpdateResponse.class)\r
+    @ApiOperation(value = "Update an existing rule; deploy it to the Drools engine if it is enabled.", response = RuleAddAndUpdateResponse.class)\r
     @Timed\r
     public RuleAddAndUpdateResponse updateCorrelationRule(@Context HttpServletRequest request,\r
-            @ApiParam(value = "alarm+ rule update request.<br>[ruleid]:<font color=\"red\">required</font>", required = true) RuleUpdateRequest ruleUpdateRequest) {\r
+            @ApiParam(value = "The request entity of the HTTP call, which comprises \"ruleid\"(required), "\r
+                    + "\"content\"(required), \"enabled\"(required) and \"description\"(optional)", required = true)\r
+                    RuleUpdateRequest ruleUpdateRequest) {\r
         Locale locale = LanguageUtil.getLocale(request);\r
         RuleAddAndUpdateResponse ruleChangeResponse;\r
         try {\r
@@ -103,30 +106,31 @@ public class RuleMgtResources {
 \r
     @DELETE\r
     @Produces(MediaType.APPLICATION_JSON)\r
-    @ApiOperation(value = "Delete the alarm+ rule,and when the enable is open also removed from the engine.")\r
+    @ApiOperation(value = "Remove a rule from Holmes.")\r
     @Timed\r
+    @Path("/{ruleid}")\r
     public boolean deleteCorrelationRule(@Context HttpServletRequest request,\r
-            @ApiParam(value = "alarm+ rule delete request.<br>[ruleid]:<font color=\"red\">required</font>", required = true) RuleDeleteRequest ruleDeleteRequest) {\r
+            @PathParam("ruleid") String ruleId) {\r
         Locale locale = LanguageUtil.getLocale(request);\r
         try {\r
-            ruleMgtWrapper.deleteCorrelationRule(ruleDeleteRequest);\r
-            log.info("delete rule:" + ruleDeleteRequest.getRuleId() + " successful");\r
+            ruleMgtWrapper.deleteCorrelationRule(new RuleDeleteRequest(ruleId));\r
+            log.info("delete rule:" + ruleId + " successful");\r
             return true;\r
         } catch (CorrelationException e) {\r
-            log.error("delete rule:" + ruleDeleteRequest.getRuleId() + " failed", e);\r
+            log.error("delete rule:" + ruleId + " failed", e);\r
             throw ExceptionUtil.buildExceptionResponse(e.getMessage());\r
         }\r
     }\r
 \r
     @GET\r
     @Produces(MediaType.APPLICATION_JSON)\r
-    @ApiOperation(value = "According to the conditions query the alarm + rules", response = RuleQueryListResponse.class)\r
+    @ApiOperation(value = "Query rules using certain criteria.", response = RuleQueryListResponse.class)\r
     @Timed\r
     public RuleQueryListResponse getCorrelationRules(@Context HttpServletRequest request,\r
-            @ApiParam(value = "query condition:<br>" + " <b>[ruleid]</b>:Rule ID;<br>"\r
-                    + "<b>[rulename]</b>:Rule name;<br>" + "<b>[creator]</b>:creator of the rule;<br>"\r
-                    + "<b>[modifier]</b>:modifier of the rule;<br>"\r
-                    + "<b>[enabled]</b>: 0 is Enabled,1 is disabled;<br><font color=\"red\">for example:</font><br>{\"ruleid\":\"rule_1484727187317\"}", required = false) @QueryParam("queryrequest") String ruleQueryRequest) {\r
+            @ApiParam(value = "A JSON string used as a query parameter, which comprises \"ruleid\"(optional), "\r
+                    + "\"rulename\"(optional), \"creator\"(optional), "\r
+                    + "\"modifier\"(optional) and \"enabled\"(optional). E.g. {\"ruleid\":\"rule_1484727187317\"}",\r
+                    required = false) @QueryParam("queryrequest") String ruleQueryRequest) {\r
         Locale locale = LanguageUtil.getLocale(request);\r
         RuleQueryListResponse ruleQueryListResponse;\r
         RuleQueryCondition ruleQueryCondition = getRuleQueryCondition(ruleQueryRequest, request);\r
diff --git a/rulemgt/src/main/resources/swagger.json b/rulemgt/src/main/resources/swagger.json
new file mode 100644 (file)
index 0000000..748a311
--- /dev/null
@@ -0,0 +1,233 @@
+{
+  "swagger" : "2.0",
+  "info" : {
+    "description" : "This page shows all the APIs available in the Holmes rule management module.",
+    "version" : "v1",
+    "title" : "API Descriptions for Holmes Rule Management",
+    "termsOfService" : "http://www.github.com/kongchen/swagger-maven-plugin",
+    "contact" : {
+      "name" : "Guangrong Fu",
+      "email" : "fu.guangrong@zte.com.cn"
+    },
+    "license" : {
+      "name" : "Apache 2.0",
+      "url" : "http://www.apache.org/licenses/LICENSE-2.0.html"
+    }
+  },
+  "basePath" : "/api/holmes-rule-mgmt/v1/",
+  "tags" : [ {
+    "name" : "Health Check"
+  }, {
+    "name" : "Holmes Rule Management"
+  } ],
+  "paths" : {
+    "/healthcheck" : {
+      "get" : {
+        "tags" : [ "Health Check" ],
+        "summary" : "Interface for the health check of the rule management module for Holmes",
+        "description" : "",
+        "operationId" : "healthCheck",
+        "produces" : [ "text/plain" ],
+        "responses" : {
+          "200" : {
+            "description" : "successful operation",
+            "schema" : {
+              "type" : "boolean"
+            }
+          }
+        }
+      }
+    },
+    "/rule" : {
+      "get" : {
+        "tags" : [ "Holmes Rule Management" ],
+        "summary" : "Query rules using certain criteria.",
+        "description" : "",
+        "operationId" : "getCorrelationRules",
+        "produces" : [ "application/json" ],
+        "parameters" : [ {
+          "name" : "queryrequest",
+          "in" : "query",
+          "description" : "A JSON string used as a query parameter, which comprises \"ruleid\"(optional), \"rulename\"(optional), \"creator\"(optional), \"modifier\"(optional) and \"enabled\"(optional). E.g. {\"ruleid\":\"rule_1484727187317\"}",
+          "required" : false,
+          "type" : "string"
+        } ],
+        "responses" : {
+          "200" : {
+            "description" : "successful operation",
+            "schema" : {
+              "$ref" : "#/definitions/RuleQueryListResponse"
+            }
+          }
+        }
+      },
+      "post" : {
+        "tags" : [ "Holmes Rule Management" ],
+        "summary" : "Update an existing rule; deploy it to the Drools engine if it is enabled.",
+        "description" : "",
+        "operationId" : "updateCorrelationRule",
+        "produces" : [ "application/json" ],
+        "parameters" : [ {
+          "in" : "body",
+          "name" : "body",
+          "description" : "The request entity of the HTTP call, which comprises \"ruleid\"(required), \"content\"(required), \"enabled\"(required) and \"description\"(optional)",
+          "required" : true,
+          "schema" : {
+            "$ref" : "#/definitions/RuleUpdateRequest"
+          }
+        } ],
+        "responses" : {
+          "200" : {
+            "description" : "successful operation",
+            "schema" : {
+              "$ref" : "#/definitions/RuleAddAndUpdateResponse"
+            }
+          }
+        }
+      },
+      "put" : {
+        "tags" : [ "Holmes Rule Management" ],
+        "summary" : "Save a rule into the database; deploy it to the Drools engine if it is enabled.",
+        "description" : "",
+        "operationId" : "addCorrelationRule",
+        "produces" : [ "application/json" ],
+        "parameters" : [ {
+          "in" : "body",
+          "name" : "body",
+          "description" : "The request entity of the HTTP call, which comprises \"rulename\"(required), \"content\"(required), \"enabled\"(required) and \"description\"(optional)",
+          "required" : true,
+          "schema" : {
+            "$ref" : "#/definitions/RuleCreateRequest"
+          }
+        } ],
+        "responses" : {
+          "200" : {
+            "description" : "successful operation",
+            "schema" : {
+              "$ref" : "#/definitions/RuleAddAndUpdateResponse"
+            }
+          }
+        }
+      }
+    },
+    "/rule/{ruleid}" : {
+      "delete" : {
+        "tags" : [ "Holmes Rule Management" ],
+        "summary" : "Remove a rule from Holmes.",
+        "description" : "",
+        "operationId" : "deleteCorrelationRule",
+        "produces" : [ "application/json" ],
+        "parameters" : [ {
+          "name" : "ruleid",
+          "in" : "path",
+          "required" : true,
+          "type" : "string"
+        } ],
+        "responses" : {
+          "200" : {
+            "description" : "successful operation",
+            "schema" : {
+              "type" : "boolean"
+            }
+          }
+        }
+      }
+    }
+  },
+  "definitions" : {
+    "RuleAddAndUpdateResponse" : {
+      "type" : "object",
+      "properties" : {
+        "ruleid" : {
+          "type" : "string"
+        }
+      }
+    },
+    "RuleCreateRequest" : {
+      "type" : "object",
+      "properties" : {
+        "description" : {
+          "type" : "string"
+        },
+        "content" : {
+          "type" : "string"
+        },
+        "enabled" : {
+          "type" : "integer",
+          "format" : "int32"
+        },
+        "rulename" : {
+          "type" : "string"
+        }
+      }
+    },
+    "RuleQueryListResponse" : {
+      "type" : "object",
+      "properties" : {
+        "rules" : {
+          "type" : "array",
+          "items" : {
+            "$ref" : "#/definitions/RuleResult4API"
+          }
+        },
+        "totalcount" : {
+          "type" : "integer",
+          "format" : "int32"
+        }
+      }
+    },
+    "RuleResult4API" : {
+      "type" : "object",
+      "properties" : {
+        "description" : {
+          "type" : "string"
+        },
+        "content" : {
+          "type" : "string"
+        },
+        "creator" : {
+          "type" : "string"
+        },
+        "modifier" : {
+          "type" : "string"
+        },
+        "enabled" : {
+          "type" : "integer",
+          "format" : "int32"
+        },
+        "ruleid" : {
+          "type" : "string"
+        },
+        "rulename" : {
+          "type" : "string"
+        },
+        "createtime" : {
+          "type" : "string",
+          "format" : "date-time"
+        },
+        "updatetime" : {
+          "type" : "string",
+          "format" : "date-time"
+        }
+      }
+    },
+    "RuleUpdateRequest" : {
+      "type" : "object",
+      "properties" : {
+        "description" : {
+          "type" : "string"
+        },
+        "content" : {
+          "type" : "string"
+        },
+        "enabled" : {
+          "type" : "integer",
+          "format" : "int32"
+        },
+        "ruleid" : {
+          "type" : "string"
+        }
+      }
+    }
+  }
+}
\ No newline at end of file
index dd68ad8..692cc19 100644 (file)
@@ -111,23 +111,23 @@ public class RuleMgtResourcesTest {
     public void deleteCorrelationRule_correlation_exception() throws Exception {\r
         thrown.expect(WebApplicationException.class);\r
 \r
-        final RuleDeleteRequest ruleDeleteRequest = new RuleDeleteRequest();\r
-        ruleMgtWrapper.deleteCorrelationRule(ruleDeleteRequest);\r
+        final String ruleId = "mockedRule";\r
+        ruleMgtWrapper.deleteCorrelationRule(EasyMock.anyObject(RuleDeleteRequest.class));\r
         EasyMock.expectLastCall().andThrow(new CorrelationException(EasyMock.anyObject(String.class)));\r
         EasyMock.expect(request.getHeader("language-option")).andReturn("en_US");\r
         PowerMock.replayAll();\r
-        ruleMgtResources.deleteCorrelationRule(request, ruleDeleteRequest);\r
+        ruleMgtResources.deleteCorrelationRule(request, ruleId);\r
         PowerMock.verifyAll();\r
     }\r
 \r
     @Test\r
     public void deleteCorrelationRule_normal() throws Exception {\r
-        final RuleDeleteRequest ruleDeleteRequest = new RuleDeleteRequest();\r
-        ruleMgtWrapper.deleteCorrelationRule(ruleDeleteRequest);\r
+        final String ruleId = "mockedRule";\r
+        ruleMgtWrapper.deleteCorrelationRule(EasyMock.anyObject(RuleDeleteRequest.class));\r
         EasyMock.expectLastCall();\r
         EasyMock.expect(request.getHeader("language-option")).andReturn("en_US");\r
         PowerMock.replayAll();\r
-        ruleMgtResources.deleteCorrelationRule(request, ruleDeleteRequest);\r
+        ruleMgtResources.deleteCorrelationRule(request, ruleId);\r
         PowerMock.verifyAll();\r
     }\r
 \r