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);
}
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);
}
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);
}
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));
}
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);
}
}
}
Aggregations