diff options
Diffstat (limited to 'sdnr/wt/mountpoint-state-provider/provider')
9 files changed, 94 insertions, 59 deletions
diff --git a/sdnr/wt/mountpoint-state-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointstateprovider/impl/Constants.java b/sdnr/wt/mountpoint-state-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointstateprovider/impl/Constants.java new file mode 100644 index 000000000..12dd160de --- /dev/null +++ b/sdnr/wt/mountpoint-state-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointstateprovider/impl/Constants.java @@ -0,0 +1,35 @@ +/* + * ============LICENSE_START======================================================= + * ONAP : ccsdk features + * ================================================================================ + * Copyright (C) 2020 highstreet technologies GmbH Intellectual Property. + * All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + */ +package org.onap.ccsdk.features.sdnr.wt.mountpointstateprovider.impl; + +public class Constants { + + public static final String NODEID = "NodeId"; + public static final String NETCONFNODESTATE = "NetConfNodeState"; + public static final String TIMESTAMP = "TimeStamp"; + + public static final String VES_DOMAIN = "notification"; + public static final String VES_PRIORITY = "Normal"; + public static final String VES_CHANGETYPE = "ConnectionState"; + + +} diff --git a/sdnr/wt/mountpoint-state-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointstateprovider/impl/MountpointNodeConnectListenerImpl.java b/sdnr/wt/mountpoint-state-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointstateprovider/impl/MountpointNodeConnectListenerImpl.java index 5cdf5abc6..466d4f4ef 100644 --- a/sdnr/wt/mountpoint-state-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointstateprovider/impl/MountpointNodeConnectListenerImpl.java +++ b/sdnr/wt/mountpoint-state-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointstateprovider/impl/MountpointNodeConnectListenerImpl.java @@ -51,13 +51,13 @@ public class MountpointNodeConnectListenerImpl implements NetconfNodeConnectList NodeId nNodeId = accessor.getNodeId(); NetconfNode netconfNode = accessor.getNetconfNode(); - LOG.debug("In onEnterConnected of MountpointNodeConnectListenerImpl - nNodeId = " + nNodeId.getValue() - + " IP Address = " + netconfNode.getHost().getIpAddress().getIpv4Address().getValue()); + LOG.debug("In onEnterConnected of MountpointNodeConnectListenerImpl - nNodeId = {}, IP Address = {}",nNodeId.getValue() + ,netconfNode.getHost().getIpAddress().getIpv4Address().getValue()); JSONObject obj = new JSONObject(); - obj.put("NodeId", nNodeId.getValue()); - obj.put("NetConfNodeState", netconfNode.getConnectionStatus().toString()); - obj.put("TimeStamp", java.time.Clock.systemUTC().instant()); + obj.put(Constants.NODEID, nNodeId.getValue()); + obj.put(Constants.NETCONFNODESTATE, netconfNode.getConnectionStatus().toString()); + obj.put(Constants.TIMESTAMP, java.time.Clock.systemUTC().instant()); mountpointStatePublisher.addToPublish(obj); } @@ -65,12 +65,12 @@ public class MountpointNodeConnectListenerImpl implements NetconfNodeConnectList @Override public void onLeaveConnected(NodeId nNodeId, Optional<NetconfNode> optionalNetconfNode) { - LOG.debug("In onLeaveConnected of MountpointNodeConnectListenerImpl - nNodeId = " + nNodeId); + LOG.debug("In onLeaveConnected of MountpointNodeConnectListenerImpl - nNodeId = {}",nNodeId); JSONObject obj = new JSONObject(); - obj.put("NodeId", nNodeId.getValue()); - obj.put("NetConfNodeState", "Unmounted"); - obj.put("TimeStamp", java.time.Clock.systemUTC().instant()); + obj.put(Constants.NODEID, nNodeId.getValue()); + obj.put(Constants.NETCONFNODESTATE, "Unmounted"); + obj.put(Constants.TIMESTAMP, java.time.Clock.systemUTC().instant()); mountpointStatePublisher.addToPublish(obj); } diff --git a/sdnr/wt/mountpoint-state-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointstateprovider/impl/MountpointNodeStateListenerImpl.java b/sdnr/wt/mountpoint-state-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointstateprovider/impl/MountpointNodeStateListenerImpl.java index d8b5a85de..46b17eb15 100644 --- a/sdnr/wt/mountpoint-state-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointstateprovider/impl/MountpointNodeStateListenerImpl.java +++ b/sdnr/wt/mountpoint-state-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointstateprovider/impl/MountpointNodeStateListenerImpl.java @@ -46,12 +46,12 @@ public class MountpointNodeStateListenerImpl implements NetconfNodeStateListener @Override public void onCreated(NodeId nNodeId, NetconfNode netconfNode) { - LOG.info("In onCreated of MountpointNodeStateListenerImpl - nNodeId = " + nNodeId.getValue() + " IP Address = " - + netconfNode.getHost().getIpAddress().getIpv4Address().toString()); + LOG.info("In onCreated of MountpointNodeStateListenerImpl - nNodeId = {}, IP Address = {}",nNodeId.getValue(), + netconfNode.getHost().getIpAddress().getIpv4Address().toString()); JSONObject obj = new JSONObject(); - obj.put("NodeId", nNodeId.getValue()); - obj.put("NetConfNodeState", netconfNode.getConnectionStatus().toString()); - obj.put("TimeStamp", java.time.Clock.systemUTC().instant()); + obj.put(Constants.NODEID, nNodeId.getValue()); + obj.put(Constants.NETCONFNODESTATE, netconfNode.getConnectionStatus().toString()); + obj.put(Constants.TIMESTAMP, java.time.Clock.systemUTC().instant()); mountpointStatePublisher.addToPublish(obj); } @@ -59,12 +59,12 @@ public class MountpointNodeStateListenerImpl implements NetconfNodeStateListener @Override public void onStateChange(NodeId nNodeId, NetconfNode netconfNode) { - LOG.info("In onStateChange of MountpointNodeStateListenerImpl - nNodeId = " + nNodeId.getValue() - + " IP Address = " + netconfNode.getHost().getIpAddress().getIpv4Address().getValue()); + LOG.info("In onStateChange of MountpointNodeStateListenerImpl - nNodeId = {}, IP Address = {}",nNodeId.getValue(), + netconfNode.getHost().getIpAddress().getIpv4Address().getValue()); JSONObject obj = new JSONObject(); - obj.put("NodeId", nNodeId.getValue()); - obj.put("NetConfNodeState", netconfNode.getConnectionStatus().toString()); - obj.put("TimeStamp", java.time.Clock.systemUTC().instant()); + obj.put(Constants.NODEID, nNodeId.getValue()); + obj.put(Constants.NETCONFNODESTATE, netconfNode.getConnectionStatus().toString()); + obj.put(Constants.TIMESTAMP, java.time.Clock.systemUTC().instant()); mountpointStatePublisher.addToPublish(obj); } @@ -72,11 +72,11 @@ public class MountpointNodeStateListenerImpl implements NetconfNodeStateListener @Override public void onRemoved(NodeId nNodeId) { - LOG.info("In onRemoved of MountpointNodeStateListenerImpl - nNodeId = " + nNodeId); + LOG.info("In onRemoved of MountpointNodeStateListenerImpl - nNodeId = {}",nNodeId); JSONObject obj = new JSONObject(); - obj.put("NodeId", nNodeId.getValue()); - obj.put("NetConfNodeState", "Removed"); - obj.put("TimeStamp", java.time.Clock.systemUTC().instant()); + obj.put(Constants.NODEID, nNodeId.getValue()); + obj.put(Constants.NETCONFNODESTATE, "Removed"); + obj.put(Constants.TIMESTAMP, java.time.Clock.systemUTC().instant()); mountpointStatePublisher.addToPublish(obj); } 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 9df37e305..e05b3f1ba 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 @@ -35,7 +35,7 @@ import org.slf4j.LoggerFactory; public class MountpointStatePublisher implements Runnable { private static final Logger LOG = LoggerFactory.getLogger(MountpointStatePublisher.class); - private List<JSONObject> stateObjects = new LinkedList<JSONObject>(); + private List<JSONObject> stateObjects = new LinkedList<>(); private boolean publish = true; private int publishPause = 5000; // Default pause between fetch - 5 seconds private VESCollectorService vesCollectorService; @@ -68,15 +68,14 @@ public class MountpointStatePublisher implements Runnable { public String createVESMessage(JSONObject msg, VESCollectorCfgService vesCfg) { MountpointStateVESMessageFormatter vesFormatter = new MountpointStateVESMessageFormatter(vesCfg); - String vesMsg = vesFormatter.createVESMessage(msg); - return vesMsg; + return vesFormatter.createVESMessage(msg); } @Override public void run() { while (publish) { try { - if (getStateObjects().size() > 0) { + if (!getStateObjects().isEmpty()) { JSONObject obj = ((LinkedList<JSONObject>) getStateObjects()).removeFirst(); String vesMsg = createVESMessage(obj, vesCollectorService.getConfig()); this.vesCollectorService.publishVESMessage(vesMsg); 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 918438e55..4ab1a9a85 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 @@ -31,9 +31,6 @@ import org.slf4j.LoggerFactory; public class MountpointStateVESMessageFormatter { private static final Logger LOG = LoggerFactory.getLogger(MountpointStateVESMessageFormatter.class); - private static final String VES_DOMAIN = "notification"; - private static final String VES_PRIORITY = "Normal"; - private static final String VES_CHANGETYPE = "ConnectionState"; private VESCollectorCfgService vesCfg; static long sequenceNo = 0; @@ -42,10 +39,20 @@ public class MountpointStateVESMessageFormatter { this.vesCfg = vesCfg; } + private static void incrSequenceNo() { + sequenceNo++; + } + + private long getSequenceNo() { + return sequenceNo; + } + public String createVESMessage(JSONObject obj) { - LOG.debug("JSON Object to format to VES is - {}", obj.toString()); + if (LOG.isDebugEnabled()) { + LOG.debug("JSON Object to format to VES is - {0}", obj); + } String vesMsg = "{}"; - sequenceNo++; + MountpointStateVESMessageFormatter.incrSequenceNo(); VESCommonEventHeaderPOJO vesCommonEventHeader = createVESCommonEventHeader(obj); VESNotificationFieldsPOJO vesNotificationFields = createVESNotificationFields(obj); @@ -59,7 +66,7 @@ public class MountpointStateVESMessageFormatter { vesMsg = objMapper.writeValueAsString(vesEvent); LOG.debug("VES message to be published - {}", vesMsg); } catch (JsonProcessingException e) { - e.printStackTrace(); + LOG.warn("Exception {} while processing JSON Message - {}", e, obj); } return vesMsg; @@ -69,9 +76,9 @@ public class MountpointStateVESMessageFormatter { private VESNotificationFieldsPOJO createVESNotificationFields(JSONObject obj) { VESNotificationFieldsPOJO vesNotificationFields = new VESNotificationFieldsPOJO(); - vesNotificationFields.setChangeIdentifier(obj.getString("NodeId")); - vesNotificationFields.setChangeType(VES_CHANGETYPE); - vesNotificationFields.setNewState(obj.getString("NetConfNodeState")); + vesNotificationFields.setChangeIdentifier(obj.getString(Constants.NODEID)); + vesNotificationFields.setChangeType(Constants.VES_CHANGETYPE); + vesNotificationFields.setNewState(obj.getString(Constants.NETCONFNODESTATE)); return vesNotificationFields; } @@ -79,17 +86,17 @@ public class MountpointStateVESMessageFormatter { private VESCommonEventHeaderPOJO createVESCommonEventHeader(JSONObject obj) { VESCommonEventHeaderPOJO vesCommonEventHeader = new VESCommonEventHeaderPOJO(); - vesCommonEventHeader.setDomain(VES_DOMAIN); + vesCommonEventHeader.setDomain(Constants.VES_DOMAIN); vesCommonEventHeader - .setEventId(obj.getString("NodeId") + "_" + obj.getString("NetConfNodeState") + "_" + sequenceNo); + .setEventId(obj.getString(Constants.NODEID) + "_" + obj.getString(Constants.NETCONFNODESTATE) + "_" + getSequenceNo()); vesCommonEventHeader - .setEventName(obj.getString("NodeId") + "_" + obj.getString("NetConfNodeState") + "_" + sequenceNo); - vesCommonEventHeader.setSourceName(obj.getString("NodeId")); - vesCommonEventHeader.setPriority(VES_PRIORITY); + .setEventName(obj.getString(Constants.NODEID) + "_" + obj.getString(Constants.NETCONFNODESTATE) + "_" + getSequenceNo()); + vesCommonEventHeader.setSourceName(obj.getString(Constants.NODEID)); + vesCommonEventHeader.setPriority(Constants.VES_PRIORITY); vesCommonEventHeader.setReportingEntityName(this.vesCfg.getReportingEntityName()); - vesCommonEventHeader.setSequence(sequenceNo); + vesCommonEventHeader.setSequence(getSequenceNo()); - Instant time = (Instant) obj.get("TimeStamp"); + Instant time = (Instant) obj.get(Constants.TIMESTAMP); vesCommonEventHeader.setLastEpochMicrosec(time.toEpochMilli() * 100); vesCommonEventHeader.setStartEpochMicrosec(time.toEpochMilli() * 100); diff --git a/sdnr/wt/mountpoint-state-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointstateprovider/impl/VESEvent.java b/sdnr/wt/mountpoint-state-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointstateprovider/impl/VESEvent.java index 13017d46c..7989166f6 100644 --- a/sdnr/wt/mountpoint-state-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointstateprovider/impl/VESEvent.java +++ b/sdnr/wt/mountpoint-state-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointstateprovider/impl/VESEvent.java @@ -21,7 +21,7 @@ import java.util.HashMap; import java.util.Map; public class VESEvent { - public Map<String, Object> event = new HashMap<String, Object>(); + private Map<String, Object> event = new HashMap<>(); public void addEventObjects(Object eventObject) { if (eventObject instanceof VESCommonEventHeaderPOJO) diff --git a/sdnr/wt/mountpoint-state-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointstateprovider/impl/VESNotificationFieldsPOJO.java b/sdnr/wt/mountpoint-state-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointstateprovider/impl/VESNotificationFieldsPOJO.java index 1963cd6ca..1d2c2dcb5 100644 --- a/sdnr/wt/mountpoint-state-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointstateprovider/impl/VESNotificationFieldsPOJO.java +++ b/sdnr/wt/mountpoint-state-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointstateprovider/impl/VESNotificationFieldsPOJO.java @@ -21,15 +21,17 @@ import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonPropertyOrder; import java.util.ArrayList; import java.util.HashMap; +import java.util.List; +import java.util.Map; @JsonPropertyOrder({"arrayOfNamedHashMap", "changeContact", "changeIdentifier", "changeType", "newState", "oldState", "notificationFieldsVersion"}) public class VESNotificationFieldsPOJO { - private ArrayList<HashMap<String, Object>> arrayOfNamedHashMap = new ArrayList<HashMap<String, Object>>(); + private List<HashMap<String, Object>> arrayOfNamedHashMap = new ArrayList<>(); @JsonIgnore - private HashMap<String, Object> namedHashMap = new HashMap<String, Object>(); + private Map<String, Object> namedHashMap = new HashMap<>(); @JsonIgnore - private HashMap<String, String> hashMap = new HashMap<String, String>(); + private Map<String, String> hashMap = new HashMap<>(); @JsonIgnore private String changeContact = ""; private String changeIdentifier = ""; @@ -42,11 +44,11 @@ public class VESNotificationFieldsPOJO { private String stateInterface = ""; private String notificationFieldsVersion = "2.0"; - public ArrayList<HashMap<String, Object>> getArrayOfNamedHashMap() { + public List<HashMap<String, Object>> getArrayOfNamedHashMap() { return arrayOfNamedHashMap; } - public void setArrayOfNamedHashMap(ArrayList<HashMap<String, Object>> arrayOfNamedHashMap) { + public void setArrayOfNamedHashMap(List<HashMap<String, Object>> arrayOfNamedHashMap) { this.arrayOfNamedHashMap = arrayOfNamedHashMap; } diff --git a/sdnr/wt/mountpoint-state-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointstateprovider/test/TestMountpointNodeStateListenerImpl.java b/sdnr/wt/mountpoint-state-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointstateprovider/test/TestMountpointNodeStateListenerImpl.java index c6a9d11e5..60841ec69 100644 --- a/sdnr/wt/mountpoint-state-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointstateprovider/test/TestMountpointNodeStateListenerImpl.java +++ b/sdnr/wt/mountpoint-state-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointstateprovider/test/TestMountpointNodeStateListenerImpl.java @@ -74,6 +74,7 @@ public class TestMountpointNodeStateListenerImpl { @Test public void testOnRemoved() { nodeStateListener.onRemoved(nNodeId); + assertNotEquals(mountpointStatePublisher.getStateObjects().size(), 0); } } diff --git a/sdnr/wt/mountpoint-state-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointstateprovider/test/TestMountpointStateProviderImpl.java b/sdnr/wt/mountpoint-state-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointstateprovider/test/TestMountpointStateProviderImpl.java index 1cebeb697..4e4ac3064 100644 --- a/sdnr/wt/mountpoint-state-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointstateprovider/test/TestMountpointStateProviderImpl.java +++ b/sdnr/wt/mountpoint-state-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointstateprovider/test/TestMountpointStateProviderImpl.java @@ -42,7 +42,7 @@ public class TestMountpointStateProviderImpl { @Test - public void before() throws InterruptedException, IOException { + public void test() throws InterruptedException, IOException { NetconfNodeStateService netconfNodeStateService = mock(NetconfNodeStateService.class); DeviceManagerServiceProvider serviceProvider = mock(DeviceManagerServiceProvider.class); VESCollectorService vesCollectorService = mock(VESCollectorService.class); @@ -57,13 +57,4 @@ public class TestMountpointStateProviderImpl { mountpointStateProvider.init(); } - /* @After - public void after() throws InterruptedException, IOException { - - try { - mountpointStateProvider.close(); - } catch (Exception e) { - System.out.println(e); - } - }*/ } |