Custom scheme-cache-directory yang models are not replicated among
[netconf.git] / netconf / netconf-topology-singleton / src / main / java / org / opendaylight / netconf / topology / singleton / impl / actors / NetconfNodeActor.java
index f81c7541f179f53a310daa9666b4af0691c520d5..a3f73e1446d045c3a00d0320d859b67a4a442a14 100644 (file)
@@ -21,20 +21,17 @@ import com.google.common.util.concurrent.MoreExecutors;
 import java.io.IOException;
 import java.util.List;
 import java.util.stream.Collectors;
-import javax.annotation.Nonnull;
-import javax.annotation.Nullable;
-import org.eclipse.jdt.annotation.NonNull;
 import org.opendaylight.controller.cluster.common.actor.AbstractUntypedActor;
 import org.opendaylight.controller.cluster.schema.provider.RemoteYangTextSourceProvider;
 import org.opendaylight.controller.cluster.schema.provider.impl.RemoteSchemaProvider;
 import org.opendaylight.controller.cluster.schema.provider.impl.YangTextSchemaSourceSerializationProxy;
-import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker;
-import org.opendaylight.controller.md.sal.dom.api.DOMDataReadOnlyTransaction;
-import org.opendaylight.controller.md.sal.dom.api.DOMDataReadWriteTransaction;
-import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction;
-import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService;
-import org.opendaylight.controller.md.sal.dom.api.DOMRpcResult;
-import org.opendaylight.controller.md.sal.dom.api.DOMRpcService;
+import org.opendaylight.mdsal.dom.api.DOMDataBroker;
+import org.opendaylight.mdsal.dom.api.DOMDataTreeReadTransaction;
+import org.opendaylight.mdsal.dom.api.DOMDataTreeReadWriteTransaction;
+import org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction;
+import org.opendaylight.mdsal.dom.api.DOMMountPointService;
+import org.opendaylight.mdsal.dom.api.DOMRpcResult;
+import org.opendaylight.mdsal.dom.api.DOMRpcService;
 import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId;
 import org.opendaylight.netconf.topology.singleton.impl.ProxyDOMRpcService;
 import org.opendaylight.netconf.topology.singleton.impl.ProxyYangTextSourceProvider;
@@ -57,11 +54,11 @@ import org.opendaylight.netconf.topology.singleton.messages.transactions.NewRead
 import org.opendaylight.netconf.topology.singleton.messages.transactions.NewReadWriteTransactionRequest;
 import org.opendaylight.netconf.topology.singleton.messages.transactions.NewWriteTransactionRequest;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
+import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
-import org.opendaylight.yangtools.yang.model.repo.api.SchemaContextFactory;
+import org.opendaylight.yangtools.yang.model.repo.api.EffectiveModelContextFactory;
 import org.opendaylight.yangtools.yang.model.repo.api.SchemaRepository;
-import org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceFilter;
 import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
 import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
 import org.opendaylight.yangtools.yang.model.repo.spi.PotentialSchemaSource;
@@ -70,7 +67,6 @@ import org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceRegistry;
 import scala.concurrent.duration.Duration;
 
 public class NetconfNodeActor extends AbstractUntypedActor {
-
     private final Duration writeTxIdleTimeout;
     private final DOMMountPointService mountPointService;
 
@@ -87,23 +83,19 @@ public class NetconfNodeActor extends AbstractUntypedActor {
     private ActorRef readTxActor;
     private List<SchemaSourceRegistration<YangTextSchemaSource>> registeredSchemas;
 
-    public static Props props(final NetconfTopologySetup setup,
-                              final RemoteDeviceId id, final SchemaSourceRegistry schemaRegistry,
-                              final SchemaRepository schemaRepository, final Timeout actorResponseWaitTime,
-                              final DOMMountPointService mountPointService) {
+    public static Props props(final NetconfTopologySetup setup, final RemoteDeviceId id,
+            final Timeout actorResponseWaitTime, final DOMMountPointService mountPointService) {
         return Props.create(NetconfNodeActor.class, () ->
-                new NetconfNodeActor(setup, id, schemaRegistry, schemaRepository, actorResponseWaitTime,
-                        mountPointService));
+                new NetconfNodeActor(setup, id, actorResponseWaitTime, mountPointService));
     }
 
     protected NetconfNodeActor(final NetconfTopologySetup setup,
-                               final RemoteDeviceId id, final SchemaSourceRegistry schemaRegistry,
-                               final SchemaRepository schemaRepository, final Timeout actorResponseWaitTime,
+                               final RemoteDeviceId id, final Timeout actorResponseWaitTime,
                                final DOMMountPointService mountPointService) {
         this.setup = setup;
         this.id = id;
-        this.schemaRegistry = schemaRegistry;
-        this.schemaRepository = schemaRepository;
+        this.schemaRegistry = setup.getSchemaResourcesDTO().getSchemaRegistry();
+        this.schemaRepository = setup.getSchemaResourcesDTO().getSchemaRepository();
         this.actorResponseWaitTime = actorResponseWaitTime;
         this.writeTxIdleTimeout = setup.getIdleTimeout();
         this.mountPointService = mountPointService;
@@ -111,7 +103,7 @@ public class NetconfNodeActor extends AbstractUntypedActor {
 
     @SuppressWarnings("checkstyle:IllegalCatch")
     @Override
-    public void handleReceive(final Object message) throws Exception {
+    public void handleReceive(final Object message) {
         LOG.debug("{}:  received message {}", id, message);
 
         if (message instanceof CreateInitialMasterActorData) { // master
@@ -119,7 +111,7 @@ public class NetconfNodeActor extends AbstractUntypedActor {
             final CreateInitialMasterActorData masterActorData = (CreateInitialMasterActorData) message;
             sourceIdentifiers = masterActorData.getSourceIndentifiers();
             this.deviceDataBroker = masterActorData.getDeviceDataBroker();
-            final DOMDataReadOnlyTransaction tx = deviceDataBroker.newReadOnlyTransaction();
+            final DOMDataTreeReadTransaction tx = deviceDataBroker.newReadOnlyTransaction();
             readTxActor = context().actorOf(ReadTransactionActor.props(tx));
             this.deviceRpc = masterActorData.getDeviceRpc();
 
@@ -153,7 +145,7 @@ public class NetconfNodeActor extends AbstractUntypedActor {
             sender().tell(new Success(readTxActor), self());
         } else if (message instanceof NewWriteTransactionRequest) { // master
             try {
-                final DOMDataWriteTransaction tx = deviceDataBroker.newWriteOnlyTransaction();
+                final DOMDataTreeWriteTransaction tx = deviceDataBroker.newWriteOnlyTransaction();
                 final ActorRef txActor = context().actorOf(WriteTransactionActor.props(tx, writeTxIdleTimeout));
                 sender().tell(new Success(txActor), self());
             } catch (final Exception t) {
@@ -162,7 +154,7 @@ public class NetconfNodeActor extends AbstractUntypedActor {
 
         } else if (message instanceof NewReadWriteTransactionRequest) {
             try {
-                final DOMDataReadWriteTransaction tx = deviceDataBroker.newReadWriteTransaction();
+                final DOMDataTreeReadWriteTransaction tx = deviceDataBroker.newReadWriteTransaction();
                 final ActorRef txActor = context().actorOf(ReadWriteTransactionActor.props(tx, writeTxIdleTimeout));
                 sender().tell(new Success(txActor), self());
             } catch (final Exception t) {
@@ -208,7 +200,7 @@ public class NetconfNodeActor extends AbstractUntypedActor {
     }
 
     private void sendYangTextSchemaSourceProxy(final SourceIdentifier sourceIdentifier, final ActorRef sender) {
-        final ListenableFuture<@NonNull YangTextSchemaSource> schemaSourceFuture =
+        final ListenableFuture<YangTextSchemaSource> schemaSourceFuture =
                 schemaRepository.getSchemaSource(sourceIdentifier, YangTextSchemaSource.class);
 
         Futures.addCallback(schemaSourceFuture, new FutureCallback<YangTextSchemaSource>() {
@@ -223,7 +215,7 @@ public class NetconfNodeActor extends AbstractUntypedActor {
             }
 
             @Override
-            public void onFailure(@Nonnull final Throwable throwable) {
+            public void onFailure(final Throwable throwable) {
                 LOG.debug("{}: getSchemaSource for {} failed", id, sourceIdentifier, throwable);
                 sender.tell(new Failure(throwable), getSelf());
             }
@@ -241,7 +233,7 @@ public class NetconfNodeActor extends AbstractUntypedActor {
 
         Futures.addCallback(rpcResult, new FutureCallback<DOMRpcResult>() {
             @Override
-            public void onSuccess(@Nullable final DOMRpcResult domRpcResult) {
+            public void onSuccess(final DOMRpcResult domRpcResult) {
                 LOG.debug("{}: invokeSlaveRpc for {}, domRpcResult: {}", id, schemaPath, domRpcResult);
 
                 if (domRpcResult == null) {
@@ -257,7 +249,7 @@ public class NetconfNodeActor extends AbstractUntypedActor {
             }
 
             @Override
-            public void onFailure(@Nonnull final Throwable throwable) {
+            public void onFailure(final Throwable throwable) {
                 recipient.tell(new Failure(throwable), getSelf());
             }
         }, MoreExecutors.directExecutor());
@@ -275,7 +267,7 @@ public class NetconfNodeActor extends AbstractUntypedActor {
         return new ProxyDOMRpcService(setup.getActorSystem(), masterReference, id, actorResponseWaitTime);
     }
 
-    private SchemaContextFactory createSchemaContextFactory(final ActorRef masterReference) {
+    private EffectiveModelContextFactory createSchemaContextFactory(final ActorRef masterReference) {
         final RemoteYangTextSourceProvider remoteYangTextSourceProvider =
                 new ProxyYangTextSourceProvider(masterReference, getContext().dispatcher(), actorResponseWaitTime);
         final RemoteSchemaProvider remoteProvider = new RemoteSchemaProvider(remoteYangTextSourceProvider,
@@ -287,16 +279,16 @@ public class NetconfNodeActor extends AbstractUntypedActor {
                                 YangTextSchemaSource.class, PotentialSchemaSource.Costs.REMOTE_IO.getValue())))
                 .collect(Collectors.toList());
 
-        return schemaRepository.createSchemaContextFactory(SchemaSourceFilter.ALWAYS_ACCEPT);
+        return schemaRepository.createEffectiveModelContextFactory();
     }
 
-    private void resolveSchemaContext(final SchemaContextFactory schemaContextFactory,
-            final SlaveSalFacade localSlaveSalManager, final ActorRef masterReference, int tries) {
-        final ListenableFuture<SchemaContext> schemaContextFuture =
-                schemaContextFactory.createSchemaContext(sourceIdentifiers);
+    private void resolveSchemaContext(final EffectiveModelContextFactory schemaContextFactory,
+            final SlaveSalFacade localSlaveSalManager, final ActorRef masterReference, final int tries) {
+        final ListenableFuture<EffectiveModelContext> schemaContextFuture =
+                schemaContextFactory.createEffectiveModelContext(sourceIdentifiers);
         Futures.addCallback(schemaContextFuture, new FutureCallback<SchemaContext>() {
             @Override
-            public void onSuccess(@Nonnull final SchemaContext result) {
+            public void onSuccess(final SchemaContext result) {
                 executeInSelf(() -> {
                     // Make sure the slaveSalManager instance hasn't changed since we initiated the schema context
                     // resolution.
@@ -310,7 +302,7 @@ public class NetconfNodeActor extends AbstractUntypedActor {
             }
 
             @Override
-            public void onFailure(@Nonnull final Throwable throwable) {
+            public void onFailure(final Throwable throwable) {
                 executeInSelf(() -> {
                     if (slaveSalManager == localSlaveSalManager) {
                         final Throwable cause = Throwables.getRootCause(throwable);
@@ -338,5 +330,4 @@ public class NetconfNodeActor extends AbstractUntypedActor {
             registeredSchemas = null;
         }
     }
-
 }