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 / MicrowaveEventListener12.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.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;
31
32 /**
33  * Important: Websocket notification must be the last action.
34  * @author herbert
35  *
36  */
37 public class MicrowaveEventListener12 implements MicrowaveModelListener {
38
39     private static final Logger LOG = LoggerFactory.getLogger(MicrowaveEventListener12.class);
40
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;
48
49     public MicrowaveEventListener12(String nodeName, WebSocketServiceClient webSocketService,
50             HtDatabaseEventsService databaseService, ProviderClient dcaeProvider,@Nullable ProviderClient aotsmClient) {
51         super();
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;
59     }
60
61     @Override
62     public void onAttributeValueChangedNotification(AttributeValueChangedNotification notification) {
63         LOG.debug("Got event of type :: {}", AttributeValueChangedNotification.class.getSimpleName());
64
65         AttributeValueChangedNotificationXml notificationXml = new AttributeValueChangedNotificationXml(nodeName,
66                 String.valueOf(notification.getCounter()), InternalDateAndTime.valueOf(notification.getTimeStamp()),
67                 notification.getObjectIdRef().getValue(), notification.getAttributeName(), notification.getNewValue());
68         /*
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);
75         */
76         databaseService.writeEventLog(notificationXml);
77
78         webSocketService.sendViaWebsockets(nodeName, notificationXml);
79     }
80
81     @Override
82     public void onObjectCreationNotification(ObjectCreationNotification notification) {
83         LOG.debug("Got event of type :: {}", ObjectCreationNotification.class.getSimpleName());
84
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());
90         /*
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());
96         */
97         databaseService.writeEventLog(notificationXml);
98
99         webSocketService.sendViaWebsockets(nodeName, notificationXml);
100
101     }
102
103     @Override
104     public void onObjectDeletionNotification(ObjectDeletionNotification notification) {
105         LOG.debug("Got event of type :: {}", ObjectDeletionNotification.class.getSimpleName());
106
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()
112                 );
113         /*
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());
119         */
120         databaseService.writeEventLog(notificationXml);
121
122         webSocketService.sendViaWebsockets(nodeName, notificationXml);
123     }
124
125     @Override
126     public void onProblemNotification(ProblemNotification notification) {
127         LOG.debug("Got event of type :: {}", ProblemNotification.class.getSimpleName());
128
129         ProblemNotificationXml notificationXml = new ProblemNotificationXml(nodeName, notification.getObjectIdRef().getValue(),
130                 notification.getProblem(), InternalSeverity.valueOf(notification.getSeverity()),
131                 notification.getCounter().toString(), InternalDateAndTime.valueOf(notification.getTimeStamp()));
132         /*
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());
138         */
139
140         databaseService.writeFaultLog(notificationXml);
141         databaseService.updateFaultCurrent(notificationXml);
142
143         dcaeProvider.sendProblemNotification(nodeName, notificationXml);
144         if(aotsmClient!=null)
145                 aotsmClient.sendProblemNotification(nodeName, notificationXml);
146
147         webSocketService.sendViaWebsockets(nodeName, notificationXml);
148
149     }
150
151     private void initCurrentProblem(ProblemNotificationXml notificationXml) {
152         databaseService.updateFaultCurrent(notificationXml);
153         if(aotsmClient!=null)
154                 aotsmClient.sendProblemNotification(this.nodeName, notificationXml);
155     }
156
157     /**
158      * Called to initialize with the current status and notify the clients
159      * @param notificationXmlList List with problems
160      */
161     public void initCurrentProblem(List<ProblemNotificationXml> notificationXmlList) {
162
163         for (ProblemNotificationXml notificationXml : notificationXmlList) {
164             initCurrentProblem(notificationXml);
165         }
166
167     }
168
169     /**
170      * Called on exit to remove everything from the current list.
171      * @return Number of deleted objects
172      */
173     public int removeAllCurrentProblemsOfNode() {
174         int deleted = databaseService.clearFaultsCurrentOfNode(nodeName);
175         return deleted;
176     }
177
178 }