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