use of akka.actor.Status.Failure in project controller by opendaylight.
the class ShardCommitCoordinator method handleAbort.
@SuppressWarnings("checkstyle:IllegalCatch")
void handleAbort(final Identifier transactionID, final ActorRef sender, final Shard shard) {
CohortEntry cohortEntry = cohortCache.remove(transactionID);
if (cohortEntry == null) {
return;
}
log.debug("{}: Aborting transaction {}", name, transactionID);
final ActorRef self = shard.getSelf();
cohortEntry.abort(new FutureCallback<Void>() {
@Override
public void onSuccess(final Void result) {
shard.getDataStore().purgeTransaction(cohortEntry.getTransactionId(), null);
if (sender != null) {
sender.tell(AbortTransactionReply.instance(cohortEntry.getClientVersion()).toSerializable(), self);
}
}
@Override
public void onFailure(final Throwable failure) {
log.error("{}: An exception happened during abort", name, failure);
shard.getDataStore().purgeTransaction(cohortEntry.getTransactionId(), null);
if (sender != null) {
sender.tell(new Failure(failure), self);
}
}
});
shard.getShardMBean().incrementAbortTransactionsCount();
}
use of akka.actor.Status.Failure in project controller by opendaylight.
the class RpcBrokerTest method testExecuteRpcFailureWithException.
@Test
public void testExecuteRpcFailureWithException() {
new TestKit(node1) {
{
when(domRpcService1.invokeRpc(eq(TEST_RPC_TYPE), Mockito.<NormalizedNode<?, ?>>any())).thenReturn(Futures.<DOMRpcResult, DOMRpcException>immediateFailedCheckedFuture(new DOMRpcImplementationNotAvailableException("NOT FOUND")));
final ExecuteRpc executeMsg = ExecuteRpc.from(TEST_RPC_ID, null);
rpcInvoker1.tell(executeMsg, getRef());
final Failure rpcResponse = expectMsgClass(duration("5 seconds"), akka.actor.Status.Failure.class);
Assert.assertTrue(rpcResponse.cause() instanceof DOMRpcException);
}
};
}
use of akka.actor.Status.Failure in project controller by opendaylight.
the class Shard method createTransaction.
@SuppressWarnings("checkstyle:IllegalCatch")
private void createTransaction(final CreateTransaction createTransaction) {
try {
if (TransactionType.fromInt(createTransaction.getTransactionType()) != TransactionType.READ_ONLY && failIfIsolatedLeader(getSender())) {
return;
}
ActorRef transactionActor = createTransaction(createTransaction.getTransactionType(), createTransaction.getTransactionId());
getSender().tell(new CreateTransactionReply(Serialization.serializedActorPath(transactionActor), createTransaction.getTransactionId(), createTransaction.getVersion()).toSerializable(), getSelf());
} catch (Exception e) {
getSender().tell(new Failure(e), getSelf());
}
}
use of akka.actor.Status.Failure in project controller by opendaylight.
the class Shard method onMakeLeaderLocal.
private void onMakeLeaderLocal() {
LOG.debug("{}: onMakeLeaderLocal received", persistenceId());
if (isLeader()) {
getSender().tell(new Status.Success(null), getSelf());
return;
}
final ActorSelection leader = getLeader();
if (leader == null) {
// Leader is not present. The cluster is most likely trying to
// elect a leader and we should let that run its normal course
// TODO we can wait for the election to complete and retry the
// request. We can also let the caller retry by sending a flag
// in the response indicating the request is "reTryable".
getSender().tell(new Failure(new LeadershipTransferFailedException("We cannot initiate leadership transfer to local node. " + "Currently there is no leader for " + persistenceId())), getSelf());
return;
}
leader.tell(new RequestLeadership(getId(), getSender()), getSelf());
}
use of akka.actor.Status.Failure in project controller by opendaylight.
the class ShardCommitCoordinator method handleCommit.
/**
* This method handles the preCommit and commit phases for a transaction.
*
* @param transactionID the ID of the transaction to commit
* @param sender the actor to which to send the response
* @param shard the transaction's shard actor
*/
void handleCommit(final Identifier transactionID, final ActorRef sender, final Shard shard) {
final CohortEntry cohortEntry = cohortCache.get(transactionID);
if (cohortEntry == null) {
// Either a long time passed between canCommit and commit and the entry was expired from the cache
// or it was aborted.
IllegalStateException ex = new IllegalStateException(String.format("%s: Cannot commit transaction %s - no cohort entry found", name, transactionID));
log.error(ex.getMessage());
sender.tell(new Failure(ex), shard.self());
return;
}
cohortEntry.setReplySender(sender);
doCommit(cohortEntry);
}
Aggregations