30d4138283e1b4c335164975c2665e75f0ea3629
[ccsdk/features.git] /
1 /*
2  * ============LICENSE_START=======================================================
3  * ONAP : ccsdk features
4  * ================================================================================
5  * Copyright (C) 2023 highstreet technologies GmbH Intellectual Property.
6  * All rights reserved.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *     http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  *
21  */
22 package org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.rpc;
23
24 import com.google.common.util.concurrent.ListenableFuture;
25 import java.util.concurrent.TimeUnit;
26 import org.eclipse.jdt.annotation.NonNull;
27 import org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.config.ORanDMConfig;
28 import org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.util.ORanDeviceManagerQNames;
29 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfDomAccessor;
30 import org.opendaylight.mdsal.dom.api.DOMRpcResult;
31 import org.opendaylight.mdsal.dom.api.DOMRpcService;
32 import org.opendaylight.yangtools.yang.common.QName;
33 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
34 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
35 import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
36 import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
37 import org.slf4j.Logger;
38 import org.slf4j.LoggerFactory;
39
40 public class ORanSupervisionRPCImpl {
41
42     private static final Logger LOG = LoggerFactory.getLogger(ORanSupervisionRPCImpl.class);
43     private static NodeIdentifier inputNodeIdentifier =
44             NodeIdentifier.create(QName.create(ORanDeviceManagerQNames.ORAN_SUPERVISION_MODULE, "input"));
45     private static NodeIdentifier supervisionNotificationIntervalIdentifier = NodeIdentifier
46             .create(QName.create(ORanDeviceManagerQNames.ORAN_SUPERVISION_MODULE, "supervision-notification-interval"));
47     private static NodeIdentifier guardTimerOverheadIdentifier = NodeIdentifier
48             .create(QName.create(ORanDeviceManagerQNames.ORAN_SUPERVISION_MODULE, "guard-timer-overhead"));
49
50     public static void invokeWatchdogReset(@NonNull NetconfDomAccessor netconfDomAccessor,
51             ORanDMConfig oruSupervisionConfig) {
52
53         LOG.debug(
54                 "Resetting suppervision-notification-interval and guard-timer-overhead watchdog timers with values {} and {} respectively",
55                 oruSupervisionConfig.getNotificationInterval(), oruSupervisionConfig.getWatchdogTimer());
56         ContainerNode rpcInputNode = Builders.containerBuilder().withNodeIdentifier(inputNodeIdentifier)
57                 .withChild(ImmutableNodes.leafNode(supervisionNotificationIntervalIdentifier,
58                         oruSupervisionConfig.getNotificationInterval()))
59                 .withChild(
60                         ImmutableNodes.leafNode(guardTimerOverheadIdentifier, oruSupervisionConfig.getWatchdogTimer()))
61                 .build();
62
63         try {
64             DOMRpcService rpcService = netconfDomAccessor.getRpcService();
65             QName supervisionWatchdogResetQN =
66                     QName.create(ORanDeviceManagerQNames.ORAN_SUPERVISION_MODULE, "supervision-watchdog-reset");
67
68             ListenableFuture<? extends DOMRpcResult> result =
69                     rpcService.invokeRpc(supervisionWatchdogResetQN, rpcInputNode);
70             DOMRpcResult rpcResult = result.get(60000, TimeUnit.MILLISECONDS);
71             if (rpcResult.value() != null) {
72                 ContainerNode rpcResultCn = (ContainerNode) rpcResult.value();
73                 LOG.debug("Result of Supervision-Watchdog-Reset = {}", rpcResultCn.prettyTree());
74             }
75         } catch (Exception e) {
76             LOG.error("{}", e);
77         }
78         return;
79
80     }
81
82 }