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();
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
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;
}
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();
* @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) {
if (Strings.isNullOrEmpty(reason)) {
future.set(createSessionDownRpcResult());
} else {
- future.set(createErrorRpcResult(RpcError.ErrorType.TRANSPORT, reason));
+ future.set(createErrorRpcResult(ErrorType.TRANSPORT, reason));
}
}
}
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
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
}