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==========================================================================
18 package org.onap.ccsdk.features.sdnr.wt.devicemanager.eventdatahandler;
20 import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.DataProvider;
21 import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.NetconfTimeStamp;
22 import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.types.NetconfTimeStampImpl;
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.util.NetworkElementConnectionEntitiyUtil;
27 import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.xml.AttributeValueChangedNotificationXml;
28 import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.xml.ObjectCreationNotificationXml;
29 import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.xml.ObjectDeletionNotificationXml;
30 import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.xml.ProblemNotificationXml;
31 import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.xml.WebSocketServiceClientInternal;
32 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.EventHandlingService;
33 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DateAndTime;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNode;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNodeConnectionStatus.ConnectionStatus;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.EventlogBuilder;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.NetworkElementConnectionEntity;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.NetworkElementDeviceType;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.SourceType;
40 import org.slf4j.Logger;
41 import org.slf4j.LoggerFactory;
44 * Responsible class for documenting changes in the ODL itself. The occurence of such an event is
45 * documented in the database and to clients. Specific example here is the registration or
46 * deregistration of a netconf device. This service has an own eventcounter to apply to the ONF
47 * Coremodel netconf behaviour.
49 * Important: Websocket notification must be the last action.
54 public class ODLEventListenerHandler implements EventHandlingService {
56 private static final Logger LOG = LoggerFactory.getLogger(ODLEventListenerHandler.class);
58 private static final NetconfTimeStamp NETCONFTIME_CONVERTER = NetconfTimeStampImpl.getConverter();
60 private final String ownKeyName;
61 private final WebSocketServiceClientInternal webSocketService;
62 private final DataProvider databaseService;
63 private final DcaeForwarderInternal aotsDcaeForwarder;
65 private int eventNumber;
67 /*---------------------------------------------------------------
72 * Create a Service to document events to clients and within a database
74 * @param ownKeyName The name of this service, that is used in the database as identification key.
75 * @param webSocketService service to direct messages to clients
76 * @param databaseService service to write to the database
77 * @param dcaeForwarder to deliver problems to external service
79 public ODLEventListenerHandler(String ownKeyName, WebSocketServiceClientInternal webSocketService,
80 DataProvider databaseService, DcaeForwarderInternal dcaeForwarder) {
83 this.ownKeyName = ownKeyName;
84 this.webSocketService = webSocketService;
86 this.databaseService = databaseService;
87 this.aotsDcaeForwarder = dcaeForwarder;
93 /*---------------------------------------------------------------
94 * Handling of ODL Controller events
98 * A registration of a mountpoint occured, that is in connect state
99 * @param registrationName of device (mountpoint name)
100 * @param nNode with mountpoint data
103 public void registration(String registrationName, NetconfNode nNode) {
105 ObjectCreationNotificationXml cNotificationXml =
106 new ObjectCreationNotificationXml(ownKeyName, popEvntNumber(),
107 InternalDateAndTime.valueOf(NETCONFTIME_CONVERTER.getTimeStamp()), registrationName);
108 NetworkElementConnectionEntity e = NetworkElementConnectionEntitiyUtil.getNetworkConnection(registrationName, nNode);
109 LOG.debug("registration networkelement-connection for {} with status {}", registrationName, e.getStatus());
111 // Write first to prevent missing entries
112 databaseService.updateNetworkConnection22(e, registrationName);
113 databaseService.writeConnectionLog(cNotificationXml.getConnectionlogEntity());
114 webSocketService.sendViaWebsockets(registrationName, cNotificationXml);
118 * mountpoint created, connection state not connected
119 * @param mountpointNodeName uuid that is nodeId or mountpointId
122 public void mountpointCreatedIndication(String mountpointNodeName, NetconfNode netconfNode) {
123 LOG.debug("mountpoint create indication for {}", mountpointNodeName);
124 this.registration(mountpointNodeName, netconfNode);
128 * @param mountpointNodeName uuid that is nodeId or mountpointId
129 * @param deviceType according to assessement
132 public void connectIndication(String mountpointNodeName, NetworkElementDeviceType deviceType) {
134 // Write first to prevent missing entries
135 LOG.debug("updating networkelement-connection devicetype for {} with {}",mountpointNodeName, deviceType);
136 NetworkElementConnectionEntity e = NetworkElementConnectionEntitiyUtil.getNetworkConnectionDeviceTpe(deviceType);
137 databaseService.updateNetworkConnectionDeviceType(e, mountpointNodeName);
139 AttributeValueChangedNotificationXml notificationXml = new AttributeValueChangedNotificationXml(ownKeyName,
140 popEvntNumber(), InternalDateAndTime.valueOf(NETCONFTIME_CONVERTER.getTimeStamp()),
141 mountpointNodeName, "deviceType", deviceType.name());
142 webSocketService.sendViaWebsockets(mountpointNodeName, notificationXml);
146 * mountpoint state changed
147 * @param mountpointNodeName
150 public void onStateChangeIndication(String mountpointNodeName, NetconfNode netconfNode) {
151 LOG.debug("mountpoint state changed indication for {}", mountpointNodeName);
152 ConnectionStatus csts = netconfNode.getConnectionStatus();
153 this.updateRegistration(mountpointNodeName, ConnectionStatus.class.getSimpleName(),
154 csts != null ? csts.getName() : "null", netconfNode);
158 * A deregistration of a mountpoint occured.
159 * @param registrationName Name of the event that is used as key in the database.
162 public void deRegistration(String registrationName) {
164 ObjectDeletionNotificationXml dNotificationXml =
165 new ObjectDeletionNotificationXml(ownKeyName, popEvntNumber(),
166 InternalDateAndTime.valueOf(NETCONFTIME_CONVERTER.getTimeStamp()), registrationName);
168 // Write first to prevent missing entries
169 databaseService.removeNetworkConnection(registrationName);
170 databaseService.writeConnectionLog(dNotificationXml.getConnectionlogEntity());
171 webSocketService.sendViaWebsockets(registrationName, dNotificationXml);
176 * Mountpoint state changed .. from connected -> connecting or unable-to-connect or vis-e-versa.
177 * @param registrationName Name of the event that is used as key in the database.
180 public void updateRegistration(String registrationName, String attribute, String attributeNewValue, NetconfNode nNode) {
181 AttributeValueChangedNotificationXml notificationXml = new AttributeValueChangedNotificationXml(ownKeyName,
182 popEvntNumber(), InternalDateAndTime.valueOf(NETCONFTIME_CONVERTER.getTimeStamp()),
183 registrationName, attribute, attributeNewValue);
184 NetworkElementConnectionEntity e = NetworkElementConnectionEntitiyUtil.getNetworkConnection(registrationName, nNode);
185 LOG.debug("updating networkelement-connection for {} with status {}", registrationName, e.getStatus());
187 databaseService.updateNetworkConnection22(e, registrationName);
188 databaseService.writeConnectionLog(notificationXml.getConnectionlogEntity());
189 webSocketService.sendViaWebsockets(registrationName, notificationXml);
193 * At a mountpoint a problem situation is indicated
195 * @param registrationName indicating object within SDN controller, normally the mountpointName
196 * @param problemName that changed
197 * @param problemSeverity of the problem according to NETCONF/YANG
200 public void onProblemNotification(String registrationName, String problemName, InternalSeverity problemSeverity) {
201 LOG.debug("Got event of {} {} {}", registrationName, problemName, problemSeverity);
204 ProblemNotificationXml notificationXml =
205 new ProblemNotificationXml(ownKeyName, registrationName, problemName, problemSeverity,
206 // popEvntNumberAsString(), InternalDateAndTime.TESTPATTERN );
207 popEvntNumber(), InternalDateAndTime.valueOf(NETCONFTIME_CONVERTER.getTimeStamp()));
209 databaseService.writeFaultLog(notificationXml.getFaultlog(SourceType.Controller));
210 databaseService.updateFaultCurrent(notificationXml.getFaultcurrent());
212 aotsDcaeForwarder.sendProblemNotificationUsingMaintenanceFilter(ownKeyName, notificationXml);
214 webSocketService.sendViaWebsockets(registrationName, notificationXml);
218 public void writeEventLog(String objectId, String msg, String value) {
220 LOG.debug("Got startComplete");
221 EventlogBuilder eventlogBuilder = new EventlogBuilder();
222 eventlogBuilder.setNodeId(ownKeyName).setTimestamp(new DateAndTime(NETCONFTIME_CONVERTER.getTimeStamp()))
223 .setObjectId(objectId).setAttributeName(msg).setNewValue(value).setCounter(popEvntNumber())
224 .setSourceType(SourceType.Controller);
225 databaseService.writeEventLog(eventlogBuilder.build());
229 /*---------------------------------------------
230 * Handling of ODL Controller events
234 * Called on exit to remove everything for a node from the current list.
236 * @param nodeName to remove all problems for
237 * @return Number of deleted objects
239 public int removeAllCurrentProblemsOfNode(String nodeName) {
240 return databaseService.clearFaultsCurrentOfNodeWithObjectId(ownKeyName, nodeName);
243 /*---------------------------------------------------------------
248 * @return the ownKeyName
250 public String getOwnKeyName() {
254 /*---------------------------------------------------------------
257 private Integer popEvntNumber() {
258 return eventNumber++;