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 java.util.List;
21 import org.eclipse.jdt.annotation.NonNull;
22 import org.eclipse.jdt.annotation.Nullable;
23 import org.onap.ccsdk.features.sdnr.wt.common.HtAssert;
24 import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.DataProvider;
25 import org.onap.ccsdk.features.sdnr.wt.devicemanager.dcaeconnector.impl.DcaeForwarderInternal;
26 import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.util.InternalSeverity;
27 import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.xml.ProblemNotificationXml;
28 import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.xml.WebSocketServiceClientInternal;
29 import org.onap.ccsdk.features.sdnr.wt.devicemanager.maintenance.impl.MaintenanceServiceImpl;
30 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.EquipmentService;
31 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.FaultService;
32 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.NotificationService;
33 import org.onap.ccsdk.features.sdnr.wt.devicemanager.toggleAlarmFilter.DevicemanagerNotificationDelayService;
34 import org.onap.ccsdk.features.sdnr.wt.devicemanager.toggleAlarmFilter.NotificationDelayFilter;
35 import org.onap.ccsdk.features.sdnr.wt.devicemanager.toggleAlarmFilter.NotificationDelayedListener;
36 import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.EquipmentData;
37 import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.EventlogNotificationBuilder;
38 import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.FaultData;
39 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DateAndTime;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.EventlogEntity;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.Faultcurrent;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.FaultcurrentBuilder;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.FaultlogEntity;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.Inventory;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.devicemanager.rev190109.AttributeValueChangedNotification;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.devicemanager.rev190109.AttributeValueChangedNotificationBuilder;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.devicemanager.rev190109.ObjectCreationNotification;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.devicemanager.rev190109.ObjectCreationNotificationBuilder;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.devicemanager.rev190109.ObjectDeletionNotification;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.devicemanager.rev190109.ObjectDeletionNotificationBuilder;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.devicemanager.rev190109.ProblemNotification;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.devicemanager.rev190109.ProblemNotificationBuilder;
53 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
54 import org.slf4j.Logger;
55 import org.slf4j.LoggerFactory;
57 public class DeviceManagerDatabaseNotificationService implements NotificationService, EquipmentService, FaultService,
58 NotificationDelayedListener<ProblemNotificationXml> {
60 private static final Logger LOG = LoggerFactory.getLogger(DeviceManagerDatabaseNotificationService.class);
62 private final @NonNull DataProvider databaseService;
63 private final @NonNull WebSocketServiceClientInternal webSocketService;
64 private @NonNull final DevicemanagerNotificationDelayService notificationDelayService;
65 private @NonNull final DcaeForwarderInternal aotsDcaeForwarder;
67 private final @NonNull MaintenanceServiceImpl maintenanceService;
70 * @param databaseService to access database
71 * @param maintenanceService
72 * @param webSocketService to send notifications
73 * @param notificationDelayService filter to prevent toggle alarms
74 * @param aotsDcaeForwarder
76 public DeviceManagerDatabaseNotificationService(@NonNull DataProvider databaseService,
77 @NonNull MaintenanceServiceImpl maintenanceService,
78 @NonNull WebSocketServiceClientInternal webSocketService,
79 @NonNull DevicemanagerNotificationDelayService notificationDelayService,
80 @NonNull DcaeForwarderInternal aotsDcaeForwarder) {
82 HtAssert.nonnull(databaseService, maintenanceService, webSocketService, notificationDelayService);
84 this.databaseService = databaseService;
85 this.maintenanceService = maintenanceService;
86 this.webSocketService = webSocketService;
87 this.notificationDelayService = notificationDelayService;
88 this.aotsDcaeForwarder = aotsDcaeForwarder;
92 public void eventNotification(@NonNull EventlogEntity eventNotification) {
93 String nodeId = eventNotification.getNodeId();
95 nodeId = "EmptyNodeId";
97 databaseService.writeEventLog(eventNotification);
98 AttributeValueChangedNotification notification = new AttributeValueChangedNotificationBuilder()
99 .setAttributeName(eventNotification.getAttributeName()).setCounter(eventNotification.getCounter())
100 .setNewValue(eventNotification.getNewValue()).setObjectIdRef(eventNotification.getObjectId())
101 .setTimeStamp(eventNotification.getTimestamp()).build();
102 this.webSocketService.sendViaWebsockets(new NodeId(nodeId), notification, AttributeValueChangedNotification.QNAME,
103 eventNotification.getTimestamp());
107 public void changeNotification(NodeId nodeId, @Nullable Integer counter, @Nullable DateAndTime timeStamp,
108 @Nullable String objectId, @Nullable String attributeName, @Nullable String newValue) {
109 EventlogEntity eventlogEntity =
110 new EventlogNotificationBuilder(nodeId, counter, timeStamp, objectId, attributeName, newValue).build();
111 this.eventNotification(eventlogEntity);
115 public void creationNotification(NodeId nodeId, @Nullable Integer counter, @Nullable DateAndTime timeStamp,
116 @Nullable String objectId) {
117 EventlogEntity eventlogEntity =
118 new EventlogNotificationBuilder(nodeId, counter, timeStamp, objectId, "creation", null).build();
119 databaseService.writeEventLog(eventlogEntity);
120 ObjectCreationNotification notification = new ObjectCreationNotificationBuilder().setCounter(counter)
121 .setObjectIdRef(objectId).setTimeStamp(eventlogEntity.getTimestamp()).build();
122 this.webSocketService.sendViaWebsockets(nodeId, notification, ObjectCreationNotification.QNAME,
123 eventlogEntity.getTimestamp());
128 public void deletionNotification(NodeId nodeId, @Nullable Integer counter, @Nullable DateAndTime timeStamp,
129 @Nullable String objectId) {
130 EventlogEntity eventlogEntity =
131 new EventlogNotificationBuilder(nodeId, counter, timeStamp, objectId, "deletion", null).build();
132 databaseService.writeEventLog(eventlogEntity);
133 ObjectDeletionNotification notification = new ObjectDeletionNotificationBuilder().setCounter(counter)
134 .setObjectIdRef(objectId).setTimeStamp(eventlogEntity.getTimestamp()).build();
135 this.webSocketService.sendViaWebsockets(nodeId, notification, ObjectDeletionNotification.QNAME,
136 eventlogEntity.getTimestamp());
140 public void writeEquipment(NodeId nodeId, @NonNull EquipmentData equipment) {
141 HtAssert.nonnull(equipment);
142 List<Inventory> list = equipment.getList();
143 HtAssert.nonnull(list);
144 databaseService.writeInventory(nodeId.getValue(), list);
149 public void faultNotification(@NonNull FaultlogEntity faultNotification) {
150 databaseService.writeFaultLog(faultNotification);
151 databaseService.updateFaultCurrent(getFaultCurrent(faultNotification));
153 ProblemNotificationXml notificationXml = new ProblemNotificationXml(faultNotification);
154 String nodeName = faultNotification.getNodeId();
155 if (NotificationDelayFilter.isEnabled()) {
156 if (notificationXml.getSeverity() == InternalSeverity.NonAlarmed) {
157 this.notificationDelayService.getInstance(nodeName, this).clearAlarmNotification(notificationXml);
159 this.notificationDelayService.getInstance(nodeName, this).pushAlarmNotification(notificationXml);
162 this.pushAlarmIfNotInMaintenance(nodeName, notificationXml);
165 ProblemNotification notification = new ProblemNotificationBuilder().setCounter(faultNotification.getCounter())
166 .setObjectIdRef(faultNotification.getObjectId()).setTimeStamp(faultNotification.getTimestamp())
167 .setProblem(faultNotification.getProblem())
168 .setSeverity(InternalSeverity.toYang(faultNotification.getSeverity())).build();
169 this.webSocketService.sendViaWebsockets(new NodeId(faultNotification.getNodeId()), notification,
170 ProblemNotification.QNAME, faultNotification.getTimestamp());
173 private void pushAlarmIfNotInMaintenance(String nodeName, ProblemNotificationXml notificationXml) {
174 if (!this.maintenanceService.isONFObjectInMaintenance(new NodeId(nodeName), notificationXml.getObjectId(),
175 notificationXml.getProblem())) {
176 this.aotsDcaeForwarder.sendProblemNotification(new NodeId(nodeName), notificationXml);
178 LOG.debug("Notification will not be sent to external services. Device " + nodeName
179 + " is in maintenance mode");
184 public int removeAllCurrentProblemsOfNode(@NonNull NodeId nodeId) {
185 int deleted = databaseService.clearFaultsCurrentOfNode(nodeId.getValue());
190 public void initCurrentProblemStatus(@NonNull NodeId nodeId, FaultData resultList) {
191 resultList.getProblemList().forEach(problem -> {
192 FaultcurrentBuilder bFaultcurrent = new FaultcurrentBuilder();
193 bFaultcurrent.fieldsFrom(problem);
194 databaseService.updateFaultCurrent(bFaultcurrent.build());
199 public int removeObjectsCurrentProblemsOfNode(@NonNull NodeId nodeId, String objectId) {
200 int deleted = databaseService.clearFaultsCurrentOfNodeWithObjectId(nodeId.getValue(), objectId);
204 private Faultcurrent getFaultCurrent(@NonNull FaultlogEntity problem) {
205 FaultcurrentBuilder bFaultcurrent = new FaultcurrentBuilder();
206 bFaultcurrent.fieldsFrom(problem);
207 return bFaultcurrent.build();
212 public void onNotificationDelay(String nodeName, ProblemNotificationXml notification) {
213 LOG.debug("Got delayed event of type :: {}", ProblemNotificationXml.class.getSimpleName());
214 this.pushAlarmIfNotInMaintenance(nodeName, notification);