2 * Copyright (c) 2017 highstreet technologies GmbH 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 javax.annotation.Nullable;
13 import org.opendaylight.mwtn.base.internalTypes.InternalDateAndTime;
14 import org.opendaylight.mwtn.base.internalTypes.InternalSeverity;
15 import org.opendaylight.mwtn.base.netconf.NetconfTimeStamp;
16 import org.opendaylight.mwtn.devicemanager.impl.ProviderClient;
17 import org.opendaylight.mwtn.devicemanager.impl.database.service.HtDatabaseEventsService;
18 import org.opendaylight.mwtn.devicemanager.impl.xml.ObjectCreationNotificationXml;
19 import org.opendaylight.mwtn.devicemanager.impl.xml.ObjectDeletionNotificationXml;
20 import org.opendaylight.mwtn.devicemanager.impl.xml.ProblemNotificationXml;
21 import org.opendaylight.mwtn.devicemanager.impl.xml.WebSocketServiceClient;
22 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.microwave.model.rev170324.ProblemNotification;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
27 * Responsible class for documenting changes in the ODL itself. The occurence of
28 * such an event is documented in the database and to clients. Specific example
29 * here is the registration or deregistration of a netconf device. This service
30 * has an own eventcounter to apply to the ONF Coremodel netconf behaviour.
32 * Important: Websocket notification must be the last action.
37 public class ODLEventListener {
39 private static final Logger LOG = LoggerFactory.getLogger(ODLEventListener.class);
41 private final String ownKeyName;
43 private final WebSocketServiceClient webSocketService;
44 private final HtDatabaseEventsService databaseService;
45 private final ProviderClient dcaeProvider;
46 private final ProviderClient aotsMProvider;
47 private int eventNumber;
49 /*---------------------------------------------------------------
54 * Create a Service to document events to clients and within a database
57 * The name of this service, that is used in the database as
59 * @param webSocketService
60 * service to direct messages to clients
61 * @param databaseService
62 * service to write to the database
64 * to deliver problems to
66 public ODLEventListener(String ownKeyName, WebSocketServiceClient webSocketService,
67 HtDatabaseEventsService databaseService, ProviderClient dcaeProvider,
68 @Nullable ProviderClient aotsMProvider) {
71 this.ownKeyName = ownKeyName;
72 this.webSocketService = webSocketService;
74 this.databaseService = databaseService;
75 this.dcaeProvider = dcaeProvider;
76 this.aotsMProvider = aotsMProvider;
82 /*---------------------------------------------------------------
87 * A registration of a mountpoint occured.
89 * @param registrationName
90 * Name of the event that is used as key in the database.
93 public void registration(String registrationName) {
95 ObjectCreationNotificationXml cNotificationXml = new ObjectCreationNotificationXml(ownKeyName,
96 popEvntNumberAsString(), InternalDateAndTime.valueOf(NetconfTimeStamp.getTimeStamp()),
99 // Write first to prevent missing entries
100 databaseService.writeEventLog(cNotificationXml);
102 webSocketService.sendViaWebsockets(registrationName, cNotificationXml);
107 * A deregistration of a mountpoint occured.
109 * @param registrationName
110 * Name of the event that is used as key in the database.
113 public void deRegistration(String registrationName) {
115 ObjectDeletionNotificationXml dNotificationXml = new ObjectDeletionNotificationXml(ownKeyName,
116 popEvntNumberAsString(), InternalDateAndTime.valueOf(NetconfTimeStamp.getTimeStamp()),
119 // Write first to prevent missing entries
120 databaseService.writeEventLog(dNotificationXml);
122 webSocketService.sendViaWebsockets(registrationName, dNotificationXml);
127 * At a mountpoint a problem situation is indicated
129 * @param registrationName
130 * indicating object within SDN controller, normally the
134 * @param problemSeverity
135 * of the problem according to NETCONF/YANG
138 public void onProblemNotification(String registrationName, String problemName, InternalSeverity problemSeverity) {
139 LOG.debug("Got event of type :: {}", ProblemNotification.class.getSimpleName());
142 ProblemNotificationXml notificationXml = new ProblemNotificationXml(ownKeyName, registrationName, problemName,
144 // popEvntNumberAsString(), InternalDateAndTime.TESTPATTERN );
145 popEvntNumberAsString(), InternalDateAndTime.valueOf(NetconfTimeStamp.getTimeStamp()));
147 databaseService.writeFaultLog(notificationXml);
148 databaseService.updateFaultCurrent(notificationXml);
150 dcaeProvider.sendProblemNotification(ownKeyName, notificationXml);
151 if (aotsMProvider != null)
152 aotsMProvider.sendProblemNotification(ownKeyName, notificationXml, false);// not a nealarm, its a
153 // sdncontroller alarm
155 webSocketService.sendViaWebsockets(registrationName, notificationXml);
159 * Called on exit to remove everything for a node from the current list.
162 * to remove all problems for
163 * @return Number of deleted objects
165 public int removeAllCurrentProblemsOfNode(String nodeName) {
166 return databaseService.clearFaultsCurrentOfNodeWithObjectId(ownKeyName, nodeName);
169 /*---------------------------------------------------------------
173 private String popEvntNumberAsString() {
174 return String.valueOf(popEvntNumber());
177 private int popEvntNumber() {
178 return eventNumber++;