9a0deae857011a4b91131361e0768eabb444aa99
[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
25 package org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.handler;
26
27 import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.DataProvider;
28 import org.onap.ccsdk.features.sdnr.wt.devicemanager.dcaeconnector.impl.DcaeForwarderInternal;
29 import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.PushNotifications;
30 import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.xml.AttributeValueChangedNotificationXml;
31 import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.xml.ProblemNotificationXml;
32 import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.xml.WebSocketServiceClientInternal;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.EventlogBuilder;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.EventlogEntity;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.FaultcurrentBuilder;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.FaultcurrentEntity;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.FaultlogBuilder;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.FaultlogEntity;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.SourceType;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.devicemanager.rev190109.PushAttributeChangeNotificationInput;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.devicemanager.rev190109.PushFaultNotificationInput;
42 import org.slf4j.Logger;
43 import org.slf4j.LoggerFactory;
44
45 public class RpcPushNotificationsHandler implements PushNotifications {
46
47     private static final Logger LOG = LoggerFactory.getLogger(RpcPushNotificationsHandler.class);
48
49     private static String OWNKEYNAME = "VES";
50     private final WebSocketServiceClientInternal webSocketService;
51     private final DataProvider databaseService;
52     private final DcaeForwarderInternal aotsDcaeForwarder;
53
54     public RpcPushNotificationsHandler(WebSocketServiceClientInternal webSocketService, DataProvider databaseService,
55             DcaeForwarderInternal aotsDcaeForwarder) {
56         super();
57         this.webSocketService = webSocketService;
58         this.databaseService = databaseService;
59         this.aotsDcaeForwarder = aotsDcaeForwarder;
60     }
61
62     @Override
63     public void pushAttributeChangeNotification(PushAttributeChangeNotificationInput input) {
64
65         LOG.debug("Got attribute change event {}", input);
66
67         EventlogBuilder enventlogBuilder = new EventlogBuilder();
68         enventlogBuilder.setSourceType(SourceType.Ves);
69         enventlogBuilder.fieldsFrom(input);
70         EventlogEntity eventlogEntity = enventlogBuilder.build();
71         databaseService.writeEventLog(eventlogEntity);
72         webSocketService.sendViaWebsockets(OWNKEYNAME, new AttributeValueChangedNotificationXml(eventlogEntity));
73
74     }
75
76     @Override
77     public void pushFaultNotification(PushFaultNotificationInput input) {
78
79         LOG.debug("Got fault event {}", input);
80
81         FaultlogBuilder faultlogBuilder = new FaultlogBuilder();
82         faultlogBuilder.setSourceType(SourceType.Ves);
83         faultlogBuilder.fieldsFrom(input);
84         FaultlogEntity faultlogEntity = faultlogBuilder.build();
85         databaseService.writeFaultLog(faultlogEntity);
86
87         FaultcurrentBuilder faultcurrentBuilder = new FaultcurrentBuilder();
88         faultcurrentBuilder.fieldsFrom(input);
89         FaultcurrentEntity faultcurrentEntity = faultcurrentBuilder.build();
90         databaseService.updateFaultCurrent(faultcurrentEntity);
91
92         ProblemNotificationXml notificationXml = new ProblemNotificationXml(faultlogEntity);
93         aotsDcaeForwarder.sendProblemNotificationUsingMaintenanceFilter(OWNKEYNAME, notificationXml);
94         webSocketService.sendViaWebsockets(OWNKEYNAME, notificationXml);
95     }
96
97 }