2 * Copyright (c) 2016 Wipro Ltd. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.mwtn.devicemanager.impl.listener;
11 import java.util.List;
13 import javax.annotation.Nullable;
15 import org.opendaylight.mwtn.base.internalTypes.InternalDateAndTime;
16 import org.opendaylight.mwtn.base.internalTypes.InternalSeverity;
17 import org.opendaylight.mwtn.devicemanager.impl.ProviderClient;
18 import org.opendaylight.mwtn.devicemanager.impl.database.service.HtDatabaseEventsService;
19 import org.opendaylight.mwtn.devicemanager.impl.xml.AttributeValueChangedNotificationXml;
20 import org.opendaylight.mwtn.devicemanager.impl.xml.ObjectCreationNotificationXml;
21 import org.opendaylight.mwtn.devicemanager.impl.xml.ObjectDeletionNotificationXml;
22 import org.opendaylight.mwtn.devicemanager.impl.xml.ProblemNotificationXml;
23 import org.opendaylight.mwtn.devicemanager.impl.xml.WebSocketServiceClient;
24 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.microwave.model.rev170324.AttributeValueChangedNotification;
25 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.microwave.model.rev170324.MicrowaveModelListener;
26 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.microwave.model.rev170324.ObjectCreationNotification;
27 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.microwave.model.rev170324.ObjectDeletionNotification;
28 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.microwave.model.rev170324.ProblemNotification;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
33 * Important: Websocket notification must be the last action.
37 public class MicrowaveEventListener12 implements MicrowaveModelListener {
39 private static final Logger LOG = LoggerFactory.getLogger(MicrowaveEventListener12.class);
41 private final String nodeName;
42 private final WebSocketServiceClient webSocketService;
43 //private final WebsocketmanagerService websocketmanagerService;
44 //private final XmlMapper xmlMapper;
45 private final HtDatabaseEventsService databaseService;
46 private final ProviderClient dcaeProvider;
47 private final @Nullable ProviderClient aotsmClient;
49 public MicrowaveEventListener12(String nodeName, WebSocketServiceClient webSocketService,
50 HtDatabaseEventsService databaseService, ProviderClient dcaeProvider,@Nullable ProviderClient aotsmClient) {
52 this.nodeName = nodeName;
53 //this.websocketmanagerService = websocketmanagerService;
54 //this.xmlMapper = xmlMapper;
55 this.webSocketService = webSocketService;
56 this.databaseService = databaseService;
57 this.dcaeProvider = dcaeProvider;
58 this.aotsmClient = aotsmClient;
62 public void onAttributeValueChangedNotification(AttributeValueChangedNotification notification) {
63 LOG.debug("Got event of type :: {}", AttributeValueChangedNotification.class.getSimpleName());
65 AttributeValueChangedNotificationXml notificationXml = new AttributeValueChangedNotificationXml(nodeName,
66 String.valueOf(notification.getCounter()), InternalDateAndTime.valueOf(notification.getTimeStamp()),
67 notification.getObjectIdRef().getValue(), notification.getAttributeName(), notification.getNewValue());
69 WebsocketEventInputBuilder builder = new WebsocketEventInputBuilder();
70 builder.setNodeName(nodeName);
71 builder.setEventType(AttributeValueChangedNotification.class.getSimpleName());
72 builder.setXmlEvent(xmlMapper.getXmlString(notificationXml));
73 WebsocketEventInput event= builder.build();
74 websocketmanagerService.websocketEvent(event);
76 databaseService.writeEventLog(notificationXml);
78 webSocketService.sendViaWebsockets(nodeName, notificationXml);
82 public void onObjectCreationNotification(ObjectCreationNotification notification) {
83 LOG.debug("Got event of type :: {}", ObjectCreationNotification.class.getSimpleName());
85 //ObjectCreationNotificationXml notificationXml = new ObjectCreationNotificationXml(nodeName, notification);
86 ObjectCreationNotificationXml notificationXml = new ObjectCreationNotificationXml( nodeName,
87 notification.getCounter().toString(),
88 InternalDateAndTime.valueOf(notification.getTimeStamp()),
89 notification.getObjectIdRef().getValue());
91 WebsocketEventInputBuilder builder = new WebsocketEventInputBuilder();
92 builder.setNodeName(nodeName);
93 builder.setEventType(notificationXml.getEventType());
94 builder.setXmlEvent(xmlMapper.getXmlString(notificationXml));
95 websocketmanagerService.websocketEvent(builder.build());
97 databaseService.writeEventLog(notificationXml);
99 webSocketService.sendViaWebsockets(nodeName, notificationXml);
104 public void onObjectDeletionNotification(ObjectDeletionNotification notification) {
105 LOG.debug("Got event of type :: {}", ObjectDeletionNotification.class.getSimpleName());
107 //ObjectDeletionNotificationXml notificationXml = new ObjectDeletionNotificationXml(nodeName, notification);
108 ObjectDeletionNotificationXml notificationXml = new ObjectDeletionNotificationXml(nodeName,
109 notification.getCounter().toString(),
110 InternalDateAndTime.valueOf(notification.getTimeStamp()),
111 notification.getObjectIdRef().getValue()
114 WebsocketEventInputBuilder builder = new WebsocketEventInputBuilder();
115 builder.setNodeName(nodeName);
116 builder.setEventType(ObjectDeletionNotification.class.getSimpleName());
117 builder.setXmlEvent(xmlMapper.getXmlString(notificationXml));
118 websocketmanagerService.websocketEvent(builder.build());
120 databaseService.writeEventLog(notificationXml);
122 webSocketService.sendViaWebsockets(nodeName, notificationXml);
126 public void onProblemNotification(ProblemNotification notification) {
127 LOG.debug("Got event of type :: {}", ProblemNotification.class.getSimpleName());
129 ProblemNotificationXml notificationXml = new ProblemNotificationXml(nodeName, notification.getObjectIdRef().getValue(),
130 notification.getProblem(), InternalSeverity.valueOf(notification.getSeverity()),
131 notification.getCounter().toString(), InternalDateAndTime.valueOf(notification.getTimeStamp()));
133 WebsocketEventInputBuilder wsBuilder = new WebsocketEventInputBuilder();
134 wsBuilder.setNodeName(nodeName);
135 wsBuilder.setEventType(ProblemNotification.class.getSimpleName());
136 wsBuilder.setXmlEvent(xmlMapper.getXmlString(notificationXml));
137 websocketmanagerService.websocketEvent(wsBuilder.build());
140 databaseService.writeFaultLog(notificationXml);
141 databaseService.updateFaultCurrent(notificationXml);
143 dcaeProvider.sendProblemNotification(nodeName, notificationXml);
144 if(aotsmClient!=null)
145 aotsmClient.sendProblemNotification(nodeName, notificationXml);
147 webSocketService.sendViaWebsockets(nodeName, notificationXml);
151 private void initCurrentProblem(ProblemNotificationXml notificationXml) {
152 databaseService.updateFaultCurrent(notificationXml);
153 if(aotsmClient!=null)
154 aotsmClient.sendProblemNotification(this.nodeName, notificationXml);
158 * Called to initialize with the current status and notify the clients
159 * @param notificationXmlList List with problems
161 public void initCurrentProblem(List<ProblemNotificationXml> notificationXmlList) {
163 for (ProblemNotificationXml notificationXml : notificationXmlList) {
164 initCurrentProblem(notificationXml);
170 * Called on exit to remove everything from the current list.
171 * @return Number of deleted objects
173 public int removeAllCurrentProblemsOfNode() {
174 int deleted = databaseService.clearFaultsCurrentOfNode(nodeName);