Search in sources :

Example 1 with GetPrefixShardRoleOutput

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.GetPrefixShardRoleOutput in project controller by opendaylight.

the class ClusterAdminRpcService method getPrefixShardRole.

@Override
public Future<RpcResult<GetPrefixShardRoleOutput>> getPrefixShardRole(final GetPrefixShardRoleInput input) {
    final InstanceIdentifier<?> identifier = input.getShardPrefix();
    if (identifier == null) {
        return newFailedRpcResultFuture("A valid shard identifier must be specified");
    }
    final DataStoreType dataStoreType = input.getDataStoreType();
    if (dataStoreType == null) {
        return newFailedRpcResultFuture("A valid DataStoreType must be specified");
    }
    LOG.info("Getting prefix shard role for shard: {}, datastore type {}", identifier, dataStoreType);
    final YangInstanceIdentifier prefix = serializer.toYangInstanceIdentifier(identifier);
    final String shardName = ClusterUtils.getCleanShardName(prefix);
    final SettableFuture<RpcResult<GetPrefixShardRoleOutput>> returnFuture = SettableFuture.create();
    ListenableFuture<GetShardRoleReply> future = sendMessageToShardManager(dataStoreType, new GetShardRole(shardName));
    Futures.addCallback(future, new FutureCallback<GetShardRoleReply>() {

        @Override
        public void onSuccess(final GetShardRoleReply reply) {
            if (reply == null) {
                returnFuture.set(ClusterAdminRpcService.<GetPrefixShardRoleOutput>newFailedRpcResultBuilder("No Shard role present. Please retry..").build());
                return;
            }
            LOG.info("Successfully received role:{} for shard {}", reply.getRole(), shardName);
            final GetPrefixShardRoleOutputBuilder builder = new GetPrefixShardRoleOutputBuilder();
            if (reply.getRole() != null) {
                builder.setRole(reply.getRole());
            }
            returnFuture.set(newSuccessfulResult(builder.build()));
        }

        @Override
        public void onFailure(final Throwable failure) {
            returnFuture.set(ClusterAdminRpcService.<GetPrefixShardRoleOutput>newFailedRpcResultBuilder("Failed to get shard role.", failure).build());
        }
    }, MoreExecutors.directExecutor());
    return returnFuture;
}
Also used : GetShardRole(org.opendaylight.controller.cluster.datastore.messages.GetShardRole) GetShardRoleReply(org.opendaylight.controller.cluster.datastore.messages.GetShardRoleReply) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) GetPrefixShardRoleOutputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.GetPrefixShardRoleOutputBuilder) DataStoreType(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.DataStoreType)

Example 2 with GetPrefixShardRoleOutput

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.GetPrefixShardRoleOutput in project controller by opendaylight.

the class ClusterAdminRpcServiceTest method testGetShardRole.

@Test
public void testGetShardRole() throws Exception {
    String name = "testGetShardRole";
    String moduleShardsConfig = "module-shards-default-member-1.conf";
    final MemberNode member1 = MemberNode.builder(memberNodes).akkaConfig("Member1").testName(name).moduleShardsConfig(moduleShardsConfig).build();
    member1.kit().waitUntilLeader(member1.configDataStore().getActorContext(), "default");
    final RpcResult<GetShardRoleOutput> successResult = getShardRole(member1, Mockito.mock(BindingNormalizedNodeSerializer.class), "default");
    verifySuccessfulRpcResult(successResult);
    assertEquals("Leader", successResult.getResult().getRole());
    final RpcResult<GetShardRoleOutput> failedResult = getShardRole(member1, Mockito.mock(BindingNormalizedNodeSerializer.class), "cars");
    verifyFailedRpcResult(failedResult);
    final ActorRef shardManager1 = member1.configDataStore().getActorContext().getShardManager();
    shardManager1.tell(new PrefixShardCreated(new PrefixShardConfiguration(new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, CarsModel.BASE_PATH), "prefix", Collections.singleton(MEMBER_1))), ActorRef.noSender());
    member1.kit().waitUntilLeader(member1.configDataStore().getActorContext(), ClusterUtils.getCleanShardName(CarsModel.BASE_PATH));
    final InstanceIdentifier<Cars> identifier = InstanceIdentifier.create(Cars.class);
    final BindingNormalizedNodeSerializer serializer = Mockito.mock(BindingNormalizedNodeSerializer.class);
    Mockito.doReturn(CarsModel.BASE_PATH).when(serializer).toYangInstanceIdentifier(identifier);
    final RpcResult<GetPrefixShardRoleOutput> prefixSuccessResult = getPrefixShardRole(member1, identifier, serializer);
    verifySuccessfulRpcResult(prefixSuccessResult);
    assertEquals("Leader", prefixSuccessResult.getResult().getRole());
    final InstanceIdentifier<People> peopleId = InstanceIdentifier.create(People.class);
    Mockito.doReturn(PeopleModel.BASE_PATH).when(serializer).toYangInstanceIdentifier(peopleId);
    final RpcResult<GetPrefixShardRoleOutput> prefixFail = getPrefixShardRole(member1, peopleId, serializer);
    verifyFailedRpcResult(prefixFail);
}
Also used : Cars(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.sal.clustering.it.car.rev140818.Cars) GetPrefixShardRoleOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.GetPrefixShardRoleOutput) MemberNode(org.opendaylight.controller.cluster.datastore.MemberNode) ActorRef(akka.actor.ActorRef) DOMDataTreeIdentifier(org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier) People(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.sal.clustering.it.people.rev140818.People) BindingNormalizedNodeSerializer(org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) PrefixShardConfiguration(org.opendaylight.controller.cluster.datastore.config.PrefixShardConfiguration) GetShardRoleOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.GetShardRoleOutput) PrefixShardCreated(org.opendaylight.controller.cluster.sharding.messages.PrefixShardCreated) Test(org.junit.Test)

Example 3 with GetPrefixShardRoleOutput

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.GetPrefixShardRoleOutput in project controller by opendaylight.

the class ClusterAdminRpcServiceTest method getPrefixShardRole.

private RpcResult<GetPrefixShardRoleOutput> getPrefixShardRole(final MemberNode memberNode, final InstanceIdentifier<?> identifier, final BindingNormalizedNodeSerializer serializer) throws Exception {
    final GetPrefixShardRoleInput input = new GetPrefixShardRoleInputBuilder().setDataStoreType(DataStoreType.Config).setShardPrefix(identifier).build();
    final ClusterAdminRpcService service = new ClusterAdminRpcService(memberNode.configDataStore(), memberNode.operDataStore(), serializer);
    return service.getPrefixShardRole(input).get(10, TimeUnit.SECONDS);
}
Also used : GetPrefixShardRoleInput(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.GetPrefixShardRoleInput) GetPrefixShardRoleInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.GetPrefixShardRoleInputBuilder)

Aggregations

ActorRef (akka.actor.ActorRef)1 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)1 Test (org.junit.Test)1 MemberNode (org.opendaylight.controller.cluster.datastore.MemberNode)1 PrefixShardConfiguration (org.opendaylight.controller.cluster.datastore.config.PrefixShardConfiguration)1 GetShardRole (org.opendaylight.controller.cluster.datastore.messages.GetShardRole)1 GetShardRoleReply (org.opendaylight.controller.cluster.datastore.messages.GetShardRoleReply)1 PrefixShardCreated (org.opendaylight.controller.cluster.sharding.messages.PrefixShardCreated)1 BindingNormalizedNodeSerializer (org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer)1 DOMDataTreeIdentifier (org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier)1 Cars (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.sal.clustering.it.car.rev140818.Cars)1 People (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.sal.clustering.it.people.rev140818.People)1 DataStoreType (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.DataStoreType)1 GetPrefixShardRoleInput (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.GetPrefixShardRoleInput)1 GetPrefixShardRoleInputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.GetPrefixShardRoleInputBuilder)1 GetPrefixShardRoleOutput (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.GetPrefixShardRoleOutput)1 GetPrefixShardRoleOutputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.GetPrefixShardRoleOutputBuilder)1 GetShardRoleOutput (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.GetShardRoleOutput)1 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)1 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)1