aboutsummaryrefslogtreecommitdiffstats
path: root/sdnr/wt/websocketmanager/provider/src
diff options
context:
space:
mode:
authorRavi Pendurty <ravi.pendurty@highstreet-technologies.com>2021-08-02 10:42:37 +0530
committerRavi Pendurty <ravi.pendurty@highstreet-technologies.com>2021-08-02 11:30:40 +0530
commit191ddbe36e3ff1bbc6e9e104a8d3626f70d49ac4 (patch)
tree7910c13eab225c9650a692c30d96c75ca45463ee /sdnr/wt/websocketmanager/provider/src
parent0b829aa95b44134cd0b5574d32d8275fdb6b2c55 (diff)
Update websocketmanager's NotificationOutput interface
Use new NotificationOutput interface Issue-ID: CCSDK-3407 Signed-off-by: Ravi Pendurty <ravi.pendurty@highstreet-technologies.com> Change-Id: Ie6c6acfe1a86c76f7ede50cdce85b4a1b99d63d1 Signed-off-by: Ravi Pendurty <ravi.pendurty@highstreet-technologies.com>
Diffstat (limited to 'sdnr/wt/websocketmanager/provider/src')
-rw-r--r--sdnr/wt/websocketmanager/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/websocketmanager/WebSocketManagerProvider.java32
-rw-r--r--sdnr/wt/websocketmanager/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/websocketmanager/WebSocketManagerSocket.java11
-rw-r--r--sdnr/wt/websocketmanager/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/websocketmanager2/test/TestSerializer.java59
3 files changed, 84 insertions, 18 deletions
diff --git a/sdnr/wt/websocketmanager/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/websocketmanager/WebSocketManagerProvider.java b/sdnr/wt/websocketmanager/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/websocketmanager/WebSocketManagerProvider.java
index 610001775..8af5cb1ee 100644
--- a/sdnr/wt/websocketmanager/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/websocketmanager/WebSocketManagerProvider.java
+++ b/sdnr/wt/websocketmanager/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/websocketmanager/WebSocketManagerProvider.java
@@ -20,6 +20,7 @@ package org.onap.ccsdk.features.sdnr.wt.websocketmanager;
import java.time.Instant;
import javax.servlet.ServletException;
import org.onap.ccsdk.features.sdnr.wt.websocketmanager.model.WebsocketManagerService;
+import org.onap.ccsdk.features.sdnr.wt.websocketmanager.model.data.DOMNotificationOutput;
import org.onap.ccsdk.features.sdnr.wt.websocketmanager.model.data.NotificationOutput;
import org.onap.ccsdk.features.sdnr.wt.yang.mapper.YangToolsMapperHelper;
import org.opendaylight.mdsal.dom.api.DOMNotification;
@@ -83,31 +84,30 @@ public class WebSocketManagerProvider implements WebsocketManagerService, AutoCl
this.wsServlet = wsServlet;
}
-
- @Override
- public void sendNotification(Notification notification, NodeId nodeId, QName eventType) {
- if(!assertNotificationType(notification, eventType)){
- return;
- }
- this.sendNotification(notification, nodeId, eventType, YangToolsMapperHelper.getTime(notification,Instant.now()));
- }
-
public static boolean assertNotificationType(Notification notification, QName eventType) {
final String yangTypeName = eventType.getLocalName();
final Class<?> cls = notification.getClass();
final String clsNameToTest = YangToolsMapperHelper.toCamelCaseClassName(yangTypeName);
- if(cls.getSimpleName().equals(clsNameToTest)) {
+ if (cls.getSimpleName().equals(clsNameToTest)) {
return true;
}
Class<?>[] ifs = cls.getInterfaces();
- for(Class<?> clsif:ifs) {
- if(clsif.getSimpleName().equals(clsNameToTest)) {
+ for (Class<?> clsif : ifs) {
+ if (clsif.getSimpleName().equals(clsNameToTest)) {
return true;
}
}
return false;
}
+ @Override
+ public void sendNotification(Notification notification, NodeId nodeId, QName eventType) {
+ if (!assertNotificationType(notification, eventType)) {
+ return;
+ }
+ this.sendNotification(notification, nodeId, eventType,
+ YangToolsMapperHelper.getTime(notification, Instant.now()));
+ }
@Override
public void sendNotification(Notification notification, NodeId nodeId, QName eventType, DateAndTime eventTime) {
@@ -117,14 +117,14 @@ public class WebSocketManagerProvider implements WebsocketManagerService, AutoCl
@Override
public void sendNotification(DOMNotification notification, NodeId nodeId, QName eventType) {
- LOG.warn("not yet implemented");
-
+ WebSocketManagerSocket.broadCast(new DOMNotificationOutput(notification, nodeId.getValue(), eventType,
+ YangToolsMapperHelper.getTime(notification, Instant.now())));
}
@Override
public void sendNotification(DOMNotification notification, NodeId nodeId, QName eventType, DateAndTime eventTime) {
- LOG.warn("not yet implemented");
-
+ WebSocketManagerSocket
+ .broadCast(new DOMNotificationOutput(notification, nodeId.getValue(), eventType, eventTime));
}
}
diff --git a/sdnr/wt/websocketmanager/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/websocketmanager/WebSocketManagerSocket.java b/sdnr/wt/websocketmanager/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/websocketmanager/WebSocketManagerSocket.java
index a642bda69..7c12c4baa 100644
--- a/sdnr/wt/websocketmanager/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/websocketmanager/WebSocketManagerSocket.java
+++ b/sdnr/wt/websocketmanager/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/websocketmanager/WebSocketManagerSocket.java
@@ -33,6 +33,8 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.eclipse.jetty.websocket.api.Session;
import org.eclipse.jetty.websocket.api.WebSocketAdapter;
+import org.onap.ccsdk.features.sdnr.wt.websocketmanager.model.data.DOMNotificationOutput;
+import org.onap.ccsdk.features.sdnr.wt.websocketmanager.model.data.INotificationOutput;
import org.onap.ccsdk.features.sdnr.wt.websocketmanager.model.data.NotificationOutput;
import org.onap.ccsdk.features.sdnr.wt.websocketmanager.model.data.ReducedSchemaInfo;
import org.onap.ccsdk.features.sdnr.wt.websocketmanager.model.data.ScopeRegistration;
@@ -247,7 +249,7 @@ public class WebSocketManagerSocket extends WebSocketAdapter {
return this.myUniqueSessionId;
}
- private void sendToAll(NotificationOutput output) {
+ private void sendToAll(INotificationOutput output) {
try {
sendToAll(output.getNodeId(), output.getType(), mapper.writeValueAsString(output));
} catch (JsonProcessingException e) {
@@ -281,7 +283,7 @@ public class WebSocketManagerSocket extends WebSocketAdapter {
}
}
- public static void broadCast(NotificationOutput output) {
+ public static void broadCast(INotificationOutput output) {
if (clientList.size() > 0) {
Set<Entry<String, WebSocketManagerSocket>> e = clientList.entrySet();
WebSocketManagerSocket s = e.iterator().next().getValue();
@@ -291,4 +293,9 @@ public class WebSocketManagerSocket extends WebSocketAdapter {
}
}
+ public static void broadCast(DOMNotificationOutput domNotificationOutput) {
+ // TODO Auto-generated method stub
+
+ }
+
}
diff --git a/sdnr/wt/websocketmanager/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/websocketmanager2/test/TestSerializer.java b/sdnr/wt/websocketmanager/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/websocketmanager2/test/TestSerializer.java
new file mode 100644
index 000000000..962838489
--- /dev/null
+++ b/sdnr/wt/websocketmanager/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/websocketmanager2/test/TestSerializer.java
@@ -0,0 +1,59 @@
+/*
+ * ============LICENSE_START=======================================================
+ * ONAP : ccsdk features
+ * ================================================================================
+ * Copyright (C) 2021 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.websocketmanager2.test;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import org.junit.Test;
+import org.onap.ccsdk.features.sdnr.wt.websocketmanager.model.data.NotificationOutput;
+import org.onap.ccsdk.features.sdnr.wt.yang.mapper.YangToolsMapper;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DateAndTime;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.devicemanager.rev190109.ObjectCreationNotification;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.devicemanager.rev190109.ObjectCreationNotificationBuilder;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class TestSerializer {
+
+ private static final Logger LOG = LoggerFactory.getLogger(TestSerializer.class);
+ private static final YangToolsMapper mapper = new YangToolsMapper();
+ private static final String TIMESTAMP = "2020-04-01T10:20:40.0Z";
+ private static final String NODEID = "node1";
+
+ @Test
+ public void test1() {
+ ObjectCreationNotification notification = new ObjectCreationNotificationBuilder().setCounter(Integer.valueOf(5)).build();
+ NotificationOutput output = new NotificationOutput(notification, NODEID, ObjectCreationNotification.QNAME,DateAndTime.getDefaultInstance(TIMESTAMP));
+ String sOutput=null;
+ try {
+ sOutput = mapper.writeValueAsString(output);
+ LOG.debug(sOutput);
+ } catch (JsonProcessingException e) {
+ e.printStackTrace();
+ fail(e.getMessage());
+ }
+ assertNotNull(sOutput);
+ assertTrue(sOutput.contains("\"type\""));
+ }
+}