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.datamanager;
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.impl.xml.AttributeValueChangedNotificationXml;
26 import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.xml.ObjectCreationNotificationXml;
27 import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.xml.ObjectDeletionNotificationXml;
28 import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.xml.ProblemNotificationXml;
29 import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.xml.WebSocketServiceClientInternal;
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.types.EquipmentData;
34 import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.EventlogNotificationBuilder;
35 import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.FaultData;
36 import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.FaultNotificationBuilder2;
37 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DateAndTime;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.EventlogEntity;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.Faultcurrent;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.FaultcurrentBuilder;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.FaultlogEntity;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.Inventory;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.SeverityType;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.SourceType;
45 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
51 public class DeviceManagerDatabaseNotificationService implements NotificationService, EquipmentService, FaultService {
53 private final DataProvider databaseService;
54 private final WebSocketServiceClientInternal webSocketService;
57 * @param databaseService to access database
58 * @param webSocketService to send notifications
60 public DeviceManagerDatabaseNotificationService(DataProvider databaseService,
61 WebSocketServiceClientInternal webSocketService) {
63 HtAssert.nonnull(databaseService);
64 HtAssert.nonnull(webSocketService);
66 this.databaseService = databaseService;
67 this.webSocketService = webSocketService;
71 public void eventNotification(@NonNull EventlogEntity eventNotification) {
72 String nodeId = eventNotification.getNodeId();
74 nodeId = "EmptyNodeId";
76 databaseService.writeEventLog(eventNotification);
77 webSocketService.sendViaWebsockets(nodeId, new AttributeValueChangedNotificationXml(eventNotification));
81 public void changeNotification(NodeId nodeId, @Nullable Integer counter, @Nullable DateAndTime timeStamp,
82 @Nullable String objectId, @Nullable String attributeName, @Nullable String newValue) {
83 EventlogEntity eventlogEntity = new EventlogNotificationBuilder(nodeId, counter, timeStamp, objectId, attributeName, newValue).build();
84 databaseService.writeEventLog(eventlogEntity);
85 webSocketService.sendViaWebsockets(nodeId.getValue(), new AttributeValueChangedNotificationXml(eventlogEntity));
89 public void creationNotification(NodeId nodeId, @Nullable Integer counter, @Nullable DateAndTime timeStamp,
90 @Nullable String objectId) {
91 EventlogEntity eventlogEntity = new EventlogNotificationBuilder(nodeId, counter, timeStamp, objectId, "creation", null).build();
92 databaseService.writeEventLog(eventlogEntity);
93 webSocketService.sendViaWebsockets(nodeId.getValue(), new ObjectCreationNotificationXml(eventlogEntity));
98 public void deletionNotification(NodeId nodeId, @Nullable Integer counter, @Nullable DateAndTime timeStamp,
99 @Nullable String objectId) {
100 EventlogEntity eventlogEntity = new EventlogNotificationBuilder(nodeId, counter, timeStamp, objectId, "deletion", null).build();
101 databaseService.writeEventLog(eventlogEntity);
102 webSocketService.sendViaWebsockets(nodeId.getValue(), new ObjectDeletionNotificationXml(eventlogEntity));
106 public void writeEquipment(@NonNull EquipmentData equipment) {
107 //equipment.getList().forEach(card -> databaseService.writeInventory(card));
108 HtAssert.nonnull(equipment);
109 List<Inventory> list = equipment.getList();
110 HtAssert.nonnull(list);
111 for (Inventory card : list) {
112 databaseService.writeInventory(card);
117 public void faultNotification(@NonNull FaultlogEntity faultNotification) {
118 databaseService.writeFaultLog(faultNotification);
119 databaseService.updateFaultCurrent(getFaultCurrent(faultNotification));
121 ProblemNotificationXml notificationXml = new ProblemNotificationXml(faultNotification);
122 String nodeName = faultNotification.getNodeId();
123 // ToggleAlarmFilter functionality
124 // if (delayFilter.processNotification(notificationXml.getSeverity() == InternalSeverity.NonAlarmed, notificationXml.getProblem(), notificationXml))
126 // dcaeForwarder.sendProblemNotificationUsingMaintenanceFilter(nodeName, notificationXml);
128 // end of ToggleAlarmFilter
130 this.webSocketService.sendViaWebsockets(nodeName, notificationXml);
134 public void faultNotification(@NonNull NodeId nodeId, @Nullable Integer counter, @Nullable DateAndTime timeStamp,
135 @Nullable String objectId, @Nullable String problem, @Nullable SeverityType severity) {
136 FaultNotificationBuilder2 bFaultlog = new FaultNotificationBuilder2(nodeId, counter, timeStamp, objectId, problem, severity, SourceType.Netconf);
137 faultNotification(bFaultlog.build());
142 public int removeAllCurrentProblemsOfNode(@NonNull NodeId nodeId) {
143 int deleted = databaseService.clearFaultsCurrentOfNode(nodeId.getValue());
148 public void initCurrentProblemStatus(@NonNull NodeId nodeId, FaultData resultList) {
149 resultList.getProblemList().forEach(problem -> {
150 FaultcurrentBuilder bFaultcurrent = new FaultcurrentBuilder();
151 bFaultcurrent.fieldsFrom(problem);
152 databaseService.updateFaultCurrent(bFaultcurrent.build());
157 public int removeObjectsCurrentProblemsOfNode(@NonNull NodeId nodeId, String objectId) {
158 int deleted = databaseService.clearFaultsCurrentOfNodeWithObjectId(nodeId.getValue(), objectId);
162 private Faultcurrent getFaultCurrent(@NonNull FaultlogEntity problem) {
163 FaultcurrentBuilder bFaultcurrent = new FaultcurrentBuilder();
164 bFaultcurrent.fieldsFrom(problem);
165 return bFaultcurrent.build();