Migrated usage of RpcService to Rpc<?,?> for eos-dom-akka.
JIRA: CONTROLLER-2085
Change-Id: I73e1df47915caacb021c97d60f0837ad27987d8e
Signed-off-by: Oleksandr Zharov <oleksandr.zharov@pantheon.tech>
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
import akka.actor.typed.javadsl.Behaviors;
import akka.cluster.typed.Cluster;
import com.google.common.annotations.VisibleForTesting;
+import com.google.common.collect.ImmutableClassToInstanceMap;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.SettableFuture;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import org.opendaylight.mdsal.eos.dom.api.DOMEntityOwnershipListener;
import org.opendaylight.mdsal.eos.dom.api.DOMEntityOwnershipListenerRegistration;
import org.opendaylight.mdsal.eos.dom.api.DOMEntityOwnershipService;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.entity.owners.norev.GetEntities;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.entity.owners.norev.GetEntitiesInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.entity.owners.norev.GetEntitiesOutput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.entity.owners.norev.GetEntity;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.entity.owners.norev.GetEntityInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.entity.owners.norev.GetEntityOutput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.entity.owners.norev.GetEntityOwner;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.entity.owners.norev.GetEntityOwnerInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.entity.owners.norev.GetEntityOwnerOutput;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.entity.owners.norev.OdlEntityOwnersService;
import org.opendaylight.yangtools.concepts.Registration;
+import org.opendaylight.yangtools.yang.binding.Rpc;
import org.opendaylight.yangtools.yang.binding.RpcOutput;
import org.opendaylight.yangtools.yang.common.Empty;
import org.opendaylight.yangtools.yang.common.RpcResult;
*/
@Singleton
@Component(immediate = true, service = { DOMEntityOwnershipService.class, DataCenterControl.class })
-public class AkkaEntityOwnershipService implements DOMEntityOwnershipService, DataCenterControl, AutoCloseable,
- OdlEntityOwnersService {
+public class AkkaEntityOwnershipService implements DOMEntityOwnershipService, DataCenterControl, AutoCloseable {
private static final Logger LOG = LoggerFactory.getLogger(AkkaEntityOwnershipService.class);
private static final String DATACENTER_PREFIX = "dc";
private static final Duration DATACENTER_OP_TIMEOUT = Duration.ofSeconds(20);
throws ExecutionException, InterruptedException {
this(actorProvider.getActorSystem(), codecTree);
- reg = rpcProvider.registerRpcImplementation(OdlEntityOwnersService.class, this);
+ reg = rpcProvider.registerRpcImplementations(ImmutableClassToInstanceMap.<Rpc<?, ?>>builder()
+ .put(GetEntity.class, this::getEntity)
+ .put(GetEntities.class, this::getEntities)
+ .put(GetEntityOwner.class, this::getEntityOwner)
+ .build());
}
@PreDestroy
AskPattern.ask(ownerSupervisor, DeactivateDataCenter::new, DATACENTER_OP_TIMEOUT, scheduler));
}
- @Override
- public ListenableFuture<RpcResult<GetEntitiesOutput>> getEntities(final GetEntitiesInput input) {
+ @VisibleForTesting
+ final ListenableFuture<RpcResult<GetEntitiesOutput>> getEntities(final GetEntitiesInput input) {
return toRpcFuture(AskPattern.ask(ownerStateChecker, GetEntitiesRequest::new, QUERY_TIMEOUT, scheduler),
reply -> reply.toOutput(iidCodec));
}
- @Override
- public ListenableFuture<RpcResult<GetEntityOutput>> getEntity(final GetEntityInput input) {
+ @VisibleForTesting
+ final ListenableFuture<RpcResult<GetEntityOutput>> getEntity(final GetEntityInput input) {
return toRpcFuture(AskPattern.ask(ownerStateChecker,
(final ActorRef<GetEntityReply> replyTo) -> new GetEntityRequest(replyTo, input), QUERY_TIMEOUT, scheduler),
GetEntityReply::toOutput);
}
- @Override
- public ListenableFuture<RpcResult<GetEntityOwnerOutput>> getEntityOwner(final GetEntityOwnerInput input) {
+ @VisibleForTesting
+ final ListenableFuture<RpcResult<GetEntityOwnerOutput>> getEntityOwner(final GetEntityOwnerInput input) {
return toRpcFuture(AskPattern.ask(ownerStateChecker,
(final ActorRef<GetEntityOwnerReply> replyTo) -> new GetEntityOwnerRequest(replyTo, input), QUERY_TIMEOUT,
scheduler), GetEntityOwnerReply::toOutput);
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.entity.owners.norev.EntityName;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.entity.owners.norev.EntityType;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.entity.owners.norev.GetEntitiesInputBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.entity.owners.norev.GetEntitiesOutput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.entity.owners.norev.GetEntityInputBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.entity.owners.norev.GetEntityOutput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.entity.owners.norev.GetEntityOwnerInputBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.entity.owners.norev.GetEntityOwnerOutput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.entity.owners.norev.NodeName;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.entity.owners.norev.get.entities.output.EntitiesKey;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.common.RpcResult;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
@Before
public void setUp() throws Exception {
system = ActorSystem.create("ClusterSystem", ConfigFactory.load());
- typedSystem = Adapter.toTyped(this.system);
+ typedSystem = Adapter.toTyped(system);
replicator = DistributedData.get(typedSystem).replicator();
service = new AkkaEntityOwnershipService(system, CODEC_CONTEXT);
@Test
public void testEntityRetrievalWithYiid() throws Exception {
- final YangInstanceIdentifier entityId = YangInstanceIdentifier.create(new NodeIdentifier(NetworkTopology.QNAME),
+ final YangInstanceIdentifier entityId = YangInstanceIdentifier.of(new NodeIdentifier(NetworkTopology.QNAME),
new NodeIdentifier(Topology.QNAME),
NodeIdentifierWithPredicates.of(Topology.QNAME, QName.create(Topology.QNAME, "topology-id"), "test"),
new NodeIdentifier(Node.QNAME),
verifyEntityOwnershipCandidateRegistration(entity, reg);
verifyEntityCandidateRegistered(ENTITY_TYPE, entityId, "member-1");
- RpcResult<GetEntityOutput> getEntityResult = service.getEntity(new GetEntityInputBuilder()
- .setName(new EntityName(CODEC_CONTEXT.fromYangInstanceIdentifier(entityId)))
- .setType(new EntityType(ENTITY_TYPE))
- .build())
- .get();
+ var getEntityResult = service.getEntity(new GetEntityInputBuilder()
+ .setName(new EntityName(CODEC_CONTEXT.fromYangInstanceIdentifier(entityId)))
+ .setType(new EntityType(ENTITY_TYPE))
+ .build())
+ .get();
assertEquals(getEntityResult.getResult().getOwnerNode().getValue(), "member-1");
assertEquals(getEntityResult.getResult().getCandidateNodes().get(0).getValue(), "member-1");
assertNull(getEntityResult.getResult().getOwnerNode());
assertTrue(getEntityResult.getResult().getCandidateNodes().isEmpty());
- final GetEntitiesOutput getEntitiesResult =
- service.getEntities(new GetEntitiesInputBuilder().build()).get().getResult();
+ final var getEntitiesResult = service.getEntities(new GetEntitiesInputBuilder().build()).get().getResult();
assertEquals(getEntitiesResult.getEntities().size(), 1);
assertTrue(getEntitiesResult.getEntities().get(new EntitiesKey(
new EntityType(ENTITY_TYPE)))
.getOwnerNode().getValue().equals("member-1"));
- final GetEntityOwnerOutput getOwnerResult = service.getEntityOwner(new GetEntityOwnerInputBuilder()
- .setName(new EntityName(CODEC_CONTEXT.fromYangInstanceIdentifier(entityId)))
- .setType(new EntityType(ENTITY_TYPE))
- .build())
- .get().getResult();
+ final var getOwnerResult = service.getEntityOwner(new GetEntityOwnerInputBuilder()
+ .setName(new EntityName(CODEC_CONTEXT.fromYangInstanceIdentifier(entityId)))
+ .setType(new EntityType(ENTITY_TYPE))
+ .build()).get().getResult();
assertEquals(getOwnerResult.getOwnerNode().getValue(), "member-1");
}
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.entity.owners.norev.EntityName;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.entity.owners.norev.EntityType;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.entity.owners.norev.GetEntitiesInputBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.entity.owners.norev.GetEntitiesOutput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.entity.owners.norev.GetEntityInputBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.entity.owners.norev.GetEntityOutput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.entity.owners.norev.GetEntityOwnerInputBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.entity.owners.norev.GetEntityOwnerOutput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.entity.owners.norev.NodeName;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.entity.owners.norev.get.entities.output.EntitiesKey;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.common.RpcResult;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
service2 = new AkkaEntityOwnershipService(system2, CODEC_CONTEXT);
// need to wait until all nodes are ready
- final Cluster cluster = Cluster.get(Adapter.toTyped(system2));
+ final var cluster = Cluster.get(Adapter.toTyped(system2));
Awaitility.await().atMost(Duration.ofSeconds(20)).until(() -> {
final List<Member> members = new ArrayList<>();
cluster.state().getMembers().forEach(members::add);
*/
@Test
public void testEntityRetrievalWithUnavailableSupervisor() throws Exception {
- final YangInstanceIdentifier entityId = YangInstanceIdentifier.create(new NodeIdentifier(NetworkTopology.QNAME),
+ final YangInstanceIdentifier entityId = YangInstanceIdentifier.of(new NodeIdentifier(NetworkTopology.QNAME),
new NodeIdentifier(Topology.QNAME),
NodeIdentifierWithPredicates.of(Topology.QNAME, QName.create(Topology.QNAME, "topology-id"), "test"),
new NodeIdentifier(Node.QNAME),
final DOMEntityOwnershipCandidateRegistration reg = service1.registerCandidate(entity);
await().untilAsserted(() -> {
- final RpcResult<GetEntityOutput> getEntityResult = service1.getEntity(new GetEntityInputBuilder()
- .setName(new EntityName(CODEC_CONTEXT.fromYangInstanceIdentifier(entityId)))
- .setType(new EntityType(ENTITY_TYPE))
- .build())
- .get();
+ final var getEntityResult = service1.getEntity(new GetEntityInputBuilder()
+ .setName(new EntityName(CODEC_CONTEXT.fromYangInstanceIdentifier(entityId)))
+ .setType(new EntityType(ENTITY_TYPE))
+ .build()).get();
assertEquals(getEntityResult.getResult().getOwnerNode().getValue(), "member-1");
assertEquals(getEntityResult.getResult().getCandidateNodes().get(0).getValue(), "member-1");
// keep this under ask timeout to make sure the singleton actor in the inactive datacenter responds with failure
// immediately, so that the rpc actor retries with distributed-data asap
await().atMost(Duration.ofSeconds(2)).untilAsserted(() -> {
- final GetEntitiesOutput getEntitiesResult =
- service2.getEntities(new GetEntitiesInputBuilder().build()).get().getResult();
+ final var getEntitiesResult = service2.getEntities(new GetEntitiesInputBuilder().build()).get().getResult();
assertEquals(getEntitiesResult.getEntities().size(), 1);
assertTrue(getEntitiesResult.getEntities().get(new EntitiesKey(
});
await().atMost(Duration.ofSeconds(2)).untilAsserted(() -> {
- final GetEntityOutput getEntityResult = service2.getEntity(new GetEntityInputBuilder()
- .setName(new EntityName(CODEC_CONTEXT.fromYangInstanceIdentifier(entityId)))
- .setType(new EntityType(ENTITY_TYPE))
- .build())
- .get().getResult();
+ final var getEntityResult = service2.getEntity(new GetEntityInputBuilder()
+ .setName(new EntityName(CODEC_CONTEXT.fromYangInstanceIdentifier(entityId)))
+ .setType(new EntityType(ENTITY_TYPE))
+ .build()).get().getResult();
assertEquals(getEntityResult.getOwnerNode().getValue(), "member-1");
assertEquals(getEntityResult.getCandidateNodes().get(0).getValue(), "member-1");
});
await().atMost(Duration.ofSeconds(2)).untilAsserted(() -> {
- final GetEntityOwnerOutput getOwnerResult = service2.getEntityOwner(new GetEntityOwnerInputBuilder()
- .setName(new EntityName(CODEC_CONTEXT.fromYangInstanceIdentifier(entityId)))
- .setType(new EntityType(ENTITY_TYPE))
- .build())
- .get().getResult();
+ final var getOwnerResult = service2.getEntityOwner(new GetEntityOwnerInputBuilder()
+ .setName(new EntityName(CODEC_CONTEXT.fromYangInstanceIdentifier(entityId)))
+ .setType(new EntityType(ENTITY_TYPE))
+ .build()).get().getResult();
assertEquals(getOwnerResult.getOwnerNode().getValue(), "member-1");
});