Search in sources :

Example 11 with Failure

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");
}
Also used : UpdateSchemaContext(org.opendaylight.controller.cluster.datastore.messages.UpdateSchemaContext) ShardLeaderStateChanged(org.opendaylight.controller.cluster.datastore.messages.ShardLeaderStateChanged) ActorRef(akka.actor.ActorRef) TestActorRef(akka.testkit.TestActorRef) RoleChangeNotification(org.opendaylight.controller.cluster.notifications.RoleChangeNotification) FindLocalShard(org.opendaylight.controller.cluster.datastore.messages.FindLocalShard) ActorInitialized(org.opendaylight.controller.cluster.datastore.messages.ActorInitialized) TestKit(akka.testkit.javadsl.TestKit) AddressFromURIString(akka.actor.AddressFromURIString) AddShardReplica(org.opendaylight.controller.cluster.datastore.messages.AddShardReplica) Failure(akka.actor.Status.Failure) Test(org.junit.Test) AbstractShardManagerTest(org.opendaylight.controller.cluster.datastore.AbstractShardManagerTest)

Example 12 with Failure

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());
    }
}
Also used : ConnectClientSuccess(org.opendaylight.controller.cluster.access.commands.ConnectClientSuccess) NotLeaderException(org.opendaylight.controller.cluster.access.commands.NotLeaderException) ClientIdentifier(org.opendaylight.controller.cluster.access.concepts.ClientIdentifier) ABIVersion(org.opendaylight.controller.cluster.access.ABIVersion) RequestException(org.opendaylight.controller.cluster.access.concepts.RequestException) UnsupportedRequestException(org.opendaylight.controller.cluster.access.concepts.UnsupportedRequestException) RuntimeRequestException(org.opendaylight.controller.cluster.access.concepts.RuntimeRequestException) Failure(akka.actor.Status.Failure)

Example 13 with Failure

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

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

Example 15 with Failure

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