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));
}
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));
}
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));
});
}
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));
}
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));
}
Aggregations