Do not touch config datastore during initiliazation 05/103605/15
authorRobert Varga <[email protected]>
Mon, 5 Dec 2022 20:06:50 +0000 (21:06 +0100)
committerRobert Varga <[email protected]>
Thu, 8 Dec 2022 01:21:24 +0000 (02:21 +0100)
We should not be introducing configuration items in the datastore, as
that places onus on operator and/or the datastore to deal with this
magic occuring. This also removes a cross-datastore transtion -- which
is no longer supported in Argon.

This means the configuration datastore is empty on startup, hence tests
need to initialize it. This also provides a stepping stone towards
allowing multiple netconf-capable topologies to exist.

JIRA: NETCONF-919
Change-Id: I0218b19f37dbd9ccd3196040193f305d5d147a89
Signed-off-by: Robert Varga <[email protected]>
netconf/netconf-topology-impl/src/main/java/org/opendaylight/netconf/topology/impl/NetconfTopologyImpl.java
netconf/netconf-topology-impl/src/test/java/org/opendaylight/netconf/topology/impl/NetconfTopologyImplTest.java
netconf/netconf-topology-singleton/src/main/java/org/opendaylight/netconf/topology/singleton/impl/NetconfTopologyManager.java
netconf/netconf-topology-singleton/src/main/java/org/opendaylight/netconf/topology/singleton/impl/utils/NetconfTopologyUtils.java
netconf/netconf-topology-singleton/src/test/java/org/opendaylight/netconf/topology/singleton/impl/MountPointEndToEndTest.java
netconf/netconf-topology-singleton/src/test/java/org/opendaylight/netconf/topology/singleton/impl/NetconfTopologyManagerTest.java

index 169dbd39d3b2ed2180478bd6fb51d3d734e56620..62ebdca2013c36ce74a6850071bec4ee21ebc1d7 100644 (file)
@@ -115,8 +115,11 @@ public class NetconfTopologyImpl extends AbstractNetconfTopology
      */
     public void init() {
         final WriteTransaction wtx = dataBroker.newWriteOnlyTransaction();
-        initTopology(wtx, LogicalDatastoreType.CONFIGURATION);
-        initTopology(wtx, LogicalDatastoreType.OPERATIONAL);
+        // FIXME: this should be a put(), as we are initializing and will be re-populating the datastore with all the
+        //        devices. Whathever has been there before should be nuked to properly re-align lifecycle
+        wtx.merge(LogicalDatastoreType.OPERATIONAL, InstanceIdentifier.builder(NetworkTopology.class)
+            .child(Topology.class, new TopologyKey(new TopologyId(topologyId)))
+            .build(), new TopologyBuilder().setTopologyId(new TopologyId(topologyId)).build());
         wtx.commit().addCallback(new FutureCallback<CommitInfo>() {
             @Override
             public void onSuccess(final CommitInfo result) {
@@ -168,14 +171,6 @@ public class NetconfTopologyImpl extends AbstractNetconfTopology
         }
     }
 
-    private void initTopology(final WriteTransaction wtx, final LogicalDatastoreType datastoreType) {
-        // FIXME: this should be a put(), as we are initializing and will be re-populating the datastore with all the
-        //        devices. Whathever has been there before should be nuked to properly re-align lifecycle
-        wtx.merge(datastoreType, InstanceIdentifier.builder(NetworkTopology.class)
-            .child(Topology.class, new TopologyKey(new TopologyId(topologyId)))
-            .build(), new TopologyBuilder().setTopologyId(new TopologyId(topologyId)).build());
-    }
-
     /**
      * Determines the Netconf Node Node ID, given the node's instance
      * identifier.
index 847dac386c2f70fac35fcaa818adc796a4cc3c95..2b98eb8a63df20d223c94acfe05c0b75cf5f54ff 100644 (file)
@@ -12,15 +12,12 @@ import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.Mockito.doNothing;
 import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.spy;
 import static org.mockito.Mockito.times;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
-import static org.opendaylight.mdsal.common.api.CommitInfo.emptyFluentFuture;
 
 import com.google.common.util.concurrent.Futures;
 import com.google.common.util.concurrent.ListenableFuture;
@@ -41,6 +38,7 @@ import org.opendaylight.mdsal.binding.api.DataObjectModification;
 import org.opendaylight.mdsal.binding.api.DataTreeModification;
 import org.opendaylight.mdsal.binding.api.RpcProviderService;
 import org.opendaylight.mdsal.binding.api.WriteTransaction;
+import org.opendaylight.mdsal.common.api.CommitInfo;
 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
 import org.opendaylight.mdsal.dom.api.DOMMountPointService;
 import org.opendaylight.netconf.client.NetconfClientDispatcher;
@@ -68,7 +66,6 @@ import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.
 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.NodeBuilder;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeKey;
-import org.opendaylight.yangtools.yang.binding.DataObject;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.IdentifiableItem;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.PathArgument;
@@ -81,43 +78,38 @@ import org.opendaylight.yangtools.yang.parser.impl.DefaultYangParserFactory;
 
 @RunWith(MockitoJUnitRunner.StrictStubs.class)
 public class NetconfTopologyImplTest {
-
     private static final NodeId NODE_ID = new NodeId("testing-node");
     private static final String TOPOLOGY_ID = "testing-topology";
 
     @Mock
     private NetconfClientDispatcher mockedClientDispatcher;
-
     @Mock
     private EventExecutor mockedEventExecutor;
-
     @Mock
     private ScheduledThreadPool mockedKeepaliveExecutor;
-
     @Mock
     private ThreadPool mockedProcessingExecutor;
-
     @Mock
     private SchemaResourceManager mockedResourceManager;
-
     @Mock
     private DataBroker dataBroker;
-
     @Mock
     private DOMMountPointService mountPointService;
-
     @Mock
     private AAAEncryptionService encryptionService;
-
     @Mock
     private RpcProviderService rpcProviderService;
+    @Mock
+    private WriteTransaction wtx;
 
     private TestingNetconfTopologyImpl topology;
     private TestingNetconfTopologyImpl spyTopology;
 
     @Before
     public void setUp() {
-        when(mockedProcessingExecutor.getExecutor()).thenReturn(MoreExecutors.newDirectExecutorService());
+        doReturn(MoreExecutors.newDirectExecutorService()).when(mockedProcessingExecutor).getExecutor();
+        doReturn(wtx).when(dataBroker).newWriteOnlyTransaction();
+        doReturn(CommitInfo.emptyFluentFuture()).when(wtx).commit();
 
         topology = new TestingNetconfTopologyImpl(TOPOLOGY_ID, mockedClientDispatcher, mockedEventExecutor,
             mockedKeepaliveExecutor, mockedProcessingExecutor, mockedResourceManager, dataBroker, mountPointService,
@@ -128,21 +120,12 @@ public class NetconfTopologyImplTest {
 
     @Test
     public void testInit() {
-        final WriteTransaction wtx = mock(WriteTransaction.class);
-        when(dataBroker.newWriteOnlyTransaction()).thenReturn(wtx);
-        doNothing().when(wtx)
-                .merge(any(LogicalDatastoreType.class), any(InstanceIdentifier.class), any(DataObject.class));
-        doReturn(emptyFluentFuture()).when(wtx).commit();
         topology.init();
 
         //verify initialization of topology
-        final InstanceIdentifier<NetworkTopology> networkTopologyId =
-                InstanceIdentifier.builder(NetworkTopology.class).build();
-        final Topology topo = new TopologyBuilder().setTopologyId(new TopologyId(TOPOLOGY_ID)).build();
-        verify(wtx).merge(LogicalDatastoreType.CONFIGURATION,
-                networkTopologyId.child(Topology.class, new TopologyKey(new TopologyId(TOPOLOGY_ID))), topo);
-        verify(wtx).merge(LogicalDatastoreType.OPERATIONAL,
-                networkTopologyId.child(Topology.class, new TopologyKey(new TopologyId(TOPOLOGY_ID))), topo);
+        verify(wtx).merge(LogicalDatastoreType.OPERATIONAL, InstanceIdentifier.builder(NetworkTopology.class)
+                .child(Topology.class, new TopologyKey(new TopologyId(TOPOLOGY_ID))).build(),
+                new TopologyBuilder().setTopologyId(new TopologyId(TOPOLOGY_ID)).build());
     }
 
     @Test
index b20bfc386621e8f0e9f202899196aa2db2f9cd97..c44fd3e9586662265b9ae923146a02c88afa4a93 100644 (file)
@@ -270,8 +270,12 @@ public class NetconfTopologyManager
 
     private ListenerRegistration<NetconfTopologyManager> registerDataTreeChangeListener() {
         final WriteTransaction wtx = dataBroker.newWriteOnlyTransaction();
-        initTopology(wtx, LogicalDatastoreType.CONFIGURATION);
-        initTopology(wtx, LogicalDatastoreType.OPERATIONAL);
+        // FIXME: how does this play out with lifecycle? In a cluster, someone needs to ensure this call happens, but
+        //        also we need to to make sure config -> oper is properly synchronized. Non-clustered case relies on
+        //        oper being transient and perhaps on a put() instead, how do we handle that in the clustered case?
+        wtx.merge(LogicalDatastoreType.OPERATIONAL, InstanceIdentifier.builder(NetworkTopology.class)
+            .child(Topology.class, new TopologyKey(new TopologyId(topologyId)))
+            .build(), new TopologyBuilder().setTopologyId(new TopologyId(topologyId)).build());
         wtx.commit().addCallback(new FutureCallback<CommitInfo>() {
             @Override
             public void onSuccess(final CommitInfo result) {
@@ -289,15 +293,6 @@ public class NetconfTopologyManager
             NetconfTopologyUtils.createTopologyListPath(topologyId).child(Node.class)), this);
     }
 
-    private void initTopology(final WriteTransaction wtx, final LogicalDatastoreType datastoreType) {
-        // FIXME: how does this play out with lifecycle? In a cluster, someone needs to ensure this call happens, but
-        //        also we need to to make sure config -> oper is properly synchronized. Non-clustered case relies on
-        //        oper being transient and perhaps on a put() instead, how do we handle that in the clustered case?
-        wtx.merge(datastoreType, InstanceIdentifier.builder(NetworkTopology.class)
-            .child(Topology.class, new TopologyKey(new TopologyId(topologyId)))
-            .build(), new TopologyBuilder().setTopologyId(new TopologyId(topologyId)).build());
-    }
-
     private NetconfTopologySetup createSetup(final InstanceIdentifier<Node> instanceIdentifier, final Node node) {
         final NetconfNode netconfNode = node.augmentation(NetconfNode.class);
         final RemoteDeviceId deviceId = NetconfNodeUtils.toRemoteDeviceId(node.getNodeId(), netconfNode);
index eba7cde7c7a7b98b10c1c9333451acb283bf4a25..5dfc088ab140506dfe6bf9235c90c47bba10d7bc 100644 (file)
@@ -7,6 +7,7 @@
  */
 package org.opendaylight.netconf.topology.singleton.impl.utils;
 
+import org.eclipse.jdt.annotation.NonNull;
 import org.opendaylight.netconf.api.DocumentedException;
 import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology;
@@ -16,8 +17,9 @@ import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.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.yang.binding.Identifier;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.IdentifiableItem;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.PathArgument;
 import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
 import org.opendaylight.yangtools.yang.common.Decimal64;
 import org.opendaylight.yangtools.yang.common.ErrorSeverity;
@@ -47,32 +49,32 @@ public final class NetconfTopologyUtils {
         return masterAddress.replace("//", "") + "_" + name;
     }
 
-    public static NodeId getNodeId(final InstanceIdentifier.PathArgument pathArgument) {
-        if (pathArgument instanceof InstanceIdentifier.IdentifiableItem) {
-            final Identifier<?> key = ((InstanceIdentifier.IdentifiableItem<?, ?>) pathArgument).getKey();
-            if (key instanceof NodeKey) {
-                return ((NodeKey) key).getNodeId();
-            }
+    public static @NonNull NodeId getNodeId(final PathArgument pathArgument) {
+        if (pathArgument instanceof IdentifiableItem<?, ?> identifiableItem
+            && identifiableItem.getKey() instanceof NodeKey nodeKey) {
+            return nodeKey.getNodeId();
         }
         throw new IllegalStateException("Unable to create NodeId from: " + pathArgument);
     }
 
-    public static KeyedInstanceIdentifier<Topology, TopologyKey> createTopologyListPath(final String topologyId) {
-        final InstanceIdentifier<NetworkTopology> networkTopology = InstanceIdentifier.create(NetworkTopology.class);
-        return networkTopology.child(Topology.class, new TopologyKey(new TopologyId(topologyId)));
+    public static @NonNull KeyedInstanceIdentifier<Topology, TopologyKey> createTopologyListPath(
+            final String topologyId) {
+        return InstanceIdentifier.create(NetworkTopology.class)
+            .child(Topology.class, new TopologyKey(new TopologyId(topologyId)));
     }
 
-    public static KeyedInstanceIdentifier<Node, NodeKey> createTopologyNodeListPath(final NodeKey key,
+    public static @NonNull KeyedInstanceIdentifier<Node, NodeKey> createTopologyNodeListPath(final NodeKey key,
             final String topologyId) {
         return createTopologyListPath(topologyId)
                 .child(Node.class, new NodeKey(new NodeId(key.getNodeId().getValue())));
     }
 
-    public static InstanceIdentifier<Node> createTopologyNodePath(final String topologyId) {
+    public static @NonNull InstanceIdentifier<Node> createTopologyNodePath(final String topologyId) {
         return createTopologyListPath(topologyId).child(Node.class);
     }
 
-    public static DocumentedException createMasterIsDownException(final RemoteDeviceId id, final Exception cause) {
+    public static @NonNull DocumentedException createMasterIsDownException(final RemoteDeviceId id,
+            final Exception cause) {
         return new DocumentedException(id + ":Master is down. Please try again.", cause,
                 ErrorType.APPLICATION, ErrorTag.OPERATION_FAILED, ErrorSeverity.WARNING);
     }
index dbfe47d9b55ca40fe14997f49a1058aeaac5609c..c63bc5e7ab16c059c0579bced5aa7d2a9fb189db 100644 (file)
@@ -28,8 +28,6 @@ import akka.testkit.javadsl.TestKit;
 import akka.util.Timeout;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.ImmutableSet;
-import com.google.common.collect.Lists;
 import com.google.common.util.concurrent.FluentFuture;
 import com.google.common.util.concurrent.Futures;
 import com.google.common.util.concurrent.ListenableFuture;
@@ -39,9 +37,8 @@ import com.typesafe.config.ConfigFactory;
 import io.netty.util.concurrent.EventExecutor;
 import io.netty.util.concurrent.GlobalEventExecutor;
 import java.io.File;
-import java.util.AbstractMap.SimpleEntry;
-import java.util.ArrayList;
 import java.util.Iterator;
+import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
 import java.util.Optional;
@@ -50,6 +47,7 @@ import java.util.concurrent.ExecutionException;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.TimeoutException;
 import org.apache.commons.io.FileUtils;
+import org.eclipse.jdt.annotation.NonNull;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
@@ -102,7 +100,6 @@ import org.opendaylight.netconf.nettyutil.ReconnectFuture;
 import org.opendaylight.netconf.sal.connect.api.DeviceActionFactory;
 import org.opendaylight.netconf.sal.connect.api.SchemaResourceManager;
 import org.opendaylight.netconf.sal.connect.impl.DefaultSchemaResourceManager;
-import org.opendaylight.netconf.sal.connect.netconf.NetconfDevice.SchemaResourcesDTO;
 import org.opendaylight.netconf.sal.connect.netconf.listener.NetconfSessionPreferences;
 import org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil;
 import org.opendaylight.netconf.topology.singleton.impl.utils.ClusteringRpcException;
@@ -130,12 +127,13 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controll
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.two.level.list.TopLevelListKey;
 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.network.topology.Topology;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyBuilder;
 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.NodeBuilder;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeKey;
 import org.opendaylight.yangtools.rfc8528.data.util.EmptyMountPointContext;
 import org.opendaylight.yangtools.util.concurrent.FluentFutures;
+import org.opendaylight.yangtools.yang.binding.DataObject;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
 import org.opendaylight.yangtools.yang.binding.YangModuleInfo;
@@ -176,7 +174,7 @@ public class MountPointEndToEndTest extends AbstractBaseSchemasTest {
     private static final String TOP_MODULE_NAME = "opendaylight-mdsal-list-test";
     private static final String ACTOR_SYSTEM_NAME = "test";
     private static final String TOPOLOGY_ID = TopologyNetconf.QNAME.getLocalName();
-    private static final KeyedInstanceIdentifier<Node, NodeKey> NODE_INSTANCE_ID =
+    private static final @NonNull KeyedInstanceIdentifier<Node, NodeKey> NODE_INSTANCE_ID =
         NetconfTopologyUtils.createTopologyNodeListPath(new NodeKey(new NodeId("node-id")), TOPOLOGY_ID);
 
     private static final String TEST_ROOT_DIRECTORY = "test-cache-root";
@@ -268,7 +266,7 @@ public class MountPointEndToEndTest extends AbstractBaseSchemasTest {
     }
 
     private void setupMaster() throws Exception {
-        AbstractConcurrentDataBrokerTest dataBrokerTest = newDataBrokerTest();
+        final var dataBrokerTest = newDataBrokerTest();
         masterDataBroker = dataBrokerTest.getDataBroker();
         deviceDOMDataBroker = dataBrokerTest.getDomBroker();
         bindingToNormalized = dataBrokerTest.getDataBrokerTestCustomizer().getAdapterContext().currentSerializer();
@@ -282,7 +280,7 @@ public class MountPointEndToEndTest extends AbstractBaseSchemasTest {
 
         doReturn(MoreExecutors.newDirectExecutorService()).when(mockThreadPool).getExecutor();
 
-        final SchemaResourcesDTO resources =  resourceManager.getSchemaResources(TEST_DEFAULT_SUBDIR, "test");
+        final var resources =  resourceManager.getSchemaResources(TEST_DEFAULT_SUBDIR, "test");
         resources.getSchemaRegistry().registerSchemaSource(
             id -> Futures.immediateFuture(YangTextSchemaSource.delegateForByteSource(id,
                     topModuleInfo.getYangTextByteSource())),
@@ -297,14 +295,14 @@ public class MountPointEndToEndTest extends AbstractBaseSchemasTest {
                 mockRpcProviderService, deviceActionFactory, resourceManager) {
             @Override
             protected NetconfTopologyContext newNetconfTopologyContext(final NetconfTopologySetup setup,
-                final ServiceGroupIdentifier serviceGroupIdent, final Timeout actorResponseWaitTime,
-                final DeviceActionFactory deviceActionFact) {
-                NetconfTopologyContext context =
-                    super.newNetconfTopologyContext(setup, serviceGroupIdent, actorResponseWaitTime, deviceActionFact);
+                    final ServiceGroupIdentifier serviceGroupIdent, final Timeout actorResponseWaitTime,
+                    final DeviceActionFactory deviceActionFact) {
+                final var context = super.newNetconfTopologyContext(setup, serviceGroupIdent, actorResponseWaitTime,
+                    deviceActionFact);
 
-                NetconfTopologyContext spiedContext = spy(context);
+                final var spiedContext = spy(context);
                 doAnswer(invocation -> {
-                    final MasterSalFacade spiedFacade = (MasterSalFacade) spy(invocation.callRealMethod());
+                    final var spiedFacade = (MasterSalFacade) spy(invocation.callRealMethod());
                     doReturn(deviceDOMDataBroker).when(spiedFacade).newDeviceDataBroker();
                     masterSalFacadeFuture.set(spiedFacade);
                     return spiedFacade;
@@ -377,19 +375,18 @@ public class MountPointEndToEndTest extends AbstractBaseSchemasTest {
         testCleanup();
     }
 
-    private MasterSalFacade testMaster() throws InterruptedException, ExecutionException, TimeoutException {
+    private MasterSalFacade testMaster() throws Exception {
         LOG.info("****** Testing master");
 
         writeNetconfNode(TEST_DEFAULT_SUBDIR, masterDataBroker);
 
-        final MasterSalFacade masterSalFacade = masterSalFacadeFuture.get(5, TimeUnit.SECONDS);
-        final ArrayList<String> capabilities = Lists.newArrayList(
-            NetconfMessageTransformUtil.NETCONF_CANDIDATE_URI.toString());
-
+        final var masterSalFacade = masterSalFacadeFuture.get(5, TimeUnit.SECONDS);
         masterSalFacade.onDeviceConnected(new EmptyMountPointContext(deviceSchemaContext),
-                NetconfSessionPreferences.fromStrings(capabilities), deviceRpcService.getRpcService());
+                NetconfSessionPreferences.fromStrings(
+                    List.of(NetconfMessageTransformUtil.NETCONF_CANDIDATE_URI.toString())),
+                deviceRpcService.getRpcService());
 
-        DOMMountPoint masterMountPoint = awaitMountPoint(masterMountPointService);
+        final var masterMountPoint = awaitMountPoint(masterMountPointService);
 
         LOG.info("****** Testing master DOMDataBroker operations");
 
@@ -401,7 +398,7 @@ public class MountPointEndToEndTest extends AbstractBaseSchemasTest {
         return masterSalFacade;
     }
 
-    private void testSlave() throws InterruptedException, ExecutionException, TimeoutException {
+    private void testSlave() throws Exception {
         LOG.info("****** Testing slave");
 
         writeNetconfNode("slave", slaveDataBroker);
@@ -448,7 +445,7 @@ public class MountPointEndToEndTest extends AbstractBaseSchemasTest {
         testDOMRpcService(getDOMRpcService(slaveMountPoint));
     }
 
-    private MasterSalFacade testMasterNodeUpdated() throws InterruptedException, ExecutionException, TimeoutException {
+    private MasterSalFacade testMasterNodeUpdated() throws Exception {
         LOG.info("****** Testing update master node");
 
         masterMountPointService.registerProvisionListener(masterMountPointListener);
@@ -459,12 +456,11 @@ public class MountPointEndToEndTest extends AbstractBaseSchemasTest {
 
         verify(masterMountPointListener, timeout(5000)).onMountPointRemoved(yangNodeInstanceId);
 
-        MasterSalFacade masterSalFacade = masterSalFacadeFuture.get(5, TimeUnit.SECONDS);
-        final ArrayList<String> capabilities = Lists.newArrayList(
-            NetconfMessageTransformUtil.NETCONF_CANDIDATE_URI.toString());
-
+        final var masterSalFacade = masterSalFacadeFuture.get(5, TimeUnit.SECONDS);
         masterSalFacade.onDeviceConnected(new EmptyMountPointContext(deviceSchemaContext),
-                NetconfSessionPreferences.fromStrings(capabilities), deviceRpcService.getRpcService());
+                NetconfSessionPreferences.fromStrings(List.of(
+                    NetconfMessageTransformUtil.NETCONF_CANDIDATE_URI.toString())),
+                deviceRpcService.getRpcService());
 
         verify(masterMountPointListener, timeout(5000)).onMountPointCreated(yangNodeInstanceId);
 
@@ -474,8 +470,7 @@ public class MountPointEndToEndTest extends AbstractBaseSchemasTest {
         return masterSalFacade;
     }
 
-    private void testMasterDisconnected(final MasterSalFacade masterSalFacade)
-            throws InterruptedException, ExecutionException, TimeoutException {
+    private void testMasterDisconnected(final MasterSalFacade masterSalFacade) throws Exception {
         LOG.info("****** Testing master disconnected");
 
         masterSalFacade.onDeviceDisconnected();
@@ -614,32 +609,34 @@ public class MountPointEndToEndTest extends AbstractBaseSchemasTest {
         assertTrue(readTx.cancel());
     }
 
-    private static void writeNetconfNode(final String cacheDir, final DataBroker databroker)
-            throws InterruptedException, ExecutionException, TimeoutException {
-        final Node node = new NodeBuilder()
-                .withKey(NODE_INSTANCE_ID.getKey())
-                .addAugmentation(new NetconfNodeBuilder()
-                    .setHost(new Host(new IpAddress(new Ipv4Address("127.0.0.1"))))
-                    .setPort(new PortNumber(Uint16.valueOf(1234)))
-                    .setActorResponseWaitTime(Uint16.valueOf(10))
-                    .setTcpOnly(Boolean.TRUE)
-                    .setSchemaless(Boolean.FALSE)
-                    .setKeepaliveDelay(Uint32.ZERO)
-                    .setConnectionTimeoutMillis(Uint32.valueOf(5000))
-                    .setDefaultRequestTimeoutMillis(Uint32.valueOf(5000))
-                    .setMaxConnectionAttempts(Uint32.ONE)
-                    .setCredentials(new LoginPwUnencryptedBuilder()
-                        .setLoginPasswordUnencrypted(new LoginPasswordUnencryptedBuilder()
-                            .setUsername("user")
-                            .setPassword("pass")
-                            .build())
+    private static void writeNetconfNode(final String cacheDir, final DataBroker dataBroker) throws Exception {
+        putData(dataBroker, NODE_INSTANCE_ID, new NodeBuilder()
+            .withKey(NODE_INSTANCE_ID.getKey())
+            .addAugmentation(new NetconfNodeBuilder()
+                .setHost(new Host(new IpAddress(new Ipv4Address("127.0.0.1"))))
+                .setPort(new PortNumber(Uint16.valueOf(1234)))
+                .setActorResponseWaitTime(Uint16.valueOf(10))
+                .setTcpOnly(Boolean.TRUE)
+                .setSchemaless(Boolean.FALSE)
+                .setKeepaliveDelay(Uint32.ZERO)
+                .setConnectionTimeoutMillis(Uint32.valueOf(5000))
+                .setDefaultRequestTimeoutMillis(Uint32.valueOf(5000))
+                .setMaxConnectionAttempts(Uint32.ONE)
+                .setCredentials(new LoginPwUnencryptedBuilder()
+                    .setLoginPasswordUnencrypted(new LoginPasswordUnencryptedBuilder()
+                        .setUsername("user")
+                        .setPassword("pass")
                         .build())
-                    .setSchemaCacheDirectory(cacheDir)
                     .build())
-                .build();
+                .setSchemaCacheDirectory(cacheDir)
+                .build())
+            .build());
+    }
 
-        final WriteTransaction writeTx = databroker.newWriteOnlyTransaction();
-        writeTx.put(LogicalDatastoreType.CONFIGURATION, NODE_INSTANCE_ID, node);
+    private static <T extends DataObject> void putData(final DataBroker databroker, final InstanceIdentifier<T> path,
+            final T data) throws Exception {
+        final var writeTx = databroker.newWriteOnlyTransaction();
+        writeTx.put(LogicalDatastoreType.CONFIGURATION, path, data);
         writeTx.commit().get(5, TimeUnit.SECONDS);
     }
 
@@ -657,28 +654,27 @@ public class MountPointEndToEndTest extends AbstractBaseSchemasTest {
     private static void verifyTopologyNodesCreated(final DataBroker dataBroker) {
         await().atMost(5, TimeUnit.SECONDS).until(() -> {
             try (ReadTransaction readTx = dataBroker.newReadOnlyTransaction()) {
-                Optional<Topology> configTopology = readTx.read(LogicalDatastoreType.CONFIGURATION,
-                        NetconfTopologyUtils.createTopologyListPath(TOPOLOGY_ID)).get(3, TimeUnit.SECONDS);
-                Optional<Topology> operTopology = readTx.read(LogicalDatastoreType.OPERATIONAL,
-                        NetconfTopologyUtils.createTopologyListPath(TOPOLOGY_ID)).get(3, TimeUnit.SECONDS);
-                return configTopology.isPresent() && operTopology.isPresent();
+                return readTx.exists(LogicalDatastoreType.OPERATIONAL,
+                    NetconfTopologyUtils.createTopologyListPath(TOPOLOGY_ID)).get(3, TimeUnit.SECONDS);
             }
         });
     }
 
     private AbstractConcurrentDataBrokerTest newDataBrokerTest() throws Exception {
-        AbstractConcurrentDataBrokerTest dataBrokerTest = new AbstractConcurrentDataBrokerTest(true) {
+        final var dataBrokerTest = new AbstractConcurrentDataBrokerTest(true) {
             @Override
-            protected Set<YangModuleInfo> getModuleInfos() throws Exception {
-                return ImmutableSet.of(BindingReflections.getModuleInfo(NetconfNode.class),
+            protected Set<YangModuleInfo> getModuleInfos() {
+                return Set.of(BindingReflections.getModuleInfo(NetconfNode.class),
                         BindingReflections.getModuleInfo(NetworkTopology.class),
-                        BindingReflections.getModuleInfo(Topology.class),
                         BindingReflections.getModuleInfo(Keystore.class),
                         topModuleInfo);
             }
         };
 
         dataBrokerTest.setup();
+
+        final var path = NetconfTopologyUtils.createTopologyListPath(TOPOLOGY_ID);
+        putData(dataBrokerTest.getDataBroker(), path, new TopologyBuilder().withKey(path.getKey()).build());
         return dataBrokerTest;
     }
 
@@ -701,16 +697,14 @@ public class MountPointEndToEndTest extends AbstractBaseSchemasTest {
 
     private static <T extends DOMService> T getMountPointService(final DOMMountPoint mountPoint,
             final Class<T> serviceClass) {
-        final Optional<T> maybeService = mountPoint.getService(serviceClass);
-        assertTrue(maybeService.isPresent());
-        return maybeService.get();
+        return mountPoint.getService(serviceClass).orElseThrow();
     }
 
     private DOMMountPoint awaitMountPoint(final DOMMountPointService mountPointService) {
         await().atMost(5, TimeUnit.SECONDS).until(() ->
                 mountPointService.getMountPoint(yangNodeInstanceId).isPresent());
 
-        return mountPointService.getMountPoint(yangNodeInstanceId).get();
+        return mountPointService.getMountPoint(yangNodeInstanceId).orElseThrow();
     }
 
     private RpcDefinition findRpcDefinition(final String rpc) {
@@ -733,7 +727,7 @@ public class MountPointEndToEndTest extends AbstractBaseSchemasTest {
 
         @Override
         public FluentFuture<DOMRpcResult> invokeRpc(final DOMRpcIdentifier rpc, final NormalizedNode input) {
-            rpcInvokedFuture.set(new SimpleEntry<>(rpc, input));
+            rpcInvokedFuture.set(Map.entry(rpc, input));
             return returnFuture;
         }
 
index b670d638b18aae4bda35653854038f48a4fddda1..fa53d4616eaaa401d0874a34ef7a7b817aae427f 100644 (file)
@@ -30,7 +30,6 @@ import java.util.Arrays;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.Objects;
-import java.util.Optional;
 import java.util.Set;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.TimeUnit;
@@ -156,12 +155,10 @@ public class NetconfTopologyManagerTest extends AbstractBaseSchemasTest {
         netconfTopologyManager.init();
 
         await().atMost(5, TimeUnit.SECONDS).until(() -> {
-            ReadTransaction readTx = dataBroker.newReadOnlyTransaction();
-            Optional<Topology> config = readTx.read(LogicalDatastoreType.CONFIGURATION,
+            try (ReadTransaction readTx = dataBroker.newReadOnlyTransaction()) {
+                return readTx.exists(LogicalDatastoreType.OPERATIONAL,
                     NetconfTopologyUtils.createTopologyListPath(TOPOLOGY_ID)).get(3, TimeUnit.SECONDS);
-            Optional<Topology> oper = readTx.read(LogicalDatastoreType.OPERATIONAL,
-                    NetconfTopologyUtils.createTopologyListPath(TOPOLOGY_ID)).get(3, TimeUnit.SECONDS);
-            return config.isPresent() && oper.isPresent();
+            }
         });
 
         // verify registration is called with right parameters