use of org.opendaylight.restconf.common.errors.RestconfDocumentedException in project netconf by opendaylight.
the class RestGetOperationTest method getDataWithInvalidDepthParameterTest.
private void getDataWithInvalidDepthParameterTest(final UriInfo uriInfo) {
try {
final QName qNameDepth1Cont = QName.create("urn:nested:module", "2014-06-3", "depth1-cont");
final YangInstanceIdentifier ii = YangInstanceIdentifier.builder().node(qNameDepth1Cont).build();
final NormalizedNode value = Builders.containerBuilder().withNodeIdentifier(new NodeIdentifier(qNameDepth1Cont)).build();
when(brokerFacade.readConfigurationData(eq(ii))).thenReturn(value);
restconfImpl.readConfigurationData("nested-module:depth1-cont", uriInfo);
fail("Expected RestconfDocumentedException");
} catch (final RestconfDocumentedException e) {
assertTrue("Unexpected error message: " + e.getErrors().get(0).getErrorMessage(), e.getErrors().get(0).getErrorMessage().contains("depth"));
}
}
use of org.opendaylight.restconf.common.errors.RestconfDocumentedException in project netconf by opendaylight.
the class QueryParams method newNotificationQueryParams.
@NonNull
public static NotificationQueryParams newNotificationQueryParams(final UriInfo uriInfo) {
StartTimeParam startTime = null;
StopTimeParam stopTime = null;
FilterParam filter = null;
LeafNodesOnlyParam leafNodesOnly = null;
SkipNotificationDataParam skipNotificationData = null;
for (Entry<String, List<String>> entry : uriInfo.getQueryParameters().entrySet()) {
final String paramName = entry.getKey();
final List<String> paramValues = entry.getValue();
try {
switch(paramName) {
case FilterParam.uriName:
filter = optionalParam(FilterParam::forUriValue, paramName, paramValues);
break;
case StartTimeParam.uriName:
startTime = optionalParam(StartTimeParam::forUriValue, paramName, paramValues);
break;
case StopTimeParam.uriName:
stopTime = optionalParam(StopTimeParam::forUriValue, paramName, paramValues);
break;
case LeafNodesOnlyParam.uriName:
leafNodesOnly = optionalParam(LeafNodesOnlyParam::forUriValue, paramName, paramValues);
break;
case SkipNotificationDataParam.uriName:
skipNotificationData = optionalParam(SkipNotificationDataParam::forUriValue, paramName, paramValues);
break;
default:
throw unhandledParam("notification", paramName);
}
} catch (IllegalArgumentException e) {
throw new RestconfDocumentedException("Invalid " + paramName + " value: " + e.getMessage(), ErrorType.PROTOCOL, ErrorTag.INVALID_VALUE, e);
}
}
try {
return NotificationQueryParams.of(startTime, stopTime, filter, leafNodesOnly, skipNotificationData);
} catch (IllegalArgumentException e) {
throw new RestconfDocumentedException("Invalid query parameters: " + e.getMessage(), e);
}
}
use of org.opendaylight.restconf.common.errors.RestconfDocumentedException in project netconf by opendaylight.
the class QueryParams method newWriteDataParams.
@NonNull
public static WriteDataParams newWriteDataParams(final UriInfo uriInfo) {
InsertParam insert = null;
PointParam point = null;
for (final Entry<String, List<String>> entry : uriInfo.getQueryParameters().entrySet()) {
final String paramName = entry.getKey();
final List<String> paramValues = entry.getValue();
try {
switch(paramName) {
case InsertParam.uriName:
insert = optionalParam(InsertParam::forUriValue, paramName, paramValues);
break;
case PointParam.uriName:
point = optionalParam(PointParam::forUriValue, paramName, paramValues);
break;
default:
throw unhandledParam("write", paramName);
}
} catch (IllegalArgumentException e) {
throw new RestconfDocumentedException("Invalid " + paramName + " value: " + e.getMessage(), ErrorType.PROTOCOL, ErrorTag.INVALID_VALUE, e);
}
}
try {
return WriteDataParams.of(insert, point);
} catch (IllegalArgumentException e) {
throw new RestconfDocumentedException("Invalid query parameters: " + e.getMessage(), e);
}
}
use of org.opendaylight.restconf.common.errors.RestconfDocumentedException in project netconf by opendaylight.
the class SchemaContextHandler method putData.
private void putData(final ContainerNode normNode) {
final DOMDataTreeWriteTransaction wTx = domDataBroker.newWriteOnlyTransaction();
wTx.put(LogicalDatastoreType.OPERATIONAL, YangInstanceIdentifier.create(NodeIdentifier.create(normNode.getIdentifier().getNodeType())), normNode);
try {
wTx.commit().get();
} catch (InterruptedException e) {
throw new RestconfDocumentedException("Problem occurred while putting data to DS.", e);
} catch (ExecutionException e) {
final TransactionCommitFailedException failure = Throwables.getCauseAs(e, TransactionCommitFailedException.class);
if (failure.getCause() instanceof ConflictingModificationAppliedException) {
/*
* Ignore error when another cluster node is already putting the same data to DS.
* We expect that cluster is homogeneous and that node was going to write the same data
* (that means no retry is needed). Transaction chain reset must be invoked to be able
* to continue writing data with another transaction after failed transaction.
* This is workaround for bug https://bugs.opendaylight.org/show_bug.cgi?id=7728
*/
LOG.warn("Ignoring that another cluster node is already putting the same data to DS.", e);
} else {
throw new RestconfDocumentedException("Problem occurred while putting data to DS.", failure);
}
}
}
use of org.opendaylight.restconf.common.errors.RestconfDocumentedException in project netconf by opendaylight.
the class RestconfDocumentedExceptionMapper method getResponseStatusCode.
/**
* Deriving of the status code from the thrown exception. At the first step, status code is tried to be read using
* {@link RestconfDocumentedException#getStatus()}. If it is {@code null}, status code will be derived from status
* codes appended to error entries (the first that will be found). If there are not any error entries,
* {@link RestconfDocumentedExceptionMapper#DEFAULT_STATUS_CODE} will be used.
*
* @param exception Thrown exception.
* @return Derived status code.
*/
private static Status getResponseStatusCode(final RestconfDocumentedException exception) {
final Status status = exception.getStatus();
if (status != null) {
// status code that is specified directly as field in exception has the precedence over error entries
return status;
}
final List<RestconfError> errors = exception.getErrors();
if (errors.isEmpty()) {
// server error
return DEFAULT_STATUS_CODE;
}
final Set<Status> allStatusCodesOfErrorEntries = errors.stream().map(restconfError -> ErrorTags.statusOf(restconfError.getErrorTag())).collect(Collectors.toCollection(LinkedHashSet::new));
// entries, we should create WARN message
if (allStatusCodesOfErrorEntries.size() > 1) {
LOG.warn("An unexpected error occurred during translation of exception {} to response: " + "Different status codes have been found in appended error entries: {}. The first error " + "entry status code is chosen for response.", exception, allStatusCodesOfErrorEntries);
}
return allStatusCodesOfErrorEntries.iterator().next();
}
Aggregations