use of akka.actor.Status.Failure in project controller by opendaylight.
the class ShardManagerTest method testAddShardReplicaWithPreExistingLocalReplicaLeader.
@Test
public void testAddShardReplicaWithPreExistingLocalReplicaLeader() throws Exception {
LOG.info("testAddShardReplicaWithPreExistingLocalReplicaLeader starting");
new TestKit(getSystem()) {
{
String memberId = "member-1-shard-default-" + shardMrgIDSuffix;
ActorRef shardManager = actorFactory.createActor(newPropsShardMgrWithMockShardActor());
shardManager.tell(new UpdateSchemaContext(TestModel.createTestContext()), getRef());
shardManager.tell(new ActorInitialized(), mockShardActor);
shardManager.tell(new ShardLeaderStateChanged(memberId, memberId, mock(DataTree.class), DataStoreVersions.CURRENT_VERSION), getRef());
shardManager.tell(new RoleChangeNotification(memberId, RaftState.Candidate.name(), RaftState.Leader.name()), mockShardActor);
shardManager.tell(new AddShardReplica(Shard.DEFAULT_NAME), getRef());
Failure resp = expectMsgClass(duration("5 seconds"), Failure.class);
assertEquals("Failure cause", AlreadyExistsException.class, resp.cause().getClass());
shardManager.tell(new FindLocalShard(Shard.DEFAULT_NAME, false), getRef());
expectMsgClass(duration("5 seconds"), LocalShardFound.class);
}
};
LOG.info("testAddShardReplicaWithPreExistingLocalReplicaLeader ending");
}
use of akka.actor.Status.Failure in project controller by opendaylight.
the class Shard method handleConnectClient.
@SuppressWarnings("checkstyle:IllegalCatch")
private void handleConnectClient(final ConnectClientRequest message) {
try {
final ClientIdentifier clientId = message.getTarget();
final LeaderFrontendState existing = findFrontend(clientId);
if (existing != null) {
existing.touch();
}
if (!isLeader() || !isLeaderActive()) {
LOG.info("{}: not currently leader, rejecting request {}. isLeader: {}, isLeaderActive: {}," + "isLeadershipTransferInProgress: {}.", persistenceId(), message, isLeader(), isLeaderActive(), isLeadershipTransferInProgress());
throw new NotLeaderException(getSelf());
}
final ABIVersion selectedVersion = selectVersion(message);
final LeaderFrontendState frontend;
if (existing == null) {
frontend = new LeaderFrontendState(persistenceId(), clientId, store);
knownFrontends.put(clientId.getFrontendId(), frontend);
LOG.debug("{}: created state {} for client {}", persistenceId(), frontend, clientId);
} else {
frontend = existing;
}
frontend.reconnect();
message.getReplyTo().tell(new ConnectClientSuccess(message.getTarget(), message.getSequence(), getSelf(), ImmutableList.of(), store.getDataTree(), CLIENT_MAX_MESSAGES).toVersion(selectedVersion), ActorRef.noSender());
} catch (RequestException | RuntimeException e) {
message.getReplyTo().tell(new Failure(e), ActorRef.noSender());
}
}
use of akka.actor.Status.Failure in project controller by opendaylight.
the class Shard method handleReadyLocalTransaction.
@SuppressWarnings("checkstyle:IllegalCatch")
private void handleReadyLocalTransaction(final ReadyLocalTransaction message) {
LOG.debug("{}: handleReadyLocalTransaction for {}", persistenceId(), message.getTransactionId());
boolean isLeaderActive = isLeaderActive();
if (isLeader() && isLeaderActive) {
try {
commitCoordinator.handleReadyLocalTransaction(message, getSender(), this);
} catch (Exception e) {
LOG.error("{}: Error handling ReadyLocalTransaction for Tx {}", persistenceId(), message.getTransactionId(), e);
getSender().tell(new Failure(e), getSelf());
}
} else {
ActorSelection leader = getLeader();
if (!isLeaderActive || leader == null) {
messageRetrySupport.addMessageToRetry(message, getSender(), "Could not process ready local transaction " + message.getTransactionId());
} else {
LOG.debug("{}: Forwarding ReadyLocalTransaction to leader {}", persistenceId(), leader);
message.setRemoteVersion(getCurrentBehavior().getLeaderPayloadVersion());
leader.forward(message, getContext());
}
}
}
use of akka.actor.Status.Failure in project controller by opendaylight.
the class ShardCommitCoordinator method handleCanCommit.
/**
* This method handles the canCommit phase for a transaction.
*
* @param transactionID the ID of the transaction to canCommit
* @param sender the actor to which to send the response
* @param shard the transaction's shard actor
*/
void handleCanCommit(final Identifier transactionID, final ActorRef sender, final Shard shard) {
// Lookup the cohort entry that was cached previously (or should have been) by
// transactionReady (via the ForwardedReadyTransaction message).
final CohortEntry cohortEntry = cohortCache.get(transactionID);
if (cohortEntry == null) {
// Either canCommit was invoked before ready (shouldn't happen) or a long time passed
// between canCommit and ready and the entry was expired from the cache or it was aborted.
IllegalStateException ex = new IllegalStateException(String.format("%s: Cannot canCommit transaction %s - no cohort entry found", name, transactionID));
log.error(ex.getMessage());
sender.tell(new Failure(ex), shard.self());
return;
}
cohortEntry.setReplySender(sender);
cohortEntry.setShard(shard);
handleCanCommit(cohortEntry);
}
use of akka.actor.Status.Failure in project controller by opendaylight.
the class ShardCommitCoordinator method abortPendingTransactions.
void abortPendingTransactions(final String reason, final Shard shard) {
final Failure failure = new Failure(new RuntimeException(reason));
Collection<ShardDataTreeCohort> pending = dataTree.getAndClearPendingTransactions();
log.debug("{}: Aborting {} pending queued transactions", name, pending.size());
for (ShardDataTreeCohort cohort : pending) {
CohortEntry cohortEntry = cohortCache.remove(cohort.getIdentifier());
if (cohortEntry == null) {
continue;
}
if (cohortEntry.getReplySender() != null) {
cohortEntry.getReplySender().tell(failure, shard.self());
}
}
cohortCache.clear();
}
Aggregations