Remove netconf-config
[netconf.git] / apps / netconf-topology / src / main / java / org / opendaylight / netconf / topology / spi / AbstractNetconfTopology.java
index 43921f32f5add08f4c6a069bafbf8ef342974eea..93f818cd78f5f0b84b598d3b65a04cb2cdb1d592 100644 (file)
@@ -10,25 +10,21 @@ package org.opendaylight.netconf.topology.spi;
 import static java.util.Objects.requireNonNull;
 
 import com.google.common.annotations.VisibleForTesting;
-import io.netty.util.concurrent.EventExecutor;
+import io.netty.util.Timer;
 import java.util.HashMap;
 import java.util.NoSuchElementException;
 import java.util.concurrent.ExecutionException;
-import java.util.concurrent.Executor;
-import java.util.concurrent.ScheduledExecutorService;
-import org.opendaylight.controller.config.threadpool.ScheduledThreadPool;
-import org.opendaylight.controller.config.threadpool.ThreadPool;
 import org.opendaylight.mdsal.binding.api.DataBroker;
 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
 import org.opendaylight.mdsal.dom.api.DOMMountPointService;
-import org.opendaylight.netconf.client.NetconfClientDispatcher;
+import org.opendaylight.netconf.client.NetconfClientFactory;
 import org.opendaylight.netconf.client.mdsal.api.BaseNetconfSchemas;
 import org.opendaylight.netconf.client.mdsal.api.DeviceActionFactory;
 import org.opendaylight.netconf.client.mdsal.api.RemoteDeviceHandler;
 import org.opendaylight.netconf.client.mdsal.api.RemoteDeviceId;
 import org.opendaylight.netconf.client.mdsal.api.SchemaResourceManager;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.optional.rev221225.NetconfNodeAugmentedOptional;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev221225.NetconfNode;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev231121.NetconfNode;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TopologyId;
@@ -44,29 +40,27 @@ public abstract class AbstractNetconfTopology {
     private static final Logger LOG = LoggerFactory.getLogger(AbstractNetconfTopology.class);
 
     private final HashMap<NodeId, NetconfNodeHandler> activeConnectors = new HashMap<>();
-    private final NetconfClientDispatcher clientDispatcher;
-    private final EventExecutor eventExecutor;
+    private final NetconfClientFactory clientFactory;
     private final DeviceActionFactory deviceActionFactory;
     private final SchemaResourceManager schemaManager;
     private final BaseNetconfSchemas baseSchemas;
     private final NetconfClientConfigurationBuilderFactory builderFactory;
+    private final Timer timer;
 
-    protected final ScheduledExecutorService keepaliveExecutor;
-    protected final Executor processingExecutor;
+    protected final NetconfTopologySchemaAssembler schemaAssembler;
     protected final DataBroker dataBroker;
     protected final DOMMountPointService mountPointService;
     protected final String topologyId;
 
-    protected AbstractNetconfTopology(final String topologyId, final NetconfClientDispatcher clientDispatcher,
-            final EventExecutor eventExecutor, final ScheduledThreadPool keepaliveExecutor,
-            final ThreadPool processingExecutor, final SchemaResourceManager schemaManager, final DataBroker dataBroker,
+    protected AbstractNetconfTopology(final String topologyId, final NetconfClientFactory clientFactory,
+            final Timer timer, final NetconfTopologySchemaAssembler schemaAssembler,
+            final SchemaResourceManager schemaManager, final DataBroker dataBroker,
             final DOMMountPointService mountPointService, final NetconfClientConfigurationBuilderFactory builderFactory,
             final DeviceActionFactory deviceActionFactory, final BaseNetconfSchemas baseSchemas) {
         this.topologyId = requireNonNull(topologyId);
-        this.clientDispatcher = clientDispatcher;
-        this.eventExecutor = eventExecutor;
-        this.keepaliveExecutor = keepaliveExecutor.getExecutor();
-        this.processingExecutor = processingExecutor.getExecutor();
+        this.clientFactory = requireNonNull(clientFactory);
+        this.timer = requireNonNull(timer);
+        this.schemaAssembler = requireNonNull(schemaAssembler);
         this.schemaManager = requireNonNull(schemaManager);
         this.deviceActionFactory = deviceActionFactory;
         this.dataBroker = requireNonNull(dataBroker);
@@ -116,7 +110,9 @@ public abstract class AbstractNetconfTopology {
             return;
         }
 
-        LOG.info("Connecting RemoteDevice{{}}, with config {}", nodeId, hideCredentials(node));
+        if (LOG.isInfoEnabled()) {
+            LOG.info("Connecting RemoteDevice{{}}, with config {}", nodeId, hideCredentials(node));
+        }
 
         // Instantiate the handler ...
         final var nodeOptional = node.augmentation(NetconfNodeAugmentedOptional.class);
@@ -124,13 +120,13 @@ public abstract class AbstractNetconfTopology {
 
         final NetconfNodeHandler nodeHandler;
         try {
-            nodeHandler = new NetconfNodeHandler(clientDispatcher, eventExecutor, keepaliveExecutor, baseSchemas,
-                schemaManager, processingExecutor, builderFactory, deviceActionFactory, deviceSalFacade, deviceId,
-                nodeId, netconfNode, nodeOptional);
+            nodeHandler = new NetconfNodeHandler(clientFactory, timer, baseSchemas, schemaManager, schemaAssembler,
+                builderFactory, deviceActionFactory, deviceSalFacade, deviceId, nodeId, netconfNode, nodeOptional);
         } catch (IllegalArgumentException e) {
             // This is a workaround for NETCONF-1114 where the encrypted password's lexical structure is not enforced
             // in the datastore and it ends up surfacing when we decrypt the password.
-            LOG.warn("RemoteDevice{{}} failed to connect", nodeId, e);
+            LOG.warn("RemoteDevice{{}} failed to connect, removing from operational datastore", nodeId, e);
+            deviceSalFacade.close();
             return;
         }
 
@@ -173,9 +169,12 @@ public abstract class AbstractNetconfTopology {
      */
     @VisibleForTesting
     static final String hideCredentials(final Node nodeConfiguration) {
-        final var netconfNodeAugmentation = nodeConfiguration.augmentation(NetconfNode.class);
-        final var nodeCredentials = netconfNodeAugmentation.getCredentials().toString();
         final var nodeConfigurationString = nodeConfiguration.toString();
-        return nodeConfigurationString.replace(nodeCredentials, "***");
+        final var netconfNodeAugmentation = nodeConfiguration.augmentation(NetconfNode.class);
+        if (netconfNodeAugmentation != null && netconfNodeAugmentation.getCredentials() != null) {
+            final var nodeCredentials = netconfNodeAugmentation.getCredentials().toString();
+            return nodeConfigurationString.replace(nodeCredentials, "***");
+        }
+        return nodeConfigurationString;
     }
 }