Merge "BUG-9048 Fix actor crash when writing incorrect data"
[netconf.git] / netconf / netconf-topology-singleton / src / main / java / org / opendaylight / netconf / topology / singleton / impl / actors / NetconfNodeActor.java
index f04430f6660d02ad9898b9097b97856d4862158d..2e46cd4a1bfbb033f2b5948116503124eb3bf567 100644 (file)
@@ -15,6 +15,7 @@ import akka.util.Timeout;
 import com.google.common.util.concurrent.CheckedFuture;
 import com.google.common.util.concurrent.FutureCallback;
 import com.google.common.util.concurrent.Futures;
+import com.google.common.util.concurrent.MoreExecutors;
 import java.io.IOException;
 import java.util.List;
 import java.util.stream.Collectors;
@@ -25,6 +26,7 @@ import org.opendaylight.controller.cluster.schema.provider.impl.RemoteSchemaProv
 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.DOMRpcException;
@@ -40,6 +42,7 @@ import org.opendaylight.netconf.topology.singleton.messages.CreateInitialMasterA
 import org.opendaylight.netconf.topology.singleton.messages.MasterActorDataInitialized;
 import org.opendaylight.netconf.topology.singleton.messages.NormalizedNodeMessage;
 import org.opendaylight.netconf.topology.singleton.messages.RefreshSetupMasterActorData;
+import org.opendaylight.netconf.topology.singleton.messages.RefreshSlaveActor;
 import org.opendaylight.netconf.topology.singleton.messages.RegisterMountPoint;
 import org.opendaylight.netconf.topology.singleton.messages.UnregisterSlaveMountPoint;
 import org.opendaylight.netconf.topology.singleton.messages.YangTextSchemaSourceRequest;
@@ -48,6 +51,8 @@ import org.opendaylight.netconf.topology.singleton.messages.rpc.InvokeRpcMessage
 import org.opendaylight.netconf.topology.singleton.messages.transactions.EmptyResultResponse;
 import org.opendaylight.netconf.topology.singleton.messages.transactions.NewReadTransactionReply;
 import org.opendaylight.netconf.topology.singleton.messages.transactions.NewReadTransactionRequest;
+import org.opendaylight.netconf.topology.singleton.messages.transactions.NewReadWriteTransactionReply;
+import org.opendaylight.netconf.topology.singleton.messages.transactions.NewReadWriteTransactionRequest;
 import org.opendaylight.netconf.topology.singleton.messages.transactions.NewWriteTransactionReply;
 import org.opendaylight.netconf.topology.singleton.messages.transactions.NewWriteTransactionRequest;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
@@ -71,12 +76,12 @@ public class NetconfNodeActor extends UntypedActor {
 
     private static final Logger LOG = LoggerFactory.getLogger(NetconfNodeActor.class);
 
-    private final SchemaSourceRegistry schemaRegistry;
-    private final SchemaRepository schemaRepository;
-    private final Timeout actorResponseWaitTime;
     private final Duration writeTxIdleTimeout;
     private final DOMMountPointService mountPointService;
 
+    private SchemaSourceRegistry schemaRegistry;
+    private SchemaRepository schemaRepository;
+    private Timeout actorResponseWaitTime;
     private RemoteDeviceId id;
     private NetconfTopologySetup setup;
     private List<SourceIdentifier> sourceIdentifiers;
@@ -109,6 +114,7 @@ public class NetconfNodeActor extends UntypedActor {
         this.mountPointService = mountPointService;
     }
 
+    @SuppressWarnings("checkstyle:IllegalCatch")
     @Override
     public void onReceive(final Object message) throws Exception {
         if (message instanceof CreateInitialMasterActorData) { // master
@@ -148,10 +154,18 @@ public class NetconfNodeActor extends UntypedActor {
                 final DOMDataWriteTransaction tx = deviceDataBroker.newWriteOnlyTransaction();
                 final ActorRef txActor = context().actorOf(WriteTransactionActor.props(tx, writeTxIdleTimeout));
                 sender().tell(new NewWriteTransactionReply(txActor), self());
-            } catch (final Throwable t) {
+            } catch (final Exception t) {
                 sender().tell(t, self());
             }
 
+        } else if (message instanceof NewReadWriteTransactionRequest) {
+            try {
+                final DOMDataReadWriteTransaction tx = deviceDataBroker.newReadWriteTransaction();
+                final ActorRef txActor = context().actorOf(ReadWriteTransactionActor.props(tx, writeTxIdleTimeout));
+                sender().tell(new NewReadWriteTransactionReply(txActor), self());
+            } catch (final Exception t) {
+                sender().tell(t, self());
+            }
         } else if (message instanceof InvokeRpcMessage) { // master
 
             final InvokeRpcMessage invokeRpcMessage = ((InvokeRpcMessage) message);
@@ -167,8 +181,14 @@ public class NetconfNodeActor extends UntypedActor {
                 slaveSalManager.close();
                 slaveSalManager = null;
             }
-
+        } else if (message instanceof RefreshSlaveActor) { //slave
+            actorResponseWaitTime = ((RefreshSlaveActor) message).getActorResponseWaitTime();
+            id = ((RefreshSlaveActor) message).getId();
+            schemaRegistry = ((RefreshSlaveActor) message).getSchemaRegistry();
+            setup = ((RefreshSlaveActor) message).getSetup();
+            schemaRepository = ((RefreshSlaveActor) message).getSchemaRepository();
         }
+
     }
 
     @Override
@@ -195,7 +215,7 @@ public class NetconfNodeActor extends UntypedActor {
             public void onFailure(@Nonnull final Throwable throwable) {
                 sender.tell(throwable, getSelf());
             }
-        });
+        }, MoreExecutors.directExecutor());
     }
 
     private void invokeSlaveRpc(final SchemaPath schemaPath, final NormalizedNodeMessage normalizedNodeMessage,
@@ -223,7 +243,7 @@ public class NetconfNodeActor extends UntypedActor {
             public void onFailure(@Nonnull final Throwable throwable) {
                 recipient.tell(throwable, getSelf());
             }
-        });
+        }, MoreExecutors.directExecutor());
     }
 
     private void registerSlaveMountPoint(final ActorRef masterReference) {
@@ -249,7 +269,7 @@ public class NetconfNodeActor extends UntypedActor {
             public void onFailure(@Nonnull final Throwable throwable) {
                 LOG.error("{}: Failed to register mount point: {}", id, throwable);
             }
-        });
+        }, MoreExecutors.directExecutor());
     }
 
     private DOMRpcService getDOMRpcService(final ActorRef masterReference) {