Search in sources :

Example 1 with DOMRpcImplementation

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

the class OpsRegistrar method updateRemoteRpcEndpoints.

private void updateRemoteRpcEndpoints(final Map<Address, Optional<RemoteRpcEndpoint>> rpcEndpoints) {
    /*
         * Updating RPC providers is a two-step process. We first add the newly-discovered RPCs and then close
         * the old registration. This minimizes churn observed by listeners, as they will not observe RPC
         * unavailability which would occur if we were to do it the other way around.
         *
         * Note that when an RPC moves from one remote node to another, we also do not want to expose the gap,
         * hence we register all new implementations before closing all registrations.
         */
    final Collection<ObjectRegistration<?>> prevRegs = new ArrayList<>(rpcEndpoints.size());
    for (Entry<Address, Optional<RemoteRpcEndpoint>> e : rpcEndpoints.entrySet()) {
        LOG.debug("Updating RPC registrations for {}", e.getKey());
        final ObjectRegistration<DOMRpcImplementation> prevReg;
        final Optional<RemoteRpcEndpoint> maybeEndpoint = e.getValue();
        if (maybeEndpoint.isPresent()) {
            final RemoteRpcEndpoint endpoint = maybeEndpoint.get();
            final RemoteRpcImplementation impl = new RemoteRpcImplementation(endpoint.getRouter(), config);
            prevReg = rpcRegs.put(e.getKey(), rpcProviderService.registerRpcImplementation(impl, endpoint.getRpcs()));
        } else {
            prevReg = rpcRegs.remove(e.getKey());
        }
        if (prevReg != null) {
            prevRegs.add(prevReg);
        }
    }
    prevRegs.forEach(ObjectRegistration::close);
}
Also used : Address(akka.actor.Address) Optional(java.util.Optional) DOMRpcImplementation(org.opendaylight.mdsal.dom.api.DOMRpcImplementation) ArrayList(java.util.ArrayList) RemoteRpcEndpoint(org.opendaylight.controller.remote.rpc.registry.RpcRegistry.RemoteRpcEndpoint) ObjectRegistration(org.opendaylight.yangtools.concepts.ObjectRegistration)

Example 2 with DOMRpcImplementation

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

the class ForwardingDOMRpcProviderServiceTest method basicTest.

@Test
public void basicTest() throws Exception {
    final DOMRpcImplementation domRpcImplementation = mock(DOMRpcImplementation.class);
    doReturn(null).when(domRpcProviderService).registerRpcImplementation(domRpcImplementation);
    this.registerRpcImplementation(domRpcImplementation);
    verify(domRpcProviderService).registerRpcImplementation(domRpcImplementation);
    doReturn(null).when(domRpcProviderService).registerRpcImplementation(domRpcImplementation, Collections.emptySet());
    this.registerRpcImplementation(domRpcImplementation, Collections.emptySet());
    verify(domRpcProviderService).registerRpcImplementation(domRpcImplementation, Collections.emptySet());
}
Also used : DOMRpcImplementation(org.opendaylight.mdsal.dom.api.DOMRpcImplementation) Test(org.junit.Test)

Example 3 with DOMRpcImplementation

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

the class GlobalDOMRpcRoutingTableEntryTest method basicTest.

@Test
public void basicTest() {
    final Map<YangInstanceIdentifier, List<DOMRpcImplementation>> rpcImplementations = new HashMap<>();
    final List<DOMRpcImplementation> rpcImplementation = new ArrayList<>();
    final RpcDefinition rpcDefinition = mock(RpcDefinition.class);
    final YangInstanceIdentifier yangInstanceIdentifier = YangInstanceIdentifier.builder().build();
    doReturn(TestModel.TEST2_QNAME).when(rpcDefinition).getQName();
    final GlobalDOMRpcRoutingTableEntry globalDOMRpcRoutingTableEntry = new GlobalDOMRpcRoutingTableEntry(rpcDefinition, new HashMap<>());
    rpcImplementation.add(getTestRpcImplementation());
    rpcImplementations.put(yangInstanceIdentifier, rpcImplementation);
    assertEquals(TestModel.TEST2_QNAME, globalDOMRpcRoutingTableEntry.getType());
    assertTrue(globalDOMRpcRoutingTableEntry.getImplementations().isEmpty());
    assertFalse(globalDOMRpcRoutingTableEntry.newInstance(rpcImplementations).getImplementations().isEmpty());
    assertTrue(globalDOMRpcRoutingTableEntry.newInstance(rpcImplementations).getImplementations().containsValue(rpcImplementation));
    final ListenableFuture<?> future = OperationInvocation.invoke(globalDOMRpcRoutingTableEntry.newInstance(rpcImplementations), TEST_CONTAINER);
    final ExecutionException ex = assertThrows(ExecutionException.class, () -> future.get(5, TimeUnit.SECONDS));
    final Throwable cause = ex.getCause();
    assertThat(cause, instanceOf(DOMRpcImplementationNotAvailableException.class));
    assertThat(cause.getMessage(), containsString(EXCEPTION_TEXT));
}
Also used : RpcDefinition(org.opendaylight.yangtools.yang.model.api.RpcDefinition) HashMap(java.util.HashMap) DOMRpcImplementationNotAvailableException(org.opendaylight.mdsal.dom.api.DOMRpcImplementationNotAvailableException) ArrayList(java.util.ArrayList) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) DOMRpcImplementation(org.opendaylight.mdsal.dom.api.DOMRpcImplementation) ArrayList(java.util.ArrayList) List(java.util.List) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Example 4 with DOMRpcImplementation

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

the class UnknownDOMRpcRoutingTableEntryTest method basicTest.

@Test
public void basicTest() throws Exception {
    final Map<YangInstanceIdentifier, List<DOMRpcImplementation>> emptyImpls = new HashMap<>();
    final List<YangInstanceIdentifier> addList1 = new ArrayList<>();
    final List<YangInstanceIdentifier> addList2 = new ArrayList<>();
    final DOMRpcImplementation testClass = getTestRpcImplementation();
    final UnknownDOMRpcRoutingTableEntry test = new UnknownDOMRpcRoutingTableEntry(TestModel.TEST_QNAME, emptyImpls);
    TEST_LIST.add(testClass);
    emptyImpls.put(YangInstanceIdentifier.empty(), TEST_LIST);
    assertNotNull(test);
    assertNotNull(test.newInstance(emptyImpls));
    assertNotNull(OperationInvocation.invoke(test, TEST_CONTAINER));
    assertNotNull(test.getImplementations());
    assertEquals(test.getImplementations(YangInstanceIdentifier.empty()), TEST_LIST);
    assertTrue(test.containsContext(YangInstanceIdentifier.empty()));
    assertTrue(test.registeredIdentifiers().contains(YangInstanceIdentifier.empty()));
    addList1.add(YangInstanceIdentifier.empty());
    addList1.add(YangInstanceIdentifier.of(TestModel.TEST_QNAME));
    addList2.add(YangInstanceIdentifier.of(TestModel.TEST2_QNAME));
    final AbstractDOMRpcRoutingTableEntry tst = (AbstractDOMRpcRoutingTableEntry) test.add(testClass, addList1);
    final AbstractDOMRpcRoutingTableEntry tst1 = (AbstractDOMRpcRoutingTableEntry) tst.add(testClass, addList2);
    final AbstractDOMRpcRoutingTableEntry tst2 = (AbstractDOMRpcRoutingTableEntry) tst1.remove(testClass, addList1);
    assertEquals(1, test.getImplementations().size());
    assertEquals(2, tst.getImplementations().size());
    assertEquals(3, tst1.getImplementations().size());
    assertNotNull(tst2.getImplementations());
    assertEquals(2, tst2.getImplementations().size());
}
Also used : HashMap(java.util.HashMap) DOMRpcImplementation(org.opendaylight.mdsal.dom.api.DOMRpcImplementation) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) Test(org.junit.Test)

Aggregations

DOMRpcImplementation (org.opendaylight.mdsal.dom.api.DOMRpcImplementation)4 ArrayList (java.util.ArrayList)3 Test (org.junit.Test)3 HashMap (java.util.HashMap)2 List (java.util.List)2 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)2 Address (akka.actor.Address)1 Optional (java.util.Optional)1 ExecutionException (java.util.concurrent.ExecutionException)1 RemoteRpcEndpoint (org.opendaylight.controller.remote.rpc.registry.RpcRegistry.RemoteRpcEndpoint)1 DOMRpcImplementationNotAvailableException (org.opendaylight.mdsal.dom.api.DOMRpcImplementationNotAvailableException)1 ObjectRegistration (org.opendaylight.yangtools.concepts.ObjectRegistration)1 RpcDefinition (org.opendaylight.yangtools.yang.model.api.RpcDefinition)1