Search in sources :

Example 1 with ErrorSeverity

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);
}
Also used : ErrorTag(org.opendaylight.yangtools.yang.common.ErrorTag) ErrorType(org.opendaylight.yangtools.yang.common.ErrorType) Node(org.w3c.dom.Node) NodeList(org.w3c.dom.NodeList) ErrorSeverity(org.opendaylight.yangtools.yang.common.ErrorSeverity)

Example 2 with ErrorSeverity

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());
}
Also used : ErrorTag(org.opendaylight.yangtools.yang.common.ErrorTag) ErrorType(org.opendaylight.yangtools.yang.common.ErrorType) DOMRpcResult(org.opendaylight.mdsal.dom.api.DOMRpcResult) RpcError(org.opendaylight.yangtools.yang.common.RpcError) NetconfDocumentedException(org.opendaylight.netconf.api.NetconfDocumentedException) ErrorSeverity(org.opendaylight.yangtools.yang.common.ErrorSeverity) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 3 with ErrorSeverity

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));
}
Also used : TransactionCommitFailedException(org.opendaylight.mdsal.common.api.TransactionCommitFailedException) ErrorTag(org.opendaylight.yangtools.yang.common.ErrorTag) ErrorType(org.opendaylight.yangtools.yang.common.ErrorType) RpcError(org.opendaylight.yangtools.yang.common.RpcError) NetconfDocumentedException(org.opendaylight.netconf.api.NetconfDocumentedException) ErrorSeverity(org.opendaylight.yangtools.yang.common.ErrorSeverity) StringJoiner(java.util.StringJoiner) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Aggregations

ErrorSeverity (org.opendaylight.yangtools.yang.common.ErrorSeverity)3 ErrorTag (org.opendaylight.yangtools.yang.common.ErrorTag)3 ErrorType (org.opendaylight.yangtools.yang.common.ErrorType)3 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)2 NetconfDocumentedException (org.opendaylight.netconf.api.NetconfDocumentedException)2 RpcError (org.opendaylight.yangtools.yang.common.RpcError)2 StringJoiner (java.util.StringJoiner)1 TransactionCommitFailedException (org.opendaylight.mdsal.common.api.TransactionCommitFailedException)1 DOMRpcResult (org.opendaylight.mdsal.dom.api.DOMRpcResult)1 Node (org.w3c.dom.Node)1 NodeList (org.w3c.dom.NodeList)1