<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>
<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>
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
@Service
@SwaggerDefinition
@Path("/healthcheck")
-@Api(tags = {"HealthCheck"})
+@Api(tags = {"Health Check"})
@Produces(MediaType.TEXT_PLAIN)
@Slf4j
public class HealthCheck {
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
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
@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
\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
\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
\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
--- /dev/null
+{
+ "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
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