Search in sources :

Example 1 with MakeLeaderLocalInput

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

the class ClusterAdminRpcService method makeLeaderLocal.

@Override
public Future<RpcResult<Void>> makeLeaderLocal(final MakeLeaderLocalInput 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");
    }
    ActorContext actorContext = dataStoreType == DataStoreType.Config ? configDataStore.getActorContext() : operDataStore.getActorContext();
    LOG.info("Moving leader to local node {} for shard {}, datastoreType {}", actorContext.getCurrentMemberName().getName(), shardName, dataStoreType);
    final scala.concurrent.Future<ActorRef> localShardReply = actorContext.findLocalShardAsync(shardName);
    final scala.concurrent.Promise<Object> makeLeaderLocalAsk = akka.dispatch.Futures.promise();
    localShardReply.onComplete(new OnComplete<ActorRef>() {

        @Override
        public void onComplete(final Throwable failure, final ActorRef actorRef) throws Throwable {
            if (failure != null) {
                LOG.warn("No local shard found for {} datastoreType {} - Cannot request leadership transfer to" + " local shard.", shardName, failure);
                makeLeaderLocalAsk.failure(failure);
            } else {
                makeLeaderLocalAsk.completeWith(actorContext.executeOperationAsync(actorRef, MakeLeaderLocal.INSTANCE, makeLeaderLocalTimeout));
            }
        }
    }, actorContext.getClientDispatcher());
    final SettableFuture<RpcResult<Void>> future = SettableFuture.create();
    makeLeaderLocalAsk.future().onComplete(new OnComplete<Object>() {

        @Override
        public void onComplete(final Throwable failure, final Object success) throws Throwable {
            if (failure != null) {
                LOG.error("Leadership transfer failed for shard {}.", shardName, failure);
                future.set(RpcResultBuilder.<Void>failed().withError(ErrorType.APPLICATION, "leadership transfer failed", failure).build());
                return;
            }
            LOG.debug("Leadership transfer complete");
            future.set(RpcResultBuilder.<Void>success().build());
        }
    }, actorContext.getClientDispatcher());
    return future;
}
Also used : ActorRef(akka.actor.ActorRef) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) DataStoreType(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.DataStoreType) ActorContext(org.opendaylight.controller.cluster.datastore.utils.ActorContext)

Aggregations

ActorRef (akka.actor.ActorRef)1 ActorContext (org.opendaylight.controller.cluster.datastore.utils.ActorContext)1 DataStoreType (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.DataStoreType)1 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)1