summaryrefslogtreecommitdiffstats
path: root/rulemgt/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'rulemgt/src/main')
-rw-r--r--rulemgt/src/main/java/org/onap/holmes/rulemgt/RuleActiveApp.java1
-rw-r--r--rulemgt/src/main/java/org/onap/holmes/rulemgt/bean/request/CorrelationCheckRule4Engine.java1
-rw-r--r--rulemgt/src/main/java/org/onap/holmes/rulemgt/bean/request/CorrelationDeployRule4Engine.java4
-rw-r--r--rulemgt/src/main/java/org/onap/holmes/rulemgt/bean/request/RuleCreateRequest.java11
-rw-r--r--rulemgt/src/main/java/org/onap/holmes/rulemgt/bean/request/RuleDeleteRequest.java2
-rw-r--r--rulemgt/src/main/java/org/onap/holmes/rulemgt/bean/request/RuleQueryCondition.java6
-rw-r--r--rulemgt/src/main/java/org/onap/holmes/rulemgt/bean/request/RuleUpdateRequest.java11
-rw-r--r--rulemgt/src/main/java/org/onap/holmes/rulemgt/bean/response/RuleAddAndUpdateResponse.java4
-rw-r--r--rulemgt/src/main/java/org/onap/holmes/rulemgt/bean/response/RuleQueryListResponse.java4
-rw-r--r--rulemgt/src/main/java/org/onap/holmes/rulemgt/bean/response/RuleResult4API.java7
-rw-r--r--rulemgt/src/main/java/org/onap/holmes/rulemgt/bolt/enginebolt/EngineService.java54
-rw-r--r--rulemgt/src/main/java/org/onap/holmes/rulemgt/bolt/enginebolt/EngineWrapper.java19
-rw-r--r--rulemgt/src/main/java/org/onap/holmes/rulemgt/constant/RuleMgtConstant.java2
-rw-r--r--rulemgt/src/main/java/org/onap/holmes/rulemgt/dcae/DcaeConfigurationPolling.java94
-rw-r--r--rulemgt/src/main/java/org/onap/holmes/rulemgt/resources/RuleMgtResources.java33
15 files changed, 135 insertions, 118 deletions
diff --git a/rulemgt/src/main/java/org/onap/holmes/rulemgt/RuleActiveApp.java b/rulemgt/src/main/java/org/onap/holmes/rulemgt/RuleActiveApp.java
index 6409794..e7f30a7 100644
--- a/rulemgt/src/main/java/org/onap/holmes/rulemgt/RuleActiveApp.java
+++ b/rulemgt/src/main/java/org/onap/holmes/rulemgt/RuleActiveApp.java
@@ -69,6 +69,7 @@ public class RuleActiveApp extends IOCApplication<RuleAppConfig> {
msinfo.setUrl("/api/holmes-rule-mgmt/v1");
msinfo.setProtocol("REST");
msinfo.setVisualRange("0|1");
+ msinfo.setEnable_ssl(true);
Set<Node> nodes = new HashSet<>();
Node node = new Node();
node.setIp(serviceAddrInfo[0]);
diff --git a/rulemgt/src/main/java/org/onap/holmes/rulemgt/bean/request/CorrelationCheckRule4Engine.java b/rulemgt/src/main/java/org/onap/holmes/rulemgt/bean/request/CorrelationCheckRule4Engine.java
index c36fce7..a056653 100644
--- a/rulemgt/src/main/java/org/onap/holmes/rulemgt/bean/request/CorrelationCheckRule4Engine.java
+++ b/rulemgt/src/main/java/org/onap/holmes/rulemgt/bean/request/CorrelationCheckRule4Engine.java
@@ -22,6 +22,5 @@ import lombok.Setter;
@Getter
@Setter
public class CorrelationCheckRule4Engine {
-
private String content;
}
diff --git a/rulemgt/src/main/java/org/onap/holmes/rulemgt/bean/request/CorrelationDeployRule4Engine.java b/rulemgt/src/main/java/org/onap/holmes/rulemgt/bean/request/CorrelationDeployRule4Engine.java
index b38ea47..4c578e4 100644
--- a/rulemgt/src/main/java/org/onap/holmes/rulemgt/bean/request/CorrelationDeployRule4Engine.java
+++ b/rulemgt/src/main/java/org/onap/holmes/rulemgt/bean/request/CorrelationDeployRule4Engine.java
@@ -16,6 +16,7 @@
package org.onap.holmes.rulemgt.bean.request;
import com.fasterxml.jackson.annotation.JsonProperty;
+import com.google.gson.annotations.SerializedName;
import lombok.Getter;
import lombok.Setter;
@@ -23,12 +24,9 @@ import lombok.Setter;
@Setter
public class CorrelationDeployRule4Engine {
- @JsonProperty(value = "content")
private String content;
- @JsonProperty(value = "engineid")
private String engineId;
- @JsonProperty(value = "loopcontrolname")
private String loopControlName;
}
diff --git a/rulemgt/src/main/java/org/onap/holmes/rulemgt/bean/request/RuleCreateRequest.java b/rulemgt/src/main/java/org/onap/holmes/rulemgt/bean/request/RuleCreateRequest.java
index c7e8a6f..8dc98d8 100644
--- a/rulemgt/src/main/java/org/onap/holmes/rulemgt/bean/request/RuleCreateRequest.java
+++ b/rulemgt/src/main/java/org/onap/holmes/rulemgt/bean/request/RuleCreateRequest.java
@@ -15,21 +15,20 @@
*/
package org.onap.holmes.rulemgt.bean.request;
-import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Getter;
import lombok.Setter;
@Setter
@Getter
public class RuleCreateRequest {
- @JsonProperty(value = "rulename")
+
private String ruleName;
- @JsonProperty(value = "loopcontrolname")
+
private String loopControlName;
- @JsonProperty
+
private String description;
- @JsonProperty
+
private String content;
- @JsonProperty
+
private int enabled;
}
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 57aeafc..49b646a 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
@@ -15,7 +15,6 @@
*/
package org.onap.holmes.rulemgt.bean.request;
-import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
@@ -27,6 +26,5 @@ import lombok.Setter;
@AllArgsConstructor
@NoArgsConstructor
public class RuleDeleteRequest {
- @JsonProperty(value = "ruleid")
private String ruleId;
}
diff --git a/rulemgt/src/main/java/org/onap/holmes/rulemgt/bean/request/RuleQueryCondition.java b/rulemgt/src/main/java/org/onap/holmes/rulemgt/bean/request/RuleQueryCondition.java
index f3b9b91..c6ba4b7 100644
--- a/rulemgt/src/main/java/org/onap/holmes/rulemgt/bean/request/RuleQueryCondition.java
+++ b/rulemgt/src/main/java/org/onap/holmes/rulemgt/bean/request/RuleQueryCondition.java
@@ -15,7 +15,7 @@
*/
package org.onap.holmes.rulemgt.bean.request;
-import com.fasterxml.jackson.annotation.JsonProperty;
+import com.google.gson.annotations.SerializedName;
import lombok.Getter;
import lombok.Setter;
@@ -23,9 +23,9 @@ import lombok.Setter;
@Setter
public class RuleQueryCondition {
- @JsonProperty(value = "ruleid")
+ @SerializedName(value = "ruleid")
private String rid;
- @JsonProperty(value = "rulename")
+ @SerializedName(value = "rulename")
private String name;
private int enabled;
private String creator;
diff --git a/rulemgt/src/main/java/org/onap/holmes/rulemgt/bean/request/RuleUpdateRequest.java b/rulemgt/src/main/java/org/onap/holmes/rulemgt/bean/request/RuleUpdateRequest.java
index 99af585..1bcd494 100644
--- a/rulemgt/src/main/java/org/onap/holmes/rulemgt/bean/request/RuleUpdateRequest.java
+++ b/rulemgt/src/main/java/org/onap/holmes/rulemgt/bean/request/RuleUpdateRequest.java
@@ -15,21 +15,20 @@
*/
package org.onap.holmes.rulemgt.bean.request;
-import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
public class RuleUpdateRequest {
- @JsonProperty
+
private String description;
- @JsonProperty
+
private String content;
- @JsonProperty
+
private int enabled;
- @JsonProperty(value="ruleid")
+
private String ruleId;
- @JsonProperty(value = "loopcontrolname")
+
private String loopControlName;
}
diff --git a/rulemgt/src/main/java/org/onap/holmes/rulemgt/bean/response/RuleAddAndUpdateResponse.java b/rulemgt/src/main/java/org/onap/holmes/rulemgt/bean/response/RuleAddAndUpdateResponse.java
index 7fe432e..760ad4f 100644
--- a/rulemgt/src/main/java/org/onap/holmes/rulemgt/bean/response/RuleAddAndUpdateResponse.java
+++ b/rulemgt/src/main/java/org/onap/holmes/rulemgt/bean/response/RuleAddAndUpdateResponse.java
@@ -15,15 +15,11 @@
*/
package org.onap.holmes.rulemgt.bean.response;
-import com.fasterxml.jackson.annotation.JsonInclude;
-import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Getter;
import lombok.Setter;
-@JsonInclude(JsonInclude.Include.ALWAYS)
@Getter
@Setter
public class RuleAddAndUpdateResponse{
- @JsonProperty(value="ruleid")
private String ruleId;
}
diff --git a/rulemgt/src/main/java/org/onap/holmes/rulemgt/bean/response/RuleQueryListResponse.java b/rulemgt/src/main/java/org/onap/holmes/rulemgt/bean/response/RuleQueryListResponse.java
index aab6dc5..9305496 100644
--- a/rulemgt/src/main/java/org/onap/holmes/rulemgt/bean/response/RuleQueryListResponse.java
+++ b/rulemgt/src/main/java/org/onap/holmes/rulemgt/bean/response/RuleQueryListResponse.java
@@ -15,18 +15,16 @@
*/
package org.onap.holmes.rulemgt.bean.response;
-import com.google.gson.annotations.SerializedName;
import lombok.Getter;
import lombok.Setter;
import java.util.ArrayList;
import java.util.List;
+
@Getter
@Setter
public class RuleQueryListResponse {
- @SerializedName(value = "rules")
private List<RuleResult4API> correlationRules = new ArrayList<RuleResult4API>();
- @SerializedName(value = "totalcount")
private int totalCount;
}
diff --git a/rulemgt/src/main/java/org/onap/holmes/rulemgt/bean/response/RuleResult4API.java b/rulemgt/src/main/java/org/onap/holmes/rulemgt/bean/response/RuleResult4API.java
index e97b94d..39e1bb6 100644
--- a/rulemgt/src/main/java/org/onap/holmes/rulemgt/bean/response/RuleResult4API.java
+++ b/rulemgt/src/main/java/org/onap/holmes/rulemgt/bean/response/RuleResult4API.java
@@ -15,30 +15,23 @@
*/
package org.onap.holmes.rulemgt.bean.response;
-import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Getter;
import lombok.Setter;
import java.util.Date;
-@JsonInclude(JsonInclude.Include.ALWAYS)
@Setter
@Getter
public class RuleResult4API {
- @JsonProperty(value = "ruleid")
private String ruleId;
- @JsonProperty(value = "rulename")
private String ruleName;
private String description;
private String content;
- @JsonProperty(value = "createtime")
private Date createTime;
private String creator;
- @JsonProperty(value = "updatetime")
private Date updateTime;
private String modifier;
private int enabled;
- @JsonProperty(value = "loopcontrolname")
private String closedControlLoopName;
}
diff --git a/rulemgt/src/main/java/org/onap/holmes/rulemgt/bolt/enginebolt/EngineService.java b/rulemgt/src/main/java/org/onap/holmes/rulemgt/bolt/enginebolt/EngineService.java
index 5dc97b4..319347e 100644
--- a/rulemgt/src/main/java/org/onap/holmes/rulemgt/bolt/enginebolt/EngineService.java
+++ b/rulemgt/src/main/java/org/onap/holmes/rulemgt/bolt/enginebolt/EngineService.java
@@ -15,17 +15,14 @@
*/
package org.onap.holmes.rulemgt.bolt.enginebolt;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import java.io.IOException;
-import javax.ws.rs.client.Client;
-import javax.ws.rs.client.ClientBuilder;
-import javax.ws.rs.client.Entity;
-import javax.ws.rs.client.WebTarget;
+import java.util.HashMap;
import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
import lombok.extern.slf4j.Slf4j;
-import org.glassfish.jersey.client.ClientConfig;
+import org.apache.http.HttpResponse;
+import org.apache.http.entity.StringEntity;
import org.jvnet.hk2.annotations.Service;
+import org.onap.holmes.common.utils.GsonUtil;
+import org.onap.holmes.common.utils.HttpsUtils;
import org.onap.holmes.rulemgt.bean.request.CorrelationCheckRule4Engine;
import org.onap.holmes.rulemgt.bean.request.CorrelationDeployRule4Engine;
import org.onap.holmes.rulemgt.constant.RuleMgtConstant;
@@ -35,32 +32,31 @@ import org.onap.holmes.common.config.MicroServiceConfig;
@Service
public class EngineService {
- protected Response delete(String packageName) throws IOException {
- Client client = createClient();
- WebTarget webTarget = client
- .target(MicroServiceConfig.getMsbServerAddrWithHttpPrefix() + RuleMgtConstant.ENGINE_PATH + "/" + packageName);
- return webTarget.request(MediaType.APPLICATION_JSON).delete();
+ protected HttpResponse delete(String packageName) throws Exception {
+ HashMap headers = createHeaders();
+ String url = MicroServiceConfig.getMsbServerAddrWithHttpPrefix() + RuleMgtConstant.ENGINE_PATH + "/" + packageName;
+ return HttpsUtils.delete(url, headers);
}
- private Client createClient() {
- ClientConfig clientConfig = new ClientConfig();
- return ClientBuilder.newClient(clientConfig);
+ protected HttpResponse check(CorrelationCheckRule4Engine correlationCheckRule4Engine)
+ throws Exception {
+ String content = GsonUtil.beanToJson(correlationCheckRule4Engine);
+ HashMap headers = createHeaders();
+ String url = MicroServiceConfig.getMsbServerAddrWithHttpPrefix() + RuleMgtConstant.ENGINE_PATH;
+ return HttpsUtils.post(url, headers, new HashMap<>(), new StringEntity(content));
}
- protected Response check(CorrelationCheckRule4Engine correlationCheckRule4Engine)
- throws IOException {
- Client client = createClient();
- ObjectMapper mapper = new ObjectMapper();
- String content = mapper.writeValueAsString(correlationCheckRule4Engine);
- WebTarget webTarget = client.target(MicroServiceConfig.getMsbServerAddrWithHttpPrefix() + RuleMgtConstant.ENGINE_PATH);
- return webTarget.request(MediaType.APPLICATION_JSON).post(Entity.entity(content, MediaType.APPLICATION_JSON));
+ protected HttpResponse deploy(CorrelationDeployRule4Engine correlationDeployRule4Engine) throws Exception {
+ String content = GsonUtil.beanToJson(correlationDeployRule4Engine);
+ HashMap headers = createHeaders();
+ String url = MicroServiceConfig.getMsbServerAddrWithHttpPrefix() + RuleMgtConstant.ENGINE_PATH;
+ return HttpsUtils.put(url, headers, new HashMap<>(), new StringEntity(content));
}
- protected Response deploy(CorrelationDeployRule4Engine correlationDeployRule4Engine) throws IOException {
- Client client = createClient();
- ObjectMapper mapper = new ObjectMapper();
- String content = mapper.writeValueAsString(correlationDeployRule4Engine);
- WebTarget webTarget = client.target(MicroServiceConfig.getMsbServerAddrWithHttpPrefix() + RuleMgtConstant.ENGINE_PATH);
- return webTarget.request(MediaType.APPLICATION_JSON).put(Entity.entity(content, MediaType.APPLICATION_JSON));
+ private HashMap<String, String> createHeaders() {
+ HashMap<String, String> headers = new HashMap<>();
+ headers.put("Content-Type", MediaType.APPLICATION_JSON);
+ headers.put("Accept", MediaType.APPLICATION_JSON);
+ return headers;
}
}
diff --git a/rulemgt/src/main/java/org/onap/holmes/rulemgt/bolt/enginebolt/EngineWrapper.java b/rulemgt/src/main/java/org/onap/holmes/rulemgt/bolt/enginebolt/EngineWrapper.java
index 733cae0..183e52f 100644
--- a/rulemgt/src/main/java/org/onap/holmes/rulemgt/bolt/enginebolt/EngineWrapper.java
+++ b/rulemgt/src/main/java/org/onap/holmes/rulemgt/bolt/enginebolt/EngineWrapper.java
@@ -16,10 +16,11 @@
package org.onap.holmes.rulemgt.bolt.enginebolt;
import javax.inject.Inject;
-import javax.ws.rs.core.Response;
import lombok.extern.slf4j.Slf4j;
import net.sf.json.JSONObject;
+import org.apache.http.HttpResponse;
import org.jvnet.hk2.annotations.Service;
+import org.onap.holmes.common.utils.HttpsUtils;
import org.onap.holmes.rulemgt.bean.request.CorrelationCheckRule4Engine;
import org.onap.holmes.rulemgt.bean.request.CorrelationDeployRule4Engine;
import org.onap.holmes.rulemgt.constant.RuleMgtConstant;
@@ -33,16 +34,16 @@ public class EngineWrapper {
private EngineService engineService;
public String deployEngine(CorrelationDeployRule4Engine correlationRule) throws CorrelationException {
- Response response;
+ HttpResponse response;
try {
response = engineService.deploy(correlationRule);
} catch (Exception e) {
throw new CorrelationException("Failed to call the rule deployment RESTful API.", e);
}
- if (response.getStatus() == RuleMgtConstant.RESPONSE_STATUS_OK) {
+ if (response.getStatusLine().getStatusCode() == RuleMgtConstant.RESPONSE_STATUS_OK) {
log.info("Succeeded in calling the rule deployment RESTful API from the engine management service.");
try {
- JSONObject json = JSONObject.fromObject(response.readEntity(String.class));
+ JSONObject json = JSONObject.fromObject(HttpsUtils.extractResponseEntity(response));
return json.get(RuleMgtConstant.PACKAGE).toString();
} catch (Exception e) {
throw new CorrelationException("Failed to parse the value returned by the engine management service.", e);
@@ -53,13 +54,13 @@ public class EngineWrapper {
}
public boolean deleteRuleFromEngine(String packageName) throws CorrelationException {
- Response response;
+ HttpResponse response;
try {
response = engineService.delete(packageName);
} catch (Exception e) {
throw new CorrelationException("Failed to call the rule deleting RESTful API.", e);
}
- if (response.getStatus() == RuleMgtConstant.RESPONSE_STATUS_OK) {
+ if (response.getStatusLine().getStatusCode() == RuleMgtConstant.RESPONSE_STATUS_OK) {
log.info("Succeeded in calling the rule deleting RESTful API from the engine management service.");
return true;
} else {
@@ -70,17 +71,17 @@ public class EngineWrapper {
public boolean checkRuleFromEngine(CorrelationCheckRule4Engine correlationCheckRule4Engine)
throws CorrelationException {
log.info("Rule Contents: " + correlationCheckRule4Engine.getContent());
- Response response;
+ HttpResponse response;
try {
response = engineService.check(correlationCheckRule4Engine);
} catch (Exception e) {
throw new CorrelationException("Failed to call the rule verification RESTful API.", e);
}
- if (response.getStatus() == RuleMgtConstant.RESPONSE_STATUS_OK) {
+ if (response.getStatusLine().getStatusCode() == RuleMgtConstant.RESPONSE_STATUS_OK) {
log.info("Succeeded in calling the rule verification RESTful API from the engine management service.");
return true;
} else {
- log.info(response.getStatus() + " " + response.getStatusInfo() + " " + response.getEntity());
+ log.info(response.getStatusLine().getStatusCode() + " " + response.getEntity());
throw new CorrelationException("Failed to verify the rule. The contents of the rule are invalid.");
}
}
diff --git a/rulemgt/src/main/java/org/onap/holmes/rulemgt/constant/RuleMgtConstant.java b/rulemgt/src/main/java/org/onap/holmes/rulemgt/constant/RuleMgtConstant.java
index a5ec87c..5ac4fe6 100644
--- a/rulemgt/src/main/java/org/onap/holmes/rulemgt/constant/RuleMgtConstant.java
+++ b/rulemgt/src/main/java/org/onap/holmes/rulemgt/constant/RuleMgtConstant.java
@@ -23,7 +23,7 @@ public class RuleMgtConstant {
public static final int STATUS_RULE_OPEN = 1;
public static final int STATUS_RULE_CLOSE = 0;
public static final int STATUS_RULE_ALL = 2;
- public static final String PACKAGE = "package";
+ public static final String PACKAGE = "packageName";
public static final String ENGINE_PATH = "/api/holmes-engine-mgmt/v1/rule";
public static final int RESPONSE_STATUS_OK = 200;
}
diff --git a/rulemgt/src/main/java/org/onap/holmes/rulemgt/dcae/DcaeConfigurationPolling.java b/rulemgt/src/main/java/org/onap/holmes/rulemgt/dcae/DcaeConfigurationPolling.java
index d0513ca..0e4f790 100644
--- a/rulemgt/src/main/java/org/onap/holmes/rulemgt/dcae/DcaeConfigurationPolling.java
+++ b/rulemgt/src/main/java/org/onap/holmes/rulemgt/dcae/DcaeConfigurationPolling.java
@@ -13,20 +13,29 @@
*/
package org.onap.holmes.rulemgt.dcae;
+import com.alibaba.fastjson.JSON;
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import com.google.gson.JsonDeserializationContext;
+import com.google.gson.JsonDeserializer;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonParseException;
+import com.google.gson.reflect.TypeToken;
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.lang.reflect.Type;
+import java.util.HashMap;
import java.util.List;
-import javax.ws.rs.client.Client;
-import javax.ws.rs.client.ClientBuilder;
-import javax.ws.rs.client.Entity;
-import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
import lombok.extern.slf4j.Slf4j;
-import org.glassfish.jersey.client.ClientConfig;
+import org.apache.http.HttpResponse;
+import org.apache.http.entity.StringEntity;
import org.onap.holmes.common.dcae.DcaeConfigurationQuery;
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.GsonUtil;
+import org.onap.holmes.common.utils.HttpsUtils;
import org.onap.holmes.common.utils.Md5Util;
import org.onap.holmes.rulemgt.bean.request.RuleCreateRequest;
import org.onap.holmes.rulemgt.bean.response.RuleQueryListResponse;
@@ -39,7 +48,7 @@ public class DcaeConfigurationPolling implements Runnable {
private String hostname;
- private String url = "http://127.0.0.1:9101/api/holmes-rule-mgmt/v1/rule";
+ private String url = "https://127.0.0.1:9101/api/holmes-rule-mgmt/v1/rule";
public DcaeConfigurationPolling(String hostname) {
this.hostname = hostname;
@@ -55,7 +64,7 @@ public class DcaeConfigurationPolling implements Runnable {
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;
}
@@ -63,9 +72,20 @@ public class DcaeConfigurationPolling implements Runnable {
prevResult = false;
} catch (CorrelationException e) {
log.error("Failed to fetch DCAE configurations. " + e.getMessage(), e);
+ } catch (Exception e) {
+ log.info("Failed to generate the MD5 information for new configurations.", e);
}
+ RuleQueryListResponse ruleQueryListResponse = null;
if (dcaeConfigurations != null) {
- RuleQueryListResponse ruleQueryListResponse = getAllCorrelationRules();
+ try {
+ ruleQueryListResponse = getAllCorrelationRules();
+ } catch (CorrelationException e) {
+ log.error("Failed to get right response!" + e.getMessage(), e);
+ } catch (IOException e) {
+ log.error("Failed to extract response entity. " + e.getMessage(), e);
+ }
+ }
+ if (ruleQueryListResponse != null) {
List<RuleResult4API> ruleResult4APIs = ruleQueryListResponse.getCorrelationRules();
deleteAllCorrelationRules(ruleResult4APIs);
try {
@@ -77,24 +97,39 @@ public class DcaeConfigurationPolling implements Runnable {
}
}
- private RuleQueryListResponse getAllCorrelationRules() {
- Client client = ClientBuilder.newClient(new ClientConfig());
- WebTarget webTarget = client.target(url);
- return webTarget.request("application/json").get()
- .readEntity(RuleQueryListResponse.class);
+ public RuleQueryListResponse getAllCorrelationRules() throws CorrelationException, IOException {
+ HashMap<String, String> headers = new HashMap<>();
+ headers.put("Content-Type", MediaType.APPLICATION_JSON);
+ HttpResponse httpResponse = HttpsUtils.get(url, headers);
+ String response = HttpsUtils.extractResponseEntity(httpResponse);
+ return JSON.parseObject(response,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());
- String content = GsonUtil.beanToJson(ruleCreateRequest);
- WebTarget webTarget = client.target(url);
- Response response = webTarget.request(MediaType.APPLICATION_JSON)
- .put(Entity.entity(content, MediaType.APPLICATION_JSON));
- suc = response.getStatus() == 200;
+ String content = "";
+ try {
+ content = GsonUtil.beanToJson(ruleCreateRequest);
+ } catch (Exception e) {
+ throw new CorrelationException("Failed to convert the message object to a json string.", e);
+ }
+ HashMap<String, String> headers = new HashMap<>();
+ headers.put("Content-Type", MediaType.APPLICATION_JSON);
+ headers.put("Accept", MediaType.APPLICATION_JSON);
+ HttpResponse httpResponse;
+ try {
+ httpResponse = HttpsUtils
+ .put(url, headers, new HashMap<>(), new StringEntity(content));
+ } catch (UnsupportedEncodingException e) {
+ throw new CorrelationException("Failed to create https entity.", e);
+ } catch (Exception e) {
+ throw new CorrelationException(e.getMessage());
+ }
+ if (httpResponse != null) {
+ suc = httpResponse.getStatusLine().getStatusCode() == 200;
+ }
if (!suc) {
break;
}
@@ -102,11 +137,16 @@ public class DcaeConfigurationPolling implements Runnable {
return suc;
}
- 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();
+ private void deleteAllCorrelationRules(List<RuleResult4API> ruleResult4APIs){
+ ruleResult4APIs.forEach(correlationRule ->{
+ HashMap<String, String> headers = new HashMap<>();
+ headers.put("Content-Type", MediaType.APPLICATION_JSON);
+ try {
+ HttpsUtils.delete(url + "/" + correlationRule.getRuleId(), headers);
+ } catch (Exception e) {
+ log.warn("Failed to delete rule, the rule id is : " + correlationRule.getRuleId()
+ + " exception messge is : " + e.getMessage(), e);
+ }
});
}
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 041377f..d3c01ae 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
@@ -5,7 +5,7 @@
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -20,6 +20,9 @@ import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.SwaggerDefinition;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
import java.util.Locale;
import javax.inject.Inject;
import javax.servlet.http.HttpServletRequest;
@@ -47,6 +50,7 @@ import org.onap.holmes.rulemgt.bean.request.RuleQueryCondition;
import org.onap.holmes.rulemgt.bean.request.RuleUpdateRequest;
import org.onap.holmes.rulemgt.bean.response.RuleAddAndUpdateResponse;
import org.onap.holmes.rulemgt.bean.response.RuleQueryListResponse;
+import org.onap.holmes.rulemgt.bean.response.RuleResult4API;
import org.onap.holmes.rulemgt.constant.RuleMgtConstant;
import org.onap.holmes.rulemgt.wrapper.RuleMgtWrapper;
@@ -67,10 +71,9 @@ public class RuleMgtResources {
response = RuleAddAndUpdateResponse.class)
@Timed
public RuleAddAndUpdateResponse addCorrelationRule(@Context HttpServletRequest request,
- @ApiParam(value =
- "The request entity of the HTTP call, which comprises \"rulename\"(required), "
- + "\"loopcontrolname\"(required), \"content\"(required), \"enabled\"(required) "
- + "and \"description\"(optional)", required = true)
+ @ApiParam(value = "The request entity of the HTTP call, which comprises \"ruleName\"(required), "
+ + "\"loopControlName\"(required), \"content\"(required), \"enabled\"(required) "
+ + "and \"description\"(optional)", required = true)
RuleCreateRequest ruleCreateRequest) {
Locale locale = LanguageUtil.getLocale(request);
RuleAddAndUpdateResponse ruleChangeResponse;
@@ -90,15 +93,13 @@ public class RuleMgtResources {
@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 =
- "The request entity of the HTTP call, which comprises \"ruleid\"(required), "
- + "\"content\"(required), \"enabled\"(required) and \"description\"(optional)", required = true)
+ @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 {
- ruleChangeResponse = ruleMgtWrapper
- .updateCorrelationRule(UserUtil.getUserName(request), ruleUpdateRequest);
+ ruleChangeResponse = ruleMgtWrapper.updateCorrelationRule(UserUtil.getUserName(request), ruleUpdateRequest);
log.info("update rule:" + ruleUpdateRequest.getRuleId() + " successful");
return ruleChangeResponse;
} catch (CorrelationException e) {
@@ -130,19 +131,18 @@ public class RuleMgtResources {
@ApiOperation(value = "Query rules using certain criteria.", response = RuleQueryListResponse.class)
@Timed
public RuleQueryListResponse getCorrelationRules(@Context HttpServletRequest request,
- @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\"}",
+ @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);
try {
ruleQueryListResponse = ruleMgtWrapper
.getCorrelationRuleByCondition(ruleQueryCondition);
- log.info("query rule successful by condition:" + JSONObject
- .fromObject(ruleQueryCondition));
+ log.info("query rule successful by condition:" + JSONObject.fromObject(ruleQueryCondition));
return ruleQueryListResponse;
} catch (CorrelationException e) {
log.error("query rule failed,cause query condition conversion failure", e);
@@ -153,7 +153,6 @@ public class RuleMgtResources {
private RuleQueryCondition getRuleQueryCondition(String queryRequest,
HttpServletRequest request) {
Locale locale = LanguageUtil.getLocale(request);
-
RuleQueryCondition ruleQueryCondition = GsonUtil.jsonToBean(queryRequest, RuleQueryCondition.class);
if (queryRequest == null) {
if(ruleQueryCondition==null){