Search in sources :

Example 1 with ErrorType

use of org.opendaylight.yangtools.yang.common.ErrorType 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 ErrorType

use of org.opendaylight.yangtools.yang.common.ErrorType 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 ErrorType

use of org.opendaylight.yangtools.yang.common.ErrorType in project netconf by opendaylight.

the class RestconfErrorTest method testRestConfDocumentedException_WithAppTagErrorInfo.

@Test
public void testRestConfDocumentedException_WithAppTagErrorInfo() {
    String expectedMessage = "Message";
    ErrorType expectedErrorType = ErrorType.RPC;
    ErrorTag expectedErrorTag = ErrorTag.IN_USE;
    String expectedErrorAppTag = "application.tag";
    String errorInfo = "<extra><sessionid>session.id</sessionid></extra>";
    RestconfError error = new RestconfError(expectedErrorType, expectedErrorTag, expectedMessage, expectedErrorAppTag, errorInfo);
    validateRestConfError(expectedMessage, expectedErrorType, expectedErrorTag, expectedErrorAppTag, errorInfo, error);
}
Also used : ErrorTag(org.opendaylight.yangtools.yang.common.ErrorTag) ErrorType(org.opendaylight.yangtools.yang.common.ErrorType) RestconfError(org.opendaylight.restconf.common.errors.RestconfError) Test(org.junit.Test)

Example 4 with ErrorType

use of org.opendaylight.yangtools.yang.common.ErrorType in project netconf by opendaylight.

the class RestconfErrorTest method testRestConfDocumentedException_NoCause.

@Test
public void testRestConfDocumentedException_NoCause() {
    String expectedMessage = "Message";
    ErrorType expectedErrorType = ErrorType.RPC;
    ErrorTag expectedErrorTag = ErrorTag.IN_USE;
    RestconfError error = new RestconfError(expectedErrorType, expectedErrorTag, expectedMessage);
    validateRestConfError(expectedMessage, expectedErrorType, expectedErrorTag, null, (String) null, error);
}
Also used : ErrorTag(org.opendaylight.yangtools.yang.common.ErrorTag) ErrorType(org.opendaylight.yangtools.yang.common.ErrorType) RestconfError(org.opendaylight.restconf.common.errors.RestconfError) Test(org.junit.Test)

Example 5 with ErrorType

use of org.opendaylight.yangtools.yang.common.ErrorType in project netconf by opendaylight.

the class RestconfErrorTest method testRestConfDocumentedException_WithAppTag.

@Test
public void testRestConfDocumentedException_WithAppTag() {
    String expectedMessage = "Message";
    ErrorType expectedErrorType = ErrorType.RPC;
    ErrorTag expectedErrorTag = ErrorTag.IN_USE;
    String expectedErrorAppTag = "application.tag";
    RestconfError error = new RestconfError(expectedErrorType, expectedErrorTag, expectedMessage, expectedErrorAppTag);
    validateRestConfError(expectedMessage, expectedErrorType, expectedErrorTag, expectedErrorAppTag, (String) null, error);
}
Also used : ErrorTag(org.opendaylight.yangtools.yang.common.ErrorTag) ErrorType(org.opendaylight.yangtools.yang.common.ErrorType) RestconfError(org.opendaylight.restconf.common.errors.RestconfError) Test(org.junit.Test)

Aggregations

ErrorTag (org.opendaylight.yangtools.yang.common.ErrorTag)6 ErrorType (org.opendaylight.yangtools.yang.common.ErrorType)6 Test (org.junit.Test)3 RestconfError (org.opendaylight.restconf.common.errors.RestconfError)3 ErrorSeverity (org.opendaylight.yangtools.yang.common.ErrorSeverity)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