import java.util.Queue;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
+import org.opendaylight.controller.config.util.xml.XmlElement;
+import org.opendaylight.controller.config.util.xml.XmlUtil;
import org.opendaylight.controller.netconf.api.NetconfDocumentedException;
import org.opendaylight.controller.netconf.api.NetconfMessage;
import org.opendaylight.controller.netconf.api.NetconfTerminationReason;
import org.opendaylight.controller.netconf.client.NetconfClientSessionListener;
import org.opendaylight.controller.netconf.client.conf.NetconfClientConfiguration;
import org.opendaylight.controller.netconf.client.conf.NetconfReconnectingClientConfiguration;
-import org.opendaylight.controller.netconf.util.xml.XmlElement;
-import org.opendaylight.controller.netconf.util.xml.XmlUtil;
import org.opendaylight.controller.sal.connect.api.RemoteDevice;
import org.opendaylight.controller.sal.connect.api.RemoteDeviceCommunicator;
import org.opendaylight.controller.sal.connect.netconf.util.NetconfMessageTransformUtil;
public class NetconfDeviceCommunicator implements NetconfClientSessionListener, RemoteDeviceCommunicator<NetconfMessage> {
- private static final Logger logger = LoggerFactory.getLogger(NetconfDeviceCommunicator.class);
+ private static final Logger LOG = LoggerFactory.getLogger(NetconfDeviceCommunicator.class);
private final RemoteDevice<NetconfSessionPreferences, NetconfMessage, NetconfDeviceCommunicator> remoteDevice;
private final Optional<NetconfSessionPreferences> overrideNetconfCapabilities;
public void onSessionUp(final NetconfClientSession session) {
sessionLock.lock();
try {
- logger.debug("{}: Session established", id);
+ LOG.debug("{}: Session established", id);
this.session = session;
NetconfSessionPreferences netconfSessionPreferences =
NetconfSessionPreferences.fromNetconfSession(session);
- logger.trace("{}: Session advertised capabilities: {}", id, netconfSessionPreferences);
+ LOG.trace("{}: Session advertised capabilities: {}", id,
+ netconfSessionPreferences);
if(overrideNetconfCapabilities.isPresent()) {
netconfSessionPreferences = netconfSessionPreferences.addModuleCaps(overrideNetconfCapabilities.get());
- logger.debug("{}: Session capabilities overridden, capabilities that will be used: {}", id, netconfSessionPreferences);
+ LOG.debug(
+ "{}: Session capabilities overridden, capabilities that will be used: {}",
+ id, netconfSessionPreferences);
}
remoteDevice.onRemoteSessionUp(netconfSessionPreferences, this);
@Override
public void operationComplete(Future<Object> future) throws Exception {
if (!future.isSuccess() && !future.isCancelled()) {
- logger.debug("{}: Connection failed", id, future.cause());
+ LOG.debug("{}: Connection failed", id, future.cause());
NetconfDeviceCommunicator.this.remoteDevice.onRemoteSessionFailed(future.cause());
}
}
@Override
public void onSessionDown(final NetconfClientSession session, final Exception e) {
- logger.warn("{}: Session went down", id, e);
+ LOG.warn("{}: Session went down", id, e);
tearDown( null );
}
@Override
public void onSessionTerminated(final NetconfClientSession session, final NetconfTerminationReason reason) {
- logger.warn("{}: Session terminated {}", id, reason);
+ LOG.warn("{}: Session terminated {}", id, reason);
tearDown( reason.getErrorMessage() );
}
requests.poll();
} else {
request = null;
- logger.warn("{}: Ignoring unsolicited message {}", id, msgToS(message));
+ LOG.warn("{}: Ignoring unsolicited message {}", id,
+ msgToS(message));
}
}
finally {
if( request != null ) {
- logger.debug("{}: Message received {}", id, message);
+ LOG.debug("{}: Message received {}", id, message);
- if(logger.isTraceEnabled()) {
- logger.trace( "{}: Matched request: {} to response: {}", id, msgToS( request.request ), msgToS( message ) );
+ if(LOG.isTraceEnabled()) {
+ LOG.trace( "{}: Matched request: {} to response: {}", id, msgToS( request.request ), msgToS( message ) );
}
try {
NetconfMessageTransformUtil.checkValidReply( request.request, message );
} catch (final NetconfDocumentedException e) {
- logger.warn( "{}: Invalid request-reply match, reply message contains different message-id, request: {}, response: {}",
- id, msgToS( request.request ), msgToS( message ), e );
+ LOG.warn(
+ "{}: Invalid request-reply match, reply message contains different message-id, request: {}, response: {}",
+ id, msgToS(request.request), msgToS(message), e);
request.future.set( RpcResultBuilder.<NetconfMessage>failed()
.withRpcError( NetconfMessageTransformUtil.toRpcError( e ) ).build() );
try {
NetconfMessageTransformUtil.checkSuccessReply(message);
} catch(final NetconfDocumentedException e) {
- logger.warn( "{}: Error reply from remote device, request: {}, response: {}", id,
- msgToS( request.request ), msgToS( message ), e );
+ LOG.warn(
+ "{}: Error reply from remote device, request: {}, response: {}",
+ id, msgToS(request.request), msgToS(message), e);
request.future.set( RpcResultBuilder.<NetconfMessage>failed()
.withRpcError( NetconfMessageTransformUtil.toRpcError( e ) ).build() );
private ListenableFuture<RpcResult<NetconfMessage>> sendRequestWithLock(
final NetconfMessage message, final QName rpc) {
- if(logger.isTraceEnabled()) {
- logger.trace("{}: Sending message {}", id, msgToS(message));
+ if(LOG.isTraceEnabled()) {
+ LOG.trace("{}: Sending message {}", id, msgToS(message));
}
if (session == null) {
- logger.warn("{}: Session is disconnected, failing RPC request {}", id, message);
+ LOG.warn("{}: Session is disconnected, failing RPC request {}",
+ id, message);
return Futures.immediateFuture( createSessionDownRpcResult() );
}
public void operationComplete(final Future<Void> future) throws Exception {
if( !future.isSuccess() ) {
// We expect that a session down will occur at this point
- logger.debug( "{}: Failed to send request {}", id,
- XmlUtil.toString(req.request.getDocument()), future.cause() );
+ LOG.debug("{}: Failed to send request {}", id,
+ XmlUtil.toString(req.request.getDocument()),
+ future.cause());
if( future.cause() != null ) {
req.future.set( createErrorRpcResult( RpcError.ErrorType.TRANSPORT,
req.future.setException( future.cause() );
}
else {
- logger.trace( "Finished sending request {}", req.request );
+ LOG.trace("Finished sending request {}", req.request);
}
}
});
}
private void processNotification(final NetconfMessage notification) {
- if(logger.isTraceEnabled()) {
- logger.trace("{}: Notification received: {}", id, notification);
+ if(LOG.isTraceEnabled()) {
+ LOG.trace("{}: Notification received: {}", id, notification);
}
remoteDevice.onNotification(notification);