Search in sources :

Example 6 with ErrorTag

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

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

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

Example 9 with ErrorTag

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

Example 10 with ErrorTag

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

the class FutureCallbackTx method addCallback.

/**
 * Add callback to the future object and close transaction chain.
 *
 * @param listenableFuture
 *             future object
 * @param txType
 *             type of operation (READ, POST, PUT, DELETE)
 * @param dataFactory
 *             factory setting result
 * @param path unique identifier of a particular node instance in the data tree
 * @throws RestconfDocumentedException
 *             if the Future throws an exception
 */
// FIXME: this is a *synchronous operation* and has to die
static <T> void addCallback(final ListenableFuture<T> listenableFuture, final String txType, final FutureDataFactory<? super T> dataFactory, final YangInstanceIdentifier path) throws RestconfDocumentedException {
    try {
        final T result = listenableFuture.get();
        dataFactory.setResult(result);
        LOG.trace("Transaction({}) SUCCESSFUL", txType);
    } catch (InterruptedException e) {
        dataFactory.setFailureStatus();
        LOG.warn("Transaction({}) FAILED!", txType, e);
        throw new RestconfDocumentedException("Transaction failed", e);
    } catch (ExecutionException e) {
        dataFactory.setFailureStatus();
        LOG.warn("Transaction({}) FAILED!", txType, e);
        final Throwable cause = e.getCause();
        if (cause instanceof TransactionCommitFailedException) {
            /* If device send some error message we want this message to get to client
                   and not just to throw it away or override it with new generic message.
                   We search for NetconfDocumentedException that was send from netconfSB
                   and we create RestconfDocumentedException accordingly.
                */
            final List<Throwable> causalChain = Throwables.getCausalChain(cause);
            for (Throwable error : causalChain) {
                if (error instanceof DocumentedException) {
                    final ErrorTag errorTag = ((DocumentedException) error).getErrorTag();
                    if (errorTag.equals(ErrorTag.DATA_EXISTS)) {
                        LOG.trace("Operation via Restconf was not executed because data at {} already exists", path);
                        throw new RestconfDocumentedException(e, new RestconfError(ErrorType.PROTOCOL, ErrorTag.DATA_EXISTS, "Data already exists", path));
                    } else if (errorTag.equals(ErrorTag.DATA_MISSING)) {
                        LOG.trace("Operation via Restconf was not executed because data at {} does not exist", path);
                        throw new RestconfDocumentedException(e, new RestconfError(ErrorType.PROTOCOL, ErrorTag.DATA_MISSING, "Data does not exist", path));
                    }
                }
                if (error instanceof NetconfDocumentedException) {
                    throw new RestconfDocumentedException(error.getMessage(), ((NetconfDocumentedException) error).getErrorType(), ((NetconfDocumentedException) error).getErrorTag(), e);
                }
            }
            throw new RestconfDocumentedException("Transaction(" + txType + ") not committed correctly", e);
        } else {
            throw new RestconfDocumentedException("Transaction failed", e);
        }
    }
}
Also used : TransactionCommitFailedException(org.opendaylight.mdsal.common.api.TransactionCommitFailedException) RestconfDocumentedException(org.opendaylight.restconf.common.errors.RestconfDocumentedException) ErrorTag(org.opendaylight.yangtools.yang.common.ErrorTag) NetconfDocumentedException(org.opendaylight.netconf.api.NetconfDocumentedException) DocumentedException(org.opendaylight.netconf.api.DocumentedException) RestconfDocumentedException(org.opendaylight.restconf.common.errors.RestconfDocumentedException) RestconfError(org.opendaylight.restconf.common.errors.RestconfError) NetconfDocumentedException(org.opendaylight.netconf.api.NetconfDocumentedException) List(java.util.List) ExecutionException(java.util.concurrent.ExecutionException)

Aggregations

ErrorTag (org.opendaylight.yangtools.yang.common.ErrorTag)10 ErrorType (org.opendaylight.yangtools.yang.common.ErrorType)6 Test (org.junit.Test)5 RestconfError (org.opendaylight.restconf.common.errors.RestconfError)5 RpcError (org.opendaylight.yangtools.yang.common.RpcError)4 NetconfDocumentedException (org.opendaylight.netconf.api.NetconfDocumentedException)3 ErrorSeverity (org.opendaylight.yangtools.yang.common.ErrorSeverity)3 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)2 TransactionCommitFailedException (org.opendaylight.mdsal.common.api.TransactionCommitFailedException)2 DOMRpcResult (org.opendaylight.mdsal.dom.api.DOMRpcResult)2 DocumentedException (org.opendaylight.netconf.api.DocumentedException)2 RestconfDocumentedException (org.opendaylight.restconf.common.errors.RestconfDocumentedException)2 List (java.util.List)1 StringJoiner (java.util.StringJoiner)1 ExecutionException (java.util.concurrent.ExecutionException)1 DefaultDOMRpcResult (org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult)1 QName (org.opendaylight.yangtools.yang.common.QName)1 Node (org.w3c.dom.Node)1 NodeList (org.w3c.dom.NodeList)1