Merge "YANG Model update for A1 Adapter"
[ccsdk/features.git] / sdnr / wt / devicemanager / provider / src / main / java / org / onap / ccsdk / features / sdnr / wt / devicemanager / dcaeconnector / impl / DcaeForwarderImpl.java
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
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
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
15  * the License.
16  * ============LICENSE_END==========================================================================
17  ******************************************************************************/
18
19 package org.onap.ccsdk.features.sdnr.wt.devicemanager.dcaeconnector.impl;
20
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.devicemanager.impl.ProviderClient;
25 import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.handler.NetconfEventListenerHandler12;
26 import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.xml.ProblemNotificationXml;
27 import org.onap.ccsdk.features.sdnr.wt.devicemanager.maintenance.MaintenanceService;
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
30
31 public class DcaeForwarderImpl implements DcaeForwarderInternal, AutoCloseable {
32
33     private static final Logger LOG = LoggerFactory.getLogger(NetconfEventListenerHandler12.class);
34
35     private final @Nullable ProviderClient aotsmClient;
36     private final ProviderClient dcaeProvider;
37     private final MaintenanceService maintenanceService;
38
39     public DcaeForwarderImpl(@Nullable ProviderClient aotsmClient, @Nullable ProviderClient dcaeProvider,
40             @NonNull MaintenanceService maintenanceService) {
41         super();
42
43         HtAssert.nonnull(maintenanceService);
44         this.aotsmClient = aotsmClient;
45         this.dcaeProvider = dcaeProvider;
46         this.maintenanceService = maintenanceService;
47     }
48
49     @Override
50         @SuppressWarnings("null")
51     public void sendProblemNotificationUsingMaintenanceFilter(String nodeId, ProblemNotificationXml notificationXml) {
52         if (!this.maintenanceService.isONFObjectInMaintenance(nodeId, notificationXml.getObjectId(),
53                 notificationXml.getProblem())) {
54             if (dcaeProvider != null) {
55                 this.dcaeProvider.sendProblemNotification(nodeId, notificationXml);
56             }
57             if (this.aotsmClient != null) {
58                 this.aotsmClient.sendProblemNotification(nodeId, notificationXml);
59             }
60         } else {
61             LOG.debug("Notification will not be sent to external services. Device " + nodeId
62                     + " is in maintenance mode");
63         }
64     }
65
66     @Override
67         public void sendProblemNotification(String nodeId, ProblemNotificationXml notificationXml) {
68         //to prevent push alarms on reconnect
69         //=> only pushed alarms are forwared to dcae
70         //dcaeProvider.sendProblemNotification(nodeName, notificationXml);
71         if(aotsmClient!=null) {
72             aotsmClient.sendProblemNotification(nodeId, notificationXml);
73         }
74
75     }
76
77     @Override
78     public void close() throws Exception {
79     }
80
81 }