Search in sources :

Example 1 with Success

use of akka.actor.Status.Success in project controller by opendaylight.

the class ShardedDataTreeActor method onProducerCreated.

private void onProducerCreated(final ProducerCreated message) {
    LOG.debug("Received ProducerCreated: {}", message);
    // fastpath if we have no peers
    if (resolver.getShardingServicePeerActorAddresses().isEmpty()) {
        getSender().tell(new Status.Success(null), noSender());
    }
    final ActorRef sender = getSender();
    final Collection<DOMDataTreeIdentifier> subtrees = message.getSubtrees();
    final List<CompletableFuture<Object>> futures = new ArrayList<>();
    for (final String address : resolver.getShardingServicePeerActorAddresses()) {
        final ActorSelection actorSelection = actorSystem.actorSelection(address);
        futures.add(FutureConverters.toJava(actorContext.executeOperationAsync(actorSelection, new NotifyProducerCreated(subtrees), DEFAULT_ASK_TIMEOUT)).toCompletableFuture());
    }
    final CompletableFuture<Void> combinedFuture = CompletableFuture.allOf(futures.toArray(new CompletableFuture[futures.size()]));
    combinedFuture.thenRun(() -> sender.tell(new Success(null), noSender())).exceptionally(throwable -> {
        sender.tell(new Status.Failure(throwable), self());
        return null;
    });
}
Also used : Status(akka.actor.Status) ActorRef(akka.actor.ActorRef) DOMDataTreeIdentifier(org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier) ArrayList(java.util.ArrayList) Success(akka.actor.Status.Success) Success(akka.actor.Status.Success) CompletableFuture(java.util.concurrent.CompletableFuture) ActorSelection(akka.actor.ActorSelection) NotifyProducerCreated(org.opendaylight.controller.cluster.sharding.messages.NotifyProducerCreated)

Example 2 with Success

use of akka.actor.Status.Success in project controller by opendaylight.

the class ClusterAdminRpcService method removeShardReplica.

@Override
public Future<RpcResult<Void>> removeShardReplica(RemoveShardReplicaInput 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");
    }
    final String memberName = input.getMemberName();
    if (Strings.isNullOrEmpty(memberName)) {
        return newFailedRpcResultFuture("A valid member name must be specified");
    }
    LOG.info("Removing replica for shard {} memberName {}, datastoreType {}", shardName, memberName, dataStoreType);
    final SettableFuture<RpcResult<Void>> returnFuture = SettableFuture.create();
    ListenableFuture<Success> future = sendMessageToShardManager(dataStoreType, new RemoveShardReplica(shardName, MemberName.forName(memberName)));
    Futures.addCallback(future, new FutureCallback<Success>() {

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

        @Override
        public void onFailure(Throwable failure) {
            onMessageFailure(String.format("Failed to remove replica for shard %s", shardName), returnFuture, failure);
        }
    }, MoreExecutors.directExecutor());
    return returnFuture;
}
Also used : RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) RemoveShardReplica(org.opendaylight.controller.cluster.datastore.messages.RemoveShardReplica) 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 3 with Success

use of akka.actor.Status.Success in project controller by opendaylight.

the class ClusterAdminRpcService method addReplicasForAllShards.

@Override
public Future<RpcResult<AddReplicasForAllShardsOutput>> addReplicasForAllShards() {
    LOG.info("Adding replicas for all shards");
    final List<Entry<ListenableFuture<Success>, ShardResultBuilder>> shardResultData = new ArrayList<>();
    Function<String, Object> messageSupplier = AddShardReplica::new;
    sendMessageToManagerForConfiguredShards(DataStoreType.Config, shardResultData, messageSupplier);
    sendMessageToManagerForConfiguredShards(DataStoreType.Operational, shardResultData, messageSupplier);
    return waitForShardResults(shardResultData, shardResults -> new AddReplicasForAllShardsOutputBuilder().setShardResult(shardResults).build(), "Failed to add replica");
}
Also used : Entry(java.util.Map.Entry) SimpleEntry(java.util.AbstractMap.SimpleEntry) ArrayList(java.util.ArrayList) AddReplicasForAllShardsOutputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.AddReplicasForAllShardsOutputBuilder) Success(akka.actor.Status.Success)

Example 4 with Success

use of akka.actor.Status.Success in project controller by opendaylight.

the class ClusterAdminRpcService method removeAllShardReplicas.

@Override
public Future<RpcResult<RemoveAllShardReplicasOutput>> removeAllShardReplicas(RemoveAllShardReplicasInput input) {
    LOG.info("Removing replicas for all shards");
    final String memberName = input.getMemberName();
    if (Strings.isNullOrEmpty(memberName)) {
        return newFailedRpcResultFuture("A valid member name must be specified");
    }
    final List<Entry<ListenableFuture<Success>, ShardResultBuilder>> shardResultData = new ArrayList<>();
    Function<String, Object> messageSupplier = shardName -> new RemoveShardReplica(shardName, MemberName.forName(memberName));
    sendMessageToManagerForConfiguredShards(DataStoreType.Config, shardResultData, messageSupplier);
    sendMessageToManagerForConfiguredShards(DataStoreType.Operational, shardResultData, messageSupplier);
    return waitForShardResults(shardResultData, shardResults -> new RemoveAllShardReplicasOutputBuilder().setShardResult(shardResults).build(), "       Failed to remove replica");
}
Also used : AddShardReplicaInput(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.AddShardReplicaInput) AddReplicasForAllShardsOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.AddReplicasForAllShardsOutput) LoggerFactory(org.slf4j.LoggerFactory) SettableFuture(com.google.common.util.concurrent.SettableFuture) ChangeShardMembersVotingStatus(org.opendaylight.controller.cluster.datastore.messages.ChangeShardMembersVotingStatus) GetPrefixShardRoleInput(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.GetPrefixShardRoleInput) Future(java.util.concurrent.Future) GetShardRoleReply(org.opendaylight.controller.cluster.datastore.messages.GetShardRoleReply) AddReplicasForAllShardsOutputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.AddReplicasForAllShardsOutputBuilder) GetShardRoleOutputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.GetShardRoleOutputBuilder) RemoveAllShardReplicasInput(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.RemoveAllShardReplicasInput) ActorRef(akka.actor.ActorRef) Map(java.util.Map) DatastoreSnapshot(org.opendaylight.controller.cluster.datastore.persisted.DatastoreSnapshot) Patterns(akka.pattern.Patterns) AddShardReplica(org.opendaylight.controller.cluster.datastore.messages.AddShardReplica) FlipMemberVotingStatesForAllShardsOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.FlipMemberVotingStatesForAllShardsOutput) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) BindingNormalizedNodeSerializer(org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer) DatastoreSnapshotList(org.opendaylight.controller.cluster.datastore.persisted.DatastoreSnapshotList) GetPrefixShardRoleOutputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.GetPrefixShardRoleOutputBuilder) Function(com.google.common.base.Function) GetShardRole(org.opendaylight.controller.cluster.datastore.messages.GetShardRole) Set(java.util.Set) ErrorType(org.opendaylight.yangtools.yang.common.RpcError.ErrorType) GetPrefixShardRoleOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.GetPrefixShardRoleOutput) List(java.util.List) DataStoreType(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.DataStoreType) GetShardRoleOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.GetShardRoleOutput) RemoveAllShardReplicasOutputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.RemoveAllShardReplicasOutputBuilder) Entry(java.util.Map.Entry) MemberVotingState(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.member.voting.states.input.MemberVotingState) MakeLeaderLocalInput(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.MakeLeaderLocalInput) RemovePrefixShardReplica(org.opendaylight.controller.cluster.datastore.messages.RemovePrefixShardReplica) MoreExecutors(com.google.common.util.concurrent.MoreExecutors) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) RemovePrefixShardReplicaInput(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.RemovePrefixShardReplicaInput) HashMap(java.util.HashMap) SerializationUtils(org.apache.commons.lang3.SerializationUtils) Timeout(akka.util.Timeout) ArrayList(java.util.ArrayList) Strings(com.google.common.base.Strings) FlipShardMembersVotingStatus(org.opendaylight.controller.cluster.datastore.messages.FlipShardMembersVotingStatus) ClusterUtils(org.opendaylight.controller.cluster.datastore.utils.ClusterUtils) DistributedDataStoreInterface(org.opendaylight.controller.cluster.datastore.DistributedDataStoreInterface) Success(akka.actor.Status.Success) ChangeMemberVotingStatesForAllShardsInput(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.ChangeMemberVotingStatesForAllShardsInput) BackupDatastoreInput(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.BackupDatastoreInput) ActorContext(org.opendaylight.controller.cluster.datastore.utils.ActorContext) OnComplete(akka.dispatch.OnComplete) GetShardRoleInput(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.GetShardRoleInput) RemoveShardReplica(org.opendaylight.controller.cluster.datastore.messages.RemoveShardReplica) SimpleEntry(java.util.AbstractMap.SimpleEntry) MakeLeaderLocal(org.opendaylight.controller.cluster.datastore.messages.MakeLeaderLocal) AddPrefixShardReplica(org.opendaylight.controller.cluster.datastore.messages.AddPrefixShardReplica) ChangeMemberVotingStatesForAllShardsOutputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.ChangeMemberVotingStatesForAllShardsOutputBuilder) AddPrefixShardReplicaInput(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.AddPrefixShardReplicaInput) ChangeMemberVotingStatesForAllShardsOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.ChangeMemberVotingStatesForAllShardsOutput) FlipMemberVotingStatesForAllShardsOutputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.FlipMemberVotingStatesForAllShardsOutputBuilder) Logger(org.slf4j.Logger) Throwables(com.google.common.base.Throwables) FileOutputStream(java.io.FileOutputStream) RemoveShardReplicaInput(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.RemoveShardReplicaInput) IOException(java.io.IOException) RemoveAllShardReplicasOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.RemoveAllShardReplicasOutput) FutureCallback(com.google.common.util.concurrent.FutureCallback) ShardResultBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.shard.result.output.ShardResultBuilder) TimeUnit(java.util.concurrent.TimeUnit) Futures(com.google.common.util.concurrent.Futures) ShardResult(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.shard.result.output.ShardResult) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) RpcResultBuilder(org.opendaylight.yangtools.yang.common.RpcResultBuilder) ClusterAdminService(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.ClusterAdminService) GetSnapshot(org.opendaylight.controller.cluster.raft.client.messages.GetSnapshot) ChangeMemberVotingStatesForShardInput(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.ChangeMemberVotingStatesForShardInput) MemberName(org.opendaylight.controller.cluster.access.concepts.MemberName) Entry(java.util.Map.Entry) SimpleEntry(java.util.AbstractMap.SimpleEntry) RemoveAllShardReplicasOutputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.RemoveAllShardReplicasOutputBuilder) ArrayList(java.util.ArrayList) RemoveShardReplica(org.opendaylight.controller.cluster.datastore.messages.RemoveShardReplica) Success(akka.actor.Status.Success)

Example 5 with Success

use of akka.actor.Status.Success 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)

Aggregations

Success (akka.actor.Status.Success)11 DataStoreType (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.DataStoreType)7 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)7 ArrayList (java.util.ArrayList)5 ActorRef (akka.actor.ActorRef)4 SimpleEntry (java.util.AbstractMap.SimpleEntry)4 Entry (java.util.Map.Entry)4 AddPrefixShardReplica (org.opendaylight.controller.cluster.datastore.messages.AddPrefixShardReplica)3 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)3 OnComplete (akka.dispatch.OnComplete)2 Patterns (akka.pattern.Patterns)2 Timeout (akka.util.Timeout)2 Function (com.google.common.base.Function)2 Strings (com.google.common.base.Strings)2 Throwables (com.google.common.base.Throwables)2 FutureCallback (com.google.common.util.concurrent.FutureCallback)2 Futures (com.google.common.util.concurrent.Futures)2 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)2 MoreExecutors (com.google.common.util.concurrent.MoreExecutors)2 SettableFuture (com.google.common.util.concurrent.SettableFuture)2