Search in sources :

Example 6 with NoShardLeaderException

use of org.opendaylight.controller.cluster.datastore.exceptions.NoShardLeaderException in project controller by opendaylight.

the class ActorContextTest method testBroadcast.

@Test
public void testBroadcast() {
    new TestKit(getSystem()) {

        {
            ActorRef shardActorRef1 = getSystem().actorOf(MessageCollectorActor.props());
            ActorRef shardActorRef2 = getSystem().actorOf(MessageCollectorActor.props());
            TestActorRef<MockShardManager> shardManagerActorRef = TestActorRef.create(getSystem(), MockShardManager.props());
            MockShardManager shardManagerActor = shardManagerActorRef.underlyingActor();
            shardManagerActor.addFindPrimaryResp("shard1", new RemotePrimaryShardFound(shardActorRef1.path().toString(), DataStoreVersions.CURRENT_VERSION));
            shardManagerActor.addFindPrimaryResp("shard2", new RemotePrimaryShardFound(shardActorRef2.path().toString(), DataStoreVersions.CURRENT_VERSION));
            shardManagerActor.addFindPrimaryResp("shard3", new NoShardLeaderException("not found"));
            Configuration mockConfig = mock(Configuration.class);
            doReturn(Sets.newLinkedHashSet(Arrays.asList("shard1", "shard2", "shard3"))).when(mockConfig).getAllShardNames();
            ActorContext actorContext = new ActorContext(getSystem(), shardManagerActorRef, mock(ClusterWrapper.class), mockConfig, DatastoreContext.newBuilder().shardInitializationTimeout(200, TimeUnit.MILLISECONDS).build(), new PrimaryShardInfoFutureCache());
            actorContext.broadcast(v -> new TestMessage(), TestMessage.class);
            MessageCollectorActor.expectFirstMatching(shardActorRef1, TestMessage.class);
            MessageCollectorActor.expectFirstMatching(shardActorRef2, TestMessage.class);
        }
    };
}
Also used : Configuration(org.opendaylight.controller.cluster.datastore.config.Configuration) ActorRef(akka.actor.ActorRef) TestActorRef(akka.testkit.TestActorRef) ClusterWrapper(org.opendaylight.controller.cluster.datastore.ClusterWrapper) TestKit(akka.testkit.javadsl.TestKit) RemotePrimaryShardFound(org.opendaylight.controller.cluster.datastore.messages.RemotePrimaryShardFound) NoShardLeaderException(org.opendaylight.controller.cluster.datastore.exceptions.NoShardLeaderException) AbstractActorTest(org.opendaylight.controller.cluster.datastore.AbstractActorTest) Test(org.junit.Test)

Example 7 with NoShardLeaderException

use of org.opendaylight.controller.cluster.datastore.exceptions.NoShardLeaderException in project controller by opendaylight.

the class RemoteTransactionContextSupport method createTransactionContext.

private void createTransactionContext(final Throwable failure, final Object response) {
    // Create the TransactionContext from the response or failure. Store the new
    // TransactionContext locally until we've completed invoking the
    // TransactionOperations. This avoids thread timing issues which could cause
    // out-of-order TransactionOperations. Eg, on a modification operation, if the
    // TransactionContext is non-null, then we directly call the TransactionContext.
    // However, at the same time, the code may be executing the cached
    // TransactionOperations. So to avoid thus timing, we don't publish the
    // TransactionContext until after we've executed all cached TransactionOperations.
    TransactionContext localTransactionContext;
    if (failure != null) {
        LOG.debug("Tx {} Creating NoOpTransaction because of error", getIdentifier(), failure);
        Throwable resultingEx = failure;
        if (failure instanceof AskTimeoutException) {
            resultingEx = new ShardLeaderNotRespondingException(String.format("Could not create a %s transaction on shard %s. The shard leader isn't responding.", parent.getType(), shardName), failure);
        } else if (!(failure instanceof NoShardLeaderException)) {
            resultingEx = new Exception(String.format("Error creating %s transaction on shard %s", parent.getType(), shardName), failure);
        }
        localTransactionContext = new NoOpTransactionContext(resultingEx, getIdentifier());
    } else if (CreateTransactionReply.isSerializedType(response)) {
        localTransactionContext = createValidTransactionContext(CreateTransactionReply.fromSerializable(response));
    } else {
        IllegalArgumentException exception = new IllegalArgumentException(String.format("Invalid reply type %s for CreateTransaction", response.getClass()));
        localTransactionContext = new NoOpTransactionContext(exception, getIdentifier());
    }
    transactionContextWrapper.executePriorTransactionOperations(localTransactionContext);
}
Also used : ShardLeaderNotRespondingException(org.opendaylight.controller.cluster.datastore.exceptions.ShardLeaderNotRespondingException) AskTimeoutException(akka.pattern.AskTimeoutException) ShardLeaderNotRespondingException(org.opendaylight.controller.cluster.datastore.exceptions.ShardLeaderNotRespondingException) NoShardLeaderException(org.opendaylight.controller.cluster.datastore.exceptions.NoShardLeaderException) AskTimeoutException(akka.pattern.AskTimeoutException) NoShardLeaderException(org.opendaylight.controller.cluster.datastore.exceptions.NoShardLeaderException)

Example 8 with NoShardLeaderException

use of org.opendaylight.controller.cluster.datastore.exceptions.NoShardLeaderException in project controller by opendaylight.

the class NoOpTransactionContext method executeRead.

@Override
public <T> void executeRead(AbstractRead<T> readCmd, SettableFuture<T> proxyFuture) {
    LOG.debug("Tx {} executeRead {} called path = {}", getIdentifier(), readCmd.getClass().getSimpleName(), readCmd.getPath());
    final Throwable t;
    if (failure instanceof NoShardLeaderException) {
        t = new DataStoreUnavailableException(failure.getMessage(), failure);
    } else {
        t = failure;
    }
    proxyFuture.setException(new ReadFailedException("Error executeRead " + readCmd.getClass().getSimpleName() + " for path " + readCmd.getPath(), t));
}
Also used : ReadFailedException(org.opendaylight.mdsal.common.api.ReadFailedException) DataStoreUnavailableException(org.opendaylight.mdsal.common.api.DataStoreUnavailableException) NoShardLeaderException(org.opendaylight.controller.cluster.datastore.exceptions.NoShardLeaderException)

Example 9 with NoShardLeaderException

use of org.opendaylight.controller.cluster.datastore.exceptions.NoShardLeaderException in project controller by opendaylight.

the class ShardManagerTest method testChangeServersVotingStatusWithNoLeader.

@Test
public void testChangeServersVotingStatusWithNoLeader() throws Exception {
    new TestKit(getSystem()) {

        {
            String memberId = "member-1-shard-default-" + shardMrgIDSuffix;
            ActorRef respondActor = actorFactory.createActor(Props.create(MockRespondActor.class, ChangeServersVotingStatus.class, new ServerChangeReply(ServerChangeStatus.NO_LEADER, null)), memberId);
            ActorRef shardManager = getSystem().actorOf(newPropsShardMgrWithMockShardActor(respondActor));
            shardManager.tell(new UpdateSchemaContext(TestModel.createTestContext()), getRef());
            shardManager.tell(new ActorInitialized(), respondActor);
            shardManager.tell(new RoleChangeNotification(memberId, null, RaftState.Follower.name()), respondActor);
            shardManager.tell(new ChangeShardMembersVotingStatus("default", ImmutableMap.of("member-2", Boolean.TRUE)), getRef());
            MessageCollectorActor.expectFirstMatching(respondActor, ChangeServersVotingStatus.class);
            Status.Failure resp = expectMsgClass(duration("5 seconds"), Status.Failure.class);
            assertEquals("Failure resposnse", true, resp.cause() instanceof NoShardLeaderException);
        }
    };
}
Also used : ChangeShardMembersVotingStatus(org.opendaylight.controller.cluster.datastore.messages.ChangeShardMembersVotingStatus) FollowerInitialSyncUpStatus(org.opendaylight.controller.cluster.raft.base.messages.FollowerInitialSyncUpStatus) ChangeShardMembersVotingStatus(org.opendaylight.controller.cluster.datastore.messages.ChangeShardMembersVotingStatus) Status(akka.actor.Status) ServerChangeStatus(org.opendaylight.controller.cluster.raft.messages.ServerChangeStatus) ChangeServersVotingStatus(org.opendaylight.controller.cluster.raft.messages.ChangeServersVotingStatus) UpdateSchemaContext(org.opendaylight.controller.cluster.datastore.messages.UpdateSchemaContext) ActorRef(akka.actor.ActorRef) TestActorRef(akka.testkit.TestActorRef) RoleChangeNotification(org.opendaylight.controller.cluster.notifications.RoleChangeNotification) TestKit(akka.testkit.javadsl.TestKit) AddressFromURIString(akka.actor.AddressFromURIString) NoShardLeaderException(org.opendaylight.controller.cluster.datastore.exceptions.NoShardLeaderException) ChangeServersVotingStatus(org.opendaylight.controller.cluster.raft.messages.ChangeServersVotingStatus) ActorInitialized(org.opendaylight.controller.cluster.datastore.messages.ActorInitialized) ServerChangeReply(org.opendaylight.controller.cluster.raft.messages.ServerChangeReply) Failure(akka.actor.Status.Failure) Test(org.junit.Test) AbstractShardManagerTest(org.opendaylight.controller.cluster.datastore.AbstractShardManagerTest)

Example 10 with NoShardLeaderException

use of org.opendaylight.controller.cluster.datastore.exceptions.NoShardLeaderException in project controller by opendaylight.

the class ConcurrentDOMDataBrokerTest method testSubmitWithCanCommitDataStoreUnavailableException.

@Test
public void testSubmitWithCanCommitDataStoreUnavailableException() throws Exception {
    doReturn(Futures.immediateFuture(true)).when(mockCohort1).canCommit();
    doReturn(Futures.immediateFuture(null)).when(mockCohort1).abort();
    NoShardLeaderException rootCause = new NoShardLeaderException("mock");
    DataStoreUnavailableException cause = new DataStoreUnavailableException(rootCause.getMessage(), rootCause);
    doReturn(Futures.immediateFailedFuture(rootCause)).when(mockCohort2).canCommit();
    doReturn(Futures.immediateFuture(null)).when(mockCohort2).abort();
    CheckedFuture<Void, TransactionCommitFailedException> future = coordinator.submit(transaction, Arrays.asList(mockCohort1, mockCohort2));
    assertFailure(future, cause, mockCohort1, mockCohort2);
}
Also used : TransactionCommitFailedException(org.opendaylight.mdsal.common.api.TransactionCommitFailedException) DataStoreUnavailableException(org.opendaylight.mdsal.common.api.DataStoreUnavailableException) NoShardLeaderException(org.opendaylight.controller.cluster.datastore.exceptions.NoShardLeaderException) Test(org.junit.Test)

Aggregations

NoShardLeaderException (org.opendaylight.controller.cluster.datastore.exceptions.NoShardLeaderException)12 Test (org.junit.Test)7 AddressFromURIString (akka.actor.AddressFromURIString)5 ExecutionException (java.util.concurrent.ExecutionException)4 RequestTimeoutException (org.opendaylight.controller.cluster.access.client.RequestTimeoutException)3 ShardLeaderNotRespondingException (org.opendaylight.controller.cluster.datastore.exceptions.ShardLeaderNotRespondingException)3 DataStoreUnavailableException (org.opendaylight.mdsal.common.api.DataStoreUnavailableException)3 TransactionCommitFailedException (org.opendaylight.mdsal.common.api.TransactionCommitFailedException)3 DOMStoreThreePhaseCommitCohort (org.opendaylight.mdsal.dom.spi.store.DOMStoreThreePhaseCommitCohort)3 ActorRef (akka.actor.ActorRef)2 TestActorRef (akka.testkit.TestActorRef)2 TestKit (akka.testkit.javadsl.TestKit)2 NotInitializedException (org.opendaylight.controller.cluster.datastore.exceptions.NotInitializedException)2 RemotePrimaryShardFound (org.opendaylight.controller.cluster.datastore.messages.RemotePrimaryShardFound)2 ReadFailedException (org.opendaylight.mdsal.common.api.ReadFailedException)2 DOMStoreReadTransaction (org.opendaylight.mdsal.dom.spi.store.DOMStoreReadTransaction)2 DOMStoreReadWriteTransaction (org.opendaylight.mdsal.dom.spi.store.DOMStoreReadWriteTransaction)2 DOMStoreWriteTransaction (org.opendaylight.mdsal.dom.spi.store.DOMStoreWriteTransaction)2 Status (akka.actor.Status)1 Failure (akka.actor.Status.Failure)1