Search in sources :

Example 16 with Failure

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();
}
Also used : ActorRef(akka.actor.ActorRef) Failure(akka.actor.Status.Failure)

Example 17 with Failure

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);
        }
    };
}
Also used : DOMRpcImplementationNotAvailableException(org.opendaylight.controller.md.sal.dom.api.DOMRpcImplementationNotAvailableException) ExecuteRpc(org.opendaylight.controller.remote.rpc.messages.ExecuteRpc) TestKit(akka.testkit.javadsl.TestKit) DOMRpcException(org.opendaylight.controller.md.sal.dom.api.DOMRpcException) Failure(akka.actor.Status.Failure) Test(org.junit.Test)

Example 18 with Failure

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());
    }
}
Also used : ActorRef(akka.actor.ActorRef) CreateTransactionReply(org.opendaylight.controller.cluster.datastore.messages.CreateTransactionReply) RetiredGenerationException(org.opendaylight.controller.cluster.access.concepts.RetiredGenerationException) NotLeaderException(org.opendaylight.controller.cluster.access.commands.NotLeaderException) LeadershipTransferFailedException(org.opendaylight.controller.cluster.raft.LeadershipTransferFailedException) IOException(java.io.IOException) RequestException(org.opendaylight.controller.cluster.access.concepts.RequestException) UnsupportedRequestException(org.opendaylight.controller.cluster.access.concepts.UnsupportedRequestException) RuntimeRequestException(org.opendaylight.controller.cluster.access.concepts.RuntimeRequestException) OutOfSequenceEnvelopeException(org.opendaylight.controller.cluster.access.commands.OutOfSequenceEnvelopeException) NoShardLeaderException(org.opendaylight.controller.cluster.datastore.exceptions.NoShardLeaderException) DataValidationFailedException(org.opendaylight.yangtools.yang.data.api.schema.tree.DataValidationFailedException) Failure(akka.actor.Status.Failure)

Example 19 with Failure

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());
}
Also used : FollowerInitialSyncUpStatus(org.opendaylight.controller.cluster.raft.base.messages.FollowerInitialSyncUpStatus) Status(akka.actor.Status) LeadershipTransferFailedException(org.opendaylight.controller.cluster.raft.LeadershipTransferFailedException) ActorSelection(akka.actor.ActorSelection) RequestLeadership(org.opendaylight.controller.cluster.raft.messages.RequestLeadership) Failure(akka.actor.Status.Failure)

Example 20 with Failure

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);
}
Also used : Failure(akka.actor.Status.Failure)

Aggregations

Failure (akka.actor.Status.Failure)31 Test (org.junit.Test)21 ActorRef (akka.actor.ActorRef)15 TestKit (akka.testkit.javadsl.TestKit)14 TestActorRef (akka.testkit.TestActorRef)10 AbstractShardManagerTest (org.opendaylight.controller.cluster.datastore.AbstractShardManagerTest)8 FollowerInitialSyncUpStatus (org.opendaylight.controller.cluster.raft.base.messages.FollowerInitialSyncUpStatus)8 AddShardReplica (org.opendaylight.controller.cluster.datastore.messages.AddShardReplica)7 BatchedModifications (org.opendaylight.controller.cluster.datastore.messages.BatchedModifications)7 AddressFromURIString (akka.actor.AddressFromURIString)6 Status (akka.actor.Status)6 UpdateSchemaContext (org.opendaylight.controller.cluster.datastore.messages.UpdateSchemaContext)6 TransactionIdentifier (org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier)5 ChangeShardMembersVotingStatus (org.opendaylight.controller.cluster.datastore.messages.ChangeShardMembersVotingStatus)5 ChangeServersVotingStatus (org.opendaylight.controller.cluster.raft.messages.ChangeServersVotingStatus)4 ServerChangeStatus (org.opendaylight.controller.cluster.raft.messages.ServerChangeStatus)4 NotLeaderException (org.opendaylight.controller.cluster.access.commands.NotLeaderException)3 RequestException (org.opendaylight.controller.cluster.access.concepts.RequestException)3 RuntimeRequestException (org.opendaylight.controller.cluster.access.concepts.RuntimeRequestException)3 UnsupportedRequestException (org.opendaylight.controller.cluster.access.concepts.UnsupportedRequestException)3