1 /*******************************************************************************
2 * ============LICENSE_START========================================================================
3 * ONAP : ccsdk feature sdnr wt
4 * =================================================================================================
5 * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved.
6 * =================================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
8 * in compliance with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software distributed under the License
13 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
14 * or implied. See the License for the specific language governing permissions and limitations under
16 * ============LICENSE_END==========================================================================
17 ******************************************************************************/
18 package org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.listener;
20 import javax.annotation.Nullable;
21 import org.onap.ccsdk.features.sdnr.wt.devicemanager.base.internalTypes.InternalDateAndTime;
22 import org.onap.ccsdk.features.sdnr.wt.devicemanager.base.internalTypes.InternalSeverity;
23 import org.onap.ccsdk.features.sdnr.wt.devicemanager.base.netconf.util.NetconfTimeStamp;
24 import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.ProviderClient;
25 import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.database.service.HtDatabaseEventsService;
26 import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.xml.AttributeValueChangedNotificationXml;
27 import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.xml.ObjectCreationNotificationXml;
28 import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.xml.ObjectDeletionNotificationXml;
29 import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.xml.ProblemNotificationXml;
30 import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.xml.WebSocketServiceClient;
31 import org.onap.ccsdk.features.sdnr.wt.devicemanager.maintenance.MaintenanceService;
32 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.microwave.model.rev170324.ProblemNotification;
33 import org.slf4j.Logger;
34 import org.slf4j.LoggerFactory;
37 * Responsible class for documenting changes in the ODL itself. The occurence of such an event is
38 * documented in the database and to clients. Specific example here is the registration or
39 * deregistration of a netconf device. This service has an own eventcounter to apply to the ONF
40 * Coremodel netconf behaviour.
42 * Important: Websocket notification must be the last action.
47 public class ODLEventListener {
49 private static final Logger LOG = LoggerFactory.getLogger(ODLEventListener.class);
51 private static final NetconfTimeStamp NETCONFTIME_CONVERTER = NetconfTimeStamp.getConverter();
53 private final String ownKeyName;
54 private final WebSocketServiceClient webSocketService;
55 private final HtDatabaseEventsService databaseService;
56 private final ProviderClient dcaeProvider;
57 private final ProviderClient aotsMProvider;
58 private final MaintenanceService maintenanceService;
60 private int eventNumber;
62 /*---------------------------------------------------------------
67 * Create a Service to document events to clients and within a database
69 * @param ownKeyName The name of this service, that is used in the database as identification key.
70 * @param webSocketService service to direct messages to clients
71 * @param databaseService service to write to the database
72 * @param dcaeProvider to deliver problems to
73 * @param maintenanceService2
75 @SuppressWarnings("javadoc")
76 public ODLEventListener(String ownKeyName, WebSocketServiceClient webSocketService,
77 HtDatabaseEventsService databaseService, ProviderClient dcaeProvider,
78 @Nullable ProviderClient aotsMProvider, MaintenanceService maintenanceService) {
81 this.ownKeyName = ownKeyName;
82 this.webSocketService = webSocketService;
84 this.databaseService = databaseService;
85 this.dcaeProvider = dcaeProvider;
86 this.aotsMProvider = aotsMProvider;
89 this.maintenanceService = maintenanceService;
93 /*---------------------------------------------------------------
94 * Handling of ODL Controller events
98 * A registration of a mountpoint occured, that is in connect state
100 * @param registrationName Name of the event that is used as key in the database.
103 public void registration(String registrationName) {
105 ObjectCreationNotificationXml cNotificationXml =
106 new ObjectCreationNotificationXml(ownKeyName, getEventNumberAsString(),
107 InternalDateAndTime.valueOf(NETCONFTIME_CONVERTER.getTimeStamp()), registrationName);
109 // Write first to prevent missing entries
110 databaseService.writeEventLog(cNotificationXml);
111 webSocketService.sendViaWebsockets(registrationName, cNotificationXml);
116 * A deregistration of a mountpoint occured.
118 * @param registrationName Name of the event that is used as key in the database.
121 public void deRegistration(String registrationName) {
123 ObjectDeletionNotificationXml dNotificationXml =
124 new ObjectDeletionNotificationXml(ownKeyName, getEventNumberAsString(),
125 InternalDateAndTime.valueOf(NETCONFTIME_CONVERTER.getTimeStamp()), registrationName);
127 // Write first to prevent missing entries
128 databaseService.writeEventLog(dNotificationXml);
129 webSocketService.sendViaWebsockets(registrationName, dNotificationXml);
134 * Mountpoint state changed .. from connected -> connecting or unable-to-connect or vis-e-versa.
136 * @param registrationName Name of the event that is used as key in the database.
138 public void updateRegistration(String registrationName, String attribute, String attributeNewValue) {
139 AttributeValueChangedNotificationXml notificationXml = new AttributeValueChangedNotificationXml(ownKeyName,
140 getEventNumberAsString(), InternalDateAndTime.valueOf(NETCONFTIME_CONVERTER.getTimeStamp()),
141 registrationName, attribute, attributeNewValue);
142 databaseService.writeEventLog(notificationXml);
143 webSocketService.sendViaWebsockets(registrationName, notificationXml);
148 * At a mountpoint a problem situation is indicated
150 * @param registrationName indicating object within SDN controller, normally the mountpointName
151 * @param problemName that changed
152 * @param problemSeverity of the problem according to NETCONF/YANG
155 public void onProblemNotification(String registrationName, String problemName, InternalSeverity problemSeverity) {
156 LOG.debug("Got event of type :: {} or {} or {}", ProblemNotification.class.getSimpleName(),
157 org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.microwave.model.rev180907.ProblemNotification.class
159 org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.microwave.model.rev181010.ProblemNotification.class
163 ProblemNotificationXml notificationXml =
164 new ProblemNotificationXml(ownKeyName, registrationName, problemName, problemSeverity,
165 // popEvntNumberAsString(), InternalDateAndTime.TESTPATTERN );
166 getEventNumberAsString(), InternalDateAndTime.valueOf(NETCONFTIME_CONVERTER.getTimeStamp()));
168 databaseService.writeFaultLog(notificationXml);
169 databaseService.updateFaultCurrent(notificationXml);
171 if (!maintenanceService.isONFObjectInMaintenance(registrationName, notificationXml.getObjectId(),
172 notificationXml.getProblem())) {
173 dcaeProvider.sendProblemNotification(ownKeyName, notificationXml);
174 if (aotsMProvider != null) {
175 aotsMProvider.sendProblemNotification(ownKeyName, notificationXml, false);// not a nealarm, its a
177 } // sdncontroller alarm
179 LOG.debug("Notification will not be sent to external services. Device " + registrationName
180 + " is in maintenance mode");
183 webSocketService.sendViaWebsockets(registrationName, notificationXml);
187 /*---------------------------------------------
188 * Handling of ODL Controller events
192 * Called on exit to remove everything for a node from the current list.
194 * @param nodeName to remove all problems for
195 * @return Number of deleted objects
197 public int removeAllCurrentProblemsOfNode(String nodeName) {
198 return databaseService.clearFaultsCurrentOfNodeWithObjectId(ownKeyName, nodeName);
201 /*---------------------------------------------------------------
206 * @return the ownKeyName
208 public String getOwnKeyName() {
212 /*---------------------------------------------------------------
216 private String getEventNumberAsString() {
217 return String.valueOf(popEvntNumber());
220 private int popEvntNumber() {
221 return eventNumber++;