Search in sources :

Example 6 with DOMRpcService

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

the class NetconfBaseOpsTest method setUp.

@Before
public void setUp() throws Exception {
    final InputStream okStream = getClass().getResourceAsStream("/netconfMessages/rpc-reply_ok.xml");
    final InputStream dataStream = getClass().getResourceAsStream("/netconfMessages/rpc-reply_get.xml");
    final NetconfMessage ok = new NetconfMessage(XmlUtil.readXmlToDocument(okStream));
    final NetconfMessage data = new NetconfMessage(XmlUtil.readXmlToDocument(dataStream));
    when(listener.sendRequest(any(), eq(NetconfMessageTransformUtil.NETCONF_GET_CONFIG_QNAME))).thenReturn(RpcResultBuilder.success(data).buildFuture());
    when(listener.sendRequest(any(), eq(NetconfMessageTransformUtil.NETCONF_GET_QNAME))).thenReturn(RpcResultBuilder.success(data).buildFuture());
    when(listener.sendRequest(any(), eq(NetconfMessageTransformUtil.NETCONF_EDIT_CONFIG_QNAME))).thenReturn(RpcResultBuilder.success(ok).buildFuture());
    when(listener.sendRequest(any(), eq(NetconfMessageTransformUtil.NETCONF_COPY_CONFIG_QNAME))).thenReturn(RpcResultBuilder.success(ok).buildFuture());
    when(listener.sendRequest(any(), eq(NetconfMessageTransformUtil.NETCONF_DISCARD_CHANGES_QNAME))).thenReturn(RpcResultBuilder.success(ok).buildFuture());
    when(listener.sendRequest(any(), eq(NetconfMessageTransformUtil.NETCONF_VALIDATE_QNAME))).thenReturn(RpcResultBuilder.success(ok).buildFuture());
    when(listener.sendRequest(any(), eq(NetconfMessageTransformUtil.NETCONF_LOCK_QNAME))).thenReturn(RpcResultBuilder.success(ok).buildFuture());
    when(listener.sendRequest(any(), eq(NetconfMessageTransformUtil.NETCONF_UNLOCK_QNAME))).thenReturn(RpcResultBuilder.success(ok).buildFuture());
    when(listener.sendRequest(any(), eq(NetconfMessageTransformUtil.NETCONF_COMMIT_QNAME))).thenReturn(RpcResultBuilder.success(ok).buildFuture());
    final MessageTransformer<NetconfMessage> transformer = new NetconfMessageTransformer(new EmptyMountPointContext(SCHEMA_CONTEXT), true, BASE_SCHEMAS.getBaseSchema());
    final DOMRpcService rpc = new NetconfDeviceRpc(SCHEMA_CONTEXT, listener, transformer);
    final RemoteDeviceId id = new RemoteDeviceId("device-1", InetSocketAddress.createUnresolved("localhost", 17830));
    callback = new NetconfRpcFutureCallback("prefix", id);
    baseOps = new NetconfBaseOps(rpc, new EmptyMountPointContext(SCHEMA_CONTEXT));
}
Also used : NetconfDeviceRpc(org.opendaylight.netconf.sal.connect.netconf.sal.NetconfDeviceRpc) RemoteDeviceId(org.opendaylight.netconf.sal.connect.util.RemoteDeviceId) EmptyMountPointContext(org.opendaylight.yangtools.rfc8528.data.util.EmptyMountPointContext) DOMRpcService(org.opendaylight.mdsal.dom.api.DOMRpcService) InputStream(java.io.InputStream) NetconfMessage(org.opendaylight.netconf.api.NetconfMessage) NetconfMessageTransformer(org.opendaylight.netconf.sal.connect.netconf.schema.mapping.NetconfMessageTransformer) Before(org.junit.Before)

Example 7 with DOMRpcService

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

the class AbstractInvokableServiceMetadata method retrievedDOMRpcService.

private void retrievedDOMRpcService(final Object service) {
    log.debug("{}: retrievedDOMRpcService {}", logName(), service);
    final DOMRpcService domRpcService = (DOMRpcService) service;
    setDependencyDesc("Available DOM RPC for binding RPC: " + rpcInterface);
    rpcListenerReg = domRpcService.registerRpcListener(new DOMRpcAvailabilityListener() {

        @Override
        public void onRpcAvailable(final Collection<DOMRpcIdentifier> rpcs) {
            onRpcsAvailable(rpcs);
        }

        @Override
        public void onRpcUnavailable(final Collection<DOMRpcIdentifier> rpcs) {
        }
    });
}
Also used : DOMRpcAvailabilityListener(org.opendaylight.mdsal.dom.api.DOMRpcAvailabilityListener) DOMRpcService(org.opendaylight.mdsal.dom.api.DOMRpcService) Collection(java.util.Collection)

Example 8 with DOMRpcService

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

the class NetconfDeviceSalFacadeTest method testOnDeviceConnected.

@Test
public void testOnDeviceConnected() {
    final EffectiveModelContext schemaContext = mock(EffectiveModelContext.class);
    final NetconfSessionPreferences netconfSessionPreferences = NetconfSessionPreferences.fromStrings(getCapabilities());
    final DOMRpcService deviceRpc = mock(DOMRpcService.class);
    deviceFacade.onDeviceConnected(new EmptyMountPointContext(schemaContext), netconfSessionPreferences, deviceRpc, null);
    verify(mountInstance, times(1)).onTopologyDeviceConnected(eq(schemaContext), any(DOMDataBroker.class), any(NetconfDataTreeService.class), eq(deviceRpc), any(NetconfDeviceNotificationService.class), isNull());
    verify(netconfDeviceTopologyAdapter, times(1)).updateDeviceData(true, netconfSessionPreferences.getNetconfDeviceCapabilities());
}
Also used : DOMRpcService(org.opendaylight.mdsal.dom.api.DOMRpcService) EmptyMountPointContext(org.opendaylight.yangtools.rfc8528.data.util.EmptyMountPointContext) NetconfDataTreeService(org.opendaylight.netconf.dom.api.NetconfDataTreeService) NetconfSessionPreferences(org.opendaylight.netconf.sal.connect.netconf.listener.NetconfSessionPreferences) DOMDataBroker(org.opendaylight.mdsal.dom.api.DOMDataBroker) EffectiveModelContext(org.opendaylight.yangtools.yang.model.api.EffectiveModelContext) Test(org.junit.Test)

Example 9 with DOMRpcService

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

the class NetconfNodeActorTest method testSlaveInvokeRpc.

@Test
public void testSlaveInvokeRpc() throws Exception {
    final List<SourceIdentifier> sourceIdentifiers = Lists.newArrayList(RevisionSourceIdentifier.create("testID"));
    initializeMaster(sourceIdentifiers);
    registerSlaveMountPoint();
    ArgumentCaptor<DOMRpcService> domRPCServiceCaptor = ArgumentCaptor.forClass(DOMRpcService.class);
    verify(mockMountPointBuilder).addService(eq(DOMRpcService.class), domRPCServiceCaptor.capture());
    final DOMRpcService slaveDomRPCService = domRPCServiceCaptor.getValue();
    assertTrue(slaveDomRPCService instanceof ProxyDOMRpcService);
    final QName testQName = QName.create("", "TestQname");
    final NormalizedNode outputNode = ImmutableContainerNodeBuilder.create().withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(testQName)).withChild(ImmutableNodes.leafNode(testQName, "foo")).build();
    final RpcError rpcError = RpcResultBuilder.newError(RpcError.ErrorType.RPC, null, "Rpc invocation failed.");
    // RPC with no response output.
    doReturn(FluentFutures.immediateNullFluentFuture()).when(mockDOMRpcService).invokeRpc(any(), any());
    DOMRpcResult result = slaveDomRPCService.invokeRpc(testQName, outputNode).get(2, TimeUnit.SECONDS);
    assertEquals(null, result);
    // RPC with response output.
    doReturn(FluentFutures.immediateFluentFuture(new DefaultDOMRpcResult(outputNode))).when(mockDOMRpcService).invokeRpc(any(), any());
    result = slaveDomRPCService.invokeRpc(testQName, outputNode).get(2, TimeUnit.SECONDS);
    assertEquals(outputNode, result.getResult());
    assertTrue(result.getErrors().isEmpty());
    // RPC with response error.
    doReturn(FluentFutures.immediateFluentFuture(new DefaultDOMRpcResult(rpcError))).when(mockDOMRpcService).invokeRpc(any(), any());
    result = slaveDomRPCService.invokeRpc(testQName, outputNode).get(2, TimeUnit.SECONDS);
    assertNull(result.getResult());
    assertEquals(rpcError, result.getErrors().iterator().next());
    // RPC with response output and error.
    doReturn(FluentFutures.immediateFluentFuture(new DefaultDOMRpcResult(outputNode, rpcError))).when(mockDOMRpcService).invokeRpc(any(), any());
    final DOMRpcResult resultOutputError = slaveDomRPCService.invokeRpc(testQName, outputNode).get(2, TimeUnit.SECONDS);
    assertEquals(outputNode, resultOutputError.getResult());
    assertEquals(rpcError, resultOutputError.getErrors().iterator().next());
    // RPC failure.
    doReturn(FluentFutures.immediateFailedFluentFuture(new ClusteringRpcException("mock"))).when(mockDOMRpcService).invokeRpc(any(), any());
    final ListenableFuture<? extends DOMRpcResult> future = slaveDomRPCService.invokeRpc(testQName, outputNode);
    final ExecutionException e = assertThrows(ExecutionException.class, () -> future.get(2, TimeUnit.SECONDS));
    final Throwable cause = e.getCause();
    assertThat(cause, instanceOf(DOMRpcException.class));
    assertEquals("mock", cause.getMessage());
}
Also used : DefaultDOMRpcResult(org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult) DOMRpcService(org.opendaylight.mdsal.dom.api.DOMRpcService) DefaultDOMRpcResult(org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult) DOMRpcResult(org.opendaylight.mdsal.dom.api.DOMRpcResult) QName(org.opendaylight.yangtools.yang.common.QName) SourceIdentifier(org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier) RevisionSourceIdentifier(org.opendaylight.yangtools.yang.model.repo.api.RevisionSourceIdentifier) RpcError(org.opendaylight.yangtools.yang.common.RpcError) DOMRpcException(org.opendaylight.mdsal.dom.api.DOMRpcException) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) ClusteringRpcException(org.opendaylight.netconf.topology.singleton.impl.utils.ClusteringRpcException) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Example 10 with DOMRpcService

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

the class OSGiRpcRouterTest method testRpc.

@Test
public void testRpc() {
    final DOMRpcService delegate = mock(DOMRpcService.class);
    doReturn(delegate).when(router).getRpcService();
    new OSGiDOMRpcService(router);
// FIXME: invoke something to test delegate()
}
Also used : DOMRpcService(org.opendaylight.mdsal.dom.api.DOMRpcService) Test(org.junit.Test)

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