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.ObjectCreationNotificationXml;
27 import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.xml.ObjectDeletionNotificationXml;
28 import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.xml.ProblemNotificationXml;
29 import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.xml.WebSocketServiceClient;
30 import org.onap.ccsdk.features.sdnr.wt.devicemanager.maintenance.MaintenanceService;
31 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.microwave.model.rev170324.ProblemNotification;
32 import org.slf4j.Logger;
33 import org.slf4j.LoggerFactory;
36 * Responsible class for documenting changes in the ODL itself. The occurence of
37 * such an event is documented in the database and to clients. Specific example
38 * here is the registration or deregistration of a netconf device. This service
39 * has an own eventcounter to apply to the ONF Coremodel netconf behaviour.
41 * Important: Websocket notification must be the last action.
46 public class ODLEventListener {
48 private static final Logger LOG = LoggerFactory.getLogger(ODLEventListener.class);
49 private static final NetconfTimeStamp NETCONFTIME_CONVERTER = NetconfTimeStamp.getConverter();
52 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 int eventNumber;
59 private final MaintenanceService maintenanceService;
60 /*---------------------------------------------------------------
65 * Create a Service to document events to clients and within a database
67 * @param ownKeyName The name of this service, that is used in the
68 * 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 /*---------------------------------------------------------------
97 * A registration of a mountpoint occured.
99 * @param registrationName Name of the event that is used as key in the
103 public void registration(String registrationName) {
105 ObjectCreationNotificationXml cNotificationXml = new ObjectCreationNotificationXml(ownKeyName,
106 popEvntNumberAsString(), InternalDateAndTime.valueOf(NETCONFTIME_CONVERTER.getTimeStamp()),
109 // Write first to prevent missing entries
110 databaseService.writeEventLog(cNotificationXml);
112 webSocketService.sendViaWebsockets(registrationName, cNotificationXml);
117 * A deregistration of a mountpoint occured.
119 * @param registrationName Name of the event that is used as key in the
123 public void deRegistration(String registrationName) {
125 ObjectDeletionNotificationXml dNotificationXml = new ObjectDeletionNotificationXml(ownKeyName,
126 popEvntNumberAsString(), InternalDateAndTime.valueOf(NETCONFTIME_CONVERTER.getTimeStamp()),
129 // Write first to prevent missing entries
130 databaseService.writeEventLog(dNotificationXml);
132 webSocketService.sendViaWebsockets(registrationName, dNotificationXml);
137 * At a mountpoint a problem situation is indicated
139 * @param registrationName indicating object within SDN controller, normally the
141 * @param problemName that changed
142 * @param problemSeverity of the problem according to NETCONF/YANG
145 public void onProblemNotification(String registrationName, String problemName, InternalSeverity problemSeverity) {
146 LOG.debug("Got event of type :: {} or {} or {}", ProblemNotification.class.getSimpleName(),
147 org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.microwave.model.rev180907.ProblemNotification.class
149 org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.microwave.model.rev181010.ProblemNotification.class
153 ProblemNotificationXml notificationXml = new ProblemNotificationXml(ownKeyName, registrationName, problemName,
155 // popEvntNumberAsString(), InternalDateAndTime.TESTPATTERN );
156 popEvntNumberAsString(), InternalDateAndTime.valueOf(NETCONFTIME_CONVERTER.getTimeStamp()));
158 databaseService.writeFaultLog(notificationXml);
159 databaseService.updateFaultCurrent(notificationXml);
161 if (!maintenanceService.isONFObjectInMaintenance(registrationName, notificationXml.getObjectId(),
162 notificationXml.getProblem())) {
163 dcaeProvider.sendProblemNotification(ownKeyName, notificationXml);
164 if (aotsMProvider != null) {
165 aotsMProvider.sendProblemNotification(ownKeyName, notificationXml, false);// not a nealarm, its a
167 } // sdncontroller alarm
169 LOG.debug("Notification will not be sent to external services. Device " + registrationName
170 + " is in maintenance mode");
173 webSocketService.sendViaWebsockets(registrationName, notificationXml);
177 * Called on exit to remove everything for a node from the current list.
179 * @param nodeName to remove all problems for
180 * @return Number of deleted objects
182 public int removeAllCurrentProblemsOfNode(String nodeName) {
183 return databaseService.clearFaultsCurrentOfNodeWithObjectId(ownKeyName, nodeName);
186 /*---------------------------------------------------------------
191 * @return the ownKeyName
193 public String getOwnKeyName() {
197 /*---------------------------------------------------------------
201 private String popEvntNumberAsString() {
202 return String.valueOf(popEvntNumber());
205 private int popEvntNumber() {
206 return eventNumber++;