--- /dev/null
+/*
+ * ============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.websocketmanager.model.data;
+
+import org.opendaylight.mdsal.dom.api.DOMNotification;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DateAndTime;
+import org.opendaylight.yangtools.yang.common.QName;
+
+public class DOMNotificationOutput implements INotificationOutput{
+
+ private DateAndTime eventTime;
+ private DOMNotification data;
+ private String nodeId;
+ private ReducedSchemaInfo type;
+
+
+ public DOMNotificationOutput() {
+
+ }
+
+ @Override
+ public DateAndTime getEventTime() {
+ return eventTime;
+ }
+
+ public void setEventTime(DateAndTime eventTime) {
+ this.eventTime = eventTime;
+ }
+
+ public DOMNotification getData() {
+ return data;
+ }
+
+ @Override
+ public String getNodeId() {
+ return this.nodeId;
+ }
+
+ @Override
+ public ReducedSchemaInfo getType() {
+ return this.type;
+ }
+
+ public void setData(DOMNotification data) {
+ this.data = data;
+ }
+
+ public void setNodeId(String nodeId) {
+ this.nodeId = nodeId;
+ }
+
+ public void setType(ReducedSchemaInfo type) {
+ this.type = type;
+ }
+
+ public DOMNotificationOutput(DOMNotification notification, String nodeId, QName type, DateAndTime eventTime) {
+ this.data = notification;
+ this.nodeId = nodeId;
+ this.eventTime = eventTime;
+ this.type = new ReducedSchemaInfo(type);
+ }
+
+}
--- /dev/null
+/*
+ * ============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.websocketmanager.model.data;
+
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DateAndTime;
+
+public interface INotificationOutput {
+
+ public DateAndTime getEventTime();
+ public String getNodeId();
+ public ReducedSchemaInfo getType();
+}
import org.opendaylight.yangtools.yang.binding.Notification;
import org.opendaylight.yangtools.yang.common.QName;
-public class NotificationOutput {
+public class NotificationOutput implements INotificationOutput{
private DateAndTime eventTime;
private Notification data;
}
+ @Override
public DateAndTime getEventTime() {
return eventTime;
}
return data;
}
+ @Override
public String getNodeId() {
return this.nodeId;
}
+ @Override
public ReducedSchemaInfo getType() {
return this.type;
}
--- /dev/null
+module websocketmanager {
+
+ yang-version 1;
+ namespace "urn:opendaylight:params:xml:ns:yang:websocketmanager";
+ prefix websocketmanager;
+
+ import ietf-yang-types {
+ prefix yang;
+ }
+ organization
+ "highstreet technologies GmbH";
+ contact
+ "Web: <https://highstreet-technologies.com>
+ ONAP: <https://wiki.onap.org/display/DW/SDN-R+Websocketmanager+Upgrade>";
+
+ description
+ "Websocketmanager Api Module
+
+ Copyright 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.";
+
+ revision 2021-03-22 {
+ description
+ "Initial revision";
+ }
+
+ notification items-dropped-notification {
+ uses items-dropped-notification-g;
+ description "none";
+ }
+ grouping items-dropped-notification-g {
+ leaf amount {
+ type uint32;
+ default 0;
+ description "Counts of notifications that were dropped.";
+ }
+ description "To be sent when notifications were dropped in fact of a set ratio limit.";
+ }
+}
<properties>
<maven.javadoc.skip>true</maven.javadoc.skip>
</properties>
-
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
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;
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) {
@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));
}
}
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;
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) {
}
}
- 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();
}
}
+ public static void broadCast(DOMNotificationOutput domNotificationOutput) {
+ // TODO Auto-generated method stub
+
+ }
+
}
--- /dev/null
+/*
+ * ============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\""));
+ }
+}