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