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.handler;
20 import org.onap.ccsdk.features.sdnr.wt.base.netconf.util.NetconfTimeStamp;
21 import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.DataProvider;
22 import org.onap.ccsdk.features.sdnr.wt.devicemanager.base.onfcore.ONFCoreNetworkElementBase;
23 import org.onap.ccsdk.features.sdnr.wt.devicemanager.dcaeconnector.impl.DcaeForwarderInternal;
24 import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.util.InternalDateAndTime;
25 import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.util.InternalSeverity;
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.WebSocketServiceClientInternal;
31 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DateAndTime;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNode;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.EventlogBuilder;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.NetworkElementConnectionEntity;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.NetworkElementDeviceType;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.SourceType;
37 import org.slf4j.Logger;
38 import org.slf4j.LoggerFactory;
41 * Responsible class for documenting changes in the ODL itself. The occurence of such an event is
42 * documented in the database and to clients. Specific example here is the registration or
43 * deregistration of a netconf device. This service has an own eventcounter to apply to the ONF
44 * Coremodel netconf behaviour.
46 * Important: Websocket notification must be the last action.
51 public class ODLEventListenerHandler {
53 private static final Logger LOG = LoggerFactory.getLogger(ODLEventListenerHandler.class);
55 private static final NetconfTimeStamp NETCONFTIME_CONVERTER = NetconfTimeStamp.getConverter();
57 private final String ownKeyName;
58 private final WebSocketServiceClientInternal webSocketService;
59 private final DataProvider databaseService;
60 private final DcaeForwarderInternal aotsDcaeForwarder;
62 private int eventNumber;
64 /*---------------------------------------------------------------
69 * Create a Service to document events to clients and within a database
71 * @param ownKeyName The name of this service, that is used in the database as identification key.
72 * @param webSocketService service to direct messages to clients
73 * @param databaseService service to write to the database
74 * @param dcaeForwarder to deliver problems to external service
76 public ODLEventListenerHandler(String ownKeyName, WebSocketServiceClientInternal webSocketService,
77 DataProvider databaseService, DcaeForwarderInternal dcaeForwarder) {
80 this.ownKeyName = ownKeyName;
81 this.webSocketService = webSocketService;
83 this.databaseService = databaseService;
84 this.aotsDcaeForwarder = dcaeForwarder;
90 /*---------------------------------------------------------------
91 * Handling of ODL Controller events
95 * A registration of a mountpoint occured, that is in connect state
96 * @param registrationName of device (mountpoint name)
97 * @param nNode with mountpoint data
99 public void registration(String registrationName, NetconfNode nNode) {
101 ObjectCreationNotificationXml cNotificationXml =
102 new ObjectCreationNotificationXml(ownKeyName, popEvntNumber(),
103 InternalDateAndTime.valueOf(NETCONFTIME_CONVERTER.getTimeStamp()), registrationName);
104 NetworkElementConnectionEntity e = ONFCoreNetworkElementBase.getNetworkConnection(registrationName, nNode);
105 LOG.debug("registration networkelement-connection for {} with status {}", registrationName, e.getStatus());
107 // Write first to prevent missing entries
108 databaseService.updateNetworkConnection22(e, registrationName);
109 databaseService.writeConnectionLog(cNotificationXml.getConnectionlogEntity());
110 webSocketService.sendViaWebsockets(registrationName, cNotificationXml);
115 * @param mountpointNodeName uuid that is nodeId or mountpointId
116 * @param deviceType according to assessement
118 public void connectIndication(String mountpointNodeName, NetworkElementDeviceType deviceType) {
119 // Write first to prevent missing entries
120 LOG.debug("updating networkelement-connection devicetype for {} with {}",mountpointNodeName, deviceType);
121 NetworkElementConnectionEntity e = ONFCoreNetworkElementBase.getNetworkConnectionDeviceTpe(deviceType);
122 databaseService.updateNetworkConnectionDeviceType(e, mountpointNodeName);
128 * A deregistration of a mountpoint occured.
130 * @param registrationName Name of the event that is used as key in the database.
133 public void deRegistration(String registrationName) {
135 ObjectDeletionNotificationXml dNotificationXml =
136 new ObjectDeletionNotificationXml(ownKeyName, popEvntNumber(),
137 InternalDateAndTime.valueOf(NETCONFTIME_CONVERTER.getTimeStamp()), registrationName);
139 // Write first to prevent missing entries
140 databaseService.removeNetworkConnection(registrationName);
141 databaseService.writeConnectionLog(dNotificationXml.getConnectionlogEntity());
142 webSocketService.sendViaWebsockets(registrationName, dNotificationXml);
147 * Mountpoint state changed .. from connected -> connecting or unable-to-connect or vis-e-versa.
149 * @param registrationName Name of the event that is used as key in the database.
151 public void updateRegistration(String registrationName, String attribute, String attributeNewValue, NetconfNode nNode) {
152 AttributeValueChangedNotificationXml notificationXml = new AttributeValueChangedNotificationXml(ownKeyName,
153 popEvntNumber(), InternalDateAndTime.valueOf(NETCONFTIME_CONVERTER.getTimeStamp()),
154 registrationName, attribute, attributeNewValue);
155 NetworkElementConnectionEntity e = ONFCoreNetworkElementBase.getNetworkConnection(registrationName, nNode);
156 LOG.debug("updating networkelement-connection for {} with status {}", registrationName, e.getStatus());
158 databaseService.updateNetworkConnection22(e, registrationName);
159 databaseService.writeConnectionLog(notificationXml.getConnectionlogEntity());
160 webSocketService.sendViaWebsockets(registrationName, notificationXml);
164 * At a mountpoint a problem situation is indicated
166 * @param registrationName indicating object within SDN controller, normally the mountpointName
167 * @param problemName that changed
168 * @param problemSeverity of the problem according to NETCONF/YANG
171 public void onProblemNotification(String registrationName, String problemName, InternalSeverity problemSeverity) {
172 LOG.debug("Got event of {} {} {}", registrationName, problemName, problemSeverity);
175 ProblemNotificationXml notificationXml =
176 new ProblemNotificationXml(ownKeyName, registrationName, problemName, problemSeverity,
177 // popEvntNumberAsString(), InternalDateAndTime.TESTPATTERN );
178 popEvntNumber(), InternalDateAndTime.valueOf(NETCONFTIME_CONVERTER.getTimeStamp()));
180 databaseService.writeFaultLog(notificationXml.getFaultlog(SourceType.Controller));
181 databaseService.updateFaultCurrent(notificationXml.getFaultcurrent());
183 aotsDcaeForwarder.sendProblemNotificationUsingMaintenanceFilter(ownKeyName, notificationXml);
185 webSocketService.sendViaWebsockets(registrationName, notificationXml);
188 public void writeEventLog(String objectId, String msg, String value) {
190 LOG.debug("Got startComplete");
191 EventlogBuilder eventlogBuilder = new EventlogBuilder();
192 eventlogBuilder.setNodeId(ownKeyName).setTimestamp(new DateAndTime(NETCONFTIME_CONVERTER.getTimeStamp()))
193 .setObjectId(objectId).setAttributeName(msg).setNewValue(value).setCounter(popEvntNumber())
194 .setSourceType(SourceType.Controller);
195 databaseService.writeEventLog(eventlogBuilder.build());
199 /*---------------------------------------------
200 * Handling of ODL Controller events
204 * Called on exit to remove everything for a node from the current list.
206 * @param nodeName to remove all problems for
207 * @return Number of deleted objects
209 public int removeAllCurrentProblemsOfNode(String nodeName) {
210 return databaseService.clearFaultsCurrentOfNodeWithObjectId(ownKeyName, nodeName);
213 /*---------------------------------------------------------------
218 * @return the ownKeyName
220 public String getOwnKeyName() {
224 /*---------------------------------------------------------------
227 private Integer popEvntNumber() {
228 return eventNumber++;