diff options
7 files changed, 341 insertions, 27 deletions
diff --git a/rulemgt-standalone/pom.xml b/rulemgt-standalone/pom.xml index 97cca2a..58d91e9 100644 --- a/rulemgt-standalone/pom.xml +++ b/rulemgt-standalone/pom.xml @@ -55,6 +55,10 @@ <exclude>Dockerfile</exclude> </excludes> </resource> + <resource> + <directory>../rulemgt/src/main/resources</directory> + <filtering>false</filtering> + </resource> </resources> <overwrite>true</overwrite> </configuration> @@ -79,6 +83,10 @@ <exclude>Dockerfile</exclude> </excludes> </resource> + <resource> + <directory>../rulemgt/src/main/resources</directory> + <filtering>false</filtering> + </resource> </resources> <overwrite>true</overwrite> </configuration> diff --git a/rulemgt/pom.xml b/rulemgt/pom.xml index 5aa0b72..013105b 100644 --- a/rulemgt/pom.xml +++ b/rulemgt/pom.xml @@ -188,7 +188,6 @@ <artifactId>guava</artifactId> <version>19.0</version> </dependency> - </dependencies> <build> <plugins> @@ -247,7 +246,6 @@ </execution> </executions> </plugin> - </plugins> <resources> <resource> @@ -261,4 +259,71 @@ </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> diff --git a/rulemgt/src/main/java/org/onap/holmes/rulemgt/bean/request/RuleDeleteRequest.java b/rulemgt/src/main/java/org/onap/holmes/rulemgt/bean/request/RuleDeleteRequest.java index 7cc4fff..57aeafc 100644 --- a/rulemgt/src/main/java/org/onap/holmes/rulemgt/bean/request/RuleDeleteRequest.java +++ b/rulemgt/src/main/java/org/onap/holmes/rulemgt/bean/request/RuleDeleteRequest.java @@ -16,12 +16,16 @@ package org.onap.holmes.rulemgt.bean.request;
import com.fasterxml.jackson.annotation.JsonProperty;
+import lombok.AllArgsConstructor;
import lombok.Getter;
+import lombok.NoArgsConstructor;
import lombok.Setter;
@Setter
@Getter
+@AllArgsConstructor
+@NoArgsConstructor
public class RuleDeleteRequest {
@JsonProperty(value = "ruleid")
private String ruleId;
diff --git a/rulemgt/src/main/java/org/onap/holmes/rulemgt/resources/HealthCheck.java b/rulemgt/src/main/java/org/onap/holmes/rulemgt/resources/HealthCheck.java index 6613edf..73d1c5b 100644 --- a/rulemgt/src/main/java/org/onap/holmes/rulemgt/resources/HealthCheck.java +++ b/rulemgt/src/main/java/org/onap/holmes/rulemgt/resources/HealthCheck.java @@ -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 { diff --git a/rulemgt/src/main/java/org/onap/holmes/rulemgt/resources/RuleMgtResources.java b/rulemgt/src/main/java/org/onap/holmes/rulemgt/resources/RuleMgtResources.java index 04578f7..00adc63 100644 --- a/rulemgt/src/main/java/org/onap/holmes/rulemgt/resources/RuleMgtResources.java +++ b/rulemgt/src/main/java/org/onap/holmes/rulemgt/resources/RuleMgtResources.java @@ -29,6 +29,7 @@ import javax.ws.rs.GET; import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Context;
@@ -36,13 +37,10 @@ import javax.ws.rs.core.MediaType; import lombok.extern.slf4j.Slf4j;
import net.sf.json.JSONObject;
import org.jvnet.hk2.annotations.Service;
-import org.onap.holmes.common.api.entity.ServiceRegisterEntity;
-import org.onap.holmes.common.config.MicroServiceConfig;
import org.onap.holmes.common.exception.CorrelationException;
import org.onap.holmes.common.utils.ExceptionUtil;
import org.onap.holmes.common.utils.JacksonUtil;
import org.onap.holmes.common.utils.LanguageUtil;
-import org.onap.holmes.common.utils.MSBRegisterUtil;
import org.onap.holmes.common.utils.UserUtil;
import org.onap.holmes.rulemgt.bean.request.RuleCreateRequest;
import org.onap.holmes.rulemgt.bean.request.RuleDeleteRequest;
@@ -56,7 +54,7 @@ import org.onap.holmes.rulemgt.wrapper.RuleMgtWrapper; @Service
@SwaggerDefinition
@Path("/rule")
-@Api(tags = {"CorrelationRules"})
+@Api(tags = {"Holmes Rule Management"})
@Produces(MediaType.APPLICATION_JSON)
@Slf4j
public class RuleMgtResources {
@@ -66,10 +64,13 @@ public class RuleMgtResources { @PUT
@Produces(MediaType.APPLICATION_JSON)
- @ApiOperation(value = "Save the alarm+ rule to the database, and deployed to the engine when the enable to open.", response = RuleAddAndUpdateResponse.class)
+ @ApiOperation(value = "Save a rule into the database; deploy it to the Drools engine if it is enabled.",
+ response = RuleAddAndUpdateResponse.class)
@Timed
public RuleAddAndUpdateResponse addCorrelationRule(@Context HttpServletRequest request,
- @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) {
+ @ApiParam(value = "The request entity of the HTTP call, which comprises \"rulename\"(required), "
+ + "\"content\"(required), \"enabled\"(required) and \"description\"(optional)", required = true)
+ RuleCreateRequest ruleCreateRequest) {
Locale locale = LanguageUtil.getLocale(request);
RuleAddAndUpdateResponse ruleChangeResponse;
try {
@@ -85,10 +86,12 @@ public class RuleMgtResources { @POST
@Produces(MediaType.APPLICATION_JSON)
- @ApiOperation(value = "Update the alarm+ rule and deployed to the engine when the enable to open.", response = RuleAddAndUpdateResponse.class)
+ @ApiOperation(value = "Update an existing rule; deploy it to the Drools engine if it is enabled.", response = RuleAddAndUpdateResponse.class)
@Timed
public RuleAddAndUpdateResponse updateCorrelationRule(@Context HttpServletRequest request,
- @ApiParam(value = "alarm+ rule update request.<br>[ruleid]:<font color=\"red\">required</font>", required = true) RuleUpdateRequest ruleUpdateRequest) {
+ @ApiParam(value = "The request entity of the HTTP call, which comprises \"ruleid\"(required), "
+ + "\"content\"(required), \"enabled\"(required) and \"description\"(optional)", required = true)
+ RuleUpdateRequest ruleUpdateRequest) {
Locale locale = LanguageUtil.getLocale(request);
RuleAddAndUpdateResponse ruleChangeResponse;
try {
@@ -103,30 +106,31 @@ public class RuleMgtResources { @DELETE
@Produces(MediaType.APPLICATION_JSON)
- @ApiOperation(value = "Delete the alarm+ rule,and when the enable is open also removed from the engine.")
+ @ApiOperation(value = "Remove a rule from Holmes.")
@Timed
+ @Path("/{ruleid}")
public boolean deleteCorrelationRule(@Context HttpServletRequest request,
- @ApiParam(value = "alarm+ rule delete request.<br>[ruleid]:<font color=\"red\">required</font>", required = true) RuleDeleteRequest ruleDeleteRequest) {
+ @PathParam("ruleid") String ruleId) {
Locale locale = LanguageUtil.getLocale(request);
try {
- ruleMgtWrapper.deleteCorrelationRule(ruleDeleteRequest);
- log.info("delete rule:" + ruleDeleteRequest.getRuleId() + " successful");
+ ruleMgtWrapper.deleteCorrelationRule(new RuleDeleteRequest(ruleId));
+ log.info("delete rule:" + ruleId + " successful");
return true;
} catch (CorrelationException e) {
- log.error("delete rule:" + ruleDeleteRequest.getRuleId() + " failed", e);
+ log.error("delete rule:" + ruleId + " failed", e);
throw ExceptionUtil.buildExceptionResponse(e.getMessage());
}
}
@GET
@Produces(MediaType.APPLICATION_JSON)
- @ApiOperation(value = "According to the conditions query the alarm + rules", response = RuleQueryListResponse.class)
+ @ApiOperation(value = "Query rules using certain criteria.", response = RuleQueryListResponse.class)
@Timed
public RuleQueryListResponse getCorrelationRules(@Context HttpServletRequest request,
- @ApiParam(value = "query condition:<br>" + " <b>[ruleid]</b>:Rule ID;<br>"
- + "<b>[rulename]</b>:Rule name;<br>" + "<b>[creator]</b>:creator of the rule;<br>"
- + "<b>[modifier]</b>:modifier of the rule;<br>"
- + "<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) {
+ @ApiParam(value = "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) @QueryParam("queryrequest") String ruleQueryRequest) {
Locale locale = LanguageUtil.getLocale(request);
RuleQueryListResponse ruleQueryListResponse;
RuleQueryCondition ruleQueryCondition = getRuleQueryCondition(ruleQueryRequest, request);
diff --git a/rulemgt/src/main/resources/swagger.json b/rulemgt/src/main/resources/swagger.json new file mode 100644 index 0000000..748a311 --- /dev/null +++ b/rulemgt/src/main/resources/swagger.json @@ -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 diff --git a/rulemgt/src/test/java/org/onap/holmes/rulemgt/resources/RuleMgtResourcesTest.java b/rulemgt/src/test/java/org/onap/holmes/rulemgt/resources/RuleMgtResourcesTest.java index dd68ad8..692cc19 100644 --- a/rulemgt/src/test/java/org/onap/holmes/rulemgt/resources/RuleMgtResourcesTest.java +++ b/rulemgt/src/test/java/org/onap/holmes/rulemgt/resources/RuleMgtResourcesTest.java @@ -111,23 +111,23 @@ public class RuleMgtResourcesTest { public void deleteCorrelationRule_correlation_exception() throws Exception {
thrown.expect(WebApplicationException.class);
- final RuleDeleteRequest ruleDeleteRequest = new RuleDeleteRequest();
- ruleMgtWrapper.deleteCorrelationRule(ruleDeleteRequest);
+ final String ruleId = "mockedRule";
+ ruleMgtWrapper.deleteCorrelationRule(EasyMock.anyObject(RuleDeleteRequest.class));
EasyMock.expectLastCall().andThrow(new CorrelationException(EasyMock.anyObject(String.class)));
EasyMock.expect(request.getHeader("language-option")).andReturn("en_US");
PowerMock.replayAll();
- ruleMgtResources.deleteCorrelationRule(request, ruleDeleteRequest);
+ ruleMgtResources.deleteCorrelationRule(request, ruleId);
PowerMock.verifyAll();
}
@Test
public void deleteCorrelationRule_normal() throws Exception {
- final RuleDeleteRequest ruleDeleteRequest = new RuleDeleteRequest();
- ruleMgtWrapper.deleteCorrelationRule(ruleDeleteRequest);
+ final String ruleId = "mockedRule";
+ ruleMgtWrapper.deleteCorrelationRule(EasyMock.anyObject(RuleDeleteRequest.class));
EasyMock.expectLastCall();
EasyMock.expect(request.getHeader("language-option")).andReturn("en_US");
PowerMock.replayAll();
- ruleMgtResources.deleteCorrelationRule(request, ruleDeleteRequest);
+ ruleMgtResources.deleteCorrelationRule(request, ruleId);
PowerMock.verifyAll();
}
|