Search in sources :

Example 31 with DOMMountPoint

use of org.opendaylight.mdsal.dom.api.DOMMountPoint in project netconf by opendaylight.

the class RestconfDataServiceImpl method patchData.

@Override
public Response patchData(final String identifier, final NormalizedNodePayload payload, final UriInfo uriInfo) {
    requireNonNull(payload);
    final InstanceIdentifierContext<? extends SchemaNode> iid = payload.getInstanceIdentifierContext();
    validInputData(iid.getSchemaNode(), payload);
    validTopLevelNodeName(iid.getInstanceIdentifier(), payload);
    validateListKeysEqualityInPayloadAndUri(payload);
    final DOMMountPoint mountPoint = payload.getInstanceIdentifierContext().getMountPoint();
    final EffectiveModelContext ref = mountPoint == null ? schemaContextHandler.get() : modelContext(mountPoint);
    final RestconfStrategy strategy = getRestconfStrategy(mountPoint);
    return PlainPatchDataTransactionUtil.patchData(payload, strategy, ref);
}
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) EffectiveModelContext(org.opendaylight.yangtools.yang.model.api.EffectiveModelContext)

Example 32 with DOMMountPoint

use of org.opendaylight.mdsal.dom.api.DOMMountPoint in project netconf by opendaylight.

the class RestconfDataServiceImpl method postData.

@Override
public Response postData(final NormalizedNodePayload payload, final UriInfo uriInfo) {
    requireNonNull(payload);
    if (payload.getInstanceIdentifierContext().getSchemaNode() instanceof ActionDefinition) {
        return invokeAction(payload);
    }
    final WriteDataParams params = QueryParams.newWriteDataParams(uriInfo);
    final DOMMountPoint mountPoint = payload.getInstanceIdentifierContext().getMountPoint();
    final RestconfStrategy strategy = getRestconfStrategy(mountPoint);
    return PostDataTransactionUtil.postData(uriInfo, payload, strategy, getSchemaContext(mountPoint), params);
}
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) ActionDefinition(org.opendaylight.yangtools.yang.model.api.ActionDefinition) WriteDataParams(org.opendaylight.restconf.nb.rfc8040.WriteDataParams)

Example 33 with DOMMountPoint

use of org.opendaylight.mdsal.dom.api.DOMMountPoint in project netconf by opendaylight.

the class XmlBodyReaderMountPointTest method checkExpectValueNormalizeNodeContext.

private static void checkExpectValueNormalizeNodeContext(final DataSchemaNode dataSchemaNode, final NormalizedNodePayload nnContext, final QName qualifiedName) {
    YangInstanceIdentifier dataNodeIdent = YangInstanceIdentifier.of(dataSchemaNode.getQName());
    final DOMMountPoint mountPoint = nnContext.getInstanceIdentifierContext().getMountPoint();
    final DataSchemaNode mountDataSchemaNode = modelContext(mountPoint).getDataChildByName(dataSchemaNode.getQName());
    assertNotNull(mountDataSchemaNode);
    if (qualifiedName != null && dataSchemaNode instanceof DataNodeContainer) {
        final DataSchemaNode child = ((DataNodeContainer) dataSchemaNode).getDataChildByName(qualifiedName);
        dataNodeIdent = YangInstanceIdentifier.builder(dataNodeIdent).node(child.getQName()).build();
        assertEquals(nnContext.getInstanceIdentifierContext().getSchemaNode(), child);
    } else {
        assertEquals(mountDataSchemaNode, dataSchemaNode);
    }
    assertNotNull(NormalizedNodes.findNode(nnContext.getData(), dataNodeIdent));
}
Also used : DataSchemaNode(org.opendaylight.yangtools.yang.model.api.DataSchemaNode) DOMMountPoint(org.opendaylight.mdsal.dom.api.DOMMountPoint) DataNodeContainer(org.opendaylight.yangtools.yang.model.api.DataNodeContainer) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)

Example 34 with DOMMountPoint

use of org.opendaylight.mdsal.dom.api.DOMMountPoint in project netconf by opendaylight.

the class ParserIdentifier method toInstanceIdentifier.

/**
 * Make {@link InstanceIdentifierContext} from {@link String} identifier
 * <br>
 * For identifiers of data NOT behind mount points returned
 * {@link InstanceIdentifierContext} is prepared with {@code null} reference of {@link DOMMountPoint} and with
 * controller's {@link SchemaContext}.
 * <br>
 * For identifiers of data behind mount points returned
 * {@link InstanceIdentifierContext} is prepared with reference of {@link DOMMountPoint} and its
 * own {@link SchemaContext}.
 *
 * @param identifier
 *           - path identifier
 * @param schemaContext
 *           - controller schema context
 * @param mountPointService
 *           - mount point service
 * @return {@link InstanceIdentifierContext}
 */
// FIXME: NETCONF-631: this method should not be here, it should be a static factory in InstanceIdentifierContext:
// 
// @NonNull InstanceIdentifierContext forUrl(identifier, schemaContexxt, mountPointService)
// 
public static InstanceIdentifierContext<?> toInstanceIdentifier(final String identifier, final EffectiveModelContext schemaContext, final Optional<DOMMountPointService> mountPointService) {
    if (identifier == null || !identifier.contains(RestconfConstants.MOUNT)) {
        return createIIdContext(schemaContext, identifier, null);
    }
    if (mountPointService.isEmpty()) {
        throw new RestconfDocumentedException("Mount point service is not available");
    }
    final Iterator<String> pathsIt = MP_SPLITTER.split(identifier).iterator();
    final String mountPointId = pathsIt.next();
    final YangInstanceIdentifier mountPath = IdentifierCodec.deserialize(mountPointId, schemaContext);
    final DOMMountPoint mountPoint = mountPointService.get().getMountPoint(mountPath).orElseThrow(() -> new RestconfDocumentedException("Mount point does not exist.", ErrorType.PROTOCOL, ErrorTags.RESOURCE_DENIED_TRANSPORT));
    final EffectiveModelContext mountSchemaContext = coerceModelContext(mountPoint);
    final String pathId = pathsIt.next().replaceFirst("/", "");
    return createIIdContext(mountSchemaContext, pathId, mountPoint);
}
Also used : RestconfDocumentedException(org.opendaylight.restconf.common.errors.RestconfDocumentedException) DOMMountPoint(org.opendaylight.mdsal.dom.api.DOMMountPoint) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) EffectiveModelContext(org.opendaylight.yangtools.yang.model.api.EffectiveModelContext)

Example 35 with DOMMountPoint

use of org.opendaylight.mdsal.dom.api.DOMMountPoint in project netconf by opendaylight.

the class RestconfInvokeOperationsServiceImpl method invokeRpc.

@Override
public void invokeRpc(final String identifier, final NormalizedNodePayload payload, final UriInfo uriInfo, final AsyncResponse ar) {
    final SchemaNode schema = payload.getInstanceIdentifierContext().getSchemaNode();
    final QName rpcName = schema.getQName();
    final DOMMountPoint mountPoint = payload.getInstanceIdentifierContext().getMountPoint();
    final ListenableFuture<? extends DOMRpcResult> future;
    final EffectiveModelContext schemaContextRef;
    if (mountPoint == null) {
        schemaContextRef = schemaContextHandler.get();
        // FIXME: this really should be a normal RPC invocation service which has its own interface with JAX-RS
        if (SAL_REMOTE_NAMESPACE.equals(rpcName.getNamespace())) {
            if (identifier.contains("create-data-change-event-subscription")) {
                future = Futures.immediateFuture(CreateStreamUtil.createDataChangeNotifiStream(payload, schemaContextRef));
            } else {
                future = Futures.immediateFailedFuture(new RestconfDocumentedException("Unsupported operation", ErrorType.RPC, ErrorTag.OPERATION_NOT_SUPPORTED));
            }
        } else {
            future = invokeRpc(payload.getData(), rpcName, rpcService);
        }
    } else {
        schemaContextRef = modelContext(mountPoint);
        future = invokeRpc(payload.getData(), rpcName, mountPoint);
    }
    Futures.addCallback(future, new FutureCallback<DOMRpcResult>() {

        @Override
        public void onSuccess(final DOMRpcResult response) {
            final var errors = response.getErrors();
            if (!errors.isEmpty()) {
                LOG.debug("RpcError message {}", response.getErrors());
                ar.resume(new RestconfDocumentedException("RPCerror message ", null, response.getErrors()));
                return;
            }
            final NormalizedNode resultData = response.getResult();
            if (resultData == null || ((ContainerNode) resultData).isEmpty()) {
                ar.resume(new WebApplicationException(Status.NO_CONTENT));
            } else {
                ar.resume(NormalizedNodePayload.of(new InstanceIdentifierContext<>(null, (RpcDefinition) schema, mountPoint, schemaContextRef), resultData));
            }
        }

        @Override
        public void onFailure(final Throwable failure) {
            ar.resume(failure);
        }
    }, MoreExecutors.directExecutor());
}
Also used : RestconfDocumentedException(org.opendaylight.restconf.common.errors.RestconfDocumentedException) DefaultDOMRpcResult(org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult) DOMRpcResult(org.opendaylight.mdsal.dom.api.DOMRpcResult) WebApplicationException(javax.ws.rs.WebApplicationException) RpcDefinition(org.opendaylight.yangtools.yang.model.api.RpcDefinition) QName(org.opendaylight.yangtools.yang.common.QName) DOMMountPoint(org.opendaylight.mdsal.dom.api.DOMMountPoint) SchemaNode(org.opendaylight.yangtools.yang.model.api.SchemaNode) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) EffectiveModelContext(org.opendaylight.yangtools.yang.model.api.EffectiveModelContext)

Aggregations

DOMMountPoint (org.opendaylight.mdsal.dom.api.DOMMountPoint)38 RestconfDocumentedException (org.opendaylight.restconf.common.errors.RestconfDocumentedException)16 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)15 EffectiveModelContext (org.opendaylight.yangtools.yang.model.api.EffectiveModelContext)13 NormalizedNode (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)9 NormalizedNodeContext (org.opendaylight.netconf.sal.rest.impl.NormalizedNodeContext)8 DataSchemaNode (org.opendaylight.yangtools.yang.model.api.DataSchemaNode)8 MdsalRestconfStrategy (org.opendaylight.restconf.nb.rfc8040.rests.transactions.MdsalRestconfStrategy)7 RestconfStrategy (org.opendaylight.restconf.nb.rfc8040.rests.transactions.RestconfStrategy)7 ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)6 Test (org.junit.Test)5 DOMRpcService (org.opendaylight.mdsal.dom.api.DOMRpcService)5 QName (org.opendaylight.yangtools.yang.common.QName)5 ListSchemaNode (org.opendaylight.yangtools.yang.model.api.ListSchemaNode)5 ArrayList (java.util.ArrayList)4 List (java.util.List)4 ExecutionException (java.util.concurrent.ExecutionException)4 DOMDataTreeReadWriteTransaction (org.opendaylight.mdsal.dom.api.DOMDataTreeReadWriteTransaction)4 RpcDefinition (org.opendaylight.yangtools.yang.model.api.RpcDefinition)4 SchemaNode (org.opendaylight.yangtools.yang.model.api.SchemaNode)4