Assign image keyname and pubkey at vnf level
[ccsdk/apps.git] / sdnr / wireless-transport / code-Carbon-SR1 / apps / devicemanager / impl / src / main / java / org / opendaylight / mwtn / devicemanager / impl / listener / MicrowaveEventListener.java
1 /*
2 * Copyright (c) 2016 Wipro Ltd. and others. All rights reserved.
3 *
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
7 */
8
9 package org.opendaylight.mwtn.devicemanager.impl.listener;
10
11 import java.util.List;
12
13 import javax.annotation.Nullable;
14
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.uri.onf.microwavemodel.notifications.rev160809.AttributeValueChangedNotification;
25 import org.opendaylight.yang.gen.v1.uri.onf.microwavemodel.notifications.rev160809.MicrowaveModelNotificationsListener;
26 import org.opendaylight.yang.gen.v1.uri.onf.microwavemodel.notifications.rev160809.ObjectCreationNotification;
27 import org.opendaylight.yang.gen.v1.uri.onf.microwavemodel.notifications.rev160809.ObjectDeletionNotification;
28 import org.opendaylight.yang.gen.v1.uri.onf.microwavemodel.notifications.rev160809.ProblemNotification;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
31 /**
32  * Important: Websocket notificatin must be the last action.
33  * @author herbert
34  *
35  */
36 public class MicrowaveEventListener implements MicrowaveModelNotificationsListener {
37
38     private static final Logger LOG = LoggerFactory.getLogger(MicrowaveEventListener.class);
39
40     private final String nodeName;
41     private final WebSocketServiceClient webSocketService;
42     private final HtDatabaseEventsService databaseService;
43     private final ProviderClient dcaeProvider;
44         private final @Nullable ProviderClient aotsmClient;
45
46     public MicrowaveEventListener(String nodeName, WebSocketServiceClient webSocketService,
47             HtDatabaseEventsService databaseService, ProviderClient dcaeProvider,@Nullable ProviderClient aotsmClient) {
48         super();
49         this.nodeName = nodeName;
50         this.webSocketService = webSocketService;
51         this.databaseService = databaseService;
52         this.dcaeProvider = dcaeProvider;
53         this.aotsmClient = aotsmClient;
54
55     }
56
57     @Override
58     public void onAttributeValueChangedNotification(AttributeValueChangedNotification notification) {
59         LOG.debug("Got event of type :: {}", AttributeValueChangedNotification.class.getSimpleName());
60
61         AttributeValueChangedNotificationXml notificationXml = new AttributeValueChangedNotificationXml(nodeName,
62                 String.valueOf(notification.getCounter()), InternalDateAndTime.valueOf(notification.getTimeStamp()),
63                 notification.getObjectIdRef().getValue(), notification.getAttributeName(), notification.getNewValue());
64
65         /*
66         WebsocketEventInputBuilder builder = new WebsocketEventInputBuilder();
67         builder.setNodeName(nodeName);
68         builder.setEventType(AttributeValueChangedNotification.class.getSimpleName());
69         builder.setXmlEvent(xmlMapper.getXmlString(notificationXml));
70         WebsocketEventInput event= builder.build();
71         websocketmanagerService.websocketEvent(event);
72         */
73         databaseService.writeEventLog(notificationXml);
74         // Last notification to client to make shure that database already changed
75         webSocketService.sendViaWebsockets(nodeName, notificationXml);
76     }
77
78     @Override
79     public void onObjectCreationNotification(ObjectCreationNotification notification) {
80         LOG.debug("Got event of type :: {}", ObjectCreationNotification.class.getSimpleName());
81
82         //ObjectCreationNotificationXml notificationXml = new ObjectCreationNotificationXml(nodeName, notification);
83         ObjectCreationNotificationXml notificationXml = new ObjectCreationNotificationXml( nodeName,
84                         notification.getCounter().toString(),
85                         InternalDateAndTime.valueOf(notification.getTimeStamp()),
86                         notification.getObjectIdRef().getValue());
87         /*public ObjectCreationNotificationXml(String nodeName, org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.microwave.model.rev170324.ObjectCreationNotification notification) {
88             super(nodeName, notification.getCounter().toString(), InternalDateAndTime.valueOf(notification.getTimeStamp()),
89                     notification.getObjectIdRef().getValue());
90         }*/
91         /*
92         WebsocketEventInputBuilder builder = new WebsocketEventInputBuilder();
93         builder.setNodeName(nodeName);
94         builder.setEventType(ObjectCreationNotification.class.getSimpleName());
95         builder.setXmlEvent(xmlMapper.getXmlString(notificationXml));
96         websocketmanagerService.websocketEvent(builder.build());
97         */
98         databaseService.writeEventLog(notificationXml);
99
100         webSocketService.sendViaWebsockets(nodeName, notificationXml);
101
102     }
103
104     @Override
105     public void onObjectDeletionNotification(ObjectDeletionNotification notification) {
106         LOG.debug("Got event of type :: {}", ObjectDeletionNotification.class.getSimpleName());
107
108         //ObjectDeletionNotificationXml notificationXml = new ObjectDeletionNotificationXml(nodeName, notification);
109         ObjectDeletionNotificationXml notificationXml = new ObjectDeletionNotificationXml(nodeName,
110                 notification.getCounter().toString(),
111                 InternalDateAndTime.valueOf(notification.getTimeStamp()),
112                 notification.getObjectIdRef().getValue()
113                 );
114         /*
115         WebsocketEventInputBuilder builder = new WebsocketEventInputBuilder();
116         builder.setNodeName(nodeName);
117         builder.setEventType(ObjectDeletionNotification.class.getSimpleName());
118         builder.setXmlEvent(xmlMapper.getXmlString(notificationXml));
119         websocketmanagerService.websocketEvent(builder.build());
120         */
121         databaseService.writeEventLog(notificationXml);
122
123         webSocketService.sendViaWebsockets(nodeName, notificationXml);
124     }
125
126     @Override
127     public void onProblemNotification(ProblemNotification notification) {
128         LOG.debug("Got event of type :: {}", ProblemNotification.class.getSimpleName());
129
130         ProblemNotificationXml notificationXml = new ProblemNotificationXml(nodeName, notification.getObjectIdRef().getValue(),
131                 notification.getProblem(), InternalSeverity.valueOf(notification.getSeverity()),
132                 notification.getCounter().toString(), InternalDateAndTime.valueOf(notification.getTimeStamp()));
133         /*
134         WebsocketEventInputBuilder wsBuilder = new WebsocketEventInputBuilder();
135         wsBuilder.setNodeName(nodeName);
136         wsBuilder.setEventType(ProblemNotification.class.getSimpleName());
137         wsBuilder.setXmlEvent(xmlMapper.getXmlString(notificationXml));
138         websocketmanagerService.websocketEvent(wsBuilder.build());
139         */
140
141         databaseService.writeFaultLog(notificationXml);
142         databaseService.updateFaultCurrent(notificationXml);
143
144         if (dcaeProvider != null) {
145                         dcaeProvider.sendProblemNotification(nodeName, notificationXml);
146                 }
147         if (aotsmClient != null) {
148                 aotsmClient.sendProblemNotification(nodeName, notificationXml);
149                 }
150
151         webSocketService.sendViaWebsockets(nodeName, notificationXml);
152
153     }
154
155     private void initCurrentProblem(ProblemNotificationXml notificationXml) {
156         databaseService.updateFaultCurrent(notificationXml);
157         if (aotsmClient != null) {
158                 aotsmClient.sendProblemNotification(this.nodeName, notificationXml);
159         }
160     }
161
162     /**
163      * Called to initialize with the current status and notify the clients
164      * @param notificationXmlList List with problems
165      */
166     public void initCurrentProblem(List<ProblemNotificationXml> notificationXmlList) {
167
168         for (ProblemNotificationXml notificationXml : notificationXmlList) {
169             initCurrentProblem(notificationXml);
170         }
171
172     }
173
174     /**
175      * Called on exit to remove everything from the current list.
176      * @return Number of deleted objects
177      */
178     public int removeAllCurrentProblemsOfNode() {
179         int deleted = databaseService.clearFaultsCurrentOfNode(nodeName);
180         return deleted;
181     }
182
183 }