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 documented in the
45 * database and to clients. Specific example here is the registration or deregistration of a netconf device. This
46 * service has an own eventcounter to apply to the ONF Coremodel netconf behaviour.
48 * Important: Websocket notification must be the last action.
53 public class ODLEventListenerHandler implements EventHandlingService {
55 private static final Logger LOG = LoggerFactory.getLogger(ODLEventListenerHandler.class);
57 private static final NetconfTimeStamp NETCONFTIME_CONVERTER = NetconfTimeStampImpl.getConverter();
59 private final String ownKeyName;
60 private final WebSocketServiceClientInternal webSocketService;
61 private final DataProvider databaseService;
62 private final DcaeForwarderInternal aotsDcaeForwarder;
64 private int eventNumber;
66 /*---------------------------------------------------------------
71 * Create a Service to document events to clients and within a database
73 * @param ownKeyName The name of this service, that is used in the database as identification key.
74 * @param webSocketService service to direct messages to clients
75 * @param databaseService service to write to the database
76 * @param dcaeForwarder to deliver problems to external service
78 public ODLEventListenerHandler(String ownKeyName, WebSocketServiceClientInternal webSocketService,
79 DataProvider databaseService, DcaeForwarderInternal dcaeForwarder) {
82 this.ownKeyName = ownKeyName;
83 this.webSocketService = webSocketService;
85 this.databaseService = databaseService;
86 this.aotsDcaeForwarder = dcaeForwarder;
92 /*---------------------------------------------------------------
93 * Handling of ODL Controller events
97 * 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 = new ObjectCreationNotificationXml(ownKeyName, popEvntNumber(),
106 InternalDateAndTime.valueOf(NETCONFTIME_CONVERTER.getTimeStamp()), registrationName);
107 NetworkElementConnectionEntity e =
108 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
120 * @param mountpointNodeName uuid that is nodeId or mountpointId
123 public void mountpointCreatedIndication(String mountpointNodeName, NetconfNode netconfNode) {
124 LOG.debug("mountpoint create indication for {}", mountpointNodeName);
125 this.registration(mountpointNodeName, netconfNode);
131 * @param mountpointNodeName uuid that is nodeId or mountpointId
132 * @param deviceType according to assessement
135 public void connectIndication(String mountpointNodeName, NetworkElementDeviceType deviceType) {
137 // Write first to prevent missing entries
138 LOG.debug("updating networkelement-connection devicetype for {} with {}", mountpointNodeName, deviceType);
139 NetworkElementConnectionEntity e =
140 NetworkElementConnectionEntitiyUtil.getNetworkConnectionDeviceTpe(deviceType);
141 databaseService.updateNetworkConnectionDeviceType(e, mountpointNodeName);
143 AttributeValueChangedNotificationXml notificationXml = new AttributeValueChangedNotificationXml(ownKeyName,
144 popEvntNumber(), InternalDateAndTime.valueOf(NETCONFTIME_CONVERTER.getTimeStamp()), mountpointNodeName,
145 "deviceType", deviceType.name());
146 webSocketService.sendViaWebsockets(mountpointNodeName, notificationXml);
150 * mountpoint state changed
152 * @param mountpointNodeName
155 public void onStateChangeIndication(String mountpointNodeName, NetconfNode netconfNode) {
156 LOG.debug("mountpoint state changed indication for {}", mountpointNodeName);
157 ConnectionStatus csts = netconfNode.getConnectionStatus();
158 this.updateRegistration(mountpointNodeName, ConnectionStatus.class.getSimpleName(),
159 csts != null ? csts.getName() : "null", netconfNode);
164 * A deregistration of a mountpoint occured.
166 * @param registrationName Name of the event that is used as key in the database.
169 public void deRegistration(String registrationName) {
171 ObjectDeletionNotificationXml dNotificationXml = new ObjectDeletionNotificationXml(ownKeyName, popEvntNumber(),
172 InternalDateAndTime.valueOf(NETCONFTIME_CONVERTER.getTimeStamp()), registrationName);
174 // Write first to prevent missing entries
175 databaseService.removeNetworkConnection(registrationName);
176 databaseService.writeConnectionLog(dNotificationXml.getConnectionlogEntity());
177 webSocketService.sendViaWebsockets(registrationName, dNotificationXml);
182 * Mountpoint state changed .. from connected -> connecting or unable-to-connect or vis-e-versa.
184 * @param registrationName Name of the event that is used as key in the database.
187 public void updateRegistration(String registrationName, String attribute, String attributeNewValue,
189 AttributeValueChangedNotificationXml notificationXml = new AttributeValueChangedNotificationXml(ownKeyName,
190 popEvntNumber(), InternalDateAndTime.valueOf(NETCONFTIME_CONVERTER.getTimeStamp()), registrationName,
191 attribute, attributeNewValue);
192 NetworkElementConnectionEntity e =
193 NetworkElementConnectionEntitiyUtil.getNetworkConnection(registrationName, nNode);
194 LOG.debug("updating networkelement-connection for {} with status {}", registrationName, e.getStatus());
196 databaseService.updateNetworkConnection22(e, registrationName);
197 databaseService.writeConnectionLog(notificationXml.getConnectionlogEntity());
198 webSocketService.sendViaWebsockets(registrationName, notificationXml);
202 * At a mountpoint a problem situation is indicated
204 * @param registrationName indicating object within SDN controller, normally the mountpointName
205 * @param problemName that changed
206 * @param problemSeverity of the problem according to NETCONF/YANG
209 public void onProblemNotification(String registrationName, String problemName, InternalSeverity problemSeverity) {
210 LOG.debug("Got event of {} {} {}", registrationName, problemName, problemSeverity);
213 ProblemNotificationXml notificationXml =
214 new ProblemNotificationXml(ownKeyName, registrationName, problemName, problemSeverity,
215 // popEvntNumberAsString(), InternalDateAndTime.TESTPATTERN );
216 popEvntNumber(), InternalDateAndTime.valueOf(NETCONFTIME_CONVERTER.getTimeStamp()));
218 databaseService.writeFaultLog(notificationXml.getFaultlog(SourceType.Controller));
219 databaseService.updateFaultCurrent(notificationXml.getFaultcurrent());
221 aotsDcaeForwarder.sendProblemNotificationUsingMaintenanceFilter(ownKeyName, notificationXml);
223 webSocketService.sendViaWebsockets(registrationName, notificationXml);
227 public void writeEventLog(String objectId, String msg, String value) {
229 LOG.debug("Got startComplete");
230 EventlogBuilder eventlogBuilder = new EventlogBuilder();
231 eventlogBuilder.setNodeId(ownKeyName).setTimestamp(new DateAndTime(NETCONFTIME_CONVERTER.getTimeStamp()))
232 .setObjectId(objectId).setAttributeName(msg).setNewValue(value).setCounter(popEvntNumber())
233 .setSourceType(SourceType.Controller);
234 databaseService.writeEventLog(eventlogBuilder.build());
238 /*---------------------------------------------
239 * Handling of ODL Controller events
243 * Called on exit to remove everything for a node from the current list.
245 * @param nodeName to remove all problems for
246 * @return Number of deleted objects
248 public int removeAllCurrentProblemsOfNode(String nodeName) {
249 return databaseService.clearFaultsCurrentOfNodeWithObjectId(ownKeyName, nodeName);
252 /*---------------------------------------------------------------
257 * @return the ownKeyName
259 public String getOwnKeyName() {
263 /*---------------------------------------------------------------
266 private Integer popEvntNumber() {
267 return eventNumber++;