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.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.params.xml.ns.yang.data.provider.rev190801.EventlogBuilder;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.NetworkElementConnectionEntity;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.NetworkElementDeviceType;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.SourceType;
39 import org.slf4j.Logger;
40 import org.slf4j.LoggerFactory;
43 * Responsible class for documenting changes in the ODL itself. The occurence of such an event is
44 * documented in the database and to clients. Specific example here is the registration or
45 * deregistration of a netconf device. This service has an own eventcounter to apply to the ONF
46 * 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
98 * @param registrationName of device (mountpoint name)
99 * @param nNode with mountpoint data
102 public void registration(String registrationName, NetconfNode nNode) {
104 ObjectCreationNotificationXml cNotificationXml =
105 new ObjectCreationNotificationXml(ownKeyName, popEvntNumber(),
106 InternalDateAndTime.valueOf(NETCONFTIME_CONVERTER.getTimeStamp()), registrationName);
107 NetworkElementConnectionEntity e = NetworkElementConnectionEntitiyUtil.getNetworkConnection(registrationName, nNode);
108 LOG.debug("registration networkelement-connection for {} with status {}", registrationName, e.getStatus());
110 // Write first to prevent missing entries
111 databaseService.updateNetworkConnection22(e, registrationName);
112 databaseService.writeConnectionLog(cNotificationXml.getConnectionlogEntity());
113 webSocketService.sendViaWebsockets(registrationName, cNotificationXml);
118 * @param mountpointNodeName uuid that is nodeId or mountpointId
119 * @param deviceType according to assessement
122 public void connectIndication(String mountpointNodeName, NetworkElementDeviceType deviceType) {
124 // Write first to prevent missing entries
125 LOG.debug("updating networkelement-connection devicetype for {} with {}",mountpointNodeName, deviceType);
126 NetworkElementConnectionEntity e = NetworkElementConnectionEntitiyUtil.getNetworkConnectionDeviceTpe(deviceType);
127 databaseService.updateNetworkConnectionDeviceType(e, mountpointNodeName);
129 AttributeValueChangedNotificationXml notificationXml = new AttributeValueChangedNotificationXml(ownKeyName,
130 popEvntNumber(), InternalDateAndTime.valueOf(NETCONFTIME_CONVERTER.getTimeStamp()),
131 mountpointNodeName, "deviceType", deviceType.name());
132 webSocketService.sendViaWebsockets(mountpointNodeName, notificationXml);
137 * A deregistration of a mountpoint occured.
138 * @param registrationName Name of the event that is used as key in the database.
141 public void deRegistration(String registrationName) {
143 ObjectDeletionNotificationXml dNotificationXml =
144 new ObjectDeletionNotificationXml(ownKeyName, popEvntNumber(),
145 InternalDateAndTime.valueOf(NETCONFTIME_CONVERTER.getTimeStamp()), registrationName);
147 // Write first to prevent missing entries
148 databaseService.removeNetworkConnection(registrationName);
149 databaseService.writeConnectionLog(dNotificationXml.getConnectionlogEntity());
150 webSocketService.sendViaWebsockets(registrationName, dNotificationXml);
155 * Mountpoint state changed .. from connected -> connecting or unable-to-connect or vis-e-versa.
156 * @param registrationName Name of the event that is used as key in the database.
160 public void updateRegistration(String registrationName, String attribute, String attributeNewValue, NetconfNode nNode) {
161 AttributeValueChangedNotificationXml notificationXml = new AttributeValueChangedNotificationXml(ownKeyName,
162 popEvntNumber(), InternalDateAndTime.valueOf(NETCONFTIME_CONVERTER.getTimeStamp()),
163 registrationName, attribute, attributeNewValue);
164 NetworkElementConnectionEntity e = NetworkElementConnectionEntitiyUtil.getNetworkConnection(registrationName, nNode);
165 LOG.debug("updating networkelement-connection for {} with status {}", registrationName, e.getStatus());
167 databaseService.updateNetworkConnection22(e, registrationName);
168 databaseService.writeConnectionLog(notificationXml.getConnectionlogEntity());
169 webSocketService.sendViaWebsockets(registrationName, notificationXml);
173 * At a mountpoint a problem situation is indicated
175 * @param registrationName indicating object within SDN controller, normally the mountpointName
176 * @param problemName that changed
177 * @param problemSeverity of the problem according to NETCONF/YANG
180 public void onProblemNotification(String registrationName, String problemName, InternalSeverity problemSeverity) {
181 LOG.debug("Got event of {} {} {}", registrationName, problemName, problemSeverity);
184 ProblemNotificationXml notificationXml =
185 new ProblemNotificationXml(ownKeyName, registrationName, problemName, problemSeverity,
186 // popEvntNumberAsString(), InternalDateAndTime.TESTPATTERN );
187 popEvntNumber(), InternalDateAndTime.valueOf(NETCONFTIME_CONVERTER.getTimeStamp()));
189 databaseService.writeFaultLog(notificationXml.getFaultlog(SourceType.Controller));
190 databaseService.updateFaultCurrent(notificationXml.getFaultcurrent());
192 aotsDcaeForwarder.sendProblemNotificationUsingMaintenanceFilter(ownKeyName, notificationXml);
194 webSocketService.sendViaWebsockets(registrationName, notificationXml);
198 public void writeEventLog(String objectId, String msg, String value) {
200 LOG.debug("Got startComplete");
201 EventlogBuilder eventlogBuilder = new EventlogBuilder();
202 eventlogBuilder.setNodeId(ownKeyName).setTimestamp(new DateAndTime(NETCONFTIME_CONVERTER.getTimeStamp()))
203 .setObjectId(objectId).setAttributeName(msg).setNewValue(value).setCounter(popEvntNumber())
204 .setSourceType(SourceType.Controller);
205 databaseService.writeEventLog(eventlogBuilder.build());
209 /*---------------------------------------------
210 * Handling of ODL Controller events
214 * Called on exit to remove everything for a node from the current list.
216 * @param nodeName to remove all problems for
217 * @return Number of deleted objects
219 public int removeAllCurrentProblemsOfNode(String nodeName) {
220 return databaseService.clearFaultsCurrentOfNodeWithObjectId(ownKeyName, nodeName);
223 /*---------------------------------------------------------------
228 * @return the ownKeyName
230 public String getOwnKeyName() {
234 /*---------------------------------------------------------------
237 private Integer popEvntNumber() {
238 return eventNumber++;