5ff6caf56b71f0be8856c1bcbf6f8701dba8675c
[ccsdk/features.git] /
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.access.dom.DomContext;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNode;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNodeConnectionStatus.ConnectionStatus;
29 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
32
33 public class NetconfAccessorImpl implements NetconfAccessor {
34
35     @SuppressWarnings("unused")
36     private static final Logger LOG = LoggerFactory.getLogger(NetconfAccessorImpl.class);
37
38     private final NodeId nodeId;
39     private final NetconfNode netconfNode;
40     private final Capabilities capabilities;
41     private final NetconfCommunicatorManager netconfCommunicatorManager;
42     private final DomContext domContext;
43
44     /**
45      * Contains all data to access and manage netconf device
46      *
47      * @param netconfCommunicatorManager
48      *
49      * @param nodeId of managed netconf node
50      * @param netconfNode information
51      * @param domContext
52      * @param dataBroker to access node
53      * @param mountpoint of netconfNode
54      */
55     public NetconfAccessorImpl(NodeId nodeId, NetconfNode netconfNode,
56             NetconfCommunicatorManager netconfCommunicatorManager, DomContext domContext) {
57         super();
58         this.nodeId = Objects.requireNonNull(nodeId);
59         this.netconfNode = Objects.requireNonNull(netconfNode);
60         this.netconfCommunicatorManager = Objects.requireNonNull(netconfCommunicatorManager);
61         this.domContext = Objects.requireNonNull(domContext);
62
63         ConnectionStatus csts = netconfNode != null ? netconfNode.getConnectionStatus() : null;
64         if (csts == null) {
65             throw new IllegalStateException(String.format("connection status for %s is not connected", nodeId));
66         }
67         Capabilities tmp = Capabilities.getAvailableCapabilities(netconfNode);
68         if (tmp.getCapabilities().size() <= 0) {
69             throw new IllegalStateException(String.format("no capabilities found for %s", nodeId));
70         }
71         this.capabilities = tmp;
72     }
73
74     /**
75      * @param nodeId with uuid of managed netconf node
76      * @param dataBroker to access node
77      */
78     public NetconfAccessorImpl(String nodeId, NetconfNode netconfNode,
79             NetconfCommunicatorManager netconfCommunicatorManager, DomContext domContext) {
80         this(new NodeId(nodeId), netconfNode, netconfCommunicatorManager, domContext);
81     }
82
83     protected NetconfAccessorImpl(NetconfAccessorImpl accessor) {
84         this.nodeId = accessor.nodeId;
85         this.netconfNode = accessor.netconfNode;
86         this.capabilities = accessor.capabilities;
87         this.netconfCommunicatorManager = accessor.netconfCommunicatorManager;
88         this.domContext = accessor.domContext;
89     }
90
91     @Override
92     public NodeId getNodeId() {
93         return nodeId;
94     }
95
96     @Override
97     public NetconfNode getNetconfNode() {
98         return netconfNode;
99     }
100
101     @Override
102     public Capabilities getCapabilites() {
103         return capabilities;
104     }
105
106     @Override
107     public Optional<NetconfBindingAccessor> getNetconfBindingAccessor() {
108         return netconfCommunicatorManager.getNetconfBindingAccessor(this);
109     }
110
111     @Override
112     public Optional<NetconfDomAccessor> getNetconfDomAccessor() {
113         return netconfCommunicatorManager.getNetconfDomAccessor(this);
114     }
115
116 }