Search in sources :

Example 1 with GetShardRoleOutputBuilder

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

the class ClusterAdminRpcService method getShardRole.

@Override
public Future<RpcResult<GetShardRoleOutput>> getShardRole(final GetShardRoleInput input) {
    final String shardName = input.getShardName();
    if (Strings.isNullOrEmpty(shardName)) {
        return newFailedRpcResultFuture("A valid shard name must be specified");
    }
    DataStoreType dataStoreType = input.getDataStoreType();
    if (dataStoreType == null) {
        return newFailedRpcResultFuture("A valid DataStoreType must be specified");
    }
    LOG.info("Getting role for shard {}, datastore type {}", shardName, dataStoreType);
    final SettableFuture<RpcResult<GetShardRoleOutput>> 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.<GetShardRoleOutput>newFailedRpcResultBuilder("No Shard role present. Please retry..").build());
                return;
            }
            LOG.info("Successfully received role:{} for shard {}", reply.getRole(), shardName);
            final GetShardRoleOutputBuilder builder = new GetShardRoleOutputBuilder();
            if (reply.getRole() != null) {
                builder.setRole(reply.getRole());
            }
            returnFuture.set(newSuccessfulResult(builder.build()));
        }

        @Override
        public void onFailure(final Throwable failure) {
            returnFuture.set(ClusterAdminRpcService.<GetShardRoleOutput>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) GetShardRoleOutputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.GetShardRoleOutputBuilder) DataStoreType(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.DataStoreType)

Aggregations

GetShardRole (org.opendaylight.controller.cluster.datastore.messages.GetShardRole)1 GetShardRoleReply (org.opendaylight.controller.cluster.datastore.messages.GetShardRoleReply)1 DataStoreType (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.DataStoreType)1 GetShardRoleOutputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.GetShardRoleOutputBuilder)1 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)1