Clean up NetconfTopology methods
[netconf.git] / netconf / sal-netconf-connector / src / main / java / org / opendaylight / netconf / sal / connect / netconf / listener / NetconfDeviceCommunicator.java
index d391bb7ad0e113b89be015f2522316d41b28714d..9644a9d6d3375fdcdc5f74d2056562ca609b8114 100644 (file)
@@ -39,20 +39,19 @@ import org.opendaylight.netconf.sal.connect.api.RemoteDeviceCommunicator;
 import org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil;
 import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId;
 import org.opendaylight.yangtools.util.concurrent.FluentFutures;
+import org.opendaylight.yangtools.yang.common.Empty;
 import org.opendaylight.yangtools.yang.common.ErrorTag;
+import org.opendaylight.yangtools.yang.common.ErrorType;
 import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.common.RpcError;
 import org.opendaylight.yangtools.yang.common.RpcResult;
 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-public class NetconfDeviceCommunicator
-        implements NetconfClientSessionListener, RemoteDeviceCommunicator<NetconfMessage> {
-
+public class NetconfDeviceCommunicator implements NetconfClientSessionListener, RemoteDeviceCommunicator {
     private static final Logger LOG = LoggerFactory.getLogger(NetconfDeviceCommunicator.class);
 
-    protected final RemoteDevice<NetconfSessionPreferences, NetconfMessage, NetconfDeviceCommunicator> remoteDevice;
+    protected final RemoteDevice<NetconfDeviceCommunicator> remoteDevice;
     private final Optional<UserPreferences> overrideNetconfCapabilities;
     protected final RemoteDeviceId id;
     private final Lock sessionLock = new ReentrantLock();
@@ -63,7 +62,7 @@ public class NetconfDeviceCommunicator
     private final Queue<Request> requests = new ArrayDeque<>();
     private NetconfClientSession currentSession;
 
-    private final SettableFuture<NetconfDeviceCapabilities> firstConnectionFuture;
+    private final SettableFuture<Empty> firstConnectionFuture = SettableFuture.create();
     private Future<?> taskFuture;
 
     // isSessionClosing indicates a close operation on the session is issued and
@@ -79,29 +78,24 @@ public class NetconfDeviceCommunicator
         return closing != 0;
     }
 
-    public NetconfDeviceCommunicator(
-            final RemoteDeviceId id,
-            final RemoteDevice<NetconfSessionPreferences, NetconfMessage, NetconfDeviceCommunicator> remoteDevice,
+    public NetconfDeviceCommunicator(final RemoteDeviceId id,
+            final RemoteDevice<NetconfDeviceCommunicator> remoteDevice,
             final UserPreferences netconfSessionPreferences, final int rpcMessageLimit) {
         this(id, remoteDevice, Optional.of(netconfSessionPreferences), rpcMessageLimit);
     }
 
-    public NetconfDeviceCommunicator(
-            final RemoteDeviceId id,
-            final RemoteDevice<NetconfSessionPreferences, NetconfMessage, NetconfDeviceCommunicator> remoteDevice,
-            final int rpcMessageLimit) {
+    public NetconfDeviceCommunicator(final RemoteDeviceId id,
+            final RemoteDevice<NetconfDeviceCommunicator> remoteDevice, final int rpcMessageLimit) {
         this(id, remoteDevice, Optional.empty(), rpcMessageLimit);
     }
 
-    private NetconfDeviceCommunicator(
-            final RemoteDeviceId id,
-            final RemoteDevice<NetconfSessionPreferences, NetconfMessage, NetconfDeviceCommunicator> remoteDevice,
+    private NetconfDeviceCommunicator(final RemoteDeviceId id,
+            final RemoteDevice<NetconfDeviceCommunicator> remoteDevice,
             final Optional<UserPreferences> overrideNetconfCapabilities, final int rpcMessageLimit) {
         concurentRpcMsgs = rpcMessageLimit;
         this.id = id;
         this.remoteDevice = remoteDevice;
         this.overrideNetconfCapabilities = overrideNetconfCapabilities;
-        firstConnectionFuture = SettableFuture.create();
         semaphore = rpcMessageLimit > 0 ? new Semaphore(rpcMessageLimit) : null;
     }
 
@@ -133,7 +127,8 @@ public class NetconfDeviceCommunicator
 
             remoteDevice.onRemoteSessionUp(netconfSessionPreferences, this);
             if (!firstConnectionFuture.isDone()) {
-                firstConnectionFuture.set(netconfSessionPreferences.getNetconfDeviceCapabilities());
+                // FIXME: right, except ... this does not include the device schema setup, so is it really useful?
+                firstConnectionFuture.set(Empty.value());
             }
         } finally {
             sessionLock.unlock();
@@ -148,8 +143,8 @@ public class NetconfDeviceCommunicator
      * @return a ListenableFuture that returns success on first successful connection and failure when the underlying
      *         reconnecting strategy runs out of reconnection attempts
      */
-    public ListenableFuture<NetconfDeviceCapabilities> initializeRemoteConnection(
-            final NetconfClientDispatcher dispatcher, final NetconfClientConfiguration config) {
+    public ListenableFuture<Empty> initializeRemoteConnection(final NetconfClientDispatcher dispatcher,
+            final NetconfClientConfiguration config) {
 
         final Future<?> connectFuture;
         if (config instanceof NetconfReconnectingClientConfiguration) {
@@ -222,7 +217,7 @@ public class NetconfDeviceCommunicator
             if (Strings.isNullOrEmpty(reason)) {
                 future.set(createSessionDownRpcResult());
             } else {
-                future.set(createErrorRpcResult(RpcError.ErrorType.TRANSPORT, reason));
+                future.set(createErrorRpcResult(ErrorType.TRANSPORT, reason));
             }
         }
 
@@ -230,14 +225,13 @@ public class NetconfDeviceCommunicator
     }
 
     private RpcResult<NetconfMessage> createSessionDownRpcResult() {
-        return createErrorRpcResult(RpcError.ErrorType.TRANSPORT,
+        return createErrorRpcResult(ErrorType.TRANSPORT,
                 String.format("The netconf session to %1$s is disconnected", id.getName()));
     }
 
-    private static RpcResult<NetconfMessage> createErrorRpcResult(final RpcError.ErrorType errorType,
-            final String message) {
+    private static RpcResult<NetconfMessage> createErrorRpcResult(final ErrorType errorType, final String message) {
         return RpcResultBuilder.<NetconfMessage>failed()
-            .withError(errorType, ErrorTag.OPERATION_FAILED.elementBody(), message).build();
+            .withError(errorType, ErrorTag.OPERATION_FAILED, message).build();
     }
 
     @Override
@@ -398,8 +392,7 @@ public class NetconfDeviceCommunicator
                         future.cause());
 
                 if (future.cause() != null) {
-                    req.future.set(createErrorRpcResult(RpcError.ErrorType.TRANSPORT,
-                            future.cause().getLocalizedMessage()));
+                    req.future.set(createErrorRpcResult(ErrorType.TRANSPORT, future.cause().getLocalizedMessage()));
                 } else {
                     req.future.set(createSessionDownRpcResult()); // assume session is down
                 }