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.opendaylight.yangtools.yang.common.XMLNamespace;
import org.opendaylight.yangtools.yang.common.YangConstants;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
}
}
- public static RpcError toRpcError(final NetconfDocumentedException ex) {
- final StringBuilder infoBuilder = new StringBuilder();
- final Map<String, String> errorInfo = ex.getErrorInfo();
- if (errorInfo != null) {
- for (final Entry<String, String> e : errorInfo.entrySet()) {
- infoBuilder.append('<').append(e.getKey()).append('>').append(e.getValue())
- .append("</").append(e.getKey()).append('>');
-
- }
- }
-
- return ex.getErrorSeverity() == ErrorSeverity.ERROR
- ? RpcResultBuilder.newError(ex.getErrorType(), ex.getErrorTag(),
- ex.getLocalizedMessage(), null, infoBuilder.toString(), ex.getCause())
- : RpcResultBuilder.newWarning(ex.getErrorType(), ex.getErrorTag(),
- ex.getLocalizedMessage(), null, infoBuilder.toString(), ex.getCause());
- }
-
public static NodeIdentifier toId(final PathArgument arg) {
return arg instanceof NodeIdentifier nodeId ? nodeId : toId(arg.getNodeType());
}
}
}
}
-
- public static RpcResult<NetconfMessage> toRpcResult(final Exception failure) {
- return RpcResultBuilder.<NetconfMessage>failed()
- .withRpcError(toRpcError(new NetconfDocumentedException(failure.getMessage(),
- ErrorType.APPLICATION, ErrorTag.MALFORMED_MESSAGE, ErrorSeverity.ERROR)))
- .build();
- }
}
import org.opendaylight.netconf.client.mdsal.impl.NetconfMessageTransformUtil;
import org.opendaylight.yangtools.util.concurrent.FluentFutures;
import org.opendaylight.yangtools.yang.common.Empty;
+import org.opendaylight.yangtools.yang.common.ErrorSeverity;
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;
public void onError(final NetconfClientSession session, final Exception failure) {
final Request request = pollRequest();
if (request != null) {
- request.future.set(NetconfMessageTransformUtil.toRpcResult(failure));
+ request.future.set(RpcResultBuilder.<NetconfMessage>failed()
+ .withRpcError(toRpcError(new NetconfDocumentedException(failure.getMessage(),
+ ErrorType.APPLICATION, ErrorTag.MALFORMED_MESSAGE, ErrorSeverity.ERROR)))
+ .build());
} else {
LOG.warn("{}: Ignoring unsolicited failure {}", id, failure.toString());
}
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());
+ request.future.set(RpcResultBuilder.<NetconfMessage>failed().withRpcError(toRpcError(e)).build());
//recursively processing message to eventually find matching request
processMessage(message);
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());
+ request.future.set(RpcResultBuilder.<NetconfMessage>failed().withRpcError(toRpcError(e)).build());
return;
}
return XmlUtil.toString(msg.getDocument());
}
+ private static RpcError toRpcError(final NetconfDocumentedException ex) {
+ final var errorInfo = ex.getErrorInfo();
+ final String infoString;
+ if (errorInfo != null) {
+ final var sb = new StringBuilder();
+ for (var e : errorInfo.entrySet()) {
+ final var tag = e.getKey();
+ sb.append('<').append(tag).append('>').append(e.getValue()).append("</").append(tag).append('>');
+ }
+ infoString = sb.toString();
+ } else {
+ infoString = "";
+ }
+
+ return ex.getErrorSeverity() == ErrorSeverity.ERROR
+ ? RpcResultBuilder.newError(ex.getErrorType(), ex.getErrorTag(), ex.getLocalizedMessage(), null,
+ infoString, ex.getCause())
+ : RpcResultBuilder.newWarning(ex.getErrorType(), ex.getErrorTag(), ex.getLocalizedMessage(), null,
+ infoString, ex.getCause());
+ }
+
@Override
public ListenableFuture<RpcResult<NetconfMessage>> sendRequest(final NetconfMessage message, final QName rpc) {
sessionLock.lock();