57f258b3b4460bebc17e20797a47bc31dc85e208
[ccsdk/features.git] /
1 /*
2  * ============LICENSE_START=======================================================
3  * ONAP : ccsdk features
4  * ================================================================================
5  * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property.
6  * All rights reserved.
7  * ================================================================================
8  * Update Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
9  * ================================================================================
10  * Licensed under the Apache License, Version 2.0 (the "License");
11  * you may not use this file except in compliance with the License.
12  * You may obtain a copy of the License at
13  *
14  *     http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  * ============LICENSE_END=======================================================
22  *
23  */
24 package org.onap.ccsdk.features.sdnr.wt.devicemanager.eventdatahandler;
25
26 import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.DataProvider;
27 import org.onap.ccsdk.features.sdnr.wt.devicemanager.dcaeconnector.impl.DcaeForwarderInternal;
28 import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.PushNotifications;
29 import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.util.InternalSeverity;
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.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.EventlogBuilder;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.EventlogEntity;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.FaultcurrentBuilder;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.FaultcurrentEntity;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.FaultlogBuilder;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.FaultlogEntity;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.SourceType;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.devicemanager.rev190109.AttributeValueChangedNotification;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.devicemanager.rev190109.AttributeValueChangedNotificationBuilder;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.devicemanager.rev190109.ProblemNotification;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.devicemanager.rev190109.ProblemNotificationBuilder;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.devicemanager.rev190109.PushAttributeChangeNotificationInput;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.devicemanager.rev190109.PushFaultNotificationInput;
45 import org.slf4j.Logger;
46 import org.slf4j.LoggerFactory;
47
48 public class RpcPushNotificationsHandler implements PushNotifications {
49
50     private static final Logger LOG = LoggerFactory.getLogger(RpcPushNotificationsHandler.class);
51
52     private static final String OWNKEYNAME = "VES";
53     private final WebSocketServiceClientInternal webSocketService;
54     private final DataProvider databaseService;
55     private final DcaeForwarderInternal aotsDcaeForwarder;
56
57     public RpcPushNotificationsHandler(WebSocketServiceClientInternal webSocketService, DataProvider databaseService,
58             DcaeForwarderInternal aotsDcaeForwarder) {
59         super();
60         this.webSocketService = webSocketService;
61         this.databaseService = databaseService;
62         this.aotsDcaeForwarder = aotsDcaeForwarder;
63     }
64
65     @Override
66     public void pushAttributeChangeNotification(PushAttributeChangeNotificationInput input) {
67
68         LOG.debug("Got attribute change event {}", input);
69
70         EventlogBuilder enventlogBuilder = new EventlogBuilder();
71         enventlogBuilder.setSourceType(SourceType.Ves);
72         enventlogBuilder.fieldsFrom(input);
73         EventlogEntity eventlogEntity = enventlogBuilder.build();
74         databaseService.writeEventLog(eventlogEntity);
75         AttributeValueChangedNotification notification =
76                 new AttributeValueChangedNotificationBuilder().setAttributeName(input.getAttributeName())
77                         .setCounter(input.getCounter()).setNewValue(input.getNewValue())
78                         .setObjectIdRef(input.getObjectId()).setTimeStamp(input.getTimestamp()).build();
79         webSocketService.sendViaWebsockets(OWNKEYNAME, notification, AttributeValueChangedNotification.QNAME,
80                 input.getTimestamp());
81
82     }
83
84     @Override
85     public void pushFaultNotification(PushFaultNotificationInput input) {
86
87         LOG.debug("Got fault event {}", input);
88
89         FaultlogBuilder faultlogBuilder = new FaultlogBuilder();
90         faultlogBuilder.setSourceType(SourceType.Ves);
91         faultlogBuilder.fieldsFrom(input);
92         FaultlogEntity faultlogEntity = faultlogBuilder.build();
93         databaseService.writeFaultLog(faultlogEntity);
94
95         FaultcurrentBuilder faultcurrentBuilder = new FaultcurrentBuilder();
96         faultcurrentBuilder.fieldsFrom(input);
97         FaultcurrentEntity faultcurrentEntity = faultcurrentBuilder.build();
98         databaseService.updateFaultCurrent(faultcurrentEntity);
99
100         ProblemNotificationXml notificationXml = new ProblemNotificationXml(faultlogEntity);
101         ProblemNotification notification = new ProblemNotificationBuilder().setProblem(input.getProblem())
102                 .setCounter(input.getCounter()).setObjectIdRef(input.getObjectId())
103                 .setSeverity(InternalSeverity.toYang(input.getSeverity())).setTimeStamp(input.getTimestamp()).build();
104         aotsDcaeForwarder.sendProblemNotificationUsingMaintenanceFilter(OWNKEYNAME, notificationXml);
105         webSocketService.sendViaWebsockets(OWNKEYNAME, notification, ProblemNotification.QNAME, input.getTimestamp());
106     }
107
108 }