use of org.opendaylight.restconf.common.errors.RestconfError 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.restconf.common.errors.RestconfError in project netconf by opendaylight.
the class QueryParamsTest method optionalParamMultipleTest.
/**
* Test when parameter is present more than once.
*/
@Test
public void optionalParamMultipleTest() {
final RestconfDocumentedException ex = assertThrows(RestconfDocumentedException.class, () -> QueryParams.optionalParam(ContentParam.uriName, List.of("config", "nonconfig", "all")));
final List<RestconfError> errors = ex.getErrors();
assertEquals(1, errors.size());
final RestconfError error = errors.get(0);
assertEquals("Error type is not correct", ErrorType.PROTOCOL, error.getErrorType());
assertEquals("Error tag is not correct", ErrorTag.INVALID_VALUE, error.getErrorTag());
}
use of org.opendaylight.restconf.common.errors.RestconfError in project netconf by opendaylight.
the class PatchDataTransactionUtil method patchData.
/**
* Process edit operations of one {@link PatchContext}. Close {@link DOMTransactionChain} if any inside of object
* {@link RestconfStrategy} provided as a parameter.
*
* @param context Patch context to be processed
* @param strategy object that perform the actual DS operations
* @param schemaContext Global schema context
* @return {@link PatchStatusContext}
*/
public static PatchStatusContext patchData(final PatchContext context, final RestconfStrategy strategy, final EffectiveModelContext schemaContext) {
final List<PatchStatusEntity> editCollection = new ArrayList<>();
boolean noError = true;
final RestconfTransaction transaction = strategy.prepareWriteExecution();
for (final PatchEntity patchEntity : context.getData()) {
if (noError) {
switch(patchEntity.getOperation()) {
case CREATE:
try {
createDataWithinTransaction(patchEntity.getTargetNode(), patchEntity.getNode(), schemaContext, transaction);
editCollection.add(new PatchStatusEntity(patchEntity.getEditId(), true, null));
} catch (final RestconfDocumentedException e) {
editCollection.add(new PatchStatusEntity(patchEntity.getEditId(), false, Lists.newArrayList(e.getErrors())));
noError = false;
}
break;
case DELETE:
try {
deleteDataWithinTransaction(patchEntity.getTargetNode(), transaction);
editCollection.add(new PatchStatusEntity(patchEntity.getEditId(), true, null));
} catch (final RestconfDocumentedException e) {
editCollection.add(new PatchStatusEntity(patchEntity.getEditId(), false, Lists.newArrayList(e.getErrors())));
noError = false;
}
break;
case MERGE:
try {
mergeDataWithinTransaction(patchEntity.getTargetNode(), patchEntity.getNode(), schemaContext, transaction);
editCollection.add(new PatchStatusEntity(patchEntity.getEditId(), true, null));
} catch (final RestconfDocumentedException e) {
editCollection.add(new PatchStatusEntity(patchEntity.getEditId(), false, Lists.newArrayList(e.getErrors())));
noError = false;
}
break;
case REPLACE:
try {
replaceDataWithinTransaction(patchEntity.getTargetNode(), patchEntity.getNode(), schemaContext, transaction);
editCollection.add(new PatchStatusEntity(patchEntity.getEditId(), true, null));
} catch (final RestconfDocumentedException e) {
editCollection.add(new PatchStatusEntity(patchEntity.getEditId(), false, Lists.newArrayList(e.getErrors())));
noError = false;
}
break;
case REMOVE:
try {
removeDataWithinTransaction(patchEntity.getTargetNode(), transaction);
editCollection.add(new PatchStatusEntity(patchEntity.getEditId(), true, null));
} catch (final RestconfDocumentedException e) {
editCollection.add(new PatchStatusEntity(patchEntity.getEditId(), false, Lists.newArrayList(e.getErrors())));
noError = false;
}
break;
default:
editCollection.add(new PatchStatusEntity(patchEntity.getEditId(), false, Lists.newArrayList(new RestconfError(ErrorType.PROTOCOL, ErrorTag.OPERATION_NOT_SUPPORTED, "Not supported Yang Patch operation"))));
noError = false;
break;
}
} else {
break;
}
}
// if no errors then submit transaction, otherwise cancel
if (noError) {
final ResponseFactory response = new ResponseFactory(Status.OK);
final FluentFuture<? extends CommitInfo> future = transaction.commit();
try {
FutureCallbackTx.addCallback(future, PATCH_TX_TYPE, response, null);
} catch (final RestconfDocumentedException e) {
// if errors occurred during transaction commit then patch failed and global errors are reported
return new PatchStatusContext(context.getPatchId(), ImmutableList.copyOf(editCollection), false, Lists.newArrayList(e.getErrors()));
}
return new PatchStatusContext(context.getPatchId(), ImmutableList.copyOf(editCollection), true, null);
} else {
transaction.cancel();
return new PatchStatusContext(context.getPatchId(), ImmutableList.copyOf(editCollection), false, null);
}
}
use of org.opendaylight.restconf.common.errors.RestconfError in project netconf by opendaylight.
the class BrokerFacadeTest method test503.
@Test
public void test503() throws Exception {
final RpcError error = RpcResultBuilder.newError(RpcError.ErrorType.TRANSPORT, ErrorTag.RESOURCE_DENIED.elementBody(), "Master is down. Please try again.");
doReturn(immediateFailedFluentFuture(new ReadFailedException("Read from transaction failed", error))).when(readTransaction).read(any(LogicalDatastoreType.class), any(YangInstanceIdentifier.class));
final RestconfDocumentedException ex = assertThrows(RestconfDocumentedException.class, () -> brokerFacade.readConfigurationData(this.instanceID, "explicit"));
final List<RestconfError> errors = ex.getErrors();
assertEquals(1, errors.size());
assertEquals("getErrorTag", ErrorTags.RESOURCE_DENIED_TRANSPORT, errors.get(0).getErrorTag());
assertEquals("getErrorType", ErrorType.TRANSPORT, errors.get(0).getErrorType());
assertEquals("getErrorMessage", "Master is down. Please try again.", errors.get(0).getErrorMessage());
}
use of org.opendaylight.restconf.common.errors.RestconfError in project netconf by opendaylight.
the class XmlPatchStatusBodyWriter method reportErrors.
private static void reportErrors(final List<RestconfError> errors, final XMLStreamWriter writer) throws XMLStreamException {
writer.writeStartElement("errors");
for (final RestconfError restconfError : errors) {
writer.writeStartElement("error-type");
writer.writeCharacters(restconfError.getErrorType().elementBody());
writer.writeEndElement();
writer.writeStartElement("error-tag");
writer.writeCharacters(restconfError.getErrorTag().elementBody());
writer.writeEndElement();
// optional node
if (restconfError.getErrorPath() != null) {
writer.writeStartElement("error-path");
writer.writeCharacters(restconfError.getErrorPath().toString());
writer.writeEndElement();
}
// optional node
if (restconfError.getErrorMessage() != null) {
writer.writeStartElement("error-message");
writer.writeCharacters(restconfError.getErrorMessage());
writer.writeEndElement();
}
// optional node
if (restconfError.getErrorInfo() != null) {
writer.writeStartElement("error-info");
writer.writeCharacters(restconfError.getErrorInfo());
writer.writeEndElement();
}
}
writer.writeEndElement();
}
Aggregations