Search in sources :

Example 1 with RestconfStrategy

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));
}
Also used : DOMMountPoint(org.opendaylight.mdsal.dom.api.DOMMountPoint) RestconfStrategy(org.opendaylight.restconf.nb.rfc8040.rests.transactions.RestconfStrategy) MdsalRestconfStrategy(org.opendaylight.restconf.nb.rfc8040.rests.transactions.MdsalRestconfStrategy)

Example 2 with RestconfStrategy

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());
}
Also used : DOMMountPoint(org.opendaylight.mdsal.dom.api.DOMMountPoint) RestconfStrategy(org.opendaylight.restconf.nb.rfc8040.rests.transactions.RestconfStrategy) MdsalRestconfStrategy(org.opendaylight.restconf.nb.rfc8040.rests.transactions.MdsalRestconfStrategy)

Example 3 with RestconfStrategy

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();
    }
}
Also used : ReadDataParams(org.opendaylight.restconf.nb.rfc8040.ReadDataParams) RestconfDocumentedException(org.opendaylight.restconf.common.errors.RestconfDocumentedException) QName(org.opendaylight.yangtools.yang.common.QName) DOMMountPoint(org.opendaylight.mdsal.dom.api.DOMMountPoint) RestconfStrategy(org.opendaylight.restconf.nb.rfc8040.rests.transactions.RestconfStrategy) MdsalRestconfStrategy(org.opendaylight.restconf.nb.rfc8040.rests.transactions.MdsalRestconfStrategy) QueryParameters(org.opendaylight.restconf.nb.rfc8040.legacy.QueryParameters) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) Revision(org.opendaylight.yangtools.yang.common.Revision) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) EffectiveModelContext(org.opendaylight.yangtools.yang.model.api.EffectiveModelContext)

Example 4 with RestconfStrategy

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();
}
Also used : RestconfDocumentedException(org.opendaylight.restconf.common.errors.RestconfDocumentedException) RestconfTransaction(org.opendaylight.restconf.nb.rfc8040.rests.transactions.RestconfTransaction)

Example 5 with RestconfStrategy

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);
    }
}
Also used : RestconfDocumentedException(org.opendaylight.restconf.common.errors.RestconfDocumentedException) InsertParam(org.opendaylight.restconf.nb.rfc8040.InsertParam) RestconfTransaction(org.opendaylight.restconf.nb.rfc8040.rests.transactions.RestconfTransaction) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)

Aggregations

MdsalRestconfStrategy (org.opendaylight.restconf.nb.rfc8040.rests.transactions.MdsalRestconfStrategy)7 RestconfStrategy (org.opendaylight.restconf.nb.rfc8040.rests.transactions.RestconfStrategy)7 DOMMountPoint (org.opendaylight.mdsal.dom.api.DOMMountPoint)6 RestconfDocumentedException (org.opendaylight.restconf.common.errors.RestconfDocumentedException)6 RestconfTransaction (org.opendaylight.restconf.nb.rfc8040.rests.transactions.RestconfTransaction)5 NormalizedNode (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)4 EffectiveModelContext (org.opendaylight.yangtools.yang.model.api.EffectiveModelContext)3 InsertParam (org.opendaylight.restconf.nb.rfc8040.InsertParam)2 WriteDataParams (org.opendaylight.restconf.nb.rfc8040.WriteDataParams)2 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)2 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1 RestconfError (org.opendaylight.restconf.common.errors.RestconfError)1 PatchEntity (org.opendaylight.restconf.common.patch.PatchEntity)1 PatchStatusContext (org.opendaylight.restconf.common.patch.PatchStatusContext)1 PatchStatusEntity (org.opendaylight.restconf.common.patch.PatchStatusEntity)1 ReadDataParams (org.opendaylight.restconf.nb.rfc8040.ReadDataParams)1 QueryParameters (org.opendaylight.restconf.nb.rfc8040.legacy.QueryParameters)1 NetconfRestconfStrategy (org.opendaylight.restconf.nb.rfc8040.rests.transactions.NetconfRestconfStrategy)1 QName (org.opendaylight.yangtools.yang.common.QName)1