Search in sources :

Example 1 with RemoteRpcEndpoint

use of org.opendaylight.controller.remote.rpc.registry.RpcRegistry.RemoteRpcEndpoint in project controller by opendaylight.

the class RpcRegistrarTest method setUp.

@Before
public void setUp() throws Exception {
    MockitoAnnotations.initMocks(this);
    system = ActorSystem.create("test");
    final TestKit testKit = new TestKit(system);
    final RemoteRpcProviderConfig config = new RemoteRpcProviderConfig.Builder("system").build();
    final Props props = RpcRegistrar.props(config, service);
    testActorRef = new TestActorRef<>(system, props, testKit.getRef(), "actorRef");
    endpointAddress = new Address("http", "local");
    final DOMRpcIdentifier firstEndpointId = DOMRpcIdentifier.create(SchemaPath.create(true, QName.create("first:identifier", "foo")));
    final DOMRpcIdentifier secondEndpointId = DOMRpcIdentifier.create(SchemaPath.create(true, QName.create("second:identifier", "bar")));
    final TestKit senderKit = new TestKit(system);
    firstEndpoint = new RemoteRpcEndpoint(senderKit.getRef(), Collections.singletonList(firstEndpointId));
    secondEndpoint = new RemoteRpcEndpoint(senderKit.getRef(), Collections.singletonList(secondEndpointId));
    Mockito.doReturn(oldReg).when(service).registerRpcImplementation(Mockito.any(RemoteRpcImplementation.class), Mockito.eq(firstEndpoint.getRpcs()));
    Mockito.doReturn(newReg).when(service).registerRpcImplementation(Mockito.any(RemoteRpcImplementation.class), Mockito.eq(secondEndpoint.getRpcs()));
    rpcRegistrar = testActorRef.underlyingActor();
}
Also used : Address(akka.actor.Address) RemoteRpcEndpoint(org.opendaylight.controller.remote.rpc.registry.RpcRegistry.RemoteRpcEndpoint) DOMRpcIdentifier(org.opendaylight.controller.md.sal.dom.api.DOMRpcIdentifier) TestKit(akka.testkit.javadsl.TestKit) Props(akka.actor.Props) Before(org.junit.Before)

Example 2 with RemoteRpcEndpoint

use of org.opendaylight.controller.remote.rpc.registry.RpcRegistry.RemoteRpcEndpoint in project controller by opendaylight.

the class RpcRegistryTest method assertEndpoints.

private static void assertEndpoints(final UpdateRemoteEndpoints msg, final Address address, final TestKit invoker) {
    final Map<Address, Optional<RemoteRpcEndpoint>> endpoints = msg.getEndpoints();
    Assert.assertEquals(1, endpoints.size());
    final Optional<RemoteRpcEndpoint> maybeEndpoint = endpoints.get(address);
    Assert.assertNotNull(maybeEndpoint);
    Assert.assertTrue(maybeEndpoint.isPresent());
    final RemoteRpcEndpoint endpoint = maybeEndpoint.get();
    final ActorRef router = endpoint.getRouter();
    Assert.assertNotNull(router);
    router.tell("hello", ActorRef.noSender());
    final String s = invoker.expectMsgClass(Duration.create(3, TimeUnit.SECONDS), String.class);
    Assert.assertEquals("hello", s);
}
Also used : UniqueAddress(akka.cluster.UniqueAddress) Address(akka.actor.Address) Optional(java.util.Optional) ActorRef(akka.actor.ActorRef) RemoteRpcEndpoint(org.opendaylight.controller.remote.rpc.registry.RpcRegistry.RemoteRpcEndpoint)

Example 3 with RemoteRpcEndpoint

use of org.opendaylight.controller.remote.rpc.registry.RpcRegistry.RemoteRpcEndpoint in project controller by opendaylight.

the class RpcRegistrar method updateRemoteEndpoints.

private void updateRemoteEndpoints(final Map<Address, Optional<RemoteRpcEndpoint>> endpoints) {
    /*
         * 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<DOMRpcImplementationRegistration<?>> prevRegs = new ArrayList<>(endpoints.size());
    for (Entry<Address, Optional<RemoteRpcEndpoint>> e : endpoints.entrySet()) {
        LOG.debug("Updating RPC registrations for {}", e.getKey());
        final DOMRpcImplementationRegistration<?> prevReg;
        final Optional<RemoteRpcEndpoint> maybeEndpoint = e.getValue();
        if (maybeEndpoint.isPresent()) {
            final RemoteRpcEndpoint endpoint = maybeEndpoint.get();
            final RemoteRpcImplementation impl = new RemoteRpcImplementation(endpoint.getRouter(), config);
            prevReg = regs.put(e.getKey(), rpcProviderService.registerRpcImplementation(impl, endpoint.getRpcs()));
        } else {
            prevReg = regs.remove(e.getKey());
        }
        if (prevReg != null) {
            prevRegs.add(prevReg);
        }
    }
    for (DOMRpcImplementationRegistration<?> r : prevRegs) {
        r.close();
    }
}
Also used : Address(akka.actor.Address) Optional(java.util.Optional) DOMRpcImplementationRegistration(org.opendaylight.controller.md.sal.dom.api.DOMRpcImplementationRegistration) ArrayList(java.util.ArrayList) RemoteRpcEndpoint(org.opendaylight.controller.remote.rpc.registry.RpcRegistry.RemoteRpcEndpoint)

Aggregations

Address (akka.actor.Address)3 RemoteRpcEndpoint (org.opendaylight.controller.remote.rpc.registry.RpcRegistry.RemoteRpcEndpoint)3 Optional (java.util.Optional)2 ActorRef (akka.actor.ActorRef)1 Props (akka.actor.Props)1 UniqueAddress (akka.cluster.UniqueAddress)1 TestKit (akka.testkit.javadsl.TestKit)1 ArrayList (java.util.ArrayList)1 Before (org.junit.Before)1 DOMRpcIdentifier (org.opendaylight.controller.md.sal.dom.api.DOMRpcIdentifier)1 DOMRpcImplementationRegistration (org.opendaylight.controller.md.sal.dom.api.DOMRpcImplementationRegistration)1