Merge "SDN-R add updated devicemanager"
[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.xml.ProblemNotificationXml;
26 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.MaintenanceService;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
29
30 public class DcaeForwarderImpl implements DcaeForwarderInternal, AutoCloseable {
31
32     private static final Logger LOG = LoggerFactory.getLogger(DcaeForwarderImpl.class);
33
34     private final @Nullable ProviderClient aotsmClient;
35     private final ProviderClient dcaeProvider;
36     private final MaintenanceService maintenanceService;
37
38     public DcaeForwarderImpl(@Nullable ProviderClient aotsmClient, @Nullable ProviderClient dcaeProvider,
39             @NonNull MaintenanceService maintenanceService) {
40         super();
41
42         HtAssert.nonnull(maintenanceService);
43         this.aotsmClient = aotsmClient;
44         this.dcaeProvider = dcaeProvider;
45         this.maintenanceService = maintenanceService;
46     }
47
48     @Override
49     @SuppressWarnings("null")
50     public void sendProblemNotificationUsingMaintenanceFilter(String nodeId, ProblemNotificationXml notificationXml) {
51         if (!this.maintenanceService.isONFObjectInMaintenance(nodeId, notificationXml.getObjectId(),
52                 notificationXml.getProblem())) {
53             if (dcaeProvider != null) {
54                 this.dcaeProvider.sendProblemNotification(nodeId, notificationXml);
55             }
56             if (this.aotsmClient != null) {
57                 this.aotsmClient.sendProblemNotification(nodeId, notificationXml);
58             }
59         } else {
60             LOG.debug("Notification will not be sent to external services. Device " + nodeId
61                     + " is in maintenance mode");
62         }
63     }
64
65     @Override
66     public void sendProblemNotification(String nodeId, ProblemNotificationXml notificationXml) {
67         //to prevent push alarms on reconnect
68         //=> only pushed alarms are forwared to dcae
69         //dcaeProvider.sendProblemNotification(nodeName, notificationXml);
70         if(aotsmClient!=null) {
71             aotsmClient.sendProblemNotification(nodeId, notificationXml);
72         }
73
74     }
75
76     @Override
77     public void close() throws Exception {
78     }
79
80 }