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);
50 private static final NetconfTimeStamp NETCONFTIME_CONVERTER = NetconfTimeStamp.getConverter();
53 private final String ownKeyName;
55 private final WebSocketServiceClient webSocketService;
56 private final HtDatabaseEventsService databaseService;
57 private final ProviderClient dcaeProvider;
58 private final ProviderClient aotsMProvider;
59 private int eventNumber;
60 private final MaintenanceService maintenanceService;
61 /*---------------------------------------------------------------
66 * Create a Service to document events to clients and within a database
68 * @param ownKeyName The name of this service, that is used in the database as identification key.
69 * @param webSocketService service to direct messages to clients
70 * @param databaseService service to write to the database
71 * @param dcaeProvider to deliver problems to
72 * @param maintenanceService2
74 @SuppressWarnings("javadoc")
75 public ODLEventListener(String ownKeyName, WebSocketServiceClient webSocketService,
76 HtDatabaseEventsService databaseService, ProviderClient dcaeProvider,
77 @Nullable ProviderClient aotsMProvider, MaintenanceService maintenanceService) {
80 this.ownKeyName = ownKeyName;
81 this.webSocketService = webSocketService;
83 this.databaseService = databaseService;
84 this.dcaeProvider = dcaeProvider;
85 this.aotsMProvider = aotsMProvider;
88 this.maintenanceService = maintenanceService;
92 /*---------------------------------------------------------------
93 * Handling of ODL Controller events
97 * A registration of a mountpoint occured, that is in connect state
99 * @param registrationName Name of the event that is used as key in the database.
102 public void registration(String registrationName) {
104 ObjectCreationNotificationXml cNotificationXml =
105 new ObjectCreationNotificationXml(ownKeyName, getEventNumberAsString(),
106 InternalDateAndTime.valueOf(NETCONFTIME_CONVERTER.getTimeStamp()), registrationName);
108 // Write first to prevent missing entries
109 databaseService.writeEventLog(cNotificationXml);
110 webSocketService.sendViaWebsockets(registrationName, cNotificationXml);
115 * A deregistration of a mountpoint occured.
117 * @param registrationName Name of the event that is used as key in the database.
120 public void deRegistration(String registrationName) {
122 ObjectDeletionNotificationXml dNotificationXml =
123 new ObjectDeletionNotificationXml(ownKeyName, getEventNumberAsString(),
124 InternalDateAndTime.valueOf(NETCONFTIME_CONVERTER.getTimeStamp()), registrationName);
126 // Write first to prevent missing entries
127 databaseService.writeEventLog(dNotificationXml);
128 webSocketService.sendViaWebsockets(registrationName, dNotificationXml);
133 * Mountpoint state changed .. from connected -> connecting or unable-to-connect or vis-e-versa.
135 * @param registrationName Name of the event that is used as key in the database.
137 public void updateRegistration(String registrationName, String attribute, String attributeNewValue) {
138 AttributeValueChangedNotificationXml notificationXml = new AttributeValueChangedNotificationXml(ownKeyName,
139 getEventNumberAsString(), InternalDateAndTime.valueOf(NETCONFTIME_CONVERTER.getTimeStamp()),
140 registrationName, attribute, attributeNewValue);
141 databaseService.writeEventLog(notificationXml);
142 webSocketService.sendViaWebsockets(registrationName, notificationXml);
147 * At a mountpoint a problem situation is indicated
149 * @param registrationName indicating object within SDN controller, normally the mountpointName
150 * @param problemName that changed
151 * @param problemSeverity of the problem according to NETCONF/YANG
154 public void onProblemNotification(String registrationName, String problemName, InternalSeverity problemSeverity) {
155 LOG.debug("Got event of type :: {} or {} or {}", ProblemNotification.class.getSimpleName(),
156 org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.microwave.model.rev180907.ProblemNotification.class
158 org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.microwave.model.rev181010.ProblemNotification.class
162 ProblemNotificationXml notificationXml =
163 new ProblemNotificationXml(ownKeyName, registrationName, problemName, problemSeverity,
164 // popEvntNumberAsString(), InternalDateAndTime.TESTPATTERN );
165 getEventNumberAsString(), InternalDateAndTime.valueOf(NETCONFTIME_CONVERTER.getTimeStamp()));
167 databaseService.writeFaultLog(notificationXml);
168 databaseService.updateFaultCurrent(notificationXml);
170 if (!maintenanceService.isONFObjectInMaintenance(registrationName, notificationXml.getObjectId(),
171 notificationXml.getProblem())) {
172 dcaeProvider.sendProblemNotification(ownKeyName, notificationXml);
173 if (aotsMProvider != null) {
174 aotsMProvider.sendProblemNotification(ownKeyName, notificationXml, false);// not a nealarm, its a
176 } // sdncontroller alarm
178 LOG.debug("Notification will not be sent to external services. Device " + registrationName
179 + " is in maintenance mode");
182 webSocketService.sendViaWebsockets(registrationName, notificationXml);
186 /*---------------------------------------------
187 * Handling of ODL Controller events
191 * Called on exit to remove everything for a node from the current list.
193 * @param nodeName to remove all problems for
194 * @return Number of deleted objects
196 public int removeAllCurrentProblemsOfNode(String nodeName) {
197 return databaseService.clearFaultsCurrentOfNodeWithObjectId(ownKeyName, nodeName);
200 /*---------------------------------------------------------------
205 * @return the ownKeyName
207 public String getOwnKeyName() {
211 /*---------------------------------------------------------------
215 private String getEventNumberAsString() {
216 return String.valueOf(popEvntNumber());
219 private int popEvntNumber() {
220 return eventNumber++;