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);
}
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);
}
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));
}
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);
}
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());
}
Aggregations