update websocketmanager
[ccsdk/features.git] / sdnr / wt / netconfnode-state-service / provider / src / main / java / org / onap / ccsdk / features / sdnr / wt / netconfnodestateservice / impl / access / NetconfAccessorImpl.java
1 /*
2  * ============LICENSE_START========================================================================
3  * ONAP : ccsdk feature sdnr wt
4  * =================================================================================================
5  * Copyright (C) 2020 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 package org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.impl.access;
19
20 import java.util.Objects;
21 import java.util.Optional;
22 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.Capabilities;
23 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfAccessor;
24 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfBindingAccessor;
25 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfDomAccessor;
26 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.impl.NetconfNodeStateServiceImpl;
27 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.impl.access.dom.DomContext;
28 import org.opendaylight.mdsal.binding.api.DataBroker;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNode;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNodeConnectionStatus.ConnectionStatus;
31 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
32 import org.slf4j.Logger;
33 import org.slf4j.LoggerFactory;
34
35 public class NetconfAccessorImpl implements NetconfAccessor {
36
37     @SuppressWarnings("unused")
38     private static final Logger LOG = LoggerFactory.getLogger(NetconfAccessorImpl.class);
39
40     private final NodeId nodeId;
41     private final NetconfNode netconfNode;
42     private final Capabilities capabilities;
43     private final NetconfCommunicatorManager netconfCommunicatorManager;
44     private final DomContext domContext;
45     private final NetconfNodeStateServiceImpl netconfNodeStateService;
46     /**
47      * Contains all data to access and manage netconf device
48      *
49      * @param netconfCommunicatorManager
50      *
51      * @param nodeId of managed netconf node
52      * @param netconfNode information
53      * @param domContext
54      * @param dataBroker to access node
55      * @param mountpoint of netconfNode
56      */
57      public NetconfAccessorImpl(NodeId nodeId, NetconfNode netconfNode,
58             NetconfCommunicatorManager netconfCommunicatorManager, DomContext domContext, NetconfNodeStateServiceImpl netconfNodeStateService) {
59         super();
60         this.nodeId = Objects.requireNonNull(nodeId);
61         this.netconfNode = Objects.requireNonNull(netconfNode);
62         this.netconfCommunicatorManager = Objects.requireNonNull(netconfCommunicatorManager);
63         this.domContext = Objects.requireNonNull(domContext);
64         this.netconfNodeStateService = Objects.requireNonNull(netconfNodeStateService);
65
66         ConnectionStatus csts = netconfNode != null ? netconfNode.getConnectionStatus() : null;
67         if (csts == null) {
68             throw new IllegalStateException(String.format("connection status for %s is not connected", nodeId));
69         }
70         Capabilities tmp = Capabilities.getAvailableCapabilities(netconfNode);
71         if (tmp.getCapabilities().size() <= 0) {
72             throw new IllegalStateException(String.format("no capabilities found for %s", nodeId));
73         }
74         this.capabilities = tmp;
75     }
76
77     public NetconfAccessorImpl(NetconfAccessorImpl accessor) {
78         this.nodeId = accessor.getNodeId();
79         this.netconfNode = accessor.getNetconfNode();
80         this.capabilities = accessor.getCapabilites();
81         this.netconfCommunicatorManager = accessor.netconfCommunicatorManager;
82         this.domContext = accessor.domContext;
83         this.netconfNodeStateService = accessor.netconfNodeStateService;
84     }
85
86     @Override
87     public NodeId getNodeId() {
88         return nodeId;
89     }
90
91     @Override
92     public NetconfNode getNetconfNode() {
93         return netconfNode;
94     }
95
96     @Override
97     public Capabilities getCapabilites() {
98         return capabilities;
99     }
100
101     @Override
102     public Optional<NetconfBindingAccessor> getNetconfBindingAccessor() {
103         return netconfCommunicatorManager.getNetconfBindingAccessor(this);
104     }
105
106     @Override
107     public Optional<NetconfDomAccessor> getNetconfDomAccessor() {
108         return netconfCommunicatorManager.getNetconfDomAccessor(this);
109     }
110
111     @Override
112     public DataBroker getControllerBindingDataBroker() {
113         return netconfNodeStateService.getDataBroker();
114     }
115
116     /**
117      * check if nc-notifications.yang is supported by the device
118      */
119     @Override
120     public boolean isNotificationsRFC5277Supported() {
121         return getCapabilites().isSupportingNamespace("urn:ietf:params:netconf:capability:notification:1.0");
122     }
123
124 }