import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.Objects;
import java.util.Optional;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import javax.annotation.Nullable;
-
import org.eclipse.jdt.annotation.NonNull;
import org.onap.ccsdk.features.sdnr.wt.common.configuration.ConfigurationFileRepresentation;
import org.onap.ccsdk.features.sdnr.wt.common.configuration.filechange.IConfigChangedListener;
import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfNodeStateListener;
import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfNodeStateService;
import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.VesNotificationListener;
+import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.impl.access.NetconfAccessorManager;
+import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.impl.access.NetconfCommunicatorManager;
+import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.impl.access.dom.DomContext;
import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.impl.conf.NetconfStateConfig;
import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.impl.conf.odlAkka.AkkaConfig;
import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.impl.conf.odlAkka.ClusterConfig;
import org.opendaylight.mdsal.binding.api.DataTreeChangeListener;
import org.opendaylight.mdsal.binding.api.DataTreeIdentifier;
import org.opendaylight.mdsal.binding.api.DataTreeModification;
-import org.opendaylight.mdsal.binding.api.MountPoint;
import org.opendaylight.mdsal.binding.api.MountPointService;
import org.opendaylight.mdsal.binding.api.NotificationPublishService;
import org.opendaylight.mdsal.binding.api.RpcProviderService;
+import org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer;
import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
+import org.opendaylight.mdsal.dom.api.DOMMountPointService;
import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider;
import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceRegistration;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNode;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeKey;
import org.opendaylight.yangtools.concepts.ListenerRegistration;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.opendaylight.yangtools.yang.model.parser.api.YangParserException;
+import org.opendaylight.yangtools.yang.model.parser.api.YangParserFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
private static final Logger LOG = LoggerFactory.getLogger(NetconfNodeStateServiceImpl.class);
private static final String APPLICATION_NAME = "NetconfNodeStateService";
- @SuppressWarnings("unused")
private static final String CONFIGURATIONFILE = "etc/netconfnode-status-service.properties";
- @SuppressWarnings("null")
private static final @NonNull InstanceIdentifier<Topology> NETCONF_TOPO_IID =
InstanceIdentifier.create(NetworkTopology.class).child(Topology.class,
new TopologyKey(new TopologyId(TopologyNetconf.QNAME.getLocalName())));
- @SuppressWarnings("null")
private static final @NonNull InstanceIdentifier<Node> NETCONF_NODE_TOPO_IID =
InstanceIdentifier.create(NetworkTopology.class)
.child(Topology.class, new TopologyKey(new TopologyId(TopologyNetconf.QNAME.getLocalName())))
.child(Node.class);
- private static final DataTreeIdentifier<Node> NETCONF_NODE_TOPO_TREE_ID =
+ private static final @NonNull DataTreeIdentifier<Node> NETCONF_NODE_TOPO_TREE_ID =
DataTreeIdentifier.create(LogicalDatastoreType.OPERATIONAL, NETCONF_NODE_TOPO_IID);
// Name of ODL controller NETCONF instance
// -- OSGi services, provided
private DataBroker dataBroker;
private MountPointService mountPointService;
+ private DOMMountPointService domMountPointService;
private RpcProviderService rpcProviderRegistry;
private IEntityDataProvider iEntityDataProvider;
@SuppressWarnings("unused")
private NotificationPublishService notificationPublishService;
@SuppressWarnings("unused")
private ClusterSingletonServiceProvider clusterSingletonServiceProvider;
+ private YangParserFactory yangParserFactory;
+ private BindingNormalizedNodeSerializer bindingNormalizedNodeSerializer;
// -- Parameter
private ListenerRegistration<L1> listenerL1;
private Boolean initializationSuccessful;
/** Manager accessor objects for connection **/
- private final NetconfAccessorManager accessorManager;
+ private NetconfAccessorManager accessorManager;
/** List of all registered listeners **/
private final List<NetconfNodeConnectListener> netconfNodeConnectListenerList;
private ConfigurationFileRepresentation configFileRepresentation;
private NetconfStateConfig config;
+ private NetconfCommunicatorManager netconfCommunicatorManager;
+ private DomContext domContext;
/** Blueprint **/
public NetconfNodeStateServiceImpl() {
this.dataBroker = null;
this.mountPointService = null;
+ this.domMountPointService = null;
this.rpcProviderRegistry = null;
this.notificationPublishService = null;
this.clusterSingletonServiceProvider = null;
+ this.yangParserFactory = null;
+ this.domContext = null;
this.listenerL1 = null;
this.listenerL2 = null;
this.netconfNodeConnectListenerList = new CopyOnWriteArrayList<>();
this.netconfNodeStateListenerList = new CopyOnWriteArrayList<>();
this.vesNotificationListenerList = new CopyOnWriteArrayList<>();
- this.accessorManager = new NetconfAccessorManager();
+ this.accessorManager = null;
this.handlingPool = new HashMap<>();
}
this.mountPointService = mountPointService;
}
+ public void setDomMountPointService(DOMMountPointService domMountPointService) {
+ this.domMountPointService = domMountPointService;
+ }
+
public void setClusterSingletonService(ClusterSingletonServiceProvider clusterSingletonService) {
this.clusterSingletonServiceProvider = clusterSingletonService;
}
this.iEntityDataProvider = iEntityDataProvider;
}
- /** Blueprint initialization **/
+ public void setYangParserFactory(YangParserFactory yangParserFactory) {
+ this.yangParserFactory = yangParserFactory;
+ }
+
+ public void setBindingNormalizedNodeSerializer(BindingNormalizedNodeSerializer bindingNormalizedNodeSerializer) {
+ this.bindingNormalizedNodeSerializer = bindingNormalizedNodeSerializer;
+ }
+
+ /** Blueprint initialization
+ * @throws YangParserException **/
public void init() {
LOG.info("Session Initiated start {}", APPLICATION_NAME);
-
+ this.domContext = new DomContext(this.yangParserFactory, this.bindingNormalizedNodeSerializer);
+ this.netconfCommunicatorManager = new NetconfCommunicatorManager(mountPointService, domMountPointService, domContext);
+ this.accessorManager = new NetconfAccessorManager(netconfCommunicatorManager, domContext);
// Start RPC Service
this.rpcApiService = new NetconfnodeStateServiceRpcApiImpl(rpcProviderRegistry, vesNotificationListenerList);
// Get configuration
close();
}
- /**
- * Getter
- *
- * @return NetconfnodeStateServiceRpcApiImpl
- */
+ public DomContext getDomContext() {
+ return Objects.requireNonNull(domContext, "Initialization not completed for domContext" );
+ }
+
public NetconfnodeStateServiceRpcApiImpl getNetconfnodeStateServiceRpcApiImpl() {
- return rpcApiService;
+ return Objects.requireNonNull(rpcApiService, "Initialization not completed for rpcApiService" );
}
@Override
/**
* Indication if init() of this bundle successfully done.
- *
+ *
* @return true if init() was successful. False if not done or not successful.
*/
public boolean isInitializationSuccessful() {
/**
* For each mounted device a mountpoint is created and this listener is called. Mountpoint was created or existing.
* Managed device is now fully connected to node/mountpoint.
- *
+ *
* @param nNodeId id of the mountpoint
* @param netconfNode mountpoint contents
*/
boolean isNetconfNodeMaster = isNetconfNodeMaster(netconfNode);
LOG.info("isNetconfNodeMaster indication {} for mountpoint {}", isNetconfNodeMaster, mountPointNodeName);
if (isNetconfNodeMaster) {
+ NetconfAccessor acessor = accessorManager.getAccessor(nNodeId, netconfNode);
+ /*
+ * --> Call Listers for onConnect() Indication
+ for (all)
+ */
+ netconfNodeConnectListenerList.forEach(item -> {
+ try {
+ item.onEnterConnected(acessor);
+ } catch (Exception e) {
+ LOG.info("Exception during onEnterConnected listener call", e);
+ }
+ });
- InstanceIdentifier<Node> instanceIdentifier =
- NETCONF_TOPO_IID.child(Node.class, new NodeKey(new NodeId(mountPointNodeName)));
-
- Optional<MountPoint> optionalMountPoint = mountPointService.getMountPoint(instanceIdentifier);
- if (!optionalMountPoint.isPresent()) {
- LOG.warn("No mountpoint available for Netconf device :: Name : {} ", mountPointNodeName);
- } else {
- // Mountpoint is present for sure
- MountPoint mountPoint = optionalMountPoint.get();
- // BindingDOMDataBrokerAdapter.BUILDER_FACTORY;
- LOG.info("Mountpoint with id: {} class:{}", mountPoint.getIdentifier(),
- mountPoint.getClass().getName());
-
- Optional<DataBroker> optionalNetconfNodeDatabroker = mountPoint.getService(DataBroker.class);
-
- if (!optionalNetconfNodeDatabroker.isPresent()) {
- LOG.info("Slave mountpoint {} without databroker", mountPointNodeName);
- } else {
- LOG.info("Master mountpoint {}", mountPointNodeName);
- DataBroker netconfNodeDataBroker = optionalNetconfNodeDatabroker.get();
- NetconfAccessor acessor =
- accessorManager.getAccessor(nNodeId, netconfNode, netconfNodeDataBroker, mountPoint);
- /*
- * --> Call Listers for onConnect() Indication
- for (all)
- */
- netconfNodeConnectListenerList.forEach(item -> {
- try {
- item.onEnterConnected(acessor);
- } catch (Exception e) {
- LOG.info("Exception during onEnterConnected listener call", e);
- }
- });
-
- LOG.info("Connect indication forwarded for {}", mountPointNodeName);
- }
- }
+ LOG.info("Connect indication forwarded for {}", mountPointNodeName);
}
}
/**
* Leave the connected status to a non connected or removed status for master mountpoint
- *
+ *
* @param action that occurred
* @param nNodeId id of the mountpoint
* @param netconfNode mountpoint contents or not available on remove
if (this.isCluster) {
LOG.debug("check if me is responsible for node");
ClusteredConnectionStatus ccs = nNode.getClusteredConnectionStatus();
- @SuppressWarnings("null")
@NonNull
String masterNodeName =
ccs == null || ccs.getNetconfMasterNode() == null ? "null" : ccs.getNetconfMasterNode();
return true;
}
+
+
@Override
public void onConfigChanged() {
this.handleDataTreeAsync = this.config.handleAsync();