diff options
Diffstat (limited to 'sdnr/wt/mountpoint-state-provider/provider/src')
3 files changed, 22 insertions, 18 deletions
diff --git a/sdnr/wt/mountpoint-state-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointstateprovider/impl/MountpointStatePublisher.java b/sdnr/wt/mountpoint-state-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointstateprovider/impl/MountpointStatePublisher.java index e05b3f1ba..e430a5e24 100644 --- a/sdnr/wt/mountpoint-state-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointstateprovider/impl/MountpointStatePublisher.java +++ b/sdnr/wt/mountpoint-state-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointstateprovider/impl/MountpointStatePublisher.java @@ -29,6 +29,7 @@ import org.eclipse.jdt.annotation.NonNull; import org.json.JSONObject; import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.VESCollectorCfgService; import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.VESCollectorService; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.VESMessage; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -66,8 +67,8 @@ public class MountpointStatePublisher implements Runnable { } - public String createVESMessage(JSONObject msg, VESCollectorCfgService vesCfg) { - MountpointStateVESMessageFormatter vesFormatter = new MountpointStateVESMessageFormatter(vesCfg); + public VESMessage createVESMessage(JSONObject msg, VESCollectorCfgService vesCfg) { + MountpointStateVESMessageFormatter vesFormatter = new MountpointStateVESMessageFormatter(vesCfg, vesCollectorService); return vesFormatter.createVESMessage(msg); } @@ -77,7 +78,7 @@ public class MountpointStatePublisher implements Runnable { try { if (!getStateObjects().isEmpty()) { JSONObject obj = ((LinkedList<JSONObject>) getStateObjects()).removeFirst(); - String vesMsg = createVESMessage(obj, vesCollectorService.getConfig()); + VESMessage vesMsg = createVESMessage(obj, vesCollectorService.getConfig()); this.vesCollectorService.publishVESMessage(vesMsg); } else { pauseThread(); diff --git a/sdnr/wt/mountpoint-state-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointstateprovider/impl/MountpointStateVESMessageFormatter.java b/sdnr/wt/mountpoint-state-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointstateprovider/impl/MountpointStateVESMessageFormatter.java index 4ab1a9a85..01a8d49ff 100644 --- a/sdnr/wt/mountpoint-state-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointstateprovider/impl/MountpointStateVESMessageFormatter.java +++ b/sdnr/wt/mountpoint-state-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointstateprovider/impl/MountpointStateVESMessageFormatter.java @@ -22,21 +22,27 @@ package org.onap.ccsdk.features.sdnr.wt.mountpointstateprovider.impl; import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; import java.time.Instant; +import org.eclipse.jdt.annotation.NonNull; import org.json.JSONObject; import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.VESCollectorCfgService; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.VESCollectorService; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.VESCommonEventHeaderPOJO; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.VESMessage; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.VESNotificationFieldsPOJO; import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class MountpointStateVESMessageFormatter { private static final Logger LOG = LoggerFactory.getLogger(MountpointStateVESMessageFormatter.class); - private VESCollectorCfgService vesCfg; + private final @NonNull VESCollectorCfgService vesCfg; + private final @NonNull VESCollectorService vesCollectorService; static long sequenceNo = 0; - public MountpointStateVESMessageFormatter(VESCollectorCfgService vesCfg) { + public MountpointStateVESMessageFormatter(VESCollectorCfgService vesCfg, VESCollectorService vesCollectorService) { this.vesCfg = vesCfg; + this.vesCollectorService = vesCollectorService; } private static void incrSequenceNo() { @@ -47,26 +53,22 @@ public class MountpointStateVESMessageFormatter { return sequenceNo; } - public String createVESMessage(JSONObject obj) { + public VESMessage createVESMessage(JSONObject obj) { if (LOG.isDebugEnabled()) { LOG.debug("JSON Object to format to VES is - {0}", obj); } - String vesMsg = "{}"; + MountpointStateVESMessageFormatter.incrSequenceNo(); VESCommonEventHeaderPOJO vesCommonEventHeader = createVESCommonEventHeader(obj); VESNotificationFieldsPOJO vesNotificationFields = createVESNotificationFields(obj); - VESEvent vesEvent = new VESEvent(); - vesEvent.addEventObjects(vesCommonEventHeader); - vesEvent.addEventObjects(vesNotificationFields); - + VESMessage vesMsg = null; try { - ObjectMapper objMapper = new ObjectMapper(); - vesMsg = objMapper.writeValueAsString(vesEvent); - LOG.debug("VES message to be published - {}", vesMsg); + vesMsg = vesCollectorService.generateVESEvent(vesCommonEventHeader, vesNotificationFields); + LOG.info("VES Message is - {}", vesMsg.getMessage()); } catch (JsonProcessingException e) { - LOG.warn("Exception {} while processing JSON Message - {}", e, obj); + LOG.error("Exception while generating VES Event - ", e); } return vesMsg; diff --git a/sdnr/wt/mountpoint-state-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointstateprovider/test/TestMountpointStatePublisher.java b/sdnr/wt/mountpoint-state-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointstateprovider/test/TestMountpointStatePublisher.java index 468e0c1ee..ebf4cb894 100644 --- a/sdnr/wt/mountpoint-state-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointstateprovider/test/TestMountpointStatePublisher.java +++ b/sdnr/wt/mountpoint-state-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointstateprovider/test/TestMountpointStatePublisher.java @@ -34,6 +34,7 @@ import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.DeviceManagerServic import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.NetconfNetworkElementService; import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.VESCollectorCfgService; import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.VESCollectorService; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.VESMessage; import org.onap.ccsdk.features.sdnr.wt.mountpointstateprovider.impl.MountpointStatePublisher; public class TestMountpointStatePublisher { @@ -41,7 +42,7 @@ public class TestMountpointStatePublisher { MountpointStatePublisher mountpointStatePublisher; VESCollectorService vesCollectorService; VESCollectorCfgService vesCfg; - String vesMsg = "{}"; + VESMessage vesMsg; JSONObject testJsonData; @Before @@ -64,7 +65,7 @@ public class TestMountpointStatePublisher { mountpointStatePublisher = new MountpointStatePublisher(vesCollectorService); mountpointStatePublisher.addToPublish(testJsonData); - //mountpointStatePublisher.getStateObjects().add(testJsonData); + mountpointStatePublisher.getStateObjects().add(testJsonData); } @Test |