Search in sources :

Example 26 with DOMMountPoint

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

the class RestGetOperationTest method getDataWithSlashesBehindMountPoint.

/**
 * MountPoint test. URI represents mount point.
 * Slashes in URI behind mount point. lst1 element with key GigabitEthernet0%2F0%2F0%2F0 (GigabitEthernet0/0/0/0) is
 * requested via GET HTTP operation. It is tested whether %2F character is replaced with simple / in
 * InstanceIdentifier parameter in method
 * {@link BrokerFacade#readConfigurationData(DOMMountPoint, YangInstanceIdentifier)} which is called in
 * method {@link RestconfImpl#readConfigurationData}
 */
@Test
public void getDataWithSlashesBehindMountPoint() throws Exception {
    final YangInstanceIdentifier awaitedInstanceIdentifier = prepareInstanceIdentifierForList();
    when(brokerFacade.readConfigurationData(any(DOMMountPoint.class), eq(awaitedInstanceIdentifier), isNull())).thenReturn(prepareCnDataForSlashesBehindMountPointTest());
    when(mountInstance.getService(DOMSchemaService.class)).thenReturn(Optional.of(FixedDOMSchemaService.of(schemaContextTestModule)));
    final String uri = "/config/ietf-interfaces:interfaces/interface/0/yang-ext:mount/" + "test-module:cont/lst1/GigabitEthernet0%2F0%2F0%2F0";
    assertEquals(200, get(uri, MediaType.APPLICATION_XML));
}
Also used : DOMMountPoint(org.opendaylight.mdsal.dom.api.DOMMountPoint) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) JerseyTest(org.glassfish.jersey.test.JerseyTest) Test(org.junit.Test)

Example 27 with DOMMountPoint

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

the class ApiDocServiceImplTest method setUp.

@Before
public void setUp() {
    final EffectiveModelContext context = YangParserTestUtils.parseYangResourceDirectory("/yang");
    final DOMSchemaService schemaService = DocGenTestHelper.createMockSchemaService(context);
    final DOMMountPoint mountPoint = mock(DOMMountPoint.class);
    when(mountPoint.getService(DOMSchemaService.class)).thenReturn(Optional.of(schemaService));
    final DOMMountPointService service = mock(DOMMountPointService.class);
    when(service.getMountPoint(INSTANCE_ID)).thenReturn(Optional.of(mountPoint));
    final MountPointSwaggerGeneratorDraft02 mountPointDraft02 = new MountPointSwaggerGeneratorDraft02(schemaService, service);
    final MountPointSwaggerGeneratorRFC8040 mountPointRFC8040 = new MountPointSwaggerGeneratorRFC8040(schemaService, service);
    final ApiDocGeneratorDraftO2 apiDocGeneratorDraftO2 = new ApiDocGeneratorDraftO2(schemaService);
    final ApiDocGeneratorRFC8040 apiDocGeneratorRFC8040 = new ApiDocGeneratorRFC8040(schemaService);
    mountPointDraft02.getMountPointSwagger().onMountPointCreated(INSTANCE_ID);
    final AllModulesDocGenerator allModulesDocGenerator = new AllModulesDocGenerator(apiDocGeneratorDraftO2, apiDocGeneratorRFC8040);
    apiDocService = new ApiDocServiceImpl(mountPointDraft02, mountPointRFC8040, apiDocGeneratorDraftO2, apiDocGeneratorRFC8040, allModulesDocGenerator);
}
Also used : MountPointSwaggerGeneratorDraft02(org.opendaylight.netconf.sal.rest.doc.impl.MountPointSwaggerGeneratorDraft02) ApiDocGeneratorDraftO2(org.opendaylight.netconf.sal.rest.doc.impl.ApiDocGeneratorDraftO2) AllModulesDocGenerator(org.opendaylight.netconf.sal.rest.doc.impl.AllModulesDocGenerator) MountPointSwaggerGeneratorRFC8040(org.opendaylight.netconf.sal.rest.doc.impl.MountPointSwaggerGeneratorRFC8040) ApiDocServiceImpl(org.opendaylight.netconf.sal.rest.doc.impl.ApiDocServiceImpl) DOMMountPoint(org.opendaylight.mdsal.dom.api.DOMMountPoint) DOMMountPointService(org.opendaylight.mdsal.dom.api.DOMMountPointService) DOMSchemaService(org.opendaylight.mdsal.dom.api.DOMSchemaService) EffectiveModelContext(org.opendaylight.yangtools.yang.model.api.EffectiveModelContext) ApiDocGeneratorRFC8040(org.opendaylight.netconf.sal.rest.doc.impl.ApiDocGeneratorRFC8040) Before(org.junit.Before)

Example 28 with DOMMountPoint

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

the class MountPointSwaggerTest method setUp.

@Before
public void setUp() {
    // We are sharing the global schema service and the mount schema service
    // in our test.
    // OK for testing - real thing would have separate instances.
    final EffectiveModelContext context = YangParserTestUtils.parseYangResourceDirectory("/yang");
    final DOMSchemaService schemaService = DocGenTestHelper.createMockSchemaService(context);
    final DOMMountPoint mountPoint = mock(DOMMountPoint.class);
    when(mountPoint.getService(DOMSchemaService.class)).thenReturn(Optional.of(schemaService));
    final DOMMountPointService service = mock(DOMMountPointService.class);
    when(service.getMountPoint(INSTANCE_ID)).thenReturn(Optional.of(mountPoint));
    final MountPointSwaggerGeneratorDraft02 generator = new MountPointSwaggerGeneratorDraft02(schemaService, service);
    swagger = generator.getMountPointSwagger();
}
Also used : MountPointSwaggerGeneratorDraft02(org.opendaylight.netconf.sal.rest.doc.impl.MountPointSwaggerGeneratorDraft02) DOMMountPoint(org.opendaylight.mdsal.dom.api.DOMMountPoint) DOMMountPointService(org.opendaylight.mdsal.dom.api.DOMMountPointService) DOMSchemaService(org.opendaylight.mdsal.dom.api.DOMSchemaService) EffectiveModelContext(org.opendaylight.yangtools.yang.model.api.EffectiveModelContext) Before(org.junit.Before)

Example 29 with DOMMountPoint

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

the class RestconfDataServiceImpl method putData.

@Override
public Response putData(final String identifier, final NormalizedNodePayload payload, final UriInfo uriInfo) {
    requireNonNull(payload);
    final WriteDataParams params = QueryParams.newWriteDataParams(uriInfo);
    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 PutDataTransactionUtil.putData(payload, ref, strategy, 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) WriteDataParams(org.opendaylight.restconf.nb.rfc8040.WriteDataParams) EffectiveModelContext(org.opendaylight.yangtools.yang.model.api.EffectiveModelContext)

Example 30 with DOMMountPoint

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

the class RestconfDataServiceImpl method invokeAction.

/**
 * Invoke Action operation.
 *
 * @param payload {@link NormalizedNodePayload} - the body of the operation
 * @return {@link NormalizedNodePayload} wrapped in {@link Response}
 */
public Response invokeAction(final NormalizedNodePayload payload) {
    final InstanceIdentifierContext<?> context = payload.getInstanceIdentifierContext();
    final DOMMountPoint mountPoint = context.getMountPoint();
    final YangInstanceIdentifier yangIIdContext = context.getInstanceIdentifier();
    final NormalizedNode data = payload.getData();
    if (yangIIdContext.isEmpty() && !NETCONF_BASE_QNAME.equals(data.getIdentifier().getNodeType())) {
        throw new RestconfDocumentedException("Instance identifier need to contain at least one path argument", ErrorType.PROTOCOL, ErrorTag.MALFORMED_MESSAGE);
    }
    final List<QName> qNames = yangIIdContext.getPathArguments().stream().filter(arg -> !(arg instanceof YangInstanceIdentifier.NodeIdentifierWithPredicates)).filter(arg -> !(arg instanceof YangInstanceIdentifier.AugmentationIdentifier)).map(PathArgument::getNodeType).collect(Collectors.toList());
    qNames.add(context.getSchemaNode().getQName());
    final Absolute schemaPath = Absolute.of(qNames);
    final DOMActionResult response;
    final EffectiveModelContext schemaContextRef;
    if (mountPoint != null) {
        response = invokeAction((ContainerNode) data, schemaPath, yangIIdContext, mountPoint);
        schemaContextRef = modelContext(mountPoint);
    } else {
        response = invokeAction((ContainerNode) data, schemaPath, yangIIdContext, actionService);
        schemaContextRef = schemaContextHandler.get();
    }
    final DOMActionResult result = checkActionResponse(response);
    ActionDefinition resultNodeSchema = null;
    ContainerNode resultData = null;
    if (result != null) {
        final Optional<ContainerNode> optOutput = result.getOutput();
        if (optOutput.isPresent()) {
            resultData = optOutput.get();
            resultNodeSchema = (ActionDefinition) context.getSchemaNode();
        }
    }
    if (resultData != null && resultData.isEmpty()) {
        return Response.status(Status.NO_CONTENT).build();
    }
    return Response.status(Status.OK).entity(NormalizedNodePayload.ofNullable(new InstanceIdentifierContext<>(yangIIdContext, resultNodeSchema, mountPoint, schemaContextRef), resultData)).build();
}
Also used : DOMDataTreeWriteTransaction(org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction) DOMActionResult(org.opendaylight.mdsal.dom.api.DOMActionResult) WriteDataParams(org.opendaylight.restconf.nb.rfc8040.WriteDataParams) PlainPatchDataTransactionUtil(org.opendaylight.restconf.nb.rfc8040.rests.utils.PlainPatchDataTransactionUtil) SchemaContext(org.opendaylight.yangtools.yang.model.api.SchemaContext) Path(javax.ws.rs.Path) LoggerFactory(org.slf4j.LoggerFactory) DOMActionException(org.opendaylight.mdsal.dom.api.DOMActionException) Absolute(org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute) STREAM_ACCESS_PATH_PART(org.opendaylight.restconf.nb.rfc8040.rests.utils.RestconfStreamsConstants.STREAM_ACCESS_PATH_PART) PatchContext(org.opendaylight.restconf.common.patch.PatchContext) Map(java.util.Map) QueryParams(org.opendaylight.restconf.nb.rfc8040.databind.jaxrs.QueryParams) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) URI(java.net.URI) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) DOMDataTreeIdentifier(org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier) DOMActionService(org.opendaylight.mdsal.dom.api.DOMActionService) ListSchemaNode(org.opendaylight.yangtools.yang.model.api.ListSchemaNode) CancellationException(java.util.concurrent.CancellationException) STREAM_LOCATION_PATH_PART(org.opendaylight.restconf.nb.rfc8040.rests.utils.RestconfStreamsConstants.STREAM_LOCATION_PATH_PART) NotificationOutputType(org.opendaylight.yang.gen.v1.urn.sal.restconf.event.subscription.rev140708.NotificationOutputTypeGrouping.NotificationOutputType) Collectors(java.util.stream.Collectors) STREAM_PATH_PART(org.opendaylight.restconf.nb.rfc8040.rests.utils.RestconfStreamsConstants.STREAM_PATH_PART) ParserIdentifier(org.opendaylight.restconf.nb.rfc8040.utils.parser.ParserIdentifier) List(java.util.List) NOTIFICATION_STREAM(org.opendaylight.restconf.nb.rfc8040.rests.utils.RestconfStreamsConstants.NOTIFICATION_STREAM) Revision(org.opendaylight.yangtools.yang.common.Revision) Response(javax.ws.rs.core.Response) DOMDataBroker(org.opendaylight.mdsal.dom.api.DOMDataBroker) PathArgument(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument) RestconfDataService(org.opendaylight.restconf.nb.rfc8040.rests.services.api.RestconfDataService) Optional(java.util.Optional) UriInfo(javax.ws.rs.core.UriInfo) DOMSchemaService(org.opendaylight.mdsal.dom.api.DOMSchemaService) MapEntryNode(org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode) SimpleDOMActionResult(org.opendaylight.mdsal.dom.spi.SimpleDOMActionResult) NotificationDefinition(org.opendaylight.yangtools.yang.model.api.NotificationDefinition) MoreExecutors(com.google.common.util.concurrent.MoreExecutors) ReadDataTransactionUtil(org.opendaylight.restconf.nb.rfc8040.rests.utils.ReadDataTransactionUtil) ReadDataParams(org.opendaylight.restconf.nb.rfc8040.ReadDataParams) PutDataTransactionUtil(org.opendaylight.restconf.nb.rfc8040.rests.utils.PutDataTransactionUtil) InstanceIdentifierContext(org.opendaylight.restconf.common.context.InstanceIdentifierContext) PostDataTransactionUtil(org.opendaylight.restconf.nb.rfc8040.rests.utils.PostDataTransactionUtil) LocalDateTime(java.time.LocalDateTime) HashMap(java.util.HashMap) DOMMountPointService(org.opendaylight.mdsal.dom.api.DOMMountPointService) NormalizedNodePayload(org.opendaylight.restconf.nb.rfc8040.legacy.NormalizedNodePayload) STREAMS_PATH(org.opendaylight.restconf.nb.rfc8040.rests.utils.RestconfStreamsConstants.STREAMS_PATH) NotificationListenerAdapter(org.opendaylight.restconf.nb.rfc8040.streams.listeners.NotificationListenerAdapter) DeleteDataTransactionUtil(org.opendaylight.restconf.nb.rfc8040.rests.utils.DeleteDataTransactionUtil) PatchStatusContext(org.opendaylight.restconf.common.patch.PatchStatusContext) ErrorType(org.opendaylight.yangtools.yang.common.ErrorType) ImmutableList(com.google.common.collect.ImmutableList) Objects.requireNonNull(java.util.Objects.requireNonNull) SchemaContextHandler(org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler) Status(javax.ws.rs.core.Response.Status) PatchDataTransactionUtil(org.opendaylight.restconf.nb.rfc8040.rests.utils.PatchDataTransactionUtil) Logger(org.slf4j.Logger) DOMDataTreeWriteOperations(org.opendaylight.mdsal.dom.api.DOMDataTreeWriteOperations) ErrorTag(org.opendaylight.yangtools.yang.common.ErrorTag) NodeIdentifierWithPredicates(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates) EffectiveModelContext(org.opendaylight.yangtools.yang.model.api.EffectiveModelContext) QueryParameters(org.opendaylight.restconf.nb.rfc8040.legacy.QueryParameters) Configuration(org.opendaylight.restconf.nb.rfc8040.streams.Configuration) QName(org.opendaylight.yangtools.yang.common.QName) RestconfStreamsSubscriptionService(org.opendaylight.restconf.nb.rfc8040.rests.services.api.RestconfStreamsSubscriptionService) SchemaNode(org.opendaylight.yangtools.yang.model.api.SchemaNode) ExecutionException(java.util.concurrent.ExecutionException) STREAM_PATH(org.opendaylight.restconf.nb.rfc8040.rests.utils.RestconfStreamsConstants.STREAM_PATH) DOMMountPoint(org.opendaylight.mdsal.dom.api.DOMMountPoint) Futures(com.google.common.util.concurrent.Futures) RestconfMappingNodeUtil(org.opendaylight.restconf.nb.rfc8040.utils.mapping.RestconfMappingNodeUtil) RestconfStrategy(org.opendaylight.restconf.nb.rfc8040.rests.transactions.RestconfStrategy) RpcResultBuilder(org.opendaylight.yangtools.yang.common.RpcResultBuilder) DateTimeFormatter(java.time.format.DateTimeFormatter) LogicalDatastoreType(org.opendaylight.mdsal.common.api.LogicalDatastoreType) Clock(java.time.Clock) MdsalRestconfStrategy(org.opendaylight.restconf.nb.rfc8040.rests.transactions.MdsalRestconfStrategy) VisibleForTesting(com.google.common.annotations.VisibleForTesting) ActionDefinition(org.opendaylight.yangtools.yang.model.api.ActionDefinition) RestconfDocumentedException(org.opendaylight.restconf.common.errors.RestconfDocumentedException) Rfc8040(org.opendaylight.restconf.nb.rfc8040.Rfc8040) RpcError(org.opendaylight.yangtools.yang.common.RpcError) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) RestconfDocumentedException(org.opendaylight.restconf.common.errors.RestconfDocumentedException) QName(org.opendaylight.yangtools.yang.common.QName) DOMMountPoint(org.opendaylight.mdsal.dom.api.DOMMountPoint) NodeIdentifierWithPredicates(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates) Absolute(org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) ActionDefinition(org.opendaylight.yangtools.yang.model.api.ActionDefinition) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) DOMActionResult(org.opendaylight.mdsal.dom.api.DOMActionResult) SimpleDOMActionResult(org.opendaylight.mdsal.dom.spi.SimpleDOMActionResult) 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