summaryrefslogtreecommitdiffstats
path: root/rulemgt/src
diff options
context:
space:
mode:
authorGuangrong Fu <fu.guangrong@zte.com.cn>2017-11-08 13:53:36 +0800
committerGuangrong Fu <fu.guangrong@zte.com.cn>2017-11-08 13:53:36 +0800
commit54c2f258c7e991cb3b5ea7753f48aab6fdf04261 (patch)
treeda461b62269544591d13720e2a8a312497056076 /rulemgt/src
parent126cfb2bef37fff35e6c1e3f3c7b03787fd923d8 (diff)
Add Defensive Codes in Case Errors Occur
Change-Id: I18d6f47516ff70086efcf6c21e727e95866c4afc Issue-ID: HOLMES-86 Signed-off-by: Guangrong Fu <fu.guangrong@zte.com.cn>
Diffstat (limited to 'rulemgt/src')
-rw-r--r--rulemgt/src/main/java/org/onap/holmes/rulemgt/dcae/DcaeConfigurationPolling.java26
1 files changed, 17 insertions, 9 deletions
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 493011c..97da7ee 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
@@ -14,21 +14,20 @@
package org.onap.holmes.rulemgt.dcae;
import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.ObjectMapper;
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.onap.holmes.common.config.MicroServiceConfig;
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.dcae.utils.DcaeConfigurationParser;
import org.onap.holmes.common.exception.CorrelationException;
+import org.onap.holmes.common.utils.JacksonUtil;
import org.onap.holmes.common.utils.Md5Util;
import org.onap.holmes.rulemgt.bean.request.RuleCreateRequest;
import org.onap.holmes.rulemgt.bean.response.RuleQueryListResponse;
@@ -49,17 +48,20 @@ public class DcaeConfigurationPolling implements Runnable {
private String prevConfigMd5 = Md5Util.md5(null);
+ private boolean prevResult = false;
+
@Override
public void run() {
DcaeConfigurations dcaeConfigurations = null;
try {
dcaeConfigurations = DcaeConfigurationQuery.getDcaeConfigurations(hostname);
String md5 = Md5Util.md5(dcaeConfigurations);
- if (prevConfigMd5.equals(md5)){
+ if (prevResult && prevConfigMd5.equals(md5)){
log.info("Operation aborted due to identical Configurations.");
return;
}
prevConfigMd5 = md5;
+ prevResult = false;
} catch (CorrelationException e) {
log.error("Failed to fetch DCAE configurations. " + e.getMessage(), e);
} catch (JsonProcessingException e) {
@@ -70,9 +72,10 @@ public class DcaeConfigurationPolling implements Runnable {
List<RuleResult4API> ruleResult4APIs = ruleQueryListResponse.getCorrelationRules();
deleteAllCorrelationRules(ruleResult4APIs);
try {
- addAllCorrelationRules(dcaeConfigurations);
+ prevResult = addAllCorrelationRules(dcaeConfigurations);
} catch (CorrelationException e) {
log.error("Failed to add rules. " + e.getMessage(), e);
+ prevResult = false;
}
}
}
@@ -84,21 +87,26 @@ public class DcaeConfigurationPolling implements Runnable {
.readEntity(RuleQueryListResponse.class);
}
- private void 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());
- ObjectMapper mapper = new ObjectMapper();
String content = null;
try {
- content = mapper.writeValueAsString(ruleCreateRequest);
+ content = JacksonUtil.beanToJson(ruleCreateRequest);
} catch (JsonProcessingException e) {
throw new CorrelationException("Failed to convert the message object to a json string.", e);
}
WebTarget webTarget = client.target(url);
- webTarget.request(MediaType.APPLICATION_JSON)
+ Response response = webTarget.request(MediaType.APPLICATION_JSON)
.put(Entity.entity(content, MediaType.APPLICATION_JSON));
+ suc = response.getStatus() == 200;
+ if (!suc) {
+ break;
+ }
}
+ return suc;
}
private void deleteAllCorrelationRules(List<RuleResult4API> ruleResult4APIs){