2801934027ee05730abd0ea50bbc5f217150658b
[ccsdk/features.git] /
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 package org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.impl.access;
19
20 import java.util.Objects;
21 import java.util.concurrent.ConcurrentHashMap;
22 import org.eclipse.jdt.annotation.NonNull;
23 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfAccessor;
24 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.impl.NetconfNodeStateServiceImpl;
25 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.impl.access.dom.DomContext;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNode;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.network.topology.topology.topology.types.TopologyNetconf;
28 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology;
29 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
30 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TopologyId;
31 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
32 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey;
33 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
34 import org.slf4j.Logger;
35 import org.slf4j.LoggerFactory;
36
37 public class NetconfAccessorManager {
38
39     private static final Logger LOG = LoggerFactory.getLogger(NetconfNodeStateServiceImpl.class);
40
41     private static final @NonNull InstanceIdentifier<Topology> NETCONF_TOPO_IID =
42             InstanceIdentifier.create(NetworkTopology.class).child(Topology.class,
43                     new TopologyKey(new TopologyId(TopologyNetconf.QNAME.getLocalName())));
44
45     private final ConcurrentHashMap<NodeId, NetconfAccessor> accessorList;
46     private final NetconfCommunicatorManager netconfCommunicatorManager;
47     private final DomContext domContext;
48
49     public NetconfAccessorManager(NetconfCommunicatorManager netconfCommunicatorManager, DomContext domContext) {
50         this.netconfCommunicatorManager = Objects.requireNonNull(netconfCommunicatorManager);
51         this.domContext = Objects.requireNonNull(domContext);
52         this.accessorList = new ConcurrentHashMap<>();
53     }
54
55     public NetconfAccessor getAccessor(NodeId nNodeId, NetconfNode netconfNode) {
56         NetconfAccessor res = new NetconfAccessorImpl(nNodeId, netconfNode, netconfCommunicatorManager, domContext);
57         NetconfAccessor previouse = accessorList.put(nNodeId, res);
58         if (Objects.nonNull(previouse)) {
59             LOG.warn("Accessor with name already available. Replaced with new one.");
60         }
61         return res;
62     }
63
64     public boolean containes(NodeId nNodeId) {
65         return accessorList.containsKey(nNodeId);
66     }
67
68     public void removeAccessor(NodeId nNodeId) {
69         accessorList.remove(nNodeId);
70     }
71
72
73
74 }