use of org.opendaylight.restconf.nb.rfc8040.rests.transactions.RestconfStrategy in project netconf by opendaylight.
the class RestconfDataServiceImpl method patchData.
@Override
public PatchStatusContext patchData(final PatchContext context, final UriInfo uriInfo) {
final DOMMountPoint mountPoint = RestconfDocumentedException.throwIfNull(context, ErrorType.PROTOCOL, ErrorTag.MALFORMED_MESSAGE, "No patch documented provided").getInstanceIdentifierContext().getMountPoint();
final RestconfStrategy strategy = getRestconfStrategy(mountPoint);
return PatchDataTransactionUtil.patchData(context, strategy, getSchemaContext(mountPoint));
}
use of org.opendaylight.restconf.nb.rfc8040.rests.transactions.RestconfStrategy in project netconf by opendaylight.
the class RestconfDataServiceImpl method deleteData.
@Override
public Response deleteData(final String identifier) {
final InstanceIdentifierContext<?> instanceIdentifier = ParserIdentifier.toInstanceIdentifier(identifier, schemaContextHandler.get(), Optional.of(mountPointService));
final DOMMountPoint mountPoint = instanceIdentifier.getMountPoint();
final RestconfStrategy strategy = getRestconfStrategy(mountPoint);
return DeleteDataTransactionUtil.deleteData(strategy, instanceIdentifier.getInstanceIdentifier());
}
use of org.opendaylight.restconf.nb.rfc8040.rests.transactions.RestconfStrategy in project netconf by opendaylight.
the class RestconfDataServiceImpl method readData.
@Override
public Response readData(final String identifier, final UriInfo uriInfo) {
final ReadDataParams readParams = QueryParams.newReadDataParams(uriInfo);
final EffectiveModelContext schemaContextRef = schemaContextHandler.get();
final InstanceIdentifierContext<?> instanceIdentifier = ParserIdentifier.toInstanceIdentifier(identifier, schemaContextRef, Optional.of(mountPointService));
final DOMMountPoint mountPoint = instanceIdentifier.getMountPoint();
// FIXME: this looks quite crazy, why do we even have it?
if (mountPoint == null && identifier != null && identifier.contains(STREAMS_PATH) && !identifier.contains(STREAM_PATH_PART)) {
createAllYangNotificationStreams(schemaContextRef, uriInfo);
}
final QueryParameters queryParams = QueryParams.newQueryParameters(readParams, instanceIdentifier);
final List<YangInstanceIdentifier> fieldPaths = queryParams.fieldPaths();
final RestconfStrategy strategy = getRestconfStrategy(mountPoint);
final NormalizedNode node;
if (fieldPaths != null && !fieldPaths.isEmpty()) {
node = ReadDataTransactionUtil.readData(readParams.content(), instanceIdentifier.getInstanceIdentifier(), strategy, readParams.withDefaults(), schemaContextRef, fieldPaths);
} else {
node = ReadDataTransactionUtil.readData(readParams.content(), instanceIdentifier.getInstanceIdentifier(), strategy, readParams.withDefaults(), schemaContextRef);
}
// FIXME: this is utter craziness, refactor it properly!
if (identifier != null && identifier.contains(STREAM_PATH) && identifier.contains(STREAM_ACCESS_PATH_PART) && identifier.contains(STREAM_LOCATION_PATH_PART)) {
final String value = (String) node.body();
final String streamName = value.substring(value.indexOf(NOTIFICATION_STREAM + '/'));
delegRestconfSubscrService.subscribeToStream(streamName, uriInfo);
}
if (node == null) {
throw new RestconfDocumentedException("Request could not be completed because the relevant data model content does not exist", ErrorType.PROTOCOL, ErrorTag.DATA_MISSING);
}
switch(readParams.content()) {
case ALL:
case CONFIG:
final QName type = node.getIdentifier().getNodeType();
return Response.status(Status.OK).entity(NormalizedNodePayload.ofReadData(instanceIdentifier, node, queryParams)).header("ETag", '"' + type.getModule().getRevision().map(Revision::toString).orElse(null) + "-" + type.getLocalName() + '"').header("Last-Modified", FORMATTER.format(LocalDateTime.now(Clock.systemUTC()))).build();
default:
return Response.status(Status.OK).entity(NormalizedNodePayload.ofReadData(instanceIdentifier, node, queryParams)).build();
}
}
use of org.opendaylight.restconf.nb.rfc8040.rests.transactions.RestconfStrategy in project netconf by opendaylight.
the class DeleteDataTransactionUtil method deleteData.
/**
* Delete data from DS via transaction.
*
* @param strategy object that perform the actual DS operations
* @return {@link Response}
*/
public static Response deleteData(final RestconfStrategy strategy, final YangInstanceIdentifier path) {
final RestconfTransaction transaction = strategy.prepareWriteExecution();
try {
transaction.delete(path);
} catch (RestconfDocumentedException e) {
// close transaction if any and pass exception further
transaction.cancel();
throw e;
}
final FluentFuture<? extends CommitInfo> future = transaction.commit();
final ResponseFactory response = new ResponseFactory(Status.NO_CONTENT);
// This method will close transactionChain if any
FutureCallbackTx.addCallback(future, DELETE_TX_TYPE, response, path);
return response.build();
}
use of org.opendaylight.restconf.nb.rfc8040.rests.transactions.RestconfStrategy in project netconf by opendaylight.
the class PostDataTransactionUtil method submitData.
/**
* Post data by type.
*
* @param path path
* @param data data
* @param strategy object that perform the actual DS operations
* @param schemaContext schema context of data
* @param point query parameter
* @param insert query parameter
* @return {@link FluentFuture}
*/
private static FluentFuture<? extends CommitInfo> submitData(final YangInstanceIdentifier path, final NormalizedNode data, final RestconfStrategy strategy, final EffectiveModelContext schemaContext, final WriteDataParams params) {
final RestconfTransaction transaction = strategy.prepareWriteExecution();
final InsertParam insert = params.insert();
if (insert == null) {
makePost(path, data, schemaContext, transaction);
return transaction.commit();
}
PutDataTransactionUtil.checkListAndOrderedType(schemaContext, path);
final NormalizedNode readData;
switch(insert) {
case FIRST:
readData = PutDataTransactionUtil.readList(strategy, path.getParent().getParent());
if (readData == null || ((NormalizedNodeContainer<?>) readData).isEmpty()) {
transaction.replace(path, data, schemaContext);
return transaction.commit();
}
checkItemDoesNotExists(strategy.exists(LogicalDatastoreType.CONFIGURATION, path), path);
transaction.remove(path.getParent().getParent());
transaction.replace(path, data, schemaContext);
transaction.replace(path.getParent().getParent(), readData, schemaContext);
return transaction.commit();
case LAST:
makePost(path, data, schemaContext, transaction);
return transaction.commit();
case BEFORE:
readData = PutDataTransactionUtil.readList(strategy, path.getParent().getParent());
if (readData == null || ((NormalizedNodeContainer<?>) readData).isEmpty()) {
transaction.replace(path, data, schemaContext);
return transaction.commit();
}
checkItemDoesNotExists(strategy.exists(LogicalDatastoreType.CONFIGURATION, path), path);
insertWithPointPost(path, data, schemaContext, params.getPoint(), (NormalizedNodeContainer<?>) readData, true, transaction);
return transaction.commit();
case AFTER:
readData = PutDataTransactionUtil.readList(strategy, path.getParent().getParent());
if (readData == null || ((NormalizedNodeContainer<?>) readData).isEmpty()) {
transaction.replace(path, data, schemaContext);
return transaction.commit();
}
checkItemDoesNotExists(strategy.exists(LogicalDatastoreType.CONFIGURATION, path), path);
insertWithPointPost(path, data, schemaContext, params.getPoint(), (NormalizedNodeContainer<?>) readData, false, transaction);
return transaction.commit();
default:
throw new RestconfDocumentedException("Used bad value of insert parameter. Possible values are first, last, before or after, but was: " + insert, ErrorType.PROTOCOL, ErrorTag.BAD_ATTRIBUTE);
}
}
Aggregations