Change-Id: Ifffe7aca1116e2706d66ecb682697df521785b57
Issue-ID: HOLMES-115
Signed-off-by: YiLi <li.yi101@zte.com.cn>
<dependency>\r
<groupId>org.onap.holmes.common</groupId>\r
<artifactId>holmes-actions</artifactId>\r
<dependency>\r
<groupId>org.onap.holmes.common</groupId>\r
<artifactId>holmes-actions</artifactId>\r
- <version>1.0.0</version>\r
+ <version>1.1.0-SNAPSHOT</version>\r
</dependency>\r
<dependency>\r
<groupId>io.dropwizard</groupId>\r
</dependency>\r
<dependency>\r
<groupId>io.dropwizard</groupId>\r
<version>1.6.5</version>\r
<scope>test</scope>\r
</dependency>\r
<version>1.6.5</version>\r
<scope>test</scope>\r
</dependency>\r
</dependencies>\r
</dependencyManagement>\r
</project>\r
</dependencies>\r
</dependencyManagement>\r
</project>\r
driverClass: org.postgresql.Driver
user: holmes
password: holmespwd
driverClass: org.postgresql.Driver
user: holmes
password: holmespwd
- url: jdbc:postgresql://10.74.156.206:5432/holmes
+ url: jdbc:postgresql://10.96.33.33:5432/holmes
properties:
charSet: UTF-8
maxWaitForConnection: 1s
properties:
charSet: UTF-8
maxWaitForConnection: 1s
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
- <version>4.3.6</version>
</dependency>
<dependency>
<groupId>com.googlecode.json-simple</groupId>
</dependency>
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>guava</artifactId>
<version>19.0</version>
</dependency>
<artifactId>guava</artifactId>
<version>19.0</version>
</dependency>
+ <!-- https://mvnrepository.com/artifact/org.codehaus.groovy.maven/gmaven-plugin -->
+ <dependency>
+ <groupId>org.codehaus.groovy.maven</groupId>
+ <artifactId>gmaven-plugin</artifactId>
+ <version>1.0</version>
+ </dependency>
+
</dependencies>
<build>
<plugins>
</dependencies>
<build>
<plugins>
*/\r
package org.onap.holmes.rulemgt.bean.response;\r
\r
*/\r
package org.onap.holmes.rulemgt.bean.response;\r
\r
-import com.fasterxml.jackson.annotation.JsonInclude;\r
-import com.fasterxml.jackson.annotation.JsonProperty;\r
+import com.google.gson.annotations.SerializedName;\r
import lombok.Getter;\r
import lombok.Setter;\r
\r
import java.util.ArrayList;\r
import java.util.List;\r
\r
import lombok.Getter;\r
import lombok.Setter;\r
\r
import java.util.ArrayList;\r
import java.util.List;\r
\r
-@JsonInclude(JsonInclude.Include.ALWAYS)\r
@Getter\r
@Setter\r
public class RuleQueryListResponse {\r
@Getter\r
@Setter\r
public class RuleQueryListResponse {\r
- @JsonProperty(value = "rules")\r
+ @SerializedName(value = "rules")\r
private List<RuleResult4API> correlationRules = new ArrayList<RuleResult4API>();\r
private List<RuleResult4API> correlationRules = new ArrayList<RuleResult4API>();\r
- @JsonProperty(value = "totalcount")\r
+ @SerializedName(value = "totalcount")\r
private int totalCount;\r
}\r
private int totalCount;\r
}\r
*/
package org.onap.holmes.rulemgt.dcae;
*/
package org.onap.holmes.rulemgt.dcae;
-import com.fasterxml.jackson.core.JsonProcessingException;
import java.util.List;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import java.util.List;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import org.onap.holmes.common.dcae.entity.DcaeConfigurations;
import org.onap.holmes.common.dcae.entity.Rule;
import org.onap.holmes.common.exception.CorrelationException;
import org.onap.holmes.common.dcae.entity.DcaeConfigurations;
import org.onap.holmes.common.dcae.entity.Rule;
import org.onap.holmes.common.exception.CorrelationException;
-import org.onap.holmes.common.utils.JacksonUtil;
+import org.onap.holmes.common.utils.GsonUtil;
import org.onap.holmes.common.utils.Md5Util;
import org.onap.holmes.rulemgt.bean.request.RuleCreateRequest;
import org.onap.holmes.rulemgt.bean.response.RuleQueryListResponse;
import org.onap.holmes.common.utils.Md5Util;
import org.onap.holmes.rulemgt.bean.request.RuleCreateRequest;
import org.onap.holmes.rulemgt.bean.response.RuleQueryListResponse;
try {
dcaeConfigurations = DcaeConfigurationQuery.getDcaeConfigurations(hostname);
String md5 = Md5Util.md5(dcaeConfigurations);
try {
dcaeConfigurations = DcaeConfigurationQuery.getDcaeConfigurations(hostname);
String md5 = Md5Util.md5(dcaeConfigurations);
- if (prevResult && prevConfigMd5.equals(md5)){
+ if (prevResult && prevConfigMd5.equals(md5)) {
log.info("Operation aborted due to identical Configurations.");
return;
}
log.info("Operation aborted due to identical Configurations.");
return;
}
prevResult = false;
} catch (CorrelationException e) {
log.error("Failed to fetch DCAE configurations. " + e.getMessage(), e);
prevResult = false;
} catch (CorrelationException e) {
log.error("Failed to fetch DCAE configurations. " + e.getMessage(), e);
- } catch (JsonProcessingException e) {
- log.info("Failed to generate the MD5 information for new configurations.", e);
}
if (dcaeConfigurations != null) {
RuleQueryListResponse ruleQueryListResponse = getAllCorrelationRules();
}
if (dcaeConfigurations != null) {
RuleQueryListResponse ruleQueryListResponse = getAllCorrelationRules();
.readEntity(RuleQueryListResponse.class);
}
.readEntity(RuleQueryListResponse.class);
}
- private boolean addAllCorrelationRules(DcaeConfigurations dcaeConfigurations) throws CorrelationException {
+ private boolean addAllCorrelationRules(DcaeConfigurations dcaeConfigurations)
+ throws CorrelationException {
boolean suc = false;
for (Rule rule : dcaeConfigurations.getDefaultRules()) {
RuleCreateRequest ruleCreateRequest = getRuleCreateRequest(rule);
Client client = ClientBuilder.newClient(new ClientConfig());
boolean suc = false;
for (Rule rule : dcaeConfigurations.getDefaultRules()) {
RuleCreateRequest ruleCreateRequest = getRuleCreateRequest(rule);
Client client = ClientBuilder.newClient(new ClientConfig());
- String content = null;
- try {
- content = JacksonUtil.beanToJson(ruleCreateRequest);
- } catch (JsonProcessingException e) {
- throw new CorrelationException("Failed to convert the message object to a json string.", e);
- }
+ String content = GsonUtil.beanToJson(ruleCreateRequest);
WebTarget webTarget = client.target(url);
Response response = webTarget.request(MediaType.APPLICATION_JSON)
.put(Entity.entity(content, MediaType.APPLICATION_JSON));
WebTarget webTarget = client.target(url);
Response response = webTarget.request(MediaType.APPLICATION_JSON)
.put(Entity.entity(content, MediaType.APPLICATION_JSON));
- private void deleteAllCorrelationRules(List<RuleResult4API> ruleResult4APIs){
- ruleResult4APIs.forEach(correlationRule ->{
+ private void deleteAllCorrelationRules(List<RuleResult4API> ruleResult4APIs) {
+ ruleResult4APIs.forEach(correlationRule -> {
Client client = ClientBuilder.newClient(new ClientConfig());
WebTarget webTarget = client.target(url + "/" + correlationRule.getRuleId());
webTarget.request(MediaType.APPLICATION_JSON).delete();
Client client = ClientBuilder.newClient(new ClientConfig());
WebTarget webTarget = client.target(url + "/" + correlationRule.getRuleId());
webTarget.request(MediaType.APPLICATION_JSON).delete();
* you may not use this file except in compliance with the License.\r
* You may obtain a copy of the License at\r
*\r
* you may not use this file except in compliance with the License.\r
* You may obtain a copy of the License at\r
*\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
*\r
* Unless required by applicable law or agreed to in writing, software\r
* distributed under the License is distributed on an "AS IS" BASIS,\r
*\r
* Unless required by applicable law or agreed to in writing, software\r
* distributed under the License is distributed on an "AS IS" BASIS,\r
import io.swagger.annotations.ApiOperation;\r
import io.swagger.annotations.ApiParam;\r
import io.swagger.annotations.SwaggerDefinition;\r
import io.swagger.annotations.ApiOperation;\r
import io.swagger.annotations.ApiParam;\r
import io.swagger.annotations.SwaggerDefinition;\r
-import java.io.IOException;\r
import java.util.Locale;\r
import javax.inject.Inject;\r
import javax.servlet.http.HttpServletRequest;\r
import java.util.Locale;\r
import javax.inject.Inject;\r
import javax.servlet.http.HttpServletRequest;\r
import org.jvnet.hk2.annotations.Service;\r
import org.onap.holmes.common.exception.CorrelationException;\r
import org.onap.holmes.common.utils.ExceptionUtil;\r
import org.jvnet.hk2.annotations.Service;\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.GsonUtil;\r
import org.onap.holmes.common.utils.LanguageUtil;\r
import org.onap.holmes.common.utils.UserUtil;\r
import org.onap.holmes.rulemgt.bean.request.RuleCreateRequest;\r
import org.onap.holmes.common.utils.LanguageUtil;\r
import org.onap.holmes.common.utils.UserUtil;\r
import org.onap.holmes.rulemgt.bean.request.RuleCreateRequest;\r
response = RuleAddAndUpdateResponse.class)\r
@Timed\r
public RuleAddAndUpdateResponse addCorrelationRule(@Context HttpServletRequest request,\r
response = RuleAddAndUpdateResponse.class)\r
@Timed\r
public RuleAddAndUpdateResponse addCorrelationRule(@Context HttpServletRequest request,\r
- @ApiParam(value = "The request entity of the HTTP call, which comprises \"rulename\"(required), "\r
- + "\"loopcontrolname\"(required), \"content\"(required), \"enabled\"(required) "\r
- + "and \"description\"(optional)", required = true)\r
+ @ApiParam(value =\r
+ "The request entity of the HTTP call, which comprises \"rulename\"(required), "\r
+ + "\"loopcontrolname\"(required), \"content\"(required), \"enabled\"(required) "\r
+ + "and \"description\"(optional)", required = true)\r
RuleCreateRequest ruleCreateRequest) {\r
Locale locale = LanguageUtil.getLocale(request);\r
RuleAddAndUpdateResponse ruleChangeResponse;\r
RuleCreateRequest ruleCreateRequest) {\r
Locale locale = LanguageUtil.getLocale(request);\r
RuleAddAndUpdateResponse ruleChangeResponse;\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
@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 = "The request entity of the HTTP call, which comprises \"ruleid\"(required), "\r
- + "\"content\"(required), \"enabled\"(required) and \"description\"(optional)", required = true)\r
+ @ApiParam(value =\r
+ "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
RuleUpdateRequest ruleUpdateRequest) {\r
Locale locale = LanguageUtil.getLocale(request);\r
RuleAddAndUpdateResponse ruleChangeResponse;\r
try {\r
- ruleChangeResponse = ruleMgtWrapper.updateCorrelationRule(UserUtil.getUserName(request), ruleUpdateRequest);\r
+ ruleChangeResponse = ruleMgtWrapper\r
+ .updateCorrelationRule(UserUtil.getUserName(request), ruleUpdateRequest);\r
log.info("update rule:" + ruleUpdateRequest.getRuleId() + " successful");\r
return ruleChangeResponse;\r
} catch (CorrelationException e) {\r
log.info("update rule:" + ruleUpdateRequest.getRuleId() + " successful");\r
return ruleChangeResponse;\r
} catch (CorrelationException e) {\r
@ApiOperation(value = "Query rules using certain criteria.", response = RuleQueryListResponse.class)\r
@Timed\r
public RuleQueryListResponse getCorrelationRules(@Context HttpServletRequest request,\r
@ApiOperation(value = "Query rules using certain criteria.", response = RuleQueryListResponse.class)\r
@Timed\r
public RuleQueryListResponse getCorrelationRules(@Context HttpServletRequest request,\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
+ @ApiParam(value =\r
+ "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
required = false) @QueryParam("queryrequest") String ruleQueryRequest) {\r
Locale locale = LanguageUtil.getLocale(request);\r
RuleQueryListResponse ruleQueryListResponse;\r
try {\r
ruleQueryListResponse = ruleMgtWrapper\r
.getCorrelationRuleByCondition(ruleQueryCondition);\r
try {\r
ruleQueryListResponse = ruleMgtWrapper\r
.getCorrelationRuleByCondition(ruleQueryCondition);\r
- log.info("query rule successful by condition:" + JSONObject.fromObject(ruleQueryCondition));\r
+ log.info("query rule successful by condition:" + JSONObject\r
+ .fromObject(ruleQueryCondition));\r
return ruleQueryListResponse;\r
} catch (CorrelationException e) {\r
log.error("query rule failed,cause query condition conversion failure", e);\r
return ruleQueryListResponse;\r
} catch (CorrelationException e) {\r
log.error("query rule failed,cause query condition conversion failure", e);\r
private RuleQueryCondition getRuleQueryCondition(String queryRequest,\r
HttpServletRequest request) {\r
Locale locale = LanguageUtil.getLocale(request);\r
private RuleQueryCondition getRuleQueryCondition(String queryRequest,\r
HttpServletRequest request) {\r
Locale locale = LanguageUtil.getLocale(request);\r
- try {\r
- RuleQueryCondition ruleQueryCondition = JacksonUtil\r
- .jsonToBean(queryRequest, RuleQueryCondition.class);\r
- if (queryRequest == null) {\r
- ruleQueryCondition.setEnabled(RuleMgtConstant.STATUS_RULE_ALL);\r
- } else if (queryRequest.indexOf("enabled") == -1) {\r
- ruleQueryCondition.setEnabled(RuleMgtConstant.STATUS_RULE_ALL);\r
+\r
+ RuleQueryCondition ruleQueryCondition = GsonUtil.jsonToBean(queryRequest, RuleQueryCondition.class);\r
+ if (queryRequest == null) {\r
+ if(ruleQueryCondition==null){\r
+ ruleQueryCondition = new RuleQueryCondition();\r
- return ruleQueryCondition;\r
- } catch (IOException e) {\r
- log.warn("queryRequest convert to json failed", e);\r
- throw ExceptionUtil.buildExceptionResponse("The request format is invalid!");\r
+ ruleQueryCondition.setEnabled(RuleMgtConstant.STATUS_RULE_ALL);\r
+ } else if (queryRequest.indexOf("enabled") == -1) {\r
+ ruleQueryCondition.setEnabled(RuleMgtConstant.STATUS_RULE_ALL);\r
+ return ruleQueryCondition;\r
import static org.junit.Assert.assertThat;
import static org.powermock.api.mockito.PowerMockito.when;
import static org.junit.Assert.assertThat;
import static org.powermock.api.mockito.PowerMockito.when;
+import com.alibaba.fastjson.JSONException;
import com.fasterxml.jackson.databind.ObjectMapper;
import javax.ws.rs.ProcessingException;
import org.junit.Before;
import com.fasterxml.jackson.databind.ObjectMapper;
import javax.ws.rs.ProcessingException;
import org.junit.Before;
public void testDaceConfigurationPolling_getDcaeConfigurations_exception() throws Exception {
PowerMock.resetAll();
thrown.expect(CorrelationException.class);
public void testDaceConfigurationPolling_getDcaeConfigurations_exception() throws Exception {
PowerMock.resetAll();
thrown.expect(CorrelationException.class);
- thrown.expectMessage("host");
+ thrown.expectMessage("syntax error, pos 1");
PowerMockito.mockStatic(MicroServiceConfig.class);
when(MicroServiceConfig.getServiceConfigInfoFromCBS("holmes-rule-mgmt"))
.thenReturn("host");
PowerMock.createMock(DcaeConfigurationParser.class);
PowerMock.expectPrivate(DcaeConfigurationParser.class, "parse", "host")
PowerMockito.mockStatic(MicroServiceConfig.class);
when(MicroServiceConfig.getServiceConfigInfoFromCBS("holmes-rule-mgmt"))
.thenReturn("host");
PowerMock.createMock(DcaeConfigurationParser.class);
PowerMock.expectPrivate(DcaeConfigurationParser.class, "parse", "host")
- .andThrow(new CorrelationException("tests")).anyTimes();
+ .andThrow(new CorrelationException("")).anyTimes();
PowerMock.replayAll();
Whitebox.invokeMethod(daceConfigurationPolling, "getDcaeConfigurations");
PowerMock.replayAll();
Whitebox.invokeMethod(daceConfigurationPolling, "getDcaeConfigurations");
\r
package org.onap.holmes.rulemgt.resources;\r
\r
\r
package org.onap.holmes.rulemgt.resources;\r
\r
+import com.google.gson.JsonSyntaxException;\r
import javax.servlet.http.HttpServletRequest;\r
import javax.ws.rs.WebApplicationException;\r
import org.easymock.EasyMock;\r
import javax.servlet.http.HttpServletRequest;\r
import javax.ws.rs.WebApplicationException;\r
import org.easymock.EasyMock;\r
\r
@Test\r
public void getCorrelationRules_param_translate_exception() {\r
\r
@Test\r
public void getCorrelationRules_param_translate_exception() {\r
- thrown.expect(WebApplicationException.class);\r
+ thrown.expect(JsonSyntaxException.class);\r
\r
String queryRequest = "this is error param";\r
EasyMock.expect(request.getHeader("language-option")).andReturn("en_US").times(2);\r
\r
String queryRequest = "this is error param";\r
EasyMock.expect(request.getHeader("language-option")).andReturn("en_US").times(2);\r