summaryrefslogtreecommitdiffstats
path: root/engine-d/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'engine-d/src/main/java')
-rw-r--r--engine-d/src/main/java/org/onap/holmes/dsa/dmaappolling/DMaaPResponseUtil.java111
-rw-r--r--engine-d/src/main/java/org/onap/holmes/engine/EngineDActiveApp.java2
-rw-r--r--engine-d/src/main/java/org/onap/holmes/engine/manager/DroolsEngine.java29
-rw-r--r--engine-d/src/main/java/org/onap/holmes/engine/resources/EngineResources.java42
-rw-r--r--engine-d/src/main/java/org/onap/holmes/engine/utils/AlarmUtil.java6
5 files changed, 84 insertions, 106 deletions
diff --git a/engine-d/src/main/java/org/onap/holmes/dsa/dmaappolling/DMaaPResponseUtil.java b/engine-d/src/main/java/org/onap/holmes/dsa/dmaappolling/DMaaPResponseUtil.java
index be30153..e7d6669 100644
--- a/engine-d/src/main/java/org/onap/holmes/dsa/dmaappolling/DMaaPResponseUtil.java
+++ b/engine-d/src/main/java/org/onap/holmes/dsa/dmaappolling/DMaaPResponseUtil.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2017 ZTE Corporation.
+ * Copyright 2017-2020 ZTE Corporation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,98 +15,73 @@
*/
package org.onap.holmes.dsa.dmaappolling;
-import com.alibaba.fastjson.JSON;
-import com.alibaba.fastjson.JSONArray;
-import com.alibaba.fastjson.JSONObject;
+import com.google.gson.JsonObject;
+import com.google.gson.JsonParser;
import org.jvnet.hk2.annotations.Service;
import org.onap.holmes.common.api.stat.AlarmAdditionalField;
import org.onap.holmes.common.api.stat.VesAlarm;
-import java.io.IOException;
-import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
+import static org.onap.holmes.common.utils.GsonUtil.*;
+
@Service
public class DMaaPResponseUtil {
- public VesAlarm convertJsonToVesAlarm(String responseJson) throws IOException {
- JSONObject jsonNode = JSON.parseObject(responseJson);
+ public VesAlarm convertJsonToVesAlarm(String responseJson) {
+ JsonObject jsonNode = JsonParser.parseString(responseJson).getAsJsonObject();
VesAlarm vesAlarm = new VesAlarm();
- JSONObject eventJson = JSON.parseObject(jsonNode.get("event") +"");
- JSONObject commonEventHeaderJson = JSON.parseObject(eventJson.get("commonEventHeader") +"");
+ JsonObject eventJson = JsonParser.parseString(jsonNode.get("event").toString()).getAsJsonObject();
+ JsonObject commonEventHeaderJson = JsonParser.parseString(eventJson.get("commonEventHeader").toString())
+ .getAsJsonObject();
convertCommonEventHeaderJsonToEvent(commonEventHeaderJson, vesAlarm);
- JSONObject faultFieldsJson = JSON.parseObject(eventJson.get("faultFields") +"");
+ JsonObject faultFieldsJson = JsonParser.parseString(eventJson.get("faultFields").toString())
+ .getAsJsonObject();
convertFaultFieldsJsonToEvent(faultFieldsJson, vesAlarm);
return vesAlarm;
}
- private void convertCommonEventHeaderJsonToEvent(JSONObject commonEventHeaderJson,
+ private void convertCommonEventHeaderJsonToEvent(JsonObject commonEventHeaderJson,
VesAlarm vesAlarm) {
- vesAlarm.setDomain((String) commonEventHeaderJson.get("domain"));
- vesAlarm.setEventId((String) commonEventHeaderJson.get("eventId"));
- vesAlarm.setEventName((String) commonEventHeaderJson.get("eventName"));
+ vesAlarm.setDomain(getAsString(commonEventHeaderJson, "domain"));
+ vesAlarm.setEventId(getAsString(commonEventHeaderJson, "eventId"));
+ vesAlarm.setEventName(getAsString(commonEventHeaderJson, "eventName"));
vesAlarm.setAlarmIsCleared(vesAlarm.getEventName().endsWith("Cleared") ? 1 : 0);
- vesAlarm.setEventType(getTextElementByNode(commonEventHeaderJson, "eventType"));
- vesAlarm.setInternalHeaderFields(
- getTextElementByNode(commonEventHeaderJson, "internalHeaderFields"));
- vesAlarm.setLastEpochMicrosec(commonEventHeaderJson.getLong("lastEpochMicrosec"));
- vesAlarm.setNfcNamingCode(getTextElementByNode(commonEventHeaderJson, "nfcNamingCode"));
- vesAlarm.setNfNamingCode(getTextElementByNode(commonEventHeaderJson, "nfNamingCode"));
- vesAlarm.setPriority((String) commonEventHeaderJson.get("priority"));
- vesAlarm.setReportingEntityId(
- getTextElementByNode(commonEventHeaderJson, "reportingEntityId"));
- vesAlarm.setReportingEntityName( (String) commonEventHeaderJson.get("reportingEntityName"));
- vesAlarm.setSequence((Integer) commonEventHeaderJson.get("sequence"));
- vesAlarm.setSourceId(getTextElementByNode(commonEventHeaderJson, "sourceId"));
- vesAlarm.setSourceName( (String) commonEventHeaderJson.get("sourceName"));
- vesAlarm.setStartEpochMicrosec(commonEventHeaderJson.getLong("startEpochMicrosec"));
- vesAlarm.setVersion(commonEventHeaderJson.getLong("version"));
+ vesAlarm.setEventType(getAsString(commonEventHeaderJson, "eventType"));
+ vesAlarm.setInternalHeaderFields(getAsString(commonEventHeaderJson, "internalHeaderFields"));
+ vesAlarm.setLastEpochMicrosec(getAsLong(commonEventHeaderJson, "lastEpochMicrosec"));
+ vesAlarm.setNfcNamingCode(getAsString(commonEventHeaderJson, "nfcNamingCode"));
+ vesAlarm.setNfNamingCode(getAsString(commonEventHeaderJson, "nfNamingCode"));
+ vesAlarm.setPriority(getAsString(commonEventHeaderJson, "priority"));
+ vesAlarm.setReportingEntityId(getAsString(commonEventHeaderJson, "reportingEntityId"));
+ vesAlarm.setReportingEntityName(getAsString(commonEventHeaderJson, "reportingEntityName"));
+ vesAlarm.setSequence(getAsInt(commonEventHeaderJson, "sequence"));
+ vesAlarm.setSourceId(getAsString(commonEventHeaderJson, "sourceId"));
+ vesAlarm.setSourceName(getAsString(commonEventHeaderJson, "sourceName"));
+ vesAlarm.setStartEpochMicrosec(getAsLong(commonEventHeaderJson, "startEpochMicrosec"));
+ vesAlarm.setVersion(getAsLong(commonEventHeaderJson, "version"));
}
- private void convertFaultFieldsJsonToEvent(JSONObject faultFieldsJson, VesAlarm vesAlarm) {
+ private void convertFaultFieldsJsonToEvent(JsonObject faultFieldsJson, VesAlarm vesAlarm) {
vesAlarm.setAlarmAdditionalInformation(getListElementByNode(faultFieldsJson, "alarmAdditionalInformation"));
- vesAlarm.setAlarmCondition(faultFieldsJson.getString("alarmCondition"));
- vesAlarm.setAlarmInterfaceA(getTextElementByNode(faultFieldsJson, "alarmInterfaceA"));
- vesAlarm.setEventCategory(getTextElementByNode(faultFieldsJson,"eventCategory"));
- vesAlarm.setEventSeverity(faultFieldsJson.getString("eventSeverity"));
- vesAlarm.setEventSourceType(faultFieldsJson.getString("eventSourceType"));
- vesAlarm.setFaultFieldsVersion(faultFieldsJson.getLong("faultFieldsVersion"));
- vesAlarm.setSpecificProblem(faultFieldsJson.getString("specificProblem"));
- vesAlarm.setVfStatus(faultFieldsJson.getString("vfStatus"));
- }
-
- private String getTextElementByNode(JSONObject jsonNode,String name){
- if(jsonNode.get(name) != null){
- return jsonNode.getString(name);
- }
- return null;
- }
-
- private Long getLongElementByNode(JSONObject jsonNode, String name) {
- if(jsonNode.get(name) != null){
- return jsonNode.getLong(name);
- }
- return null;
+ vesAlarm.setAlarmCondition(getAsString(faultFieldsJson, "alarmCondition"));
+ vesAlarm.setAlarmInterfaceA(getAsString(faultFieldsJson, "alarmInterfaceA"));
+ vesAlarm.setEventCategory(getAsString(faultFieldsJson, "eventCategory"));
+ vesAlarm.setEventSeverity(getAsString(faultFieldsJson, "eventSeverity"));
+ vesAlarm.setEventSourceType(getAsString(faultFieldsJson, "eventSourceType"));
+ vesAlarm.setFaultFieldsVersion(getAsLong(faultFieldsJson, "faultFieldsVersion"));
+ vesAlarm.setSpecificProblem(getAsString(faultFieldsJson, "specificProblem"));
+ vesAlarm.setVfStatus(getAsString(faultFieldsJson, "vfStatus"));
}
- private List<AlarmAdditionalField> getListElementByNode(JSONObject jsonNode, String name){
- List<AlarmAdditionalField> alarms = new ArrayList<AlarmAdditionalField>();
- if (jsonNode.get(name) != null) {
- JSONArray alarmAdditionalInformations = jsonNode.getJSONArray(name);
- for (int i = 0; i < alarmAdditionalInformations.size(); i++) {
- JSONObject jsonObject = alarmAdditionalInformations.getJSONObject(i);
- if (jsonObject.get("name") != null
- && jsonObject.get("value") != null) {
- AlarmAdditionalField field = new AlarmAdditionalField();
- field.setName(getTextElementByNode(jsonObject, "name"));
- field.setValue(getTextElementByNode(jsonObject, "value"));
- alarms.add(field);
- }
- }
+ private List<AlarmAdditionalField> getListElementByNode(JsonObject jsonNode, String name) {
+ if (jsonNode.has(name) && !jsonNode.get(name).isJsonNull()) {
+ return jsonToList(jsonNode.get(name).toString(), AlarmAdditionalField.class);
}
- return alarms;
+ return Collections.emptyList();
}
}
diff --git a/engine-d/src/main/java/org/onap/holmes/engine/EngineDActiveApp.java b/engine-d/src/main/java/org/onap/holmes/engine/EngineDActiveApp.java
index 9417242..49627fa 100644
--- a/engine-d/src/main/java/org/onap/holmes/engine/EngineDActiveApp.java
+++ b/engine-d/src/main/java/org/onap/holmes/engine/EngineDActiveApp.java
@@ -24,7 +24,6 @@ import org.onap.holmes.common.utils.HttpsUtils;
import org.onap.holmes.common.utils.MSBRegisterUtil;
import org.onap.holmes.common.utils.transactionid.TransactionIdFilter;
import org.onap.holmes.engine.dcae.DcaeConfigurationPolling;
-import org.onap.holmes.engine.resources.EngineResources;
import org.onap.msb.sdk.discovery.entity.MicroServiceInfo;
import org.onap.msb.sdk.discovery.entity.Node;
@@ -47,7 +46,6 @@ public class EngineDActiveApp extends IOCApplication<EngineDAppConfig> {
public void run(EngineDAppConfig configuration, Environment environment) throws Exception {
super.run(configuration, environment);
- environment.jersey().register(new EngineResources());
try {
new MSBRegisterUtil().register2Msb(createMicroServiceInfo());
} catch (CorrelationException e) {
diff --git a/engine-d/src/main/java/org/onap/holmes/engine/manager/DroolsEngine.java b/engine-d/src/main/java/org/onap/holmes/engine/manager/DroolsEngine.java
index f26a03d..6808e98 100644
--- a/engine-d/src/main/java/org/onap/holmes/engine/manager/DroolsEngine.java
+++ b/engine-d/src/main/java/org/onap/holmes/engine/manager/DroolsEngine.java
@@ -26,16 +26,14 @@ import org.kie.api.builder.model.KieBaseModel;
import org.kie.api.builder.model.KieModuleModel;
import org.kie.api.builder.model.KieSessionModel;
import org.kie.api.conf.EqualityBehaviorOption;
-import org.kie.api.conf.EventProcessingOption;
import org.kie.api.io.Resource;
import org.kie.api.runtime.KieContainer;
import org.kie.api.runtime.KieSession;
-import org.kie.api.runtime.conf.ClockTypeOption;
import org.kie.api.runtime.rule.FactHandle;
import org.onap.holmes.common.api.entity.AlarmInfo;
import org.onap.holmes.common.api.entity.CorrelationRule;
import org.onap.holmes.common.api.stat.VesAlarm;
-import org.onap.holmes.common.dmaap.DmaapService;
+import org.onap.holmes.common.dmaap.store.ClosedLoopControlNameCache;
import org.onap.holmes.common.exception.AlarmInfoException;
import org.onap.holmes.common.exception.CorrelationException;
import org.onap.holmes.common.utils.DbDaoUtil;
@@ -56,20 +54,33 @@ import java.util.stream.Collectors;
@Service
public class DroolsEngine {
- @Inject
+ private final static int ENABLE = 1;
+ private final Map<String, String> deployed = new ConcurrentHashMap<>();
private RuleMgtWrapper ruleMgtWrapper;
- @Inject
private DbDaoUtil daoUtil;
-
- private final static int ENABLE = 1;
+ private ClosedLoopControlNameCache closedLoopControlNameCache;
private AlarmInfoDao alarmInfoDao;
- private final Map<String, String> deployed = new ConcurrentHashMap<>();
private KieServices ks = KieServices.Factory.get();
private ReleaseId releaseId = ks.newReleaseId("org.onap.holmes", "rules", "1.0.0-SNAPSHOT");
private ReleaseId compilationRelease = ks.newReleaseId("org.onap.holmes", "compilation", "1.0.0-SNAPSHOT");
private KieContainer container;
private KieSession session;
+ @Inject
+ public void setRuleMgtWrapper(RuleMgtWrapper ruleMgtWrapper) {
+ this.ruleMgtWrapper = ruleMgtWrapper;
+ }
+
+ @Inject
+ public void setDaoUtil(DbDaoUtil daoUtil) {
+ this.daoUtil = daoUtil;
+ }
+
+ @Inject
+ public void setClosedLoopControlNameCache(ClosedLoopControlNameCache closedLoopControlNameCache) {
+ this.closedLoopControlNameCache = closedLoopControlNameCache;
+ }
+
@PostConstruct
private void init() {
alarmInfoDao = daoUtil.getJdbiDaoByOnDemand(AlarmInfoDao.class);
@@ -120,7 +131,7 @@ public class DroolsEngine {
for (CorrelationRule rule : rules) {
if (!StringUtils.isEmpty(rule.getContent())) {
deployRule(rule.getContent());
- DmaapService.loopControlNames.put(rule.getPackageName(), rule.getClosedControlLoopName());
+ closedLoopControlNameCache.put(rule.getPackageName(), rule.getClosedControlLoopName());
}
}
diff --git a/engine-d/src/main/java/org/onap/holmes/engine/resources/EngineResources.java b/engine-d/src/main/java/org/onap/holmes/engine/resources/EngineResources.java
index 3bfb2e8..0aa3a59 100644
--- a/engine-d/src/main/java/org/onap/holmes/engine/resources/EngineResources.java
+++ b/engine-d/src/main/java/org/onap/holmes/engine/resources/EngineResources.java
@@ -20,23 +20,9 @@ import com.codahale.metrics.annotation.Timed;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
-import java.util.Locale;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-import javax.inject.Inject;
-import javax.servlet.http.HttpServletRequest;
-import javax.ws.rs.DELETE;
-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.core.Context;
-import javax.ws.rs.core.MediaType;
import lombok.extern.slf4j.Slf4j;
import org.jvnet.hk2.annotations.Service;
-import org.onap.holmes.common.dmaap.DmaapService;
+import org.onap.holmes.common.dmaap.store.ClosedLoopControlNameCache;
import org.onap.holmes.common.exception.CorrelationException;
import org.onap.holmes.common.utils.ExceptionUtil;
import org.onap.holmes.common.utils.LanguageUtil;
@@ -45,16 +31,30 @@ import org.onap.holmes.engine.request.CompileRuleRequest;
import org.onap.holmes.engine.request.DeployRuleRequest;
import org.onap.holmes.engine.response.CorrelationRuleResponse;
+import javax.inject.Inject;
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.*;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import java.util.Locale;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
@Service
@Path("/rule")
@Api(tags = {"Holmes Engine Management"})
@Produces(MediaType.APPLICATION_JSON)
@Slf4j
public class EngineResources {
- private Pattern packagePattern = Pattern.compile("package[\\s]+([^;]+)[;\\s]*");
-
@Inject
DroolsEngine droolsEngine;
+ private Pattern packagePattern = Pattern.compile("package[\\s]+([^;]+)[;\\s]*");
+ private ClosedLoopControlNameCache closedLoopControlNameCache;
+
+ @Inject
+ public void setClosedLoopControlNameCache(ClosedLoopControlNameCache closedLoopControlNameCache) {
+ this.closedLoopControlNameCache = closedLoopControlNameCache;
+ }
@PUT
@Produces(MediaType.APPLICATION_JSON)
@@ -74,13 +74,13 @@ public class EngineResources {
throw new CorrelationException("Could not find package name in rule: "+deployRuleRequest.getContent());
}
- DmaapService.loopControlNames
+ closedLoopControlNameCache
.put(packageName, deployRuleRequest.getLoopControlName());
String packageNameRet = droolsEngine.deployRule(deployRuleRequest);
if (!packageName.equals(packageNameRet)) {
log.info("The parsed package name is different from that returned by the engine.");
- DmaapService.loopControlNames.remove(packageName);
- DmaapService.loopControlNames
+ closedLoopControlNameCache.remove(packageName);
+ closedLoopControlNameCache
.put(packageNameRet, deployRuleRequest.getLoopControlName());
}
log.info("Rule deployed. Package name: " + packageNameRet);
@@ -108,7 +108,7 @@ public class EngineResources {
try {
droolsEngine.undeployRule(packageName);
- DmaapService.loopControlNames.remove(packageName);
+ closedLoopControlNameCache.remove(packageName);
} catch (CorrelationException correlationException) {
log.error(correlationException.getMessage(), correlationException);
throw ExceptionUtil.buildExceptionResponse(correlationException.getMessage());
diff --git a/engine-d/src/main/java/org/onap/holmes/engine/utils/AlarmUtil.java b/engine-d/src/main/java/org/onap/holmes/engine/utils/AlarmUtil.java
index ca93066..c7eb02b 100644
--- a/engine-d/src/main/java/org/onap/holmes/engine/utils/AlarmUtil.java
+++ b/engine-d/src/main/java/org/onap/holmes/engine/utils/AlarmUtil.java
@@ -19,7 +19,6 @@ import java.util.HashMap;
import java.util.Map;
import org.jvnet.hk2.annotations.Service;
import org.onap.holmes.common.api.stat.Alarm;
-import org.onap.holmes.common.producer.MQProducer;
@Service
public class AlarmUtil {
@@ -91,9 +90,4 @@ public class AlarmUtil {
rootPriorityMap.put(ruleId, map);
}
-
- public MQProducer getMqProducer() {
- MQProducer mqProducer = new MQProducer();
- return mqProducer;
- }
}