Search in sources :

Example 6 with DataStoreType

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.DataStoreType 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)

Example 7 with DataStoreType

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.DataStoreType 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)

Example 8 with DataStoreType

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

the class ClusterAdminRpcService method addShardReplica.

@Override
public Future<RpcResult<Void>> addShardReplica(final AddShardReplicaInput 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("Adding replica for shard {}", shardName);
    final SettableFuture<RpcResult<Void>> returnFuture = SettableFuture.create();
    ListenableFuture<Success> future = sendMessageToShardManager(dataStoreType, new AddShardReplica(shardName));
    Futures.addCallback(future, new FutureCallback<Success>() {

        @Override
        public void onSuccess(Success success) {
            LOG.info("Successfully added replica for shard {}", shardName);
            returnFuture.set(newSuccessfulResult());
        }

        @Override
        public void onFailure(Throwable failure) {
            onMessageFailure(String.format("Failed to add replica for shard %s", shardName), returnFuture, failure);
        }
    }, MoreExecutors.directExecutor());
    return returnFuture;
}
Also used : RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) AddShardReplica(org.opendaylight.controller.cluster.datastore.messages.AddShardReplica) Success(akka.actor.Status.Success) DataStoreType(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.DataStoreType)

Example 9 with DataStoreType

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

the class ClusterAdminRpcService method changeMemberVotingStatesForShard.

@Override
public Future<RpcResult<Void>> changeMemberVotingStatesForShard(ChangeMemberVotingStatesForShardInput 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");
    }
    List<MemberVotingState> memberVotingStates = input.getMemberVotingState();
    if (memberVotingStates == null || memberVotingStates.isEmpty()) {
        return newFailedRpcResultFuture("No member voting state input was specified");
    }
    ChangeShardMembersVotingStatus changeVotingStatus = toChangeShardMembersVotingStatus(shardName, memberVotingStates);
    LOG.info("Change member voting states for shard {}: {}", shardName, changeVotingStatus.getMeberVotingStatusMap());
    final SettableFuture<RpcResult<Void>> returnFuture = SettableFuture.create();
    ListenableFuture<Success> future = sendMessageToShardManager(dataStoreType, changeVotingStatus);
    Futures.addCallback(future, new FutureCallback<Success>() {

        @Override
        public void onSuccess(Success success) {
            LOG.info("Successfully changed member voting states for shard {}", shardName);
            returnFuture.set(newSuccessfulResult());
        }

        @Override
        public void onFailure(Throwable failure) {
            onMessageFailure(String.format("Failed to change member voting states for shard %s", shardName), returnFuture, failure);
        }
    }, MoreExecutors.directExecutor());
    return returnFuture;
}
Also used : ChangeShardMembersVotingStatus(org.opendaylight.controller.cluster.datastore.messages.ChangeShardMembersVotingStatus) MemberVotingState(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.member.voting.states.input.MemberVotingState) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) Success(akka.actor.Status.Success) DataStoreType(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.DataStoreType)

Example 10 with DataStoreType

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.DataStoreType 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)

Aggregations

RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)9 DataStoreType (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.DataStoreType)8 Success (akka.actor.Status.Success)5 Optional (com.google.common.base.Optional)3 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)3 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Objects (java.util.Objects)2 GetShardRole (org.opendaylight.controller.cluster.datastore.messages.GetShardRole)2 GetShardRoleReply (org.opendaylight.controller.cluster.datastore.messages.GetShardRoleReply)2 ActorContext (org.opendaylight.controller.cluster.datastore.utils.ActorContext)2 MergeCommand (org.opendaylight.netvirt.elan.l2gw.ha.commands.MergeCommand)2 HwvtepPhysicalLocatorAugmentation (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepPhysicalLocatorAugmentation)2 Node (org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node)2 DataObject (org.opendaylight.yangtools.yang.binding.DataObject)2 InstanceIdentifier (org.opendaylight.yangtools.yang.binding.InstanceIdentifier)2 ActorRef (akka.actor.ActorRef)1 Lists (com.google.common.collect.Lists)1