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