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
 
  10  * http://www.apache.org/licenses/LICENSE-2.0
 
  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
 
  16  * ============LICENSE_END==========================================================================
 
  18 package org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.impl.access;
 
  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.rev221225.NetconfNode;
 
  27 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev221225.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;
 
  37 public class NetconfAccessorManager {
 
  39     private static final Logger LOG = LoggerFactory.getLogger(NetconfNodeStateServiceImpl.class);
 
  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())));
 
  45     private final ConcurrentHashMap<NodeId, NetconfAccessor> accessorList;
 
  46     private final NetconfCommunicatorManager netconfCommunicatorManager;
 
  47     private final DomContext domContext;
 
  48     private final NetconfNodeStateServiceImpl netconfNodeStateService;
 
  50     public NetconfAccessorManager(NetconfCommunicatorManager netconfCommunicatorManager, DomContext domContext, NetconfNodeStateServiceImpl netconfNodeStateService) {
 
  51         this.netconfCommunicatorManager = Objects.requireNonNull(netconfCommunicatorManager);
 
  52         this.domContext = Objects.requireNonNull(domContext);
 
  53         this.accessorList = new ConcurrentHashMap<>();
 
  54         this.netconfNodeStateService = Objects.requireNonNull(netconfNodeStateService);
 
  57     public NetconfAccessor getAccessor(NodeId nNodeId, NetconfNode netconfNode) {
 
  58         NetconfAccessor res = new NetconfAccessorImpl(nNodeId, netconfNode, netconfCommunicatorManager, domContext, netconfNodeStateService);
 
  59         NetconfAccessor previouse = accessorList.putIfAbsent(nNodeId, res);
 
  60         if (Objects.nonNull(previouse)) {
 
  61             LOG.warn("Accessor with name already available. Don't add {}", nNodeId);
 
  66     public boolean containes(NodeId nNodeId) {
 
  67         return accessorList.containsKey(nNodeId);
 
  70     public void removeAccessor(NodeId nNodeId) {
 
  71         NetconfAccessor previouse = accessorList.remove(nNodeId);
 
  72         if (Objects.nonNull(previouse)) {
 
  73             LOG.warn("Accessor with name was not available during remove {}", nNodeId);