Search in sources :

Example 1 with DOMRpcService

use of org.opendaylight.mdsal.dom.api.DOMRpcService in project mdsal by opendaylight.

the class DOMMountPointServiceImplTest method testMountPointRegistration.

@Test
public void testMountPointRegistration() {
    final DOMMountPointListener mountPointListener = mock(DOMMountPointListener.class);
    doNothing().when(mountPointListener).onMountPointCreated(PATH);
    mountPointService.registerProvisionListener(mountPointListener);
    // Create a mount point with schema context and a DOMService
    final DOMMountPointBuilder mountPointBuilder = mountPointService.createMountPoint(PATH);
    final DOMRpcService rpcService = mock(DOMRpcService.class);
    mountPointBuilder.addService(DOMRpcService.class, rpcService);
    mountPointBuilder.register();
    // Verify listener has been notified and mount point is accessible from mount point service
    verify(mountPointListener).onMountPointCreated(eq(PATH));
    assertTrue(mountPointService.getMountPoint(PATH).isPresent());
    // Verify mount point schema context and service
    final DOMMountPoint mountPoint = mountPointService.getMountPoint(PATH).get();
    assertTrue(mountPoint.getService(DOMRpcService.class).isPresent());
    assertEquals(rpcService, mountPoint.getService(DOMRpcService.class).get());
}
Also used : DOMRpcService(org.opendaylight.mdsal.dom.api.DOMRpcService) DOMMountPointListener(org.opendaylight.mdsal.dom.api.DOMMountPointListener) DOMMountPointBuilder(org.opendaylight.mdsal.dom.api.DOMMountPointService.DOMMountPointBuilder) DOMMountPoint(org.opendaylight.mdsal.dom.api.DOMMountPoint) Test(org.junit.Test)

Example 2 with DOMRpcService

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

the class RestconfImplTest method testRpcForMountpoint.

@Test
public void testRpcForMountpoint() throws Exception {
    final UriInfo uriInfo = mock(UriInfo.class);
    doReturn(new MultivaluedHashMap<>()).when(uriInfo).getQueryParameters(anyBoolean());
    final NormalizedNodeContext ctx = mock(NormalizedNodeContext.class);
    final InstanceIdentifierContext<?> iiCtx = mock(InstanceIdentifierContext.class);
    doReturn(iiCtx).when(ctx).getInstanceIdentifierContext();
    final SchemaNode schemaNode = mock(SchemaNode.class);
    doReturn(schemaNode).when(iiCtx).getSchemaNode();
    doReturn(QName.create("namespace", "2010-10-10", "localname")).when(schemaNode).getQName();
    final DOMMountPoint mount = mock(DOMMountPoint.class);
    doReturn(mount).when(iiCtx).getMountPoint();
    final DOMRpcService rpcService = mock(DOMRpcService.class);
    doReturn(Optional.of(rpcService)).when(mount).getService(DOMRpcService.class);
    doReturn(immediateFluentFuture(mock(DOMRpcResult.class))).when(rpcService).invokeRpc(any(QName.class), any(NormalizedNode.class));
    this.restconfImpl.invokeRpc("randomId", ctx, uriInfo);
    this.restconfImpl.invokeRpc("ietf-netconf", ctx, uriInfo);
    verify(rpcService, times(2)).invokeRpc(any(QName.class), any());
}
Also used : ListSchemaNode(org.opendaylight.yangtools.yang.model.api.ListSchemaNode) SchemaNode(org.opendaylight.yangtools.yang.model.api.SchemaNode) DataSchemaNode(org.opendaylight.yangtools.yang.model.api.DataSchemaNode) LeafSchemaNode(org.opendaylight.yangtools.yang.model.api.LeafSchemaNode) DOMRpcService(org.opendaylight.mdsal.dom.api.DOMRpcService) QName(org.opendaylight.yangtools.yang.common.QName) DOMMountPoint(org.opendaylight.mdsal.dom.api.DOMMountPoint) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) UriInfo(javax.ws.rs.core.UriInfo) NormalizedNodeContext(org.opendaylight.netconf.sal.rest.impl.NormalizedNodeContext) Test(org.junit.Test)

Example 3 with DOMRpcService

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

the class RestconfImpl method invokeRpc.

@SuppressFBWarnings(value = "NP_LOAD_OF_KNOWN_NULL_VALUE", justification = "Looks like a false positive, see below FIXME")
private NormalizedNodeContext invokeRpc(final String identifier, final UriInfo uriInfo) {
    final DOMMountPoint mountPoint;
    final String identifierEncoded;
    final EffectiveModelContext schemaContext;
    if (identifier.contains(ControllerContext.MOUNT)) {
        // mounted RPC call - look up mount instance.
        final InstanceIdentifierContext<?> mountPointId = controllerContext.toMountPointIdentifier(identifier);
        mountPoint = mountPointId.getMountPoint();
        schemaContext = modelContext(mountPoint);
        final int startOfRemoteRpcName = identifier.lastIndexOf(ControllerContext.MOUNT) + ControllerContext.MOUNT.length() + 1;
        final String remoteRpcName = identifier.substring(startOfRemoteRpcName);
        identifierEncoded = remoteRpcName;
    } else if (identifier.indexOf('/') == CHAR_NOT_FOUND) {
        identifierEncoded = identifier;
        mountPoint = null;
        schemaContext = controllerContext.getGlobalSchema();
    } else {
        LOG.debug("Identifier {} cannot contain slash character (/).", identifier);
        throw new RestconfDocumentedException(String.format("Identifier %n%s%ncan\'t contain slash character (/).%n" + "If slash is part of identifier name then use %%2F placeholder.", identifier), ErrorType.PROTOCOL, ErrorTag.INVALID_VALUE);
    }
    final String identifierDecoded = ControllerContext.urlPathArgDecode(identifierEncoded);
    final RpcDefinition rpc;
    if (mountPoint == null) {
        rpc = controllerContext.getRpcDefinition(identifierDecoded);
    } else {
        rpc = findRpc(modelContext(mountPoint), identifierDecoded);
    }
    if (rpc == null) {
        LOG.debug("RPC {} does not exist.", identifierDecoded);
        throw new RestconfDocumentedException("RPC does not exist.", ErrorType.RPC, ErrorTag.UNKNOWN_ELEMENT);
    }
    if (!rpc.getInput().getChildNodes().isEmpty()) {
        LOG.debug("No input specified for RPC {} with an input section", rpc);
        throw new RestconfDocumentedException("No input specified for RPC " + rpc + " with an input section defined", ErrorType.RPC, ErrorTag.MISSING_ELEMENT);
    }
    final ContainerNode input = defaultInput(rpc.getQName());
    final ListenableFuture<? extends DOMRpcResult> response;
    if (mountPoint != null) {
        final Optional<DOMRpcService> mountRpcServices = mountPoint.getService(DOMRpcService.class);
        if (mountRpcServices.isEmpty()) {
            throw new RestconfDocumentedException("Rpc service is missing.");
        }
        response = mountRpcServices.get().invokeRpc(rpc.getQName(), input);
    } else {
        response = broker.invokeRpc(rpc.getQName(), input);
    }
    final NormalizedNode result = checkRpcResponse(response).getResult();
    if (result != null && ((ContainerNode) result).isEmpty()) {
        throw new WebApplicationException(Response.Status.NO_CONTENT);
    }
    // doing that work.
    return new NormalizedNodeContext(new InstanceIdentifierContext<>(null, rpc, mountPoint, schemaContext), result, QueryParametersParser.parseWriterParameters(uriInfo));
}
Also used : RestconfDocumentedException(org.opendaylight.restconf.common.errors.RestconfDocumentedException) DOMRpcService(org.opendaylight.mdsal.dom.api.DOMRpcService) RpcDefinition(org.opendaylight.yangtools.yang.model.api.RpcDefinition) WebApplicationException(javax.ws.rs.WebApplicationException) DOMMountPoint(org.opendaylight.mdsal.dom.api.DOMMountPoint) DOMMountPoint(org.opendaylight.mdsal.dom.api.DOMMountPoint) NormalizedNodeContext(org.opendaylight.netconf.sal.rest.impl.NormalizedNodeContext) 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) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 4 with DOMRpcService

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

the class RestconfImpl method invokeRpc.

@Override
public NormalizedNodeContext invokeRpc(final String identifier, final NormalizedNodeContext payload, final UriInfo uriInfo) {
    if (payload == null) {
        // no payload specified, reroute this to no payload invokeRpc implementation
        return invokeRpc(identifier, uriInfo);
    }
    final SchemaNode schema = payload.getInstanceIdentifierContext().getSchemaNode();
    final ListenableFuture<? extends DOMRpcResult> response;
    final DOMMountPoint mountPoint = payload.getInstanceIdentifierContext().getMountPoint();
    final NormalizedNode input = nonnullInput(schema, payload.getData());
    final EffectiveModelContext schemaContext;
    if (mountPoint != null) {
        final Optional<DOMRpcService> mountRpcServices = mountPoint.getService(DOMRpcService.class);
        if (mountRpcServices.isEmpty()) {
            LOG.debug("Error: Rpc service is missing.");
            throw new RestconfDocumentedException("Rpc service is missing.");
        }
        schemaContext = modelContext(mountPoint);
        response = mountRpcServices.get().invokeRpc(schema.getQName(), input);
    } else {
        final XMLNamespace namespace = schema.getQName().getNamespace();
        if (namespace.toString().equals(SAL_REMOTE_NAMESPACE)) {
            if (identifier.contains(CREATE_DATA_SUBSCR)) {
                response = invokeSalRemoteRpcSubscribeRPC(payload);
            } else if (identifier.contains(CREATE_NOTIFICATION_STREAM)) {
                response = invokeSalRemoteRpcNotifiStrRPC(payload);
            } else {
                final String msg = "Not supported operation";
                LOG.warn(msg);
                throw new RestconfDocumentedException(msg, ErrorType.RPC, ErrorTag.OPERATION_NOT_SUPPORTED);
            }
        } else {
            response = broker.invokeRpc(schema.getQName(), input);
        }
        schemaContext = controllerContext.getGlobalSchema();
    }
    final DOMRpcResult result = checkRpcResponse(response);
    RpcDefinition resultNodeSchema = null;
    final NormalizedNode resultData;
    if (result != null && result.getResult() != null) {
        resultData = result.getResult();
        resultNodeSchema = (RpcDefinition) payload.getInstanceIdentifierContext().getSchemaNode();
    } else {
        resultData = null;
    }
    if (resultData != null && ((ContainerNode) resultData).isEmpty()) {
        throw new WebApplicationException(Response.Status.NO_CONTENT);
    } else {
        return new NormalizedNodeContext(new InstanceIdentifierContext<>(null, resultNodeSchema, mountPoint, schemaContext), resultData, QueryParametersParser.parseWriterParameters(uriInfo));
    }
}
Also used : RestconfDocumentedException(org.opendaylight.restconf.common.errors.RestconfDocumentedException) DOMRpcService(org.opendaylight.mdsal.dom.api.DOMRpcService) DefaultDOMRpcResult(org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult) DOMRpcResult(org.opendaylight.mdsal.dom.api.DOMRpcResult) RpcDefinition(org.opendaylight.yangtools.yang.model.api.RpcDefinition) WebApplicationException(javax.ws.rs.WebApplicationException) DOMMountPoint(org.opendaylight.mdsal.dom.api.DOMMountPoint) NormalizedNodeContext(org.opendaylight.netconf.sal.rest.impl.NormalizedNodeContext) ContainerSchemaNode(org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode) LeafListSchemaNode(org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode) ListSchemaNode(org.opendaylight.yangtools.yang.model.api.ListSchemaNode) SchemaNode(org.opendaylight.yangtools.yang.model.api.SchemaNode) DataSchemaNode(org.opendaylight.yangtools.yang.model.api.DataSchemaNode) LeafSchemaNode(org.opendaylight.yangtools.yang.model.api.LeafSchemaNode) XMLNamespace(org.opendaylight.yangtools.yang.common.XMLNamespace) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) EffectiveModelContext(org.opendaylight.yangtools.yang.model.api.EffectiveModelContext)

Example 5 with DOMRpcService

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

the class MountedDeviceListener method trackNotificationsPerformance.

private void trackNotificationsPerformance(final YangInstanceIdentifier path) {
    // 1. get nodeId from the path
    final String nodeId = TestUtils.getNodeId(path).get();
    // 2. extract needed services from the mount point
    final DOMMountPoint mountPoint = mountPointService.getMountPoint(path).orElseThrow(() -> new RuntimeException("Unable to get mountpoint"));
    final DOMRpcService rpcService = mountPoint.getService(DOMRpcService.class).orElseThrow(() -> new RuntimeException("Unable to get RPC Service from the mountpoint"));
    final DOMNotificationService notificationService = mountPoint.getService(DOMNotificationService.class).orElseThrow(() -> new RuntimeException("Unable to get NotificationService from the mountpoint"));
    // 3. create a listener for the notifications
    listeners.put(path, notificationService.registerNotificationListener(new NotificationsCounter(nodeId, serializer), Absolute.of(VrfRouteNotification.QNAME)));
    // 4. send 'create-subscription' request to the device
    final StreamNameType streamNameType = new StreamNameType(STREAM_DEFAULT_NAME);
    final CreateSubscriptionInputBuilder subscriptionInputBuilder = new CreateSubscriptionInputBuilder();
    subscriptionInputBuilder.setStream(streamNameType);
    final CreateSubscriptionInput input = subscriptionInputBuilder.build();
    final ContainerNode inputNode = serializer.toNormalizedNodeRpcData(input);
    final ListenableFuture<? extends DOMRpcResult> resultFuture = rpcService.invokeRpc(CREATE_SUBSCRIPTION_QNAME, inputNode);
    Futures.addCallback(resultFuture, new FutureCallback<DOMRpcResult>() {

        @Override
        public void onSuccess(@Nullable final DOMRpcResult rpcResult) {
            LOG.info("Notification stream subscription succesfully completed");
        }

        @Override
        public void onFailure(final Throwable throwable) {
            LOG.error("Notification stream subscription failed");
        }
    }, MoreExecutors.directExecutor());
}
Also used : StreamNameType(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.notification._1._0.rev080714.StreamNameType) DOMRpcService(org.opendaylight.mdsal.dom.api.DOMRpcService) DOMRpcResult(org.opendaylight.mdsal.dom.api.DOMRpcResult) DOMMountPoint(org.opendaylight.mdsal.dom.api.DOMMountPoint) DOMNotificationService(org.opendaylight.mdsal.dom.api.DOMNotificationService) NotificationsCounter(org.opendaylight.netconf.test.perf.notifications.NotificationsCounter) CreateSubscriptionInput(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.notification._1._0.rev080714.CreateSubscriptionInput) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) CreateSubscriptionInputBuilder(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.notification._1._0.rev080714.CreateSubscriptionInputBuilder)

Aggregations

DOMRpcService (org.opendaylight.mdsal.dom.api.DOMRpcService)10 Test (org.junit.Test)5 DOMMountPoint (org.opendaylight.mdsal.dom.api.DOMMountPoint)5 NormalizedNode (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)4 DOMRpcResult (org.opendaylight.mdsal.dom.api.DOMRpcResult)3 NormalizedNodeContext (org.opendaylight.netconf.sal.rest.impl.NormalizedNodeContext)3 EffectiveModelContext (org.opendaylight.yangtools.yang.model.api.EffectiveModelContext)3 WebApplicationException (javax.ws.rs.WebApplicationException)2 DefaultDOMRpcResult (org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult)2 RestconfDocumentedException (org.opendaylight.restconf.common.errors.RestconfDocumentedException)2 EmptyMountPointContext (org.opendaylight.yangtools.rfc8528.data.util.EmptyMountPointContext)2 QName (org.opendaylight.yangtools.yang.common.QName)2 ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)2 DataSchemaNode (org.opendaylight.yangtools.yang.model.api.DataSchemaNode)2 LeafSchemaNode (org.opendaylight.yangtools.yang.model.api.LeafSchemaNode)2 ListSchemaNode (org.opendaylight.yangtools.yang.model.api.ListSchemaNode)2 RpcDefinition (org.opendaylight.yangtools.yang.model.api.RpcDefinition)2 SchemaNode (org.opendaylight.yangtools.yang.model.api.SchemaNode)2 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)1 InputStream (java.io.InputStream)1