use of org.opendaylight.yangtools.yang.common.ErrorSeverity in project netconf by opendaylight.
the class DocumentedException method fromXMLDocument.
public static DocumentedException fromXMLDocument(final Document fromDoc) {
ErrorType errorType = ErrorType.APPLICATION;
ErrorTag errorTag = ErrorTag.OPERATION_FAILED;
ErrorSeverity errorSeverity = ErrorSeverity.ERROR;
Map<String, String> errorInfo = null;
String errorMessage = "";
String allErrorMessages = "";
Node rpcReply = fromDoc.getDocumentElement();
// FIXME: we only handle one rpc-error. For now, shove extra errorMessages found in multiple rpc-error in the
// errorInfo Map to at least let them propagate back to caller.
// this will be solved through migration to YangNetconfErrorAware, as that allows reporting multipl
// error events
int rpcErrorCount = 0;
NodeList replyChildren = rpcReply.getChildNodes();
for (int i = 0; i < replyChildren.getLength(); i++) {
Node replyChild = replyChildren.item(i);
if (RPC_ERROR.equals(replyChild.getLocalName())) {
rpcErrorCount++;
NodeList rpcErrorChildren = replyChild.getChildNodes();
for (int j = 0; j < rpcErrorChildren.getLength(); j++) {
Node rpcErrorChild = rpcErrorChildren.item(j);
// FIXME: use a switch expression here
if (ERROR_TYPE.equals(rpcErrorChild.getLocalName())) {
final ErrorType type = ErrorType.forElementBody(rpcErrorChild.getTextContent());
// FIXME: this should be a hard error
errorType = type != null ? type : ErrorType.APPLICATION;
} else if (ERROR_TAG.equals(rpcErrorChild.getLocalName())) {
errorTag = new ErrorTag(rpcErrorChild.getTextContent());
} else if (ERROR_SEVERITY.equals(rpcErrorChild.getLocalName())) {
final ErrorSeverity sev = ErrorSeverity.forElementBody(rpcErrorChild.getTextContent());
// FIXME: this should be a hard error
errorSeverity = sev != null ? sev : ErrorSeverity.ERROR;
} else if (ERROR_MESSAGE.equals(rpcErrorChild.getLocalName())) {
errorMessage = rpcErrorChild.getTextContent();
allErrorMessages = allErrorMessages + errorMessage;
} else if (ERROR_INFO.equals(rpcErrorChild.getLocalName())) {
errorInfo = parseErrorInfo(rpcErrorChild);
}
}
}
}
if (rpcErrorCount > 1) {
if (errorInfo == null) {
errorInfo = new HashMap<>();
}
errorInfo.put("Multiple Errors Found", allErrorMessages);
}
return new DocumentedException(errorMessage, errorType, errorTag, errorSeverity, errorInfo);
}
use of org.opendaylight.yangtools.yang.common.ErrorSeverity in project netconf by opendaylight.
the class AbstractWriteTx method extractResult.
@SuppressFBWarnings(value = "UPM_UNCALLED_PRIVATE_METHOD", justification = "https://github.com/spotbugs/spotbugs/issues/811")
private void extractResult(final List<DOMRpcResult> domRpcResults, final SettableFuture<RpcResult<Void>> transformed) {
ErrorType errType = ErrorType.APPLICATION;
ErrorSeverity errSeverity = ErrorSeverity.ERROR;
StringBuilder msgBuilder = new StringBuilder();
boolean errorsEncouneterd = false;
String errorTag = "operation-failed";
for (final DOMRpcResult domRpcResult : domRpcResults) {
if (!domRpcResult.getErrors().isEmpty()) {
errorsEncouneterd = true;
final RpcError error = domRpcResult.getErrors().iterator().next();
errType = error.getErrorType().toNetconf();
errSeverity = error.getSeverity().toNetconf();
msgBuilder.append(error.getMessage());
msgBuilder.append(error.getInfo());
errorTag = error.getTag();
}
}
if (errorsEncouneterd) {
final NetconfDocumentedException exception = new NetconfDocumentedException(id + ":RPC during tx failed. " + msgBuilder, errType, new ErrorTag(errorTag), errSeverity);
transformed.setException(exception);
return;
}
transformed.set(RpcResultBuilder.<Void>success().build());
}
use of org.opendaylight.yangtools.yang.common.ErrorSeverity in project netconf by opendaylight.
the class NetconfRestconfTransaction method toCommitFailedException.
@SuppressFBWarnings(value = "UPM_UNCALLED_PRIVATE_METHOD", justification = "https://github.com/spotbugs/spotbugs/issues/811")
private static TransactionCommitFailedException toCommitFailedException(final Collection<? extends RpcError> errors) {
ErrorType errType = ErrorType.APPLICATION;
ErrorSeverity errSeverity = ErrorSeverity.ERROR;
StringJoiner msgBuilder = new StringJoiner(" ");
ErrorTag errorTag = ErrorTag.OPERATION_FAILED;
for (final RpcError error : errors) {
errType = error.getErrorType().toNetconf();
errSeverity = error.getSeverity().toNetconf();
msgBuilder.add(error.getMessage());
msgBuilder.add(error.getInfo());
errorTag = new ErrorTag(error.getTag());
}
return new TransactionCommitFailedException("Netconf transaction commit failed", new NetconfDocumentedException("RPC during tx failed. " + msgBuilder.toString(), errType, errorTag, errSeverity));
}
Aggregations