Search in sources :

Example 1 with Dispatchers

use of org.opendaylight.controller.cluster.common.actor.Dispatchers in project controller by opendaylight.

the class ShardManager method changeShardMembersVotingStatus.

private void changeShardMembersVotingStatus(final ChangeServersVotingStatus changeServersVotingStatus, final String shardName, final ActorRef shardActorRef, final ActorRef sender) {
    if (isShardReplicaOperationInProgress(shardName, sender)) {
        return;
    }
    shardReplicaOperationsInProgress.add(shardName);
    DatastoreContext datastoreContext = newShardDatastoreContextBuilder(shardName).build();
    final ShardIdentifier shardId = getShardIdentifier(cluster.getCurrentMemberName(), shardName);
    LOG.debug("{}: Sending ChangeServersVotingStatus message {} to local shard {}", persistenceId(), changeServersVotingStatus, shardActorRef.path());
    Timeout timeout = new Timeout(datastoreContext.getShardLeaderElectionTimeout().duration().$times(2));
    Future<Object> futureObj = ask(shardActorRef, changeServersVotingStatus, timeout);
    futureObj.onComplete(new OnComplete<Object>() {

        @Override
        public void onComplete(final Throwable failure, final Object response) {
            shardReplicaOperationsInProgress.remove(shardName);
            if (failure != null) {
                String msg = String.format("ChangeServersVotingStatus request to local shard %s failed", shardActorRef.path());
                LOG.debug("{}: {}", persistenceId(), msg, failure);
                sender.tell(new Status.Failure(new RuntimeException(msg, failure)), self());
            } else {
                LOG.debug("{}: Received {} from local shard {}", persistenceId(), response, shardActorRef.path());
                ServerChangeReply replyMsg = (ServerChangeReply) response;
                if (replyMsg.getStatus() == ServerChangeStatus.OK) {
                    LOG.debug("{}: ChangeServersVotingStatus succeeded for shard {}", persistenceId(), shardName);
                    sender.tell(new Status.Success(null), getSelf());
                } else if (replyMsg.getStatus() == ServerChangeStatus.INVALID_REQUEST) {
                    sender.tell(new Status.Failure(new IllegalArgumentException(String.format("The requested voting state change for shard %s is invalid. At least one member " + "must be voting", shardId.getShardName()))), getSelf());
                } else {
                    LOG.warn("{}: ChangeServersVotingStatus failed for shard {} with status {}", persistenceId(), shardName, replyMsg.getStatus());
                    Exception error = getServerChangeException(ChangeServersVotingStatus.class, replyMsg.getStatus(), shardActorRef.path().toString(), shardId);
                    sender.tell(new Status.Failure(error), getSelf());
                }
            }
        }
    }, new Dispatchers(context().system().dispatchers()).getDispatcher(Dispatchers.DispatcherType.Client));
}
Also used : FollowerInitialSyncUpStatus(org.opendaylight.controller.cluster.raft.base.messages.FollowerInitialSyncUpStatus) ChangeShardMembersVotingStatus(org.opendaylight.controller.cluster.datastore.messages.ChangeShardMembersVotingStatus) FlipShardMembersVotingStatus(org.opendaylight.controller.cluster.datastore.messages.FlipShardMembersVotingStatus) Status(akka.actor.Status) ServerChangeStatus(org.opendaylight.controller.cluster.raft.messages.ServerChangeStatus) ChangeServersVotingStatus(org.opendaylight.controller.cluster.raft.messages.ChangeServersVotingStatus) Timeout(akka.util.Timeout) ShardIdentifier(org.opendaylight.controller.cluster.datastore.identifiers.ShardIdentifier) SaveSnapshotSuccess(akka.persistence.SaveSnapshotSuccess) DeleteSnapshotsSuccess(akka.persistence.DeleteSnapshotsSuccess) AlreadyExistsException(org.opendaylight.controller.cluster.datastore.exceptions.AlreadyExistsException) PrimaryNotFoundException(org.opendaylight.controller.cluster.datastore.exceptions.PrimaryNotFoundException) NotInitializedException(org.opendaylight.controller.cluster.datastore.exceptions.NotInitializedException) TimeoutException(java.util.concurrent.TimeoutException) NoShardLeaderException(org.opendaylight.controller.cluster.datastore.exceptions.NoShardLeaderException) DatastoreContext(org.opendaylight.controller.cluster.datastore.DatastoreContext) ServerChangeReply(org.opendaylight.controller.cluster.raft.messages.ServerChangeReply) SaveSnapshotFailure(akka.persistence.SaveSnapshotFailure) DeleteSnapshotsFailure(akka.persistence.DeleteSnapshotsFailure) Dispatchers(org.opendaylight.controller.cluster.common.actor.Dispatchers)

Example 2 with Dispatchers

use of org.opendaylight.controller.cluster.common.actor.Dispatchers in project controller by opendaylight.

the class ShardManager method removePrefixShardReplica.

private void removePrefixShardReplica(final RemovePrefixShardReplica contextMessage, final String shardName, final String primaryPath, final ActorRef sender) {
    if (isShardReplicaOperationInProgress(shardName, sender)) {
        return;
    }
    shardReplicaOperationsInProgress.add(shardName);
    final ShardIdentifier shardId = getShardIdentifier(contextMessage.getMemberName(), shardName);
    final DatastoreContext datastoreContext = newShardDatastoreContextBuilder(shardName).build();
    // inform ShardLeader to remove this shard as a replica by sending an RemoveServer message
    LOG.debug("{}: Sending RemoveServer message to peer {} for shard {}", persistenceId(), primaryPath, shardId);
    Timeout removeServerTimeout = new Timeout(datastoreContext.getShardLeaderElectionTimeout().duration());
    Future<Object> futureObj = ask(getContext().actorSelection(primaryPath), new RemoveServer(shardId.toString()), removeServerTimeout);
    futureObj.onComplete(new OnComplete<Object>() {

        @Override
        public void onComplete(final Throwable failure, final Object response) {
            if (failure != null) {
                shardReplicaOperationsInProgress.remove(shardName);
                String msg = String.format("RemoveServer request to leader %s for shard %s failed", primaryPath, shardName);
                LOG.debug("{}: {}", persistenceId(), msg, failure);
                // FAILURE
                sender.tell(new Status.Failure(new RuntimeException(msg, failure)), self());
            } else {
                // SUCCESS
                self().tell(new WrappedShardResponse(shardId, response, primaryPath), sender);
            }
        }
    }, new Dispatchers(context().system().dispatchers()).getDispatcher(Dispatchers.DispatcherType.Client));
}
Also used : Timeout(akka.util.Timeout) ShardIdentifier(org.opendaylight.controller.cluster.datastore.identifiers.ShardIdentifier) DatastoreContext(org.opendaylight.controller.cluster.datastore.DatastoreContext) RemoveServer(org.opendaylight.controller.cluster.raft.messages.RemoveServer) SaveSnapshotFailure(akka.persistence.SaveSnapshotFailure) DeleteSnapshotsFailure(akka.persistence.DeleteSnapshotsFailure) Dispatchers(org.opendaylight.controller.cluster.common.actor.Dispatchers)

Example 3 with Dispatchers

use of org.opendaylight.controller.cluster.common.actor.Dispatchers in project controller by opendaylight.

the class ShardManager method onFlipShardMembersVotingStatus.

private void onFlipShardMembersVotingStatus(final FlipShardMembersVotingStatus flipMembersVotingStatus) {
    LOG.debug("{}: onFlipShardMembersVotingStatus: {}", persistenceId(), flipMembersVotingStatus);
    ActorRef sender = getSender();
    final String shardName = flipMembersVotingStatus.getShardName();
    findLocalShard(shardName, sender, localShardFound -> {
        Future<Object> future = ask(localShardFound.getPath(), GetOnDemandRaftState.INSTANCE, Timeout.apply(30, TimeUnit.SECONDS));
        future.onComplete(new OnComplete<Object>() {

            @Override
            public void onComplete(final Throwable failure, final Object response) {
                if (failure != null) {
                    sender.tell(new Status.Failure(new RuntimeException(String.format("Failed to access local shard %s", shardName), failure)), self());
                    return;
                }
                OnDemandRaftState raftState = (OnDemandRaftState) response;
                Map<String, Boolean> serverVotingStatusMap = new HashMap<>();
                for (Entry<String, Boolean> e : raftState.getPeerVotingStates().entrySet()) {
                    serverVotingStatusMap.put(e.getKey(), !e.getValue());
                }
                serverVotingStatusMap.put(getShardIdentifier(cluster.getCurrentMemberName(), shardName).toString(), !raftState.isVoting());
                changeShardMembersVotingStatus(new ChangeServersVotingStatus(serverVotingStatusMap), shardName, localShardFound.getPath(), sender);
            }
        }, new Dispatchers(context().system().dispatchers()).getDispatcher(Dispatchers.DispatcherType.Client));
    });
}
Also used : ActorRef(akka.actor.ActorRef) GetOnDemandRaftState(org.opendaylight.controller.cluster.raft.client.messages.GetOnDemandRaftState) OnDemandRaftState(org.opendaylight.controller.cluster.raft.client.messages.OnDemandRaftState) Entry(java.util.Map.Entry) ChangeServersVotingStatus(org.opendaylight.controller.cluster.raft.messages.ChangeServersVotingStatus) Map(java.util.Map) HashMap(java.util.HashMap) SaveSnapshotFailure(akka.persistence.SaveSnapshotFailure) DeleteSnapshotsFailure(akka.persistence.DeleteSnapshotsFailure) Dispatchers(org.opendaylight.controller.cluster.common.actor.Dispatchers)

Example 4 with Dispatchers

use of org.opendaylight.controller.cluster.common.actor.Dispatchers in project controller by opendaylight.

the class ShardManager method execAddShard.

private void execAddShard(final String shardName, final ShardInformation shardInfo, final RemotePrimaryShardFound response, final boolean removeShardOnFailure, final ActorRef sender) {
    final String localShardAddress = peerAddressResolver.getShardActorAddress(shardName, cluster.getCurrentMemberName());
    // inform ShardLeader to add this shard as a replica by sending an AddServer message
    LOG.debug("{}: Sending AddServer message to peer {} for shard {}", persistenceId(), response.getPrimaryPath(), shardInfo.getShardId());
    final Timeout addServerTimeout = new Timeout(shardInfo.getDatastoreContext().getShardLeaderElectionTimeout().duration());
    final Future<Object> futureObj = ask(getContext().actorSelection(response.getPrimaryPath()), new AddServer(shardInfo.getShardId().toString(), localShardAddress, true), addServerTimeout);
    futureObj.onComplete(new OnComplete<Object>() {

        @Override
        public void onComplete(final Throwable failure, final Object addServerResponse) {
            if (failure != null) {
                LOG.debug("{}: AddServer request to {} for {} failed", persistenceId(), response.getPrimaryPath(), shardName, failure);
                final String msg = String.format("AddServer request to leader %s for shard %s failed", response.getPrimaryPath(), shardName);
                self().tell(new ForwardedAddServerFailure(shardName, msg, failure, removeShardOnFailure), sender);
            } else {
                self().tell(new ForwardedAddServerReply(shardInfo, (AddServerReply) addServerResponse, response.getPrimaryPath(), removeShardOnFailure), sender);
            }
        }
    }, new Dispatchers(context().system().dispatchers()).getDispatcher(Dispatchers.DispatcherType.Client));
}
Also used : Timeout(akka.util.Timeout) Dispatchers(org.opendaylight.controller.cluster.common.actor.Dispatchers) AddServer(org.opendaylight.controller.cluster.raft.messages.AddServer)

Example 5 with Dispatchers

use of org.opendaylight.controller.cluster.common.actor.Dispatchers in project controller by opendaylight.

the class ShardManager method findLocalShard.

private void findLocalShard(final String shardName, final ActorRef sender, final Consumer<LocalShardFound> onLocalShardFound) {
    Timeout findLocalTimeout = new Timeout(datastoreContextFactory.getBaseDatastoreContext().getShardInitializationTimeout().duration().$times(2));
    Future<Object> futureObj = ask(getSelf(), new FindLocalShard(shardName, true), findLocalTimeout);
    futureObj.onComplete(new OnComplete<Object>() {

        @Override
        public void onComplete(final Throwable failure, final Object response) {
            if (failure != null) {
                LOG.debug("{}: Received failure from FindLocalShard for shard {}", persistenceId, shardName, failure);
                sender.tell(new Status.Failure(new RuntimeException(String.format("Failed to find local shard %s", shardName), failure)), self());
            } else {
                if (response instanceof LocalShardFound) {
                    getSelf().tell((RunnableMessage) () -> onLocalShardFound.accept((LocalShardFound) response), sender);
                } else if (response instanceof LocalShardNotFound) {
                    String msg = String.format("Local shard %s does not exist", shardName);
                    LOG.debug("{}: {}", persistenceId, msg);
                    sender.tell(new Status.Failure(new IllegalArgumentException(msg)), self());
                } else {
                    String msg = String.format("Failed to find local shard %s: received response: %s", shardName, response);
                    LOG.debug("{}: {}", persistenceId, msg);
                    sender.tell(new Status.Failure(response instanceof Throwable ? (Throwable) response : new RuntimeException(msg)), self());
                }
            }
        }
    }, new Dispatchers(context().system().dispatchers()).getDispatcher(Dispatchers.DispatcherType.Client));
}
Also used : FollowerInitialSyncUpStatus(org.opendaylight.controller.cluster.raft.base.messages.FollowerInitialSyncUpStatus) ChangeShardMembersVotingStatus(org.opendaylight.controller.cluster.datastore.messages.ChangeShardMembersVotingStatus) FlipShardMembersVotingStatus(org.opendaylight.controller.cluster.datastore.messages.FlipShardMembersVotingStatus) Status(akka.actor.Status) ServerChangeStatus(org.opendaylight.controller.cluster.raft.messages.ServerChangeStatus) ChangeServersVotingStatus(org.opendaylight.controller.cluster.raft.messages.ChangeServersVotingStatus) LocalShardFound(org.opendaylight.controller.cluster.datastore.messages.LocalShardFound) LocalShardNotFound(org.opendaylight.controller.cluster.datastore.messages.LocalShardNotFound) Timeout(akka.util.Timeout) FindLocalShard(org.opendaylight.controller.cluster.datastore.messages.FindLocalShard) SaveSnapshotFailure(akka.persistence.SaveSnapshotFailure) DeleteSnapshotsFailure(akka.persistence.DeleteSnapshotsFailure) Dispatchers(org.opendaylight.controller.cluster.common.actor.Dispatchers)

Aggregations

Dispatchers (org.opendaylight.controller.cluster.common.actor.Dispatchers)16 Timeout (akka.util.Timeout)8 Test (org.junit.Test)6 DeleteSnapshotsFailure (akka.persistence.DeleteSnapshotsFailure)5 SaveSnapshotFailure (akka.persistence.SaveSnapshotFailure)5 ActorRef (akka.actor.ActorRef)4 DatastoreContext (org.opendaylight.controller.cluster.datastore.DatastoreContext)3 NotInitializedException (org.opendaylight.controller.cluster.datastore.exceptions.NotInitializedException)3 ShardIdentifier (org.opendaylight.controller.cluster.datastore.identifiers.ShardIdentifier)3 FindLocalShard (org.opendaylight.controller.cluster.datastore.messages.FindLocalShard)3 LocalShardFound (org.opendaylight.controller.cluster.datastore.messages.LocalShardFound)3 LocalShardNotFound (org.opendaylight.controller.cluster.datastore.messages.LocalShardNotFound)3 ChangeServersVotingStatus (org.opendaylight.controller.cluster.raft.messages.ChangeServersVotingStatus)3 ActorSystem (akka.actor.ActorSystem)2 Props (akka.actor.Props)2 Status (akka.actor.Status)2 Terminated (akka.actor.Terminated)2 ExecutionContexts (akka.dispatch.ExecutionContexts)2 Futures (akka.dispatch.Futures)2 MessageDispatcher (akka.dispatch.MessageDispatcher)2