Further rework of base schemas 34/89734/3
authorRobert Varga <robert.varga@pantheon.tech>
Mon, 11 May 2020 11:32:07 +0000 (13:32 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Wed, 13 May 2020 11:45:32 +0000 (13:45 +0200)
As it turns out we cannot really instantiate base schemas without
a proper parser, as would be required in static contexts. Let us
turn them into a proper component, so that it can be injected at
runtime.

JIRA: NETCONF-683
Change-Id: I65b90f3042d9354443dfa4052413d531626f4376
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
42 files changed:
netconf/callhome-provider/src/main/java/org/opendaylight/netconf/callhome/mount/BaseCallHomeTopology.java
netconf/callhome-provider/src/main/java/org/opendaylight/netconf/callhome/mount/CallHomeMountDispatcher.java
netconf/callhome-provider/src/main/java/org/opendaylight/netconf/callhome/mount/CallHomeTopology.java
netconf/callhome-provider/src/main/resources/OSGI-INF/blueprint/callhome-topology.xml
netconf/callhome-provider/src/test/java/org/opendaylight/netconf/callhome/mount/CallHomeMountDispatcherTest.java
netconf/netconf-topology-impl/src/main/java/org/opendaylight/netconf/topology/impl/NetconfTopologyImpl.java
netconf/netconf-topology-impl/src/main/resources/OSGI-INF/blueprint/netconf-topology.xml
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/RemoteDeviceConnectorImpl.java
netconf/netconf-topology-singleton/src/main/java/org/opendaylight/netconf/topology/singleton/impl/utils/NetconfTopologySetup.java
netconf/netconf-topology-singleton/src/main/resources/OSGI-INF/blueprint/netconf-topology-singleton.xml
netconf/netconf-topology-singleton/src/test/java/org/opendaylight/netconf/topology/singleton/impl/AbstractBaseSchemasTest.java [new file with mode: 0644]
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/NetconfNodeActorTest.java
netconf/netconf-topology-singleton/src/test/java/org/opendaylight/netconf/topology/singleton/impl/NetconfNodeManagerTest.java
netconf/netconf-topology-singleton/src/test/java/org/opendaylight/netconf/topology/singleton/impl/NetconfTopologyManagerTest.java
netconf/netconf-topology-singleton/src/test/java/org/opendaylight/netconf/topology/singleton/impl/RemoteDeviceConnectorImplTest.java
netconf/netconf-topology/src/main/java/org/opendaylight/netconf/topology/spi/AbstractNetconfTopology.java
netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/NetconfDevice.java
netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/NetconfDeviceBuilder.java
netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/NetconfStateSchemas.java
netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/SchemalessNetconfDevice.java
netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/schema/mapping/BaseNetconfSchemas.java [new file with mode: 0644]
netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/schema/mapping/BaseRpcSchemalessTransformer.java
netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/schema/mapping/BaseSchema.java
netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/schema/mapping/DefaultBaseNetconfSchemas.java [new file with mode: 0644]
netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/schema/mapping/NetconfMessageTransformer.java
netconf/sal-netconf-connector/src/main/resources/OSGI-INF/blueprint/sal-netconf-connector.xml
netconf/sal-netconf-connector/src/test/java/org/opendaylight/netconf/sal/connect/netconf/AbstractBaseSchemasTest.java [new file with mode: 0644]
netconf/sal-netconf-connector/src/test/java/org/opendaylight/netconf/sal/connect/netconf/AbstractTestModelTest.java
netconf/sal-netconf-connector/src/test/java/org/opendaylight/netconf/sal/connect/netconf/NetconfDeviceTest.java
netconf/sal-netconf-connector/src/test/java/org/opendaylight/netconf/sal/connect/netconf/NetconfStateSchemasTest.java
netconf/sal-netconf-connector/src/test/java/org/opendaylight/netconf/sal/connect/netconf/NetconfToNotificationTest.java
netconf/sal-netconf-connector/src/test/java/org/opendaylight/netconf/sal/connect/netconf/NetconfToRpcRequestTest.java
netconf/sal-netconf-connector/src/test/java/org/opendaylight/netconf/sal/connect/netconf/SchemalessNetconfDeviceTest.java
netconf/sal-netconf-connector/src/test/java/org/opendaylight/netconf/sal/connect/netconf/sal/NetconfDeviceRpcTest.java
netconf/sal-netconf-connector/src/test/java/org/opendaylight/netconf/sal/connect/netconf/sal/SchemalessNetconfDeviceRpcTest.java
netconf/sal-netconf-connector/src/test/java/org/opendaylight/netconf/sal/connect/netconf/sal/tx/NetconfDeviceWriteOnlyTxTest.java
netconf/sal-netconf-connector/src/test/java/org/opendaylight/netconf/sal/connect/netconf/schema/mapping/BaseRpcSchemalessTransformerTest.java
netconf/sal-netconf-connector/src/test/java/org/opendaylight/netconf/sal/connect/netconf/schema/mapping/NetconfMessageTransformerTest.java
netconf/sal-netconf-connector/src/test/java/org/opendaylight/netconf/sal/connect/netconf/util/NetconfBaseOpsTest.java

index 844e474586d617cddc7462d12322a820d16a93e0..25233357ba38236bfaeb67edb539032132a18244 100644 (file)
@@ -16,6 +16,7 @@ import org.opendaylight.mdsal.dom.api.DOMMountPointService;
 import org.opendaylight.netconf.client.NetconfClientDispatcher;
 import org.opendaylight.netconf.sal.connect.api.DeviceActionFactory;
 import org.opendaylight.netconf.sal.connect.api.SchemaResourceManager;
+import org.opendaylight.netconf.sal.connect.netconf.schema.mapping.BaseNetconfSchemas;
 import org.opendaylight.netconf.topology.spi.AbstractNetconfTopology;
 
 abstract class BaseCallHomeTopology extends AbstractNetconfTopology {
@@ -27,9 +28,10 @@ abstract class BaseCallHomeTopology extends AbstractNetconfTopology {
                          final DataBroker dataBroker,
                          final DOMMountPointService mountPointService,
                          final AAAEncryptionService encryptionService,
-                         final DeviceActionFactory deviceActionFactory) {
+                         final DeviceActionFactory deviceActionFactory,
+                         final BaseNetconfSchemas baseSchemas) {
         super(topologyId, clientDispatcher, eventExecutor, keepaliveExecutor,
               processingExecutor, schemaRepositoryProvider, dataBroker, mountPointService,
-              encryptionService, deviceActionFactory);
+              encryptionService, deviceActionFactory, baseSchemas);
     }
 }
index de843caab21ff7826fb247e8cfb5725b28b9ca7a..407fa8e60ee87ab37e7a5d25e067d28eb3f16506 100644 (file)
@@ -7,6 +7,8 @@
  */
 package org.opendaylight.netconf.callhome.mount;
 
+import static java.util.Objects.requireNonNull;
+
 import io.netty.util.concurrent.EventExecutor;
 import io.netty.util.concurrent.FailedFuture;
 import io.netty.util.concurrent.Future;
@@ -26,6 +28,7 @@ import org.opendaylight.netconf.client.conf.NetconfClientConfiguration;
 import org.opendaylight.netconf.client.conf.NetconfReconnectingClientConfiguration;
 import org.opendaylight.netconf.sal.connect.api.DeviceActionFactory;
 import org.opendaylight.netconf.sal.connect.api.SchemaResourceManager;
+import org.opendaylight.netconf.sal.connect.netconf.schema.mapping.BaseNetconfSchemas;
 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.Node;
 import org.slf4j.Logger;
@@ -53,20 +56,22 @@ public class CallHomeMountDispatcher implements NetconfClientDispatcher, CallHom
     };
 
     private final DeviceActionFactory deviceActionFactory;
+    private final BaseNetconfSchemas baseSchemas;
 
     public CallHomeMountDispatcher(final String topologyId, final EventExecutor eventExecutor,
                                    final ScheduledThreadPool keepaliveExecutor, final ThreadPool processingExecutor,
-                                   final SchemaResourceManager schemaRepositoryProvider, final DataBroker dataBroker,
+                                   final SchemaResourceManager schemaRepositoryProvider,
+                                   final BaseNetconfSchemas baseSchemas, final DataBroker dataBroker,
                                    final DOMMountPointService mountService,
                                    final AAAEncryptionService encryptionService) {
-        this(topologyId, eventExecutor, keepaliveExecutor, processingExecutor, schemaRepositoryProvider, dataBroker,
-                mountService, encryptionService, null);
+        this(topologyId, eventExecutor, keepaliveExecutor, processingExecutor, schemaRepositoryProvider, baseSchemas,
+            dataBroker, mountService, encryptionService, null);
     }
 
     public CallHomeMountDispatcher(final String topologyId, final EventExecutor eventExecutor,
             final ScheduledThreadPool keepaliveExecutor, final ThreadPool processingExecutor,
-            final SchemaResourceManager schemaRepositoryProvider, final DataBroker dataBroker,
-            final DOMMountPointService mountService,
+            final SchemaResourceManager schemaRepositoryProvider, final BaseNetconfSchemas baseSchemas,
+            final DataBroker dataBroker, final DOMMountPointService mountService,
             final AAAEncryptionService encryptionService, final DeviceActionFactory deviceActionFactory) {
         this.topologyId = topologyId;
         this.eventExecutor = eventExecutor;
@@ -75,6 +80,7 @@ public class CallHomeMountDispatcher implements NetconfClientDispatcher, CallHom
         this.schemaRepositoryProvider = schemaRepositoryProvider;
         this.deviceActionFactory = deviceActionFactory;
         this.sessionManager = new CallHomeMountSessionManager();
+        this.baseSchemas = requireNonNull(baseSchemas);
         this.dataBroker = dataBroker;
         this.mountService = mountService;
         this.encryptionService = encryptionService;
@@ -102,7 +108,8 @@ public class CallHomeMountDispatcher implements NetconfClientDispatcher, CallHom
 
     void createTopology() {
         this.topology = new CallHomeTopology(topologyId, this, eventExecutor, keepaliveExecutor, processingExecutor,
-                schemaRepositoryProvider, dataBroker, mountService, encryptionService, deviceActionFactory);
+                schemaRepositoryProvider, dataBroker, mountService, encryptionService, baseSchemas,
+                deviceActionFactory);
     }
 
     @Override
index f6f185dc05ab3d2d2392ac41797963c26dd749ad..be5e3956c4e37df653f53a738e61e596ee6a9d2b 100644 (file)
@@ -19,6 +19,7 @@ import org.opendaylight.netconf.sal.connect.api.RemoteDeviceHandler;
 import org.opendaylight.netconf.sal.connect.api.SchemaResourceManager;
 import org.opendaylight.netconf.sal.connect.netconf.listener.NetconfSessionPreferences;
 import org.opendaylight.netconf.sal.connect.netconf.sal.NetconfDeviceSalFacade;
+import org.opendaylight.netconf.sal.connect.netconf.schema.mapping.BaseNetconfSchemas;
 import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId;
 
 public class CallHomeTopology extends BaseCallHomeTopology {
@@ -28,10 +29,10 @@ public class CallHomeTopology extends BaseCallHomeTopology {
             final ScheduledThreadPool keepaliveExecutor, final ThreadPool processingExecutor,
             final SchemaResourceManager schemaRepositoryProvider,
             final DataBroker dataBroker, final DOMMountPointService mountPointService,
-            final AAAEncryptionService encryptionService) {
+            final AAAEncryptionService encryptionService, final BaseNetconfSchemas baseSchemas) {
         this(topologyId, clientDispatcher, eventExecutor,
                 keepaliveExecutor, processingExecutor, schemaRepositoryProvider,
-                dataBroker, mountPointService, encryptionService, null);
+                dataBroker, mountPointService, encryptionService, baseSchemas, null);
     }
 
     public CallHomeTopology(final String topologyId, final NetconfClientDispatcher clientDispatcher,
@@ -39,11 +40,11 @@ public class CallHomeTopology extends BaseCallHomeTopology {
                             final ScheduledThreadPool keepaliveExecutor, final ThreadPool processingExecutor,
                             final SchemaResourceManager schemaRepositoryProvider,
                             final DataBroker dataBroker, final DOMMountPointService mountPointService,
-                            final AAAEncryptionService encryptionService,
+                            final AAAEncryptionService encryptionService, final BaseNetconfSchemas baseSchemas,
                             final DeviceActionFactory deviceActionFactory) {
         super(topologyId, clientDispatcher, eventExecutor,
                 keepaliveExecutor, processingExecutor, schemaRepositoryProvider,
-                dataBroker, mountPointService, encryptionService, deviceActionFactory);
+                dataBroker, mountPointService, encryptionService, deviceActionFactory, baseSchemas);
     }
 
     @Override
index c3a6c2dfd191dd347c8636a4aa7b28a6d63547d8..990db2d227399bae40b089a6d3397c779c75f93b 100644 (file)
@@ -29,6 +29,8 @@
                interface="org.opendaylight.netconf.sal.connect.api.DeviceActionFactory"/>
     <reference id="schemaManager"
                interface="org.opendaylight.netconf.sal.connect.api.SchemaResourceManager"/>
+    <reference id="baseSchemas"
+               interface="org.opendaylight.netconf.sal.connect.netconf.schema.mapping.BaseNetconfSchemas"/>
 
     <bean id="callhomeProvider" class="org.opendaylight.netconf.callhome.mount.IetfZeroTouchCallHomeServerProvider"
           init-method="init"
@@ -44,6 +46,7 @@
         <argument ref="keepAliveExecutor"/>
         <argument ref="processingExecutor"/>
         <argument ref="schemaManager"/>
+        <argument ref="baseSchemas"/>
         <argument ref="dataBroker"/>
         <argument ref="domMountPointService"/>
         <argument ref="encryptionService"/>
index d2037dcf33bb3933350973c919867b6403ceeeba..cbdf09b3044e2ba5a3d2e00a5b4e4b41ff04af9a 100644 (file)
@@ -36,6 +36,7 @@ import org.opendaylight.netconf.client.conf.NetconfClientConfigurationBuilder;
 import org.opendaylight.netconf.nettyutil.ReconnectStrategy;
 import org.opendaylight.netconf.nettyutil.handler.ssh.authentication.AuthenticationHandler;
 import org.opendaylight.netconf.sal.connect.api.SchemaResourceManager;
+import org.opendaylight.netconf.sal.connect.netconf.schema.mapping.BaseNetconfSchemas;
 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.Node;
 
@@ -54,6 +55,7 @@ public class CallHomeMountDispatcherTest {
     private CallHomeTopology mockTopology;
     private CallHomeProtocolSessionContext mockProtoSess;
     private AAAEncryptionService mockEncryptionService;
+    private BaseNetconfSchemas mockBaseSchemas;
 
     @Before
     public void setup() {
@@ -68,9 +70,10 @@ public class CallHomeMountDispatcherTest {
         mockTopology = mock(CallHomeTopology.class);
         mockProtoSess = mock(CallHomeProtocolSessionContext.class);
         mockEncryptionService = mock(AAAEncryptionService.class);
+        mockBaseSchemas = mock(BaseNetconfSchemas.class);
 
         instance = new CallHomeMountDispatcher(topologyId, mockExecutor, mockKeepAlive,
-                mockProcessingExecutor, mockSchemaRepoProvider, mockDataBroker, mockMount,
+                mockProcessingExecutor, mockSchemaRepoProvider, mockBaseSchemas, mockDataBroker, mockMount,
                 mockEncryptionService) {
             @Override
             public CallHomeMountSessionManager getSessionManager() {
index 1a3a443b2317f1a9575b26dfc00f160359f1c33b..326488605fc14ca22127f6b0668387ed862b9bc8 100644 (file)
@@ -30,6 +30,7 @@ import org.opendaylight.netconf.sal.connect.api.RemoteDeviceHandler;
 import org.opendaylight.netconf.sal.connect.api.SchemaResourceManager;
 import org.opendaylight.netconf.sal.connect.netconf.listener.NetconfSessionPreferences;
 import org.opendaylight.netconf.sal.connect.netconf.sal.NetconfDeviceSalFacade;
+import org.opendaylight.netconf.sal.connect.netconf.schema.mapping.BaseNetconfSchemas;
 import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId;
 import org.opendaylight.netconf.topology.spi.AbstractNetconfTopology;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology;
@@ -60,9 +61,9 @@ public class NetconfTopologyImpl extends AbstractNetconfTopology
             final ThreadPool processingExecutor,
             final SchemaResourceManager schemaRepositoryProvider,
             final DataBroker dataBroker, final DOMMountPointService mountPointService,
-            final AAAEncryptionService encryptionService) {
+            final AAAEncryptionService encryptionService, final BaseNetconfSchemas baseSchemas) {
         this(topologyId, clientDispatcher, eventExecutor, keepaliveExecutor, processingExecutor,
-                schemaRepositoryProvider, dataBroker, mountPointService, encryptionService, null);
+                schemaRepositoryProvider, dataBroker, mountPointService, encryptionService, baseSchemas, null);
     }
 
     public NetconfTopologyImpl(final String topologyId, final NetconfClientDispatcher clientDispatcher,
@@ -70,10 +71,11 @@ public class NetconfTopologyImpl extends AbstractNetconfTopology
             final ThreadPool processingExecutor,
             final SchemaResourceManager schemaRepositoryProvider,
             final DataBroker dataBroker, final DOMMountPointService mountPointService,
-            final AAAEncryptionService encryptionService,
+            final AAAEncryptionService encryptionService, final BaseNetconfSchemas baseSchemas,
             final DeviceActionFactory deviceActionFactory) {
         super(topologyId, clientDispatcher, eventExecutor, keepaliveExecutor, processingExecutor,
-                schemaRepositoryProvider, dataBroker, mountPointService, encryptionService, deviceActionFactory);
+                schemaRepositoryProvider, dataBroker, mountPointService, encryptionService, deviceActionFactory,
+                baseSchemas);
     }
 
     @Override
index ca6af6c3a3594eafea765e072a558c184afddba5..7b61fdf0ca97c92b2a95e7230db4921a47c4dce5 100644 (file)
@@ -33,6 +33,8 @@
                interface="org.opendaylight.netconf.sal.connect.api.DeviceActionFactory"/>
     <reference id="schemaManager"
                interface="org.opendaylight.netconf.sal.connect.api.SchemaResourceManager"/>
+    <reference id="baseSchemas"
+               interface="org.opendaylight.netconf.sal.connect.netconf.schema.mapping.BaseNetconfSchemas"/>
 
     <cm:property-placeholder persistent-id="org.opendaylight.netconf.topology.sb.keypair" update-strategy="none">
       <cm:default-properties>
@@ -57,6 +59,7 @@
         <property name="privateKeyPath" value="${private-key-path}"/>
         <property name="privateKeyPassphrase" value="${private-key-passphrase}"/>
         <argument ref="encryptionService" />
+        <argument ref="baseSchemas"/>
         <argument ref="deviceActionFactory"/>
     </bean>
 
index c8e808e7dc10b69c4bdc038b5ab4f27dae686f0b..9558c982575488553b3db567d4fd89c37b388a21 100644 (file)
@@ -48,6 +48,8 @@ import org.opendaylight.netconf.client.conf.NetconfClientConfiguration;
 import org.opendaylight.netconf.client.conf.NetconfReconnectingClientConfiguration;
 import org.opendaylight.netconf.sal.connect.api.SchemaResourceManager;
 import org.opendaylight.netconf.sal.connect.netconf.listener.NetconfDeviceCapabilities;
+import org.opendaylight.netconf.sal.connect.netconf.schema.mapping.BaseNetconfSchemas;
+import org.opendaylight.netconf.sal.connect.netconf.schema.mapping.DefaultBaseNetconfSchemas;
 import org.opendaylight.netconf.topology.spi.AbstractNetconfTopology;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Host;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
@@ -74,6 +76,7 @@ import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.IdentifiableIt
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.PathArgument;
 import org.opendaylight.yangtools.yang.common.Uint16;
 import org.opendaylight.yangtools.yang.common.Uint32;
+import org.opendaylight.yangtools.yang.parser.impl.YangParserFactoryImpl;
 
 @RunWith(MockitoJUnitRunner.StrictStubs.class)
 public class NetconfTopologyImplTest {
@@ -268,6 +271,8 @@ public class NetconfTopologyImplTest {
     }
 
     public static class TestingNetconfTopologyImpl extends NetconfTopologyImpl {
+        private static final BaseNetconfSchemas BASE_SCHEMAS =
+                new DefaultBaseNetconfSchemas(new YangParserFactoryImpl());
 
         public TestingNetconfTopologyImpl(final String topologyId, final NetconfClientDispatcher clientDispatcher,
                                           final EventExecutor eventExecutor,
@@ -278,7 +283,7 @@ public class NetconfTopologyImplTest {
                                           final AAAEncryptionService encryptionService) {
             super(topologyId, clientDispatcher, eventExecutor, keepaliveExecutor,
                     processingExecutor, schemaRepositoryProvider, dataBroker,
-                  mountPointService, encryptionService);
+                  mountPointService, encryptionService, BASE_SCHEMAS);
         }
 
         @Override
index ce4f0868b5a6fd1a3d435293aa04e60d79158fb7..7e9d230d9d451c8e966068c68b2f64b55a4206e4 100644 (file)
@@ -42,6 +42,7 @@ import org.opendaylight.mdsal.singleton.common.api.ServiceGroupIdentifier;
 import org.opendaylight.netconf.client.NetconfClientDispatcher;
 import org.opendaylight.netconf.sal.connect.api.DeviceActionFactory;
 import org.opendaylight.netconf.sal.connect.api.SchemaResourceManager;
+import org.opendaylight.netconf.sal.connect.netconf.schema.mapping.BaseNetconfSchemas;
 import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId;
 import org.opendaylight.netconf.topology.singleton.api.NetconfTopologySingletonService;
 import org.opendaylight.netconf.topology.singleton.impl.utils.NetconfTopologySetup;
@@ -72,6 +73,7 @@ public class NetconfTopologyManager
     private final Map<InstanceIdentifier<Node>, ClusterSingletonServiceRegistration>
             clusterRegistrations = new ConcurrentHashMap<>();
 
+    private final BaseNetconfSchemas baseSchemas;
     private final DataBroker dataBroker;
     private final DOMRpcProviderService rpcProviderRegistry;
     private final DOMActionProviderService actionProviderRegistry;
@@ -87,11 +89,13 @@ public class NetconfTopologyManager
     private final AAAEncryptionService encryptionService;
     private final DeviceActionFactory deviceActionFactory;
     private final SchemaResourceManager resourceManager;
+
     private ListenerRegistration<NetconfTopologyManager> dataChangeListenerRegistration;
     private String privateKeyPath;
     private String privateKeyPassphrase;
 
-    public NetconfTopologyManager(final DataBroker dataBroker, final DOMRpcProviderService rpcProviderRegistry,
+    public NetconfTopologyManager(final BaseNetconfSchemas baseSchemas, final DataBroker dataBroker,
+                                  final DOMRpcProviderService rpcProviderRegistry,
                                   final DOMActionProviderService actionProviderService,
                                   final ClusterSingletonServiceProvider clusterSingletonServiceProvider,
                                   final ScheduledThreadPool keepaliveExecutor, final ThreadPool processingExecutor,
@@ -102,6 +106,7 @@ public class NetconfTopologyManager
                                   final AAAEncryptionService encryptionService,
                                   final DeviceActionFactory deviceActionFactory,
                                   final SchemaResourceManager resourceManager) {
+        this.baseSchemas = requireNonNull(baseSchemas);
         this.dataBroker = requireNonNull(dataBroker);
         this.rpcProviderRegistry = requireNonNull(rpcProviderRegistry);
         this.actionProviderRegistry = requireNonNull(actionProviderService);
@@ -290,6 +295,7 @@ public class NetconfTopologyManager
 
         final NetconfTopologySetupBuilder builder = NetconfTopologySetupBuilder.create()
                 .setClusterSingletonServiceProvider(clusterSingletonServiceProvider)
+                .setBaseSchemas(baseSchemas)
                 .setDataBroker(dataBroker)
                 .setInstanceIdentifier(instanceIdentifier)
                 .setRpcProviderRegistry(rpcProviderRegistry)
index a971eabc60e504d935438b06346b2969b32975d7..2945267306713b42ea4cafa2e34c070363f955b1 100644 (file)
@@ -200,12 +200,14 @@ public class RemoteDeviceConnectorImpl implements RemoteDeviceConnector {
 
         final RemoteDevice<NetconfSessionPreferences, NetconfMessage, NetconfDeviceCommunicator> device;
         if (node.isSchemaless()) {
-            device = new SchemalessNetconfDevice(remoteDeviceId, salFacade);
+            device = new SchemalessNetconfDevice(netconfTopologyDeviceSetup.getBaseSchemas(), remoteDeviceId,
+                salFacade);
         } else {
             device = new NetconfDeviceBuilder()
                     .setReconnectOnSchemasChange(reconnectOnChangedSchema)
                     .setSchemaResourcesDTO(schemaResourcesDTO)
                     .setGlobalProcessingExecutor(netconfTopologyDeviceSetup.getProcessingExecutor())
+                    .setBaseSchemas(netconfTopologyDeviceSetup.getBaseSchemas())
                     .setId(remoteDeviceId)
                     .setDeviceActionFactory(deviceActionFactory)
                     .setSalFacade(salFacade)
index 355c4e55994926d16cb7370a59ae48a4db3e5aa4..1c96ae323b6efdf6884873ec5c2730a853a791fd 100644 (file)
@@ -7,6 +7,8 @@
  */
 package org.opendaylight.netconf.topology.singleton.impl.utils;
 
+import static java.util.Objects.requireNonNull;
+
 import akka.actor.ActorSystem;
 import com.google.common.util.concurrent.ListeningExecutorService;
 import io.netty.util.concurrent.EventExecutor;
@@ -18,6 +20,7 @@ import org.opendaylight.mdsal.dom.api.DOMRpcProviderService;
 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider;
 import org.opendaylight.netconf.client.NetconfClientDispatcher;
 import org.opendaylight.netconf.sal.connect.netconf.NetconfDevice;
+import org.opendaylight.netconf.sal.connect.netconf.schema.mapping.BaseNetconfSchemas;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import scala.concurrent.duration.Duration;
@@ -41,6 +44,7 @@ public class NetconfTopologySetup {
     private final String privateKeyPath;
     private final String privateKeyPassphrase;
     private final AAAEncryptionService encryptionService;
+    private final BaseNetconfSchemas baseSchemas;
 
     NetconfTopologySetup(final NetconfTopologySetupBuilder builder) {
         this.clusterSingletonServiceProvider = builder.getClusterSingletonServiceProvider();
@@ -60,6 +64,7 @@ public class NetconfTopologySetup {
         this.privateKeyPath = builder.getPrivateKeyPath();
         this.privateKeyPassphrase = builder.getPrivateKeyPassphrase();
         this.encryptionService = builder.getEncryptionService();
+        this.baseSchemas = builder.getBaseSchemas();
     }
 
     public ClusterSingletonServiceProvider getClusterSingletonServiceProvider() {
@@ -130,8 +135,11 @@ public class NetconfTopologySetup {
         return encryptionService;
     }
 
-    public static class NetconfTopologySetupBuilder {
+    public BaseNetconfSchemas getBaseSchemas() {
+        return baseSchemas;
+    }
 
+    public static class NetconfTopologySetupBuilder {
         private ClusterSingletonServiceProvider clusterSingletonServiceProvider;
         private DOMRpcProviderService rpcProviderRegistry;
         private DOMActionProviderService actionProviderRegistry;
@@ -149,11 +157,21 @@ public class NetconfTopologySetup {
         private String privateKeyPath;
         private String privateKeyPassphrase;
         private AAAEncryptionService encryptionService;
+        private BaseNetconfSchemas baseSchemas;
 
         public NetconfTopologySetupBuilder() {
 
         }
 
+        BaseNetconfSchemas getBaseSchemas() {
+            return requireNonNull(baseSchemas, "BaseSchemas not initialized");
+        }
+
+        public NetconfTopologySetupBuilder setBaseSchemas(final BaseNetconfSchemas baseSchemas) {
+            this.baseSchemas = requireNonNull(baseSchemas);
+            return this;
+        }
+
         ClusterSingletonServiceProvider getClusterSingletonServiceProvider() {
             return clusterSingletonServiceProvider;
         }
index acc59c117c99a6db6ac07de13d2dbe4745090843..34972d483d024656009b81d406d724eaa6610394 100644 (file)
@@ -40,6 +40,8 @@ and is available at http://www.eclipse.org/legal/epl-v10.html
                interface="org.opendaylight.netconf.sal.connect.api.DeviceActionFactory"/>
     <reference id="schemaManager"
                interface="org.opendaylight.netconf.sal.connect.api.SchemaResourceManager"/>
+    <reference id="baseSchemas"
+               interface="org.opendaylight.netconf.sal.connect.netconf.schema.mapping.BaseNetconfSchemas"/>
     <odl:clustered-app-config
             id="singletonConfig"
             binding-class="org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.topology.singleton.config.rev170419.Config"
@@ -60,6 +62,7 @@ and is available at http://www.eclipse.org/legal/epl-v10.html
           init-method="init" destroy-method="close">
         <cm:managed-properties persistent-id="org.opendaylight.netconf.topology.sb.keypair"
                                update-strategy="container-managed"/>
+        <argument ref="baseSchemas"/>
         <argument ref="dataBroker"/>
         <argument ref="rpcRegistry"/>
         <argument ref="actionRegistry"/>
diff --git a/netconf/netconf-topology-singleton/src/test/java/org/opendaylight/netconf/topology/singleton/impl/AbstractBaseSchemasTest.java b/netconf/netconf-topology-singleton/src/test/java/org/opendaylight/netconf/topology/singleton/impl/AbstractBaseSchemasTest.java
new file mode 100644 (file)
index 0000000..7e10737
--- /dev/null
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2020 PANTHEON.tech, s.r.o. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.netconf.topology.singleton.impl;
+
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.opendaylight.netconf.sal.connect.netconf.schema.mapping.BaseNetconfSchemas;
+import org.opendaylight.netconf.sal.connect.netconf.schema.mapping.DefaultBaseNetconfSchemas;
+import org.opendaylight.yangtools.yang.parser.impl.YangParserFactoryImpl;
+
+public abstract class AbstractBaseSchemasTest {
+    protected static BaseNetconfSchemas BASE_SCHEMAS;
+
+    @BeforeClass
+    public static void initBaseSchemas() {
+        BASE_SCHEMAS = new DefaultBaseNetconfSchemas(new YangParserFactoryImpl());
+    }
+
+    @AfterClass
+    public static void freeBaseSchemas() {
+        BASE_SCHEMAS = null;
+    }
+}
index b6f83ad969764aa8272f1fd7c0835c50a62ea5d1..6725ee3135571013abd1d4e1a7c4d0994a924876 100644 (file)
@@ -165,7 +165,7 @@ import org.slf4j.LoggerFactory;
  * @author Thomas Pantelis
  */
 @RunWith(MockitoJUnitRunner.class)
-public class MountPointEndToEndTest {
+public class MountPointEndToEndTest extends AbstractBaseSchemasTest {
     private static final Logger LOG = LoggerFactory.getLogger(MountPointEndToEndTest.class);
 
     private static final String TOP_MODULE_NAME = "opendaylight-mdsal-list-test";
@@ -288,10 +288,11 @@ public class MountPointEndToEndTest {
             PotentialSchemaSource.create(RevisionSourceIdentifier.create(TOP_MODULE_NAME,
                     topModuleInfo.getName().getRevision()), YangTextSchemaSource.class, 1));
 
-        masterNetconfTopologyManager = new NetconfTopologyManager(masterDataBroker, mockRpcProviderRegistry,
-            mockActionProviderRegistry, masterClusterSingletonServiceProvider, mockKeepaliveExecutor, mockThreadPool,
-                mockMasterActorSystemProvider, eventExecutor, mockClientDispatcher, TOPOLOGY_ID, config,
-                masterMountPointService, mockEncryptionService, deviceActionFactory, resourceManager) {
+        masterNetconfTopologyManager = new NetconfTopologyManager(BASE_SCHEMAS, masterDataBroker,
+                mockRpcProviderRegistry, mockActionProviderRegistry, masterClusterSingletonServiceProvider,
+                mockKeepaliveExecutor, mockThreadPool, mockMasterActorSystemProvider, eventExecutor,
+                mockClientDispatcher, TOPOLOGY_ID, config, masterMountPointService, mockEncryptionService,
+                deviceActionFactory, resourceManager) {
             @Override
             protected NetconfTopologyContext newNetconfTopologyContext(final NetconfTopologySetup setup,
                 final ServiceGroupIdentifier serviceGroupIdent, final Timeout actorResponseWaitTime,
@@ -327,7 +328,7 @@ public class MountPointEndToEndTest {
         doReturn(mockSlaveClusterSingletonServiceReg).when(mockSlaveClusterSingletonServiceProvider)
                 .registerClusterSingletonService(any());
 
-        slaveNetconfTopologyManager = new NetconfTopologyManager(slaveDataBroker, mockRpcProviderRegistry,
+        slaveNetconfTopologyManager = new NetconfTopologyManager(BASE_SCHEMAS, slaveDataBroker, mockRpcProviderRegistry,
             mockActionProviderRegistry, mockSlaveClusterSingletonServiceProvider, mockKeepaliveExecutor, mockThreadPool,
                 mockSlaveActorSystemProvider, eventExecutor, mockClientDispatcher, TOPOLOGY_ID, config,
                 slaveMountPointService, mockEncryptionService, deviceActionFactory, resourceManager) {
index 8fc8473b4542302188abcfc04db477ca5c0bd328..d168478b8850150ecd6b3178892552138e8143f7 100644 (file)
@@ -119,7 +119,7 @@ import scala.concurrent.Await;
 import scala.concurrent.Future;
 import scala.concurrent.duration.Duration;
 
-public class NetconfNodeActorTest {
+public class NetconfNodeActorTest extends AbstractBaseSchemasTest {
 
     private static final Timeout TIMEOUT = new Timeout(Duration.create(5, "seconds"));
     private static final RevisionSourceIdentifier SOURCE_IDENTIFIER1 = RevisionSourceIdentifier.create("yang1");
@@ -187,7 +187,8 @@ public class NetconfNodeActorTest {
         doReturn(masterSchemaRepository).when(schemaResourceDTO).getSchemaRepository();
         doReturn(mockRegistry).when(schemaResourceDTO).getSchemaRegistry();
         final NetconfTopologySetup setup = NetconfTopologySetupBuilder.create().setActorSystem(system)
-                .setIdleTimeout(Duration.apply(1, TimeUnit.SECONDS)).setSchemaResourceDTO(schemaResourceDTO).build();
+                .setIdleTimeout(Duration.apply(1, TimeUnit.SECONDS)).setSchemaResourceDTO(schemaResourceDTO)
+                .setBaseSchemas(BASE_SCHEMAS).build();
 
         final Props props = NetconfNodeActor.props(setup, remoteDeviceId, TIMEOUT, mockMountPointService);
 
@@ -222,7 +223,7 @@ public class NetconfNodeActorTest {
         final RemoteDeviceId newRemoteDeviceId = new RemoteDeviceId("netconf-topology2",
                 new InetSocketAddress(InetAddresses.forString("127.0.0.2"), 9999));
 
-        final NetconfTopologySetup newSetup = NetconfTopologySetupBuilder.create()
+        final NetconfTopologySetup newSetup = NetconfTopologySetupBuilder.create().setBaseSchemas(BASE_SCHEMAS)
                 .setSchemaResourceDTO(schemaResourceDTO).setActorSystem(system).build();
 
         masterRef.tell(new RefreshSetupMasterActorData(newSetup, newRemoteDeviceId), testKit.getRef());
@@ -231,7 +232,7 @@ public class NetconfNodeActorTest {
     }
 
     @Test
-    public void tesAskForMasterMountPoint() {
+    public void testAskForMasterMountPoint() {
 
         // Test with master not setup yet.
 
@@ -332,8 +333,11 @@ public class NetconfNodeActorTest {
         SchemaResourcesDTO schemaResourceDTO2 = mock(SchemaResourcesDTO.class);
         doReturn(mockRegistry).when(schemaResourceDTO2).getSchemaRegistry();
         doReturn(mockSchemaRepository).when(schemaResourceDTO2).getSchemaRepository();
-        final NetconfTopologySetup setup = NetconfTopologySetupBuilder.create().setSchemaResourceDTO(schemaResourceDTO2)
-                .setActorSystem(system).build();
+        final NetconfTopologySetup setup = NetconfTopologySetupBuilder.create()
+                .setSchemaResourceDTO(schemaResourceDTO2)
+                .setBaseSchemas(BASE_SCHEMAS)
+                .setActorSystem(system)
+                .build();
 
         final ActorRef slaveRef = system.actorOf(NetconfNodeActor.props(setup, remoteDeviceId, TIMEOUT,
                 mockMountPointService));
@@ -413,7 +417,8 @@ public class NetconfNodeActorTest {
         doReturn(repository).when(schemaResourceDTO2).getSchemaRegistry();
         doReturn(repository).when(schemaResourceDTO2).getSchemaRepository();
         final NetconfTopologySetup setup = NetconfTopologySetupBuilder.create().setActorSystem(system)
-                .setSchemaResourceDTO(schemaResourceDTO2).setIdleTimeout(Duration.apply(1, TimeUnit.SECONDS)).build();
+                .setSchemaResourceDTO(schemaResourceDTO2).setIdleTimeout(Duration.apply(1, TimeUnit.SECONDS))
+                .setBaseSchemas(BASE_SCHEMAS).build();
         final Props props = NetconfNodeActor.props(setup, remoteDeviceId, TIMEOUT, mockMountPointService);
         ActorRef actor = TestActorRef.create(system, props, "master_messages_2");
 
@@ -625,7 +630,7 @@ public class NetconfNodeActorTest {
         doReturn(mockSchemaRepository).when(schemaResourceDTO2).getSchemaRepository();
         final ActorRef slaveRef = system.actorOf(NetconfNodeActor.props(
                 NetconfTopologySetupBuilder.create().setSchemaResourceDTO(schemaResourceDTO2).setActorSystem(system)
-                .build(), remoteDeviceId, TIMEOUT, mockMountPointService));
+                .setBaseSchemas(BASE_SCHEMAS).build(), remoteDeviceId, TIMEOUT, mockMountPointService));
 
         doReturn(Futures.immediateFuture(mockSchemaContext))
                 .when(mockSchemaContextFactory).createEffectiveModelContext(anyCollection());
index 21f3c1439da43b61ae940aa4c32d4aa342553ab9..d9cfec0b1d4295c0d45bff11eef85763aa744a7e 100644 (file)
@@ -98,7 +98,7 @@ import org.opendaylight.yangtools.yang.parser.rfc7950.repo.TextToASTTransformer;
  *
  * @author Thomas Pantelis
  */
-public class NetconfNodeManagerTest {
+public class NetconfNodeManagerTest extends AbstractBaseSchemasTest {
     private static final String ACTOR_SYSTEM_NAME = "test";
     private static final RemoteDeviceId DEVICE_ID = new RemoteDeviceId("device", new InetSocketAddress(65535));
     private static final List<SourceIdentifier> SOURCE_IDENTIFIERS =
@@ -168,7 +168,7 @@ public class NetconfNodeManagerTest {
         NetconfTopologySetup masterSetup = new NetconfTopologySetup.NetconfTopologySetupBuilder()
                 .setActorSystem(masterSystem).setDataBroker(mockDataBroker).setSchemaResourceDTO(
                         new NetconfDevice.SchemaResourcesDTO(masterSchemaRepository, masterSchemaRepository,
-                                mockSchemaContextFactory, mockSchemasResolver)).build();
+                                mockSchemaContextFactory, mockSchemasResolver)).setBaseSchemas(BASE_SCHEMAS).build();
 
         testMasterActorRef = TestActorRef.create(masterSystem, Props.create(TestMasterActor.class, masterSetup,
                 DEVICE_ID, responseTimeout, mockMountPointService).withDispatcher(Dispatchers.DefaultDispatcherId()),
@@ -181,7 +181,7 @@ public class NetconfNodeManagerTest {
         NetconfTopologySetup slaveSetup = new NetconfTopologySetup.NetconfTopologySetupBuilder()
                 .setActorSystem(slaveSystem).setDataBroker(mockDataBroker).setSchemaResourceDTO(
                         new NetconfDevice.SchemaResourcesDTO(slaveSchemaRepository, slaveSchemaRepository,
-                                mockSchemaContextFactory, mockSchemasResolver)).build();
+                                mockSchemaContextFactory, mockSchemasResolver)).setBaseSchemas(BASE_SCHEMAS).build();
 
         netconfNodeManager = new NetconfNodeManager(slaveSetup, DEVICE_ID, responseTimeout,
                 mockMountPointService);
index c35842fcdb3d244d7848dc31a150b447237fb6f9..5c6812396514d19684eadd9066299f20dba2325a 100644 (file)
@@ -83,7 +83,7 @@ import org.opendaylight.yangtools.yang.binding.YangModuleInfo;
 import org.opendaylight.yangtools.yang.common.Uint16;
 import org.opendaylight.yangtools.yang.parser.impl.YangParserFactoryImpl;
 
-public class NetconfTopologyManagerTest {
+public class NetconfTopologyManagerTest extends AbstractBaseSchemasTest {
     private static final Uint16 ACTOR_RESPONSE_WAIT_TIME = Uint16.valueOf(10);
     private static final String TOPOLOGY_ID = "topologyID";
 
@@ -129,8 +129,8 @@ public class NetconfTopologyManagerTest {
         final DeviceActionFactory deviceActionFactory = mock(DeviceActionFactory.class);
 
         final Config config = new ConfigBuilder().setWriteTransactionIdleTimeout(Uint16.ZERO).build();
-        netconfTopologyManager = new NetconfTopologyManager(dataBroker, rpcProviderRegistry, actionProviderRegistry,
-                clusterSingletonServiceProvider, keepaliveExecutor, processingThreadPool,
+        netconfTopologyManager = new NetconfTopologyManager(BASE_SCHEMAS, dataBroker, rpcProviderRegistry,
+                actionProviderRegistry, clusterSingletonServiceProvider, keepaliveExecutor, processingThreadPool,
                 actorSystemProvider, eventExecutor, clientDispatcher, TOPOLOGY_ID, config,
                 mountPointService, encryptionService, deviceActionFactory,
                 new DefaultSchemaResourceManager(new YangParserFactoryImpl())) {
index abc5bac4e789cd742433f13e6dbd6756b702334a..5039b65dc9d16dff0094aa116cd107f848ceb437 100644 (file)
@@ -67,7 +67,7 @@ import org.opendaylight.yangtools.yang.common.Uint32;
 import org.opendaylight.yangtools.yang.parser.impl.YangParserFactoryImpl;
 import scala.concurrent.duration.Duration;
 
-public class RemoteDeviceConnectorImplTest {
+public class RemoteDeviceConnectorImplTest extends AbstractBaseSchemasTest {
 
     private static final NodeId NODE_ID = new NodeId("testing-node");
     private static final String TOPOLOGY_ID = "testing-topology";
@@ -124,16 +124,17 @@ public class RemoteDeviceConnectorImplTest {
         doNothing().when(writeTx).merge(eq(LogicalDatastoreType.OPERATIONAL), any(), any());
         doReturn("Some object").when(writeTx).getIdentifier();
         doReturn(emptyFluentFuture()).when(writeTx).commit();
-        builder = new NetconfTopologySetup.NetconfTopologySetupBuilder();
-        builder.setDataBroker(dataBroker);
-        builder.setRpcProviderRegistry(rpcProviderRegistry);
-        builder.setClusterSingletonServiceProvider(clusterSingletonServiceProvider);
-        builder.setKeepaliveExecutor(keepaliveExecutor);
-        builder.setProcessingExecutor(processingExecutor);
-        builder.setActorSystem(actorSystem);
-        builder.setEventExecutor(eventExecutor);
-        builder.setNetconfClientDispatcher(clientDispatcher);
-        builder.setTopologyId(TOPOLOGY_ID);
+        builder = new NetconfTopologySetup.NetconfTopologySetupBuilder()
+                .setBaseSchemas(BASE_SCHEMAS)
+                .setDataBroker(dataBroker)
+                .setRpcProviderRegistry(rpcProviderRegistry)
+                .setClusterSingletonServiceProvider(clusterSingletonServiceProvider)
+                .setKeepaliveExecutor(keepaliveExecutor)
+                .setProcessingExecutor(processingExecutor)
+                .setActorSystem(actorSystem)
+                .setEventExecutor(eventExecutor)
+                .setNetconfClientDispatcher(clientDispatcher)
+                .setTopologyId(TOPOLOGY_ID);
     }
 
     @SuppressWarnings("unchecked")
index 478ca7f6e328d7e66e3e39d1ce7dd42baf2f53f8..cb5249fef4e96eac66aced8bb7ad24a0dcf80a80 100644 (file)
@@ -58,6 +58,7 @@ import org.opendaylight.netconf.sal.connect.netconf.listener.UserPreferences;
 import org.opendaylight.netconf.sal.connect.netconf.sal.KeepaliveSalFacade;
 import org.opendaylight.netconf.sal.connect.netconf.sal.NetconfKeystoreAdapter;
 import org.opendaylight.netconf.sal.connect.netconf.schema.YangLibrarySchemaYangSourceProvider;
+import org.opendaylight.netconf.sal.connect.netconf.schema.mapping.BaseNetconfSchemas;
 import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId;
 import org.opendaylight.netconf.sal.connect.util.SslHandlerFactoryImpl;
 import org.opendaylight.netconf.topology.api.NetconfTopology;
@@ -106,6 +107,7 @@ public abstract class AbstractNetconfTopology implements NetconfTopology {
     private final DeviceActionFactory deviceActionFactory;
     private final NetconfKeystoreAdapter keystoreAdapter;
     private final SchemaResourceManager schemaManager;
+    private final BaseNetconfSchemas baseSchemas;
 
     protected final ScheduledThreadPool keepaliveExecutor;
     protected final ListeningExecutorService processingExecutor;
@@ -117,12 +119,14 @@ public abstract class AbstractNetconfTopology implements NetconfTopology {
     protected final AAAEncryptionService encryptionService;
     protected final HashMap<NodeId, NetconfConnectorDTO> activeConnectors = new HashMap<>();
 
+
     protected AbstractNetconfTopology(final String topologyId, final NetconfClientDispatcher clientDispatcher,
                                       final EventExecutor eventExecutor, final ScheduledThreadPool keepaliveExecutor,
                                       final ThreadPool processingExecutor, final SchemaResourceManager schemaManager,
                                       final DataBroker dataBroker, final DOMMountPointService mountPointService,
                                       final AAAEncryptionService encryptionService,
-                                      final DeviceActionFactory deviceActionFactory) {
+                                      final DeviceActionFactory deviceActionFactory,
+                                      final BaseNetconfSchemas baseSchemas) {
         this.topologyId = topologyId;
         this.clientDispatcher = clientDispatcher;
         this.eventExecutor = eventExecutor;
@@ -133,6 +137,7 @@ public abstract class AbstractNetconfTopology implements NetconfTopology {
         this.dataBroker = dataBroker;
         this.mountPointService = mountPointService;
         this.encryptionService = encryptionService;
+        this.baseSchemas = requireNonNull(baseSchemas);
 
         this.keystoreAdapter = new NetconfKeystoreAdapter(dataBroker);
     }
@@ -234,7 +239,7 @@ public abstract class AbstractNetconfTopology implements NetconfTopology {
 
         final RemoteDevice<NetconfSessionPreferences, NetconfMessage, NetconfDeviceCommunicator> device;
         if (node.isSchemaless()) {
-            device = new SchemalessNetconfDevice(remoteDeviceId, salFacade);
+            device = new SchemalessNetconfDevice(baseSchemas, remoteDeviceId, salFacade);
         } else {
             device = createNetconfDevice(remoteDeviceId, salFacade, nodeId, node, nodeOptional);
         }
@@ -276,6 +281,7 @@ public abstract class AbstractNetconfTopology implements NetconfTopology {
                 .setEventExecutor(eventExecutor)
                 .setNodeOptional(nodeOptional)
                 .setDeviceActionFactory(deviceActionFactory)
+                .setBaseSchemas(baseSchemas)
                 .build();
 
         final YangLibrary yangLibrary = node.getYangLibrary();
index 0c589810ca0b3d22d9b847e706a2be25bd0cef1b..eca7be202f80982b4e3725ecbf273a82f50c42c9 100644 (file)
@@ -46,6 +46,7 @@ import org.opendaylight.netconf.sal.connect.netconf.listener.NetconfDeviceCapabi
 import org.opendaylight.netconf.sal.connect.netconf.listener.NetconfDeviceCommunicator;
 import org.opendaylight.netconf.sal.connect.netconf.listener.NetconfSessionPreferences;
 import org.opendaylight.netconf.sal.connect.netconf.sal.NetconfDeviceRpc;
+import org.opendaylight.netconf.sal.connect.netconf.schema.mapping.BaseNetconfSchemas;
 import org.opendaylight.netconf.sal.connect.netconf.schema.mapping.BaseSchema;
 import org.opendaylight.netconf.sal.connect.netconf.schema.mapping.NetconfMessageTransformer;
 import org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil;
@@ -107,6 +108,7 @@ public class NetconfDevice
     private final NetconfDeviceSchemasResolver stateSchemasResolver;
     private final NotificationHandler notificationHandler;
     private final boolean reconnectOnSchemasChange;
+    private final BaseNetconfSchemas baseSchemas;
     private final NetconfNode node;
     private final EventExecutor eventExecutor;
     private final NetconfNodeAugmentedOptional nodeOptional;
@@ -117,19 +119,19 @@ public class NetconfDevice
     // Message transformer is constructed once the schemas are available
     private MessageTransformer<NetconfMessage> messageTransformer;
 
-    public NetconfDevice(final SchemaResourcesDTO schemaResourcesDTO, final RemoteDeviceId id,
-                         final RemoteDeviceHandler<NetconfSessionPreferences> salFacade,
-                         final ListeningExecutorService globalProcessingExecutor,
-                         final boolean reconnectOnSchemasChange) {
-        this(schemaResourcesDTO, id, salFacade, globalProcessingExecutor, reconnectOnSchemasChange, null, null, null,
-                null);
+    public NetconfDevice(final SchemaResourcesDTO schemaResourcesDTO, final BaseNetconfSchemas baseSchemas,
+            final RemoteDeviceId id, final RemoteDeviceHandler<NetconfSessionPreferences> salFacade,
+            final ListeningExecutorService globalProcessingExecutor, final boolean reconnectOnSchemasChange) {
+        this(schemaResourcesDTO, baseSchemas, id, salFacade, globalProcessingExecutor, reconnectOnSchemasChange, null,
+            null, null, null);
     }
 
-    public NetconfDevice(final SchemaResourcesDTO schemaResourcesDTO, final RemoteDeviceId id,
-            final RemoteDeviceHandler<NetconfSessionPreferences> salFacade,
+    public NetconfDevice(final SchemaResourcesDTO schemaResourcesDTO, final BaseNetconfSchemas baseSchemas,
+            final RemoteDeviceId id, final RemoteDeviceHandler<NetconfSessionPreferences> salFacade,
             final ListeningExecutorService globalProcessingExecutor, final boolean reconnectOnSchemasChange,
             final DeviceActionFactory deviceActionFactory, final NetconfNode node, final EventExecutor eventExecutor,
             final NetconfNodeAugmentedOptional nodeOptional) {
+        this.baseSchemas = requireNonNull(baseSchemas);
         this.id = id;
         this.reconnectOnSchemasChange = reconnectOnSchemasChange;
         this.deviceActionFactory = deviceActionFactory;
@@ -251,10 +253,8 @@ public class NetconfDevice
         //NetconfDevice.SchemaSetup can complete after NetconfDeviceCommunicator was closed. In that case do nothing,
         //since salFacade.onDeviceDisconnected was already called.
         if (connected) {
-            final BaseSchema baseSchema =
-                remoteSessionCapabilities.isNotificationsSupported()
-                        ? BaseSchema.BASE_NETCONF_CTX_WITH_NOTIFICATIONS : BaseSchema.BASE_NETCONF_CTX;
-            this.messageTransformer = new NetconfMessageTransformer(result, true, baseSchema);
+            this.messageTransformer = new NetconfMessageTransformer(result, true,
+                resolveBaseSchema(remoteSessionCapabilities.isNotificationsSupported()));
 
             // salFacade.onDeviceConnected has to be called before the notification handler is initialized
             this.salFacade.onDeviceConnected(result, remoteSessionCapabilities, deviceRpc,
@@ -366,13 +366,14 @@ public class NetconfDevice
         notificationHandler.handleNotification(notification);
     }
 
-    private static BaseSchema resolveBaseSchema(final boolean notificationSupport) {
-        return notificationSupport ? BaseSchema.BASE_NETCONF_CTX_WITH_NOTIFICATIONS : BaseSchema.BASE_NETCONF_CTX;
+    private BaseSchema resolveBaseSchema(final boolean notificationSupport) {
+        return notificationSupport ? baseSchemas.getBaseSchemaWithNotifications() : baseSchemas.getBaseSchema();
     }
 
     protected NetconfDeviceRpc getDeviceSpecificRpc(final MountPointContext result,
             final RemoteDeviceCommunicator<NetconfMessage> listener) {
-        return new NetconfDeviceRpc(result.getSchemaContext(), listener, new NetconfMessageTransformer(result, true));
+        return new NetconfDeviceRpc(result.getSchemaContext(), listener,
+            new NetconfMessageTransformer(result, true, baseSchemas.getBaseSchema()));
     }
 
     /**
index 7ed01542597ce229f21b5bb78ba6334cc67f634d..641de973095522d74b70a044723678a25f095b74 100644 (file)
@@ -14,6 +14,7 @@ import io.netty.util.concurrent.EventExecutor;
 import org.opendaylight.netconf.sal.connect.api.DeviceActionFactory;
 import org.opendaylight.netconf.sal.connect.api.RemoteDeviceHandler;
 import org.opendaylight.netconf.sal.connect.netconf.listener.NetconfSessionPreferences;
+import org.opendaylight.netconf.sal.connect.netconf.schema.mapping.BaseNetconfSchemas;
 import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.optional.rev190614.NetconfNodeAugmentedOptional;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNode;
@@ -29,6 +30,7 @@ public class NetconfDeviceBuilder {
     private NetconfNode node;
     private EventExecutor eventExecutor;
     private NetconfNodeAugmentedOptional nodeOptional;
+    private BaseNetconfSchemas baseSchemas;
 
     public NetconfDeviceBuilder() {
     }
@@ -78,14 +80,20 @@ public class NetconfDeviceBuilder {
         return this;
     }
 
+    public NetconfDeviceBuilder setBaseSchemas(final BaseNetconfSchemas baseSchemas) {
+        this.baseSchemas = requireNonNull(baseSchemas);
+        return this;
+    }
+
     public NetconfDevice build() {
         validation();
-        return new NetconfDevice(this.schemaResourcesDTO, this.id, this.salFacade, this.globalProcessingExecutor,
-                this.reconnectOnSchemasChange, this.deviceActionFactory, this.node, this.eventExecutor,
-                this.nodeOptional);
+        return new NetconfDevice(this.schemaResourcesDTO, this.baseSchemas, this.id, this.salFacade,
+            this.globalProcessingExecutor, this.reconnectOnSchemasChange, this.deviceActionFactory, this.node,
+            this.eventExecutor, this.nodeOptional);
     }
 
     private void validation() {
+        requireNonNull(this.baseSchemas, "BaseSchemas is not initialized");
         requireNonNull(this.id, "RemoteDeviceId is not initialized");
         requireNonNull(this.salFacade, "RemoteDeviceHandler is not initialized");
         requireNonNull(this.globalProcessingExecutor, "ExecutorService is not initialized");
index 543e19762ac53407add28a8e36b0ca06443ad42f..80923a3994ba57270c99a60a7242a7dd0c2ef2d8 100644 (file)
@@ -11,8 +11,11 @@ import static com.google.common.base.Preconditions.checkArgument;
 import static com.google.common.base.Preconditions.checkState;
 import static com.google.common.base.Verify.verify;
 import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil.NETCONF_DATA_NODEID;
+import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil.NETCONF_FILTER_NODEID;
+import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil.NETCONF_FILTER_QNAME;
 import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil.NETCONF_GET_NODEID;
 import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil.NETCONF_GET_PATH;
+import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil.NETCONF_TYPE_QNAME;
 import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil.toId;
 
 import com.google.common.annotations.VisibleForTesting;
@@ -26,11 +29,12 @@ import java.util.Optional;
 import java.util.Set;
 import java.util.concurrent.ExecutionException;
 import javax.xml.stream.XMLStreamException;
+import javax.xml.transform.dom.DOMSource;
 import org.opendaylight.mdsal.dom.api.DOMRpcResult;
 import org.opendaylight.mdsal.dom.api.DOMRpcService;
+import org.opendaylight.netconf.api.xml.XmlUtil;
 import org.opendaylight.netconf.sal.connect.api.NetconfDeviceSchemas;
 import org.opendaylight.netconf.sal.connect.netconf.listener.NetconfSessionPreferences;
-import org.opendaylight.netconf.sal.connect.netconf.schema.mapping.BaseSchema;
 import org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil;
 import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId;
 import org.opendaylight.netconf.util.NetconfUtil;
@@ -53,24 +57,43 @@ import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
 import org.xml.sax.SAXException;
 
 /**
  * Holds QNames for all yang modules reported by ietf-netconf-monitoring/state/schemas.
  */
 public final class NetconfStateSchemas implements NetconfDeviceSchemas {
-
-    private static final Logger LOG = LoggerFactory.getLogger(NetconfStateSchemas.class);
-
     public static final NetconfStateSchemas EMPTY = new NetconfStateSchemas(ImmutableSet.of());
 
+    private static final Logger LOG = LoggerFactory.getLogger(NetconfStateSchemas.class);
     private static final YangInstanceIdentifier STATE_SCHEMAS_IDENTIFIER =
             YangInstanceIdentifier.builder().node(NetconfState.QNAME).node(Schemas.QNAME).build();
-
-    private static final ContainerNode GET_SCHEMAS_RPC = Builders.containerBuilder()
-            .withNodeIdentifier(NETCONF_GET_NODEID)
-            .withChild(NetconfMessageTransformUtil.toFilterStructure(STATE_SCHEMAS_IDENTIFIER,
-                BaseSchema.BASE_NETCONF_CTX_WITH_NOTIFICATIONS.getSchemaContext())).build();
+    private static final ContainerNode GET_SCHEMAS_RPC;
+
+    static {
+        final Document document = XmlUtil.newDocument();
+
+        final Element filterElem = XmlUtil.createElement(document, NETCONF_FILTER_QNAME.getLocalName(),
+            Optional.of(NETCONF_FILTER_QNAME.getNamespace().toString()));
+        filterElem.setAttributeNS(NETCONF_FILTER_QNAME.getNamespace().toString(), NETCONF_TYPE_QNAME.getLocalName(),
+            "subtree");
+
+        final Element stateElem = XmlUtil.createElement(document, NetconfState.QNAME.getLocalName(),
+            Optional.of(NetconfState.QNAME.getNamespace().toString()));
+        stateElem.appendChild(XmlUtil.createElement(document, Schemas.QNAME.getLocalName(),
+            Optional.of(Schemas.QNAME.getNamespace().toString())));
+        filterElem.appendChild(stateElem);
+
+        GET_SCHEMAS_RPC = Builders.containerBuilder()
+                .withNodeIdentifier(NETCONF_GET_NODEID)
+                .withChild(Builders.anyXmlBuilder()
+                    .withNodeIdentifier(NETCONF_FILTER_NODEID)
+                    .withValue(new DOMSource(filterElem))
+                    .build())
+                .build();
+    }
 
     private final Set<RemoteYangSchema> availableYangSchemas;
 
index 310f5a90687594cabd6cb7e3416a48374f1f3c9e..2d2d0e29bdc5210303e96c4cb2816d82cdf34465 100644 (file)
@@ -7,6 +7,8 @@
  */
 package org.opendaylight.netconf.sal.connect.netconf;
 
+import static java.util.Objects.requireNonNull;
+
 import com.google.common.annotations.VisibleForTesting;
 import org.opendaylight.netconf.api.NetconfMessage;
 import org.opendaylight.netconf.sal.connect.api.RemoteDevice;
@@ -14,58 +16,65 @@ import org.opendaylight.netconf.sal.connect.api.RemoteDeviceHandler;
 import org.opendaylight.netconf.sal.connect.netconf.listener.NetconfDeviceCommunicator;
 import org.opendaylight.netconf.sal.connect.netconf.listener.NetconfSessionPreferences;
 import org.opendaylight.netconf.sal.connect.netconf.sal.SchemalessNetconfDeviceRpc;
+import org.opendaylight.netconf.sal.connect.netconf.schema.mapping.BaseNetconfSchemas;
 import org.opendaylight.netconf.sal.connect.netconf.schema.mapping.BaseRpcSchemalessTransformer;
-import org.opendaylight.netconf.sal.connect.netconf.schema.mapping.BaseSchema;
 import org.opendaylight.netconf.sal.connect.netconf.schema.mapping.SchemalessMessageTransformer;
 import org.opendaylight.netconf.sal.connect.util.MessageCounter;
 import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId;
 
-public class SchemalessNetconfDevice implements
-        RemoteDevice<NetconfSessionPreferences, NetconfMessage, NetconfDeviceCommunicator> {
-
+public class SchemalessNetconfDevice
+        implements RemoteDevice<NetconfSessionPreferences, NetconfMessage, NetconfDeviceCommunicator> {
+    private final BaseNetconfSchemas baseSchemas;
     private final RemoteDeviceId id;
     private final RemoteDeviceHandler<NetconfSessionPreferences> salFacade;
     private final SchemalessMessageTransformer messageTransformer;
     private final BaseRpcSchemalessTransformer rpcTransformer;
 
-    public SchemalessNetconfDevice(final RemoteDeviceId id,
+    public SchemalessNetconfDevice(final BaseNetconfSchemas baseSchemas, final RemoteDeviceId id,
                                    final RemoteDeviceHandler<NetconfSessionPreferences> salFacade) {
+        this.baseSchemas = requireNonNull(baseSchemas);
         this.id = id;
         this.salFacade = salFacade;
         final MessageCounter counter = new MessageCounter();
-        rpcTransformer = new BaseRpcSchemalessTransformer(counter);
+        rpcTransformer = new BaseRpcSchemalessTransformer(baseSchemas, counter);
         messageTransformer = new SchemalessMessageTransformer(counter);
     }
 
     @VisibleForTesting
-    SchemalessNetconfDevice(final RemoteDeviceId id, final RemoteDeviceHandler<NetconfSessionPreferences> salFacade,
+    SchemalessNetconfDevice(final BaseNetconfSchemas baseSchemas, final RemoteDeviceId id,
+                            final RemoteDeviceHandler<NetconfSessionPreferences> salFacade,
                             final SchemalessMessageTransformer messageTransformer) {
+        this.baseSchemas = requireNonNull(baseSchemas);
         this.id = id;
         this.salFacade = salFacade;
         final MessageCounter counter = new MessageCounter();
-        rpcTransformer = new BaseRpcSchemalessTransformer(counter);
+        rpcTransformer = new BaseRpcSchemalessTransformer(baseSchemas, counter);
         this.messageTransformer = messageTransformer;
     }
 
-    @Override public void onRemoteSessionUp(final NetconfSessionPreferences remoteSessionCapabilities,
+    @Override
+    public void onRemoteSessionUp(final NetconfSessionPreferences remoteSessionCapabilities,
                                             final NetconfDeviceCommunicator netconfDeviceCommunicator) {
         final SchemalessNetconfDeviceRpc schemalessNetconfDeviceRpc = new SchemalessNetconfDeviceRpc(id,
                 netconfDeviceCommunicator, rpcTransformer, messageTransformer);
 
-        salFacade.onDeviceConnected(BaseSchema.BASE_NETCONF_CTX.getMountPointContext(),
+        salFacade.onDeviceConnected(baseSchemas.getBaseSchema().getMountPointContext(),
                 remoteSessionCapabilities, schemalessNetconfDeviceRpc);
 
     }
 
-    @Override public void onRemoteSessionDown() {
+    @Override
+    public void onRemoteSessionDown() {
         salFacade.onDeviceDisconnected();
     }
 
-    @Override public void onRemoteSessionFailed(final Throwable throwable) {
+    @Override
+    public void onRemoteSessionFailed(final Throwable throwable) {
         salFacade.onDeviceFailed(throwable);
     }
 
-    @Override public void onNotification(final NetconfMessage notification) {
+    @Override
+    public void onNotification(final NetconfMessage notification) {
         salFacade.onNotification(messageTransformer.toNotification(notification));
     }
 }
diff --git a/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/schema/mapping/BaseNetconfSchemas.java b/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/schema/mapping/BaseNetconfSchemas.java
new file mode 100644 (file)
index 0000000..666d529
--- /dev/null
@@ -0,0 +1,21 @@
+/*
+ * Copyright (c) 2020 PANTHEON.tech, s.r.o. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.netconf.sal.connect.netconf.schema.mapping;
+
+import com.google.common.annotations.Beta;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.opendaylight.yangtools.concepts.Immutable;
+
+@Beta
+@NonNullByDefault
+public interface BaseNetconfSchemas extends Immutable {
+
+    BaseSchema getBaseSchema();
+
+    BaseSchema getBaseSchemaWithNotifications();
+}
index 6cec8afe814caf4ee428d7d6d2b2bfcb434e9497..9ad2417e81496ce9524b25b46376ba647fc1d3a1 100644 (file)
@@ -8,8 +8,8 @@
 package org.opendaylight.netconf.sal.connect.netconf.schema.mapping;
 
 import com.google.common.base.Preconditions;
+import com.google.common.collect.ImmutableMap;
 import java.io.IOException;
-import java.util.Map;
 import javax.xml.stream.XMLStreamException;
 import javax.xml.transform.dom.DOMResult;
 import javax.xml.transform.dom.DOMSource;
@@ -28,8 +28,8 @@ import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
 import org.opendaylight.yangtools.yang.data.api.schema.DOMSourceAnyxmlNode;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
 import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
+import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
 import org.opendaylight.yangtools.yang.model.api.RpcDefinition;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
@@ -38,13 +38,14 @@ import org.w3c.dom.Element;
  * Transforms base netconf RPCs.
  */
 public class BaseRpcSchemalessTransformer implements MessageTransformer<NetconfMessage> {
-
-    private static final Map<QName, ? extends RpcDefinition> MAPPED_RPCS = BaseSchema.BASE_NETCONF_CTX.getMappedRpcs();
-    private static final SchemaContext SCHEMA_CONTEXT = BaseSchema.BASE_NETCONF_CTX.getSchemaContext();
-
+    private final ImmutableMap<QName, ? extends RpcDefinition> mappedRpcs;
+    private final EffectiveModelContext modelContext;
     private final MessageCounter counter;
 
-    public BaseRpcSchemalessTransformer(final MessageCounter counter) {
+    public BaseRpcSchemalessTransformer(final BaseNetconfSchemas baseSchemas, final MessageCounter counter) {
+        final BaseSchema baseSchema = baseSchemas.getBaseSchema();
+        mappedRpcs = baseSchema.getMappedRpcs();
+        modelContext = baseSchema.getEffectiveModelContext();
         this.counter = counter;
     }
 
@@ -58,8 +59,8 @@ public class BaseRpcSchemalessTransformer implements MessageTransformer<NetconfM
         // In case no input for rpc is defined, we can simply construct the payload here
         final QName rpcQName = rpc.getLastComponent();
 
-        final RpcDefinition mappedRpc = Preconditions.checkNotNull(MAPPED_RPCS.get(rpcQName),
-            "Unknown rpc %s, available rpcs: %s", rpcQName, MAPPED_RPCS.keySet());
+        final RpcDefinition mappedRpc = Preconditions.checkNotNull(mappedRpcs.get(rpcQName),
+            "Unknown rpc %s, available rpcs: %s", rpcQName, mappedRpcs.keySet());
         final DOMResult domResult = NetconfMessageTransformUtil.prepareDomResultForRpcRequest(rpcQName, counter);
         if (mappedRpc.getInput().getChildNodes().isEmpty()) {
             return new NetconfMessage(domResult.getNode().getOwnerDocument());
@@ -74,8 +75,7 @@ public class BaseRpcSchemalessTransformer implements MessageTransformer<NetconfM
         final DOMResult result = domResult;
 
         try {
-            NetconfMessageTransformUtil.writeNormalizedRpc((ContainerNode) payload, result,
-                    inputPath, SCHEMA_CONTEXT);
+            NetconfMessageTransformUtil.writeNormalizedRpc((ContainerNode) payload, result, inputPath, modelContext);
         } catch (final XMLStreamException | IOException | IllegalStateException e) {
             throw new IllegalStateException("Unable to serialize " + inputPath, e);
         }
index 9a4c8e6a699170e4e8d1a6e7d5b39fa64e0c3984..5466e069e3e72e554e87f4f8c8e0aed269bfc75a 100644 (file)
@@ -9,40 +9,21 @@ package org.opendaylight.netconf.sal.connect.netconf.schema.mapping;
 
 import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.Maps;
-import java.util.Arrays;
 import org.eclipse.jdt.annotation.NonNull;
-import org.opendaylight.binding.runtime.spi.BindingRuntimeHelpers;
+import org.opendaylight.yangtools.concepts.Immutable;
 import org.opendaylight.yangtools.rcf8528.data.util.EmptyMountPointContext;
-import org.opendaylight.yangtools.yang.binding.YangModuleInfo;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContextProvider;
 import org.opendaylight.yangtools.yang.model.api.RpcDefinition;
 
-public enum BaseSchema implements EffectiveModelContextProvider {
-    BASE_NETCONF_CTX(
-        org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.base._1._0.rev110601
-            .$YangModuleInfoImpl.getInstance(),
-        org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.extension.rev131210
-            .$YangModuleInfoImpl.getInstance()
-    ),
-    BASE_NETCONF_CTX_WITH_NOTIFICATIONS(
-        org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.extension.rev131210
-            .$YangModuleInfoImpl.getInstance(),
-        org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.notification._1._0.rev080714
-            .$YangModuleInfoImpl.getInstance(),
-        org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.base._1._0.rev110601
-            .$YangModuleInfoImpl.getInstance(),
-        org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206
-            .$YangModuleInfoImpl.getInstance()
-    );
-
+public final class BaseSchema implements EffectiveModelContextProvider, Immutable {
     private final @NonNull ImmutableMap<QName, ? extends RpcDefinition> mappedRpcs;
     private final @NonNull EmptyMountPointContext mountContext;
 
-    BaseSchema(final YangModuleInfo... modules) {
-        mountContext = new EmptyMountPointContext(BindingRuntimeHelpers.createEffectiveModel(Arrays.asList(modules)));
-        mappedRpcs = Maps.uniqueIndex(getSchemaContext().getOperations(), RpcDefinition::getQName);
+    BaseSchema(final EffectiveModelContext context) {
+        mountContext = new EmptyMountPointContext(context);
+        mappedRpcs = Maps.uniqueIndex(context.getOperations(), RpcDefinition::getQName);
     }
 
     @NonNull ImmutableMap<QName, ? extends RpcDefinition> getMappedRpcs() {
diff --git a/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/schema/mapping/DefaultBaseNetconfSchemas.java b/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/schema/mapping/DefaultBaseNetconfSchemas.java
new file mode 100644 (file)
index 0000000..eb01725
--- /dev/null
@@ -0,0 +1,60 @@
+/*
+ * Copyright (c) 2020 PANTHEON.tech, s.r.o. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.netconf.sal.connect.netconf.schema.mapping;
+
+import com.google.common.annotations.Beta;
+import java.util.Arrays;
+import javax.inject.Inject;
+import javax.inject.Singleton;
+import org.eclipse.jdt.annotation.NonNull;
+import org.opendaylight.binding.runtime.spi.BindingRuntimeHelpers;
+import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
+import org.opendaylight.yangtools.yang.model.parser.api.YangParserFactory;
+
+@Beta
+@Singleton
+public final class DefaultBaseNetconfSchemas implements BaseNetconfSchemas {
+    private final @NonNull BaseSchema withoutNotifications;
+    private final @NonNull BaseSchema withNotifications;
+
+    @Inject
+    public DefaultBaseNetconfSchemas(final YangParserFactory parserFactory) {
+        withoutNotifications = new BaseSchema(withoutNotifications(parserFactory));
+        withNotifications = new BaseSchema(withNotifications(parserFactory));
+    }
+
+    @Override
+    public @NonNull BaseSchema getBaseSchema() {
+        return withoutNotifications;
+    }
+
+    @Override
+    public @NonNull BaseSchema getBaseSchemaWithNotifications() {
+        return withNotifications;
+    }
+
+    private static EffectiveModelContext withoutNotifications(final YangParserFactory parserFactory) {
+        return BindingRuntimeHelpers.createEffectiveModel(parserFactory, Arrays.asList(
+            org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.base._1._0.rev110601
+                .$YangModuleInfoImpl.getInstance(),
+            org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.extension.rev131210
+                .$YangModuleInfoImpl.getInstance()));
+    }
+
+    private static EffectiveModelContext withNotifications(final YangParserFactory parserFactory) {
+        return BindingRuntimeHelpers.createEffectiveModel(parserFactory, Arrays.asList(
+            org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.extension.rev131210
+                .$YangModuleInfoImpl.getInstance(),
+            org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.notification._1._0.rev080714
+                .$YangModuleInfoImpl.getInstance(),
+            org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.base._1._0.rev110601
+                .$YangModuleInfoImpl.getInstance(),
+            org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206
+                .$YangModuleInfoImpl.getInstance()));
+    }
+}
index 8f1353d6ccdde6cb7af645d6b0c08cc539d22781..0e937ba37fb3a22d5a34c6fee44757fd1dbb60c0 100644 (file)
@@ -94,10 +94,6 @@ public class NetconfMessageTransformer implements MessageTransformer<NetconfMess
     private final boolean strictParsing;
     private final ImmutableMap<SchemaPath, ActionDefinition> actions;
 
-    public NetconfMessageTransformer(final MountPointContext mountContext, final boolean strictParsing) {
-        this(mountContext, strictParsing, BaseSchema.BASE_NETCONF_CTX);
-    }
-
     public NetconfMessageTransformer(final MountPointContext mountContext, final boolean strictParsing,
                                      final BaseSchema baseSchema) {
         this.counter = new MessageCounter();
index 827144b2d81f3b45a786ffa0bab457aa35b2b2b7..423664c4e1cc32f95a9098e1401f908eb643241a 100644 (file)
@@ -29,4 +29,12 @@ and is available at http://www.eclipse.org/legal/epl-v10.html
 
     <service ref="schemaResourceManager"
              interface="org.opendaylight.netconf.sal.connect.api.SchemaResourceManager"/>
+
+    <bean id="baseNetconfSchemas"
+          class="org.opendaylight.netconf.sal.connect.netconf.schema.mapping.DefaultBaseNetconfSchemas">
+        <argument ref="parserFactory"/>
+    </bean>
+
+    <service ref="baseNetconfSchemas"
+             interface="org.opendaylight.netconf.sal.connect.netconf.schema.mapping.BaseNetconfSchemas"/>
 </blueprint>
diff --git a/netconf/sal-netconf-connector/src/test/java/org/opendaylight/netconf/sal/connect/netconf/AbstractBaseSchemasTest.java b/netconf/sal-netconf-connector/src/test/java/org/opendaylight/netconf/sal/connect/netconf/AbstractBaseSchemasTest.java
new file mode 100644 (file)
index 0000000..cc34b40
--- /dev/null
@@ -0,0 +1,29 @@
+/*
+ * Copyright (c) 2020 PANTHEON.tech, s.r.o. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.netconf.sal.connect.netconf;
+
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.opendaylight.netconf.sal.connect.netconf.schema.mapping.BaseNetconfSchemas;
+import org.opendaylight.netconf.sal.connect.netconf.schema.mapping.DefaultBaseNetconfSchemas;
+import org.opendaylight.yangtools.yang.parser.impl.YangParserFactoryImpl;
+
+public abstract class AbstractBaseSchemasTest {
+    protected static BaseNetconfSchemas BASE_SCHEMAS;
+
+    @BeforeClass
+    public static void initBaseSchemas() {
+        BASE_SCHEMAS = new DefaultBaseNetconfSchemas(new YangParserFactoryImpl());
+    }
+
+    @AfterClass
+    public static void freeBaseSchemas() {
+        BASE_SCHEMAS = null;
+    }
+
+}
index 5c73e06d88c9a1786135724db7df3351b4867cf2..9baac226f27980ae0f9ddcd311182ab0354ab3a4 100644 (file)
@@ -12,7 +12,7 @@ import org.junit.BeforeClass;
 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
 
-public abstract class AbstractTestModelTest {
+public abstract class AbstractTestModelTest extends AbstractBaseSchemasTest {
     protected static EffectiveModelContext SCHEMA_CONTEXT;
 
     @BeforeClass
index 1313b609d5c7cf6f37ea056fdb4ecec9019a56c2..2e6ecb66cb29f430ae44008afcff76b4c395f4b9 100644 (file)
@@ -156,6 +156,7 @@ public class NetconfDeviceTest extends AbstractTestModelTest {
                 .setGlobalProcessingExecutor(getExecutor())
                 .setId(getId())
                 .setSalFacade(facade)
+                .setBaseSchemas(BASE_SCHEMAS)
                 .build();
         // Monitoring supported
         final NetconfSessionPreferences sessionCaps =
@@ -192,6 +193,7 @@ public class NetconfDeviceTest extends AbstractTestModelTest {
                 .setGlobalProcessingExecutor(getExecutor())
                 .setId(getId())
                 .setSalFacade(facade)
+                .setBaseSchemas(BASE_SCHEMAS)
                 .build();
 
         // Monitoring not supported
@@ -241,6 +243,7 @@ public class NetconfDeviceTest extends AbstractTestModelTest {
                 .setReconnectOnSchemasChange(true)
                 .setSchemaResourcesDTO(schemaResourcesDTO)
                 .setGlobalProcessingExecutor(getExecutor())
+                .setBaseSchemas(BASE_SCHEMAS)
                 .setId(getId())
                 .setSalFacade(facade)
                 .build();
@@ -288,6 +291,7 @@ public class NetconfDeviceTest extends AbstractTestModelTest {
                 .setGlobalProcessingExecutor(getExecutor())
                 .setId(getId())
                 .setSalFacade(facade)
+                .setBaseSchemas(BASE_SCHEMAS)
                 .build();
 
         final NetconfSessionPreferences sessionCaps = getSessionCaps(true,
@@ -321,6 +325,7 @@ public class NetconfDeviceTest extends AbstractTestModelTest {
                 .setGlobalProcessingExecutor(getExecutor())
                 .setId(getId())
                 .setSalFacade(facade)
+                .setBaseSchemas(BASE_SCHEMAS)
                 .build();
         final NetconfSessionPreferences sessionCaps = getSessionCaps(true,
                 Lists.newArrayList(TEST_NAMESPACE + "?module=" + TEST_MODULE + "&amp;revision=" + TEST_REVISION));
@@ -358,6 +363,7 @@ public class NetconfDeviceTest extends AbstractTestModelTest {
                 .setGlobalProcessingExecutor(getExecutor())
                 .setId(getId())
                 .setSalFacade(facade)
+                .setBaseSchemas(BASE_SCHEMAS)
                 .build();
         final NetconfSessionPreferences sessionCaps = getSessionCaps(true,
                 Lists.newArrayList(TEST_NAMESPACE + "?module=" + TEST_MODULE + "&amp;revision=" + TEST_REVISION));
@@ -387,6 +393,7 @@ public class NetconfDeviceTest extends AbstractTestModelTest {
                 .setGlobalProcessingExecutor(getExecutor())
                 .setId(getId())
                 .setSalFacade(facade)
+                .setBaseSchemas(BASE_SCHEMAS)
                 .build();
         final NetconfDevice netconfSpy = Mockito.spy(device);
 
index 72734dc92a08d345614134e2d92044ec16b746ee..dc08b9292c4d886f7310a6f1ceb3276c927ccda1 100644 (file)
@@ -33,14 +33,14 @@ import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Ignore;
 import org.junit.Test;
+import org.junit.runner.RunWith;
 import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnitRunner;
 import org.opendaylight.mdsal.dom.api.DOMRpcImplementationNotAvailableException;
 import org.opendaylight.mdsal.dom.api.DOMRpcResult;
 import org.opendaylight.mdsal.dom.api.DOMRpcService;
 import org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult;
 import org.opendaylight.netconf.sal.connect.netconf.listener.NetconfSessionPreferences;
-import org.opendaylight.netconf.sal.connect.netconf.schema.mapping.BaseSchema;
 import org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil;
 import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.NetconfState;
@@ -62,7 +62,8 @@ import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-public class NetconfStateSchemasTest {
+@RunWith(MockitoJUnitRunner.StrictStubs.class)
+public class NetconfStateSchemasTest extends AbstractBaseSchemasTest {
 
     private static final Logger LOG = LoggerFactory.getLogger(NetconfStateSchemasTest.class);
 
@@ -80,8 +81,7 @@ public class NetconfStateSchemasTest {
 
     @Before
     public void setUp() throws Exception {
-        MockitoAnnotations.initMocks(this);
-        schemaContext = BaseSchema.BASE_NETCONF_CTX_WITH_NOTIFICATIONS.getEffectiveModelContext();
+        schemaContext = BASE_SCHEMAS.getBaseSchemaWithNotifications().getEffectiveModelContext();
         final DataSchemaNode schemasNode =
                 ((ContainerSchemaNode) schemaContext
                         .getDataChildByName(NetconfState.QNAME)).getDataChildByName(Schemas.QNAME);
index 249bf065e85048ad8ce1401e3df6c6054523b6d9..365acb668b0efd4ed06fe2297febf64ccdb162cd 100644 (file)
@@ -29,7 +29,7 @@ import org.opendaylight.yangtools.yang.model.api.Module;
 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
 import org.w3c.dom.Document;
 
-public class NetconfToNotificationTest {
+public class NetconfToNotificationTest extends AbstractBaseSchemasTest {
 
     NetconfMessageTransformer messageTransformer;
 
@@ -65,14 +65,16 @@ public class NetconfToNotificationTest {
     @Test(expected =  IllegalArgumentException.class)
     public void testMostRecentWrongYangModel() throws Exception {
         final EffectiveModelContext schemaContext = getNotificationSchemaContext(getClass(), true);
-        messageTransformer = new NetconfMessageTransformer(new EmptyMountPointContext(schemaContext), true);
+        messageTransformer = new NetconfMessageTransformer(new EmptyMountPointContext(schemaContext), true,
+            BASE_SCHEMAS.getBaseSchema());
         messageTransformer.toNotification(userNotification);
     }
 
     @Test
     public void testToNotificationFunction() throws Exception {
         final EffectiveModelContext schemaContext = getNotificationSchemaContext(getClass(), false);
-        messageTransformer = new NetconfMessageTransformer(new EmptyMountPointContext(schemaContext), true);
+        messageTransformer = new NetconfMessageTransformer(new EmptyMountPointContext(schemaContext), true,
+            BASE_SCHEMAS.getBaseSchema());
         final DOMNotification domNotification = messageTransformer.toNotification(userNotification);
         final ContainerNode root = domNotification.getBody();
         assertNotNull(root);
index 12e6b07fdcc7d17aed348ed7e1cbdbc498accf80..fc47f360c6424ec56699eceae11751a78b21079f 100644 (file)
@@ -14,6 +14,7 @@ import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTr
 import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil.toPath;
 
 import java.util.Collection;
+import org.junit.Before;
 import org.junit.BeforeClass;
 import org.junit.Test;
 import org.opendaylight.netconf.api.NetconfMessage;
@@ -21,21 +22,18 @@ import org.opendaylight.netconf.api.xml.XmlUtil;
 import org.opendaylight.netconf.sal.connect.netconf.schema.mapping.NetconfMessageTransformer;
 import org.opendaylight.yangtools.rcf8528.data.util.EmptyMountPointContext;
 import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
-import org.opendaylight.yangtools.yang.data.api.schema.LeafNode;
 import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
-import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeBuilder;
+import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
 import org.opendaylight.yangtools.yang.model.api.Module;
 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
 import org.w3c.dom.Document;
 
-public class NetconfToRpcRequestTest {
+public class NetconfToRpcRequestTest extends AbstractBaseSchemasTest {
 
     private static final String TEST_MODEL_NAMESPACE = "urn:opendaylight:params:xml:ns:yang:controller:md:sal:rpc-test";
     private static final String REVISION = "2014-07-14";
-    private static final QName INPUT_QNAME = QName.create(TEST_MODEL_NAMESPACE, REVISION, "input");
     private static final QName STREAM_NAME = QName.create(TEST_MODEL_NAMESPACE, REVISION, "stream-name");
     private static final QName SUBSCRIBE_RPC_NAME = QName.create(TEST_MODEL_NAMESPACE, REVISION, "subscribe");
 
@@ -44,12 +42,10 @@ public class NetconfToRpcRequestTest {
     private static final String CONFIG_TEST_REVISION = "2014-07-21";
     private static final QName EDIT_CONFIG_QNAME =
             QName.create(CONFIG_TEST_NAMESPACE, CONFIG_TEST_REVISION, "edit-config");
-    private static final QName GET_QNAME = QName.create(CONFIG_TEST_NAMESPACE, CONFIG_TEST_REVISION, "get");
-    private static final QName GET_CONFIG_QNAME =
-            QName.create(CONFIG_TEST_NAMESPACE, CONFIG_TEST_REVISION, "get-config");
 
     static EffectiveModelContext cfgCtx;
-    static NetconfMessageTransformer messageTransformer;
+
+    private  NetconfMessageTransformer messageTransformer;
 
     @BeforeClass
     public static void setup() {
@@ -59,21 +55,20 @@ public class NetconfToRpcRequestTest {
 
         cfgCtx = YangParserTestUtils.parseYangResources(NetconfToRpcRequestTest.class,
             "/schemas/config-test-rpc.yang", "/schemas/rpc-notification-subscription.yang");
-        messageTransformer = new NetconfMessageTransformer(new EmptyMountPointContext(cfgCtx), true);
     }
 
-    private static LeafNode<Object> buildLeaf(final QName running, final Object value) {
-        return Builders.leafBuilder().withNodeIdentifier(toId(running)).withValue(value).build();
+    @Before
+    public void before() {
+        messageTransformer = new NetconfMessageTransformer(new EmptyMountPointContext(cfgCtx), true,
+            BASE_SCHEMAS.getBaseSchema());
     }
 
     @Test
     public void testUserDefinedRpcCall() throws Exception {
-        final DataContainerNodeBuilder<YangInstanceIdentifier.NodeIdentifier, ContainerNode> rootBuilder =
-                Builders.containerBuilder();
-        rootBuilder.withNodeIdentifier(toId(SUBSCRIBE_RPC_NAME));
-
-        rootBuilder.withChild(buildLeaf(STREAM_NAME, "NETCONF"));
-        final ContainerNode root = rootBuilder.build();
+        final ContainerNode root = Builders.containerBuilder()
+                .withNodeIdentifier(toId(SUBSCRIBE_RPC_NAME))
+                .withChild(ImmutableNodes.leafNode(STREAM_NAME, "NETCONF"))
+                .build();
 
         final NetconfMessage message = messageTransformer.toRpcRequest(toPath(SUBSCRIBE_RPC_NAME), root);
         assertNotNull(message);
index 1f32d1b62d4ad5473efa598f3b2a41441a12f5e0..6cb2effeaff54626601af928d19917106f47397a 100644 (file)
@@ -32,7 +32,7 @@ import org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransform
 import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId;
 import org.opendaylight.yangtools.rfc8528.data.api.MountPointContext;
 
-public class SchemalessNetconfDeviceTest {
+public class SchemalessNetconfDeviceTest extends AbstractBaseSchemasTest {
 
     private static final String TEST_NAMESPACE = "test:namespace";
     private static final String TEST_MODULE = "test-module";
@@ -47,7 +47,8 @@ public class SchemalessNetconfDeviceTest {
                 InetSocketAddress.createUnresolved("localhost", 22));
         final Throwable throwable = new Throwable();
 
-        final SchemalessNetconfDevice device = new SchemalessNetconfDevice(remoteDeviceId, facade, messageTransformer);
+        final SchemalessNetconfDevice device = new SchemalessNetconfDevice(BASE_SCHEMAS, remoteDeviceId, facade,
+            messageTransformer);
 
         final NetconfSessionPreferences sessionCaps = getSessionCaps(true,
                 Lists.newArrayList(TEST_NAMESPACE + "?module=" + TEST_MODULE + "&amp;revision=" + TEST_REVISION));
index 1d3c6e12e4cb7de7a3c71398740cf91f09900bdd..56fe3b16f515ea688d133ad903ca27092e8a933d 100644 (file)
@@ -30,6 +30,7 @@ import org.opendaylight.mdsal.dom.api.DOMRpcResult;
 import org.opendaylight.netconf.api.NetconfMessage;
 import org.opendaylight.netconf.api.xml.XmlUtil;
 import org.opendaylight.netconf.sal.connect.api.RemoteDeviceCommunicator;
+import org.opendaylight.netconf.sal.connect.netconf.AbstractBaseSchemasTest;
 import org.opendaylight.netconf.sal.connect.netconf.schema.mapping.NetconfMessageTransformer;
 import org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.base._1._0.rev110601.IetfNetconfService;
@@ -47,7 +48,7 @@ import org.opendaylight.yangtools.yang.model.api.RpcDefinition;
 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
 import org.w3c.dom.Node;
 
-public class NetconfDeviceRpcTest {
+public class NetconfDeviceRpcTest extends AbstractBaseSchemasTest {
     private static EffectiveModelContext SCHEMA_CONTEXT;
 
     @Mock
@@ -73,7 +74,7 @@ public class NetconfDeviceRpcTest {
     public void setUp() throws Exception {
         MockitoAnnotations.initMocks(this);
         NetconfMessageTransformer transformer = new NetconfMessageTransformer(
-            new EmptyMountPointContext(SCHEMA_CONTEXT), true);
+            new EmptyMountPointContext(SCHEMA_CONTEXT), true, BASE_SCHEMAS.getBaseSchema());
         final NetconfMessage reply = new NetconfMessage(XmlUtil.readXmlToDocument(
                 "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n"
                         + "<rpc-reply xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\" message-id=\"101\">\n"
index 3c3a24d28abe46fc72800e54fac0f9d907282e2a..40c56f783a31ef552b1b352fbfa99e619cc2f45d 100644 (file)
@@ -23,6 +23,7 @@ import org.mockito.MockitoAnnotations;
 import org.opendaylight.netconf.api.NetconfMessage;
 import org.opendaylight.netconf.api.xml.XmlUtil;
 import org.opendaylight.netconf.sal.connect.api.RemoteDeviceCommunicator;
+import org.opendaylight.netconf.sal.connect.netconf.AbstractBaseSchemasTest;
 import org.opendaylight.netconf.sal.connect.netconf.schema.mapping.BaseRpcSchemalessTransformer;
 import org.opendaylight.netconf.sal.connect.netconf.schema.mapping.SchemalessMessageTransformer;
 import org.opendaylight.netconf.sal.connect.util.MessageCounter;
@@ -36,7 +37,7 @@ import org.opendaylight.yangtools.yang.model.api.SchemaPath;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-public class SchemalessNetconfDeviceRpcTest {
+public class SchemalessNetconfDeviceRpcTest extends AbstractBaseSchemasTest {
 
     private static final Logger LOG = LoggerFactory.getLogger(SchemalessNetconfDeviceRpcTest.class);
 
@@ -54,7 +55,7 @@ public class SchemalessNetconfDeviceRpcTest {
         final MessageCounter counter = new MessageCounter();
         deviceRpc = new SchemalessNetconfDeviceRpc(
                 new RemoteDeviceId("device1", InetSocketAddress.createUnresolved("0.0.0.0", 17830)), listener,
-                new BaseRpcSchemalessTransformer(counter), new SchemalessMessageTransformer(counter));
+                new BaseRpcSchemalessTransformer(BASE_SCHEMAS, counter), new SchemalessMessageTransformer(counter));
 
     }
 
index 53c1a37ea3ab7705c0add6dcd1f1698c6bf2364b..31789e96a3c18edd01ae51b2f459ddd20813da95 100644 (file)
@@ -28,14 +28,15 @@ import java.util.concurrent.ExecutionException;
 import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
+import org.junit.runner.RunWith;
 import org.mockito.ArgumentCaptor;
 import org.mockito.InOrder;
 import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnitRunner;
 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
 import org.opendaylight.mdsal.dom.api.DOMRpcService;
 import org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult;
-import org.opendaylight.netconf.sal.connect.netconf.schema.mapping.BaseSchema;
+import org.opendaylight.netconf.sal.connect.netconf.AbstractBaseSchemasTest;
 import org.opendaylight.netconf.sal.connect.netconf.util.NetconfBaseOps;
 import org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil;
 import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId;
@@ -51,7 +52,8 @@ import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
 
-public class NetconfDeviceWriteOnlyTxTest {
+@RunWith(MockitoJUnitRunner.StrictStubs.class)
+public class NetconfDeviceWriteOnlyTxTest extends AbstractBaseSchemasTest {
 
     private final RemoteDeviceId id = new RemoteDeviceId("test-mount", new InetSocketAddress(99));
 
@@ -60,9 +62,7 @@ public class NetconfDeviceWriteOnlyTxTest {
     private YangInstanceIdentifier yangIId;
 
     @Before
-    public void setUp() throws Exception {
-        MockitoAnnotations.initMocks(this);
-
+    public void setUp() {
         final FluentFuture<DefaultDOMRpcResult> successFuture =
                 FluentFutures.immediateFluentFuture(new DefaultDOMRpcResult((NormalizedNode<?, ?>) null));
 
@@ -139,7 +139,7 @@ public class NetconfDeviceWriteOnlyTxTest {
                 .when(rpc).invokeRpc(any(SchemaPath.class), any(ContainerNode.class));
 
         final WriteRunningTx tx = new WriteRunningTx(id,
-            new NetconfBaseOps(rpc, BaseSchema.BASE_NETCONF_CTX_WITH_NOTIFICATIONS.getEffectiveModelContext()), false);
+            new NetconfBaseOps(rpc, BASE_SCHEMAS.getBaseSchemaWithNotifications().getEffectiveModelContext()), false);
 
         tx.delete(LogicalDatastoreType.CONFIGURATION, yangIId);
         tx.commit();
@@ -158,7 +158,7 @@ public class NetconfDeviceWriteOnlyTxTest {
         doReturn(FluentFutures.immediateFluentFuture(new DefaultDOMRpcResult((NormalizedNode<?, ?>) null)))
                 .when(rpc).invokeRpc(any(SchemaPath.class), any(ContainerNode.class));
         final WriteCandidateTx tx = new WriteCandidateTx(
-                id, new NetconfBaseOps(rpc, BaseSchema.BASE_NETCONF_CTX.getEffectiveModelContext()), false);
+                id, new NetconfBaseOps(rpc, BASE_SCHEMAS.getBaseSchema().getEffectiveModelContext()), false);
         final TxListener listener = mock(TxListener.class);
         tx.addListener(listener);
         tx.delete(LogicalDatastoreType.CONFIGURATION, yangIId);
@@ -174,7 +174,7 @@ public class NetconfDeviceWriteOnlyTxTest {
         doReturn(FluentFutures.immediateFluentFuture(new DefaultDOMRpcResult((NormalizedNode<?, ?>) null)))
                 .when(rpc).invokeRpc(any(SchemaPath.class), isNull());
         final WriteCandidateTx tx = new WriteCandidateTx(
-                id, new NetconfBaseOps(rpc, BaseSchema.BASE_NETCONF_CTX.getEffectiveModelContext()), false);
+                id, new NetconfBaseOps(rpc, BASE_SCHEMAS.getBaseSchema().getEffectiveModelContext()), false);
         final TxListener listener = mock(TxListener.class);
         tx.addListener(listener);
         tx.delete(LogicalDatastoreType.CONFIGURATION, yangIId);
@@ -191,7 +191,7 @@ public class NetconfDeviceWriteOnlyTxTest {
         doReturn(FluentFutures.immediateFailedFluentFuture(cause))
                 .when(rpc).invokeRpc(any(SchemaPath.class), any(ContainerNode.class));
         final WriteCandidateTx tx = new WriteCandidateTx(
-                id, new NetconfBaseOps(rpc, BaseSchema.BASE_NETCONF_CTX.getEffectiveModelContext()), false);
+                id, new NetconfBaseOps(rpc, BASE_SCHEMAS.getBaseSchema().getEffectiveModelContext()), false);
         final TxListener listener = mock(TxListener.class);
         tx.addListener(listener);
         tx.delete(LogicalDatastoreType.CONFIGURATION, yangIId);
index c5c1a6fb51cf702f222e234891b8fd540625966a..027518e24cbda19e94a9b5db6750cbda69ea1b54 100644 (file)
@@ -18,6 +18,7 @@ import org.junit.Test;
 import org.opendaylight.mdsal.dom.api.DOMRpcResult;
 import org.opendaylight.netconf.api.NetconfMessage;
 import org.opendaylight.netconf.api.xml.XmlUtil;
+import org.opendaylight.netconf.sal.connect.netconf.AbstractBaseSchemasTest;
 import org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil;
 import org.opendaylight.netconf.sal.connect.util.MessageCounter;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.base._1._0.rev110601.copy.config.input.target.ConfigTarget;
@@ -34,7 +35,7 @@ import org.opendaylight.yangtools.yang.model.api.SchemaPath;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 
-public class BaseRpcSchemalessTransformerTest {
+public class BaseRpcSchemalessTransformerTest extends AbstractBaseSchemasTest {
 
     static {
         XMLUnit.setIgnoreWhitespace(true);
@@ -62,7 +63,7 @@ public class BaseRpcSchemalessTransformerTest {
 
     @Before
     public void setUp() throws Exception {
-        transformer = new BaseRpcSchemalessTransformer(new MessageCounter());
+        transformer = new BaseRpcSchemalessTransformer(BASE_SCHEMAS, new MessageCounter());
     }
 
     @Test(expected = UnsupportedOperationException.class)
index bb78a324cbf28789e100bff7d76a9314d27f6d76..155c1c60e0476f03e0737cd029f538a7c1aa41a5 100644 (file)
@@ -55,6 +55,7 @@ import org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier;
 import org.opendaylight.mdsal.dom.api.DOMRpcResult;
 import org.opendaylight.netconf.api.NetconfMessage;
 import org.opendaylight.netconf.api.xml.XmlUtil;
+import org.opendaylight.netconf.sal.connect.netconf.AbstractBaseSchemasTest;
 import org.opendaylight.netconf.sal.connect.netconf.schema.NetconfRemoteSchemaYangSourceProvider;
 import org.opendaylight.netconf.sal.connect.netconf.util.NetconfBaseOps;
 import org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil;
@@ -90,7 +91,7 @@ import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
 import org.w3c.dom.Node;
 import org.xml.sax.SAXException;
 
-public class NetconfMessageTransformerTest {
+public class NetconfMessageTransformerTest extends AbstractBaseSchemasTest {
 
     private static final String REVISION_EXAMPLE_SERVER_FARM = "2018-08-07";
     private static final String URN_EXAMPLE_SERVER_FARM = "urn:example:server-farm";
@@ -192,7 +193,7 @@ public class NetconfMessageTransformerTest {
 
         netconfMessageTransformer = getTransformer(SCHEMA);
         actionNetconfMessageTransformer = new NetconfMessageTransformer(new EmptyMountPointContext(ACTION_SCHEMA),
-            true);
+            true, BASE_SCHEMAS.getBaseSchema());
     }
 
     @Test
@@ -208,7 +209,7 @@ public class NetconfMessageTransformerTest {
     @Test
     public void testCreateSubscriberNotificationSchemaNotPresent() throws Exception {
         final NetconfMessageTransformer transformer = new NetconfMessageTransformer(new EmptyMountPointContext(SCHEMA),
-            true, BaseSchema.BASE_NETCONF_CTX_WITH_NOTIFICATIONS);
+            true, BASE_SCHEMAS.getBaseSchemaWithNotifications());
         NetconfMessage netconfMessage = transformer.toRpcRequest(
                 toPath(CREATE_SUBSCRIPTION_RPC_QNAME),
                 CREATE_SUBSCRIPTION_RPC_CONTENT
@@ -416,7 +417,7 @@ public class NetconfMessageTransformerTest {
                 .node(NetconfState.QNAME).node(Schemas.QNAME).node(Schema.QNAME)
                 .nodeWithKey(Schema.QNAME, keys).build();
         final DataContainerChild<?, ?> editConfigStructure =
-                createEditConfigStructure(BaseSchema.BASE_NETCONF_CTX_WITH_NOTIFICATIONS.getSchemaContext(), id,
+                createEditConfigStructure(BASE_SCHEMAS.getBaseSchemaWithNotifications().getEffectiveModelContext(), id,
                     Optional.empty(), Optional.ofNullable(schemaNode));
 
         final DataContainerChild<?, ?> target = NetconfBaseOps.getTargetNode(NETCONF_CANDIDATE_QNAME);
@@ -478,7 +479,7 @@ public class NetconfMessageTransformerTest {
     }
 
     private static NetconfMessageTransformer getTransformer(final EffectiveModelContext schema) {
-        return new NetconfMessageTransformer(new EmptyMountPointContext(schema), true);
+        return new NetconfMessageTransformer(new EmptyMountPointContext(schema), true, BASE_SCHEMAS.getBaseSchema());
     }
 
     @Test
index 0fce822e6a116b2a4334ddd2c75b0687d1295df9..0320a6e2c04327aca0afd21748502caad5dbd617 100644 (file)
@@ -91,7 +91,7 @@ public class NetconfBaseOpsTest extends AbstractTestModelTest {
         when(listener.sendRequest(any(), eq(NetconfMessageTransformUtil.NETCONF_COMMIT_QNAME)))
                 .thenReturn(FluentFuture.from(RpcResultBuilder.success(ok).buildFuture()));
         final MessageTransformer<NetconfMessage> transformer = new NetconfMessageTransformer(
-            new EmptyMountPointContext(SCHEMA_CONTEXT), true);
+            new EmptyMountPointContext(SCHEMA_CONTEXT), true, BASE_SCHEMAS.getBaseSchema());
         final DOMRpcService rpc = new NetconfDeviceRpc(SCHEMA_CONTEXT, listener, transformer);
         final RemoteDeviceId id =
                 new RemoteDeviceId("device-1", InetSocketAddress.createUnresolved("localhost", 17830));