Search in sources :

Example 1 with PrimaryNotFoundException

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

the class ActorContext method findPrimaryShardAsync.

public Future<PrimaryShardInfo> findPrimaryShardAsync(final String shardName) {
    Future<PrimaryShardInfo> ret = primaryShardInfoCache.getIfPresent(shardName);
    if (ret != null) {
        return ret;
    }
    Future<Object> future = executeOperationAsync(shardManager, new FindPrimary(shardName, true), shardInitializationTimeout);
    return future.transform(new Mapper<Object, PrimaryShardInfo>() {

        @Override
        public PrimaryShardInfo checkedApply(Object response) throws UnknownMessageException {
            if (response instanceof RemotePrimaryShardFound) {
                LOG.debug("findPrimaryShardAsync received: {}", response);
                RemotePrimaryShardFound found = (RemotePrimaryShardFound) response;
                return onPrimaryShardFound(shardName, found.getPrimaryPath(), found.getPrimaryVersion(), null);
            } else if (response instanceof LocalPrimaryShardFound) {
                LOG.debug("findPrimaryShardAsync received: {}", response);
                LocalPrimaryShardFound found = (LocalPrimaryShardFound) response;
                return onPrimaryShardFound(shardName, found.getPrimaryPath(), DataStoreVersions.CURRENT_VERSION, found.getLocalShardDataTree());
            } else if (response instanceof NotInitializedException) {
                throw (NotInitializedException) response;
            } else if (response instanceof PrimaryNotFoundException) {
                throw (PrimaryNotFoundException) response;
            } else if (response instanceof NoShardLeaderException) {
                throw (NoShardLeaderException) response;
            }
            throw new UnknownMessageException(String.format("FindPrimary returned unkown response: %s", response));
        }
    }, FIND_PRIMARY_FAILURE_TRANSFORMER, getClientDispatcher());
}
Also used : PrimaryNotFoundException(org.opendaylight.controller.cluster.datastore.exceptions.PrimaryNotFoundException) UnknownMessageException(org.opendaylight.controller.cluster.datastore.exceptions.UnknownMessageException) NotInitializedException(org.opendaylight.controller.cluster.datastore.exceptions.NotInitializedException) RemotePrimaryShardFound(org.opendaylight.controller.cluster.datastore.messages.RemotePrimaryShardFound) NoShardLeaderException(org.opendaylight.controller.cluster.datastore.exceptions.NoShardLeaderException) FindPrimary(org.opendaylight.controller.cluster.datastore.messages.FindPrimary) LocalPrimaryShardFound(org.opendaylight.controller.cluster.datastore.messages.LocalPrimaryShardFound) PrimaryShardInfo(org.opendaylight.controller.cluster.datastore.messages.PrimaryShardInfo)

Example 2 with PrimaryNotFoundException

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

the class TransactionProxyTest method testExceptionOnInitialCreateTransaction.

private void testExceptionOnInitialCreateTransaction(final Exception exToThrow, final Invoker invoker) throws Exception {
    ActorRef actorRef = getSystem().actorOf(Props.create(DoNothingActor.class));
    if (exToThrow instanceof PrimaryNotFoundException) {
        doReturn(Futures.failed(exToThrow)).when(mockActorContext).findPrimaryShardAsync(anyString());
    } else {
        doReturn(primaryShardInfoReply(getSystem(), actorRef)).when(mockActorContext).findPrimaryShardAsync(anyString());
    }
    doReturn(Futures.failed(exToThrow)).when(mockActorContext).executeOperationAsync(any(ActorSelection.class), any(), any(Timeout.class));
    TransactionProxy transactionProxy = new TransactionProxy(mockComponentFactory, READ_ONLY);
    propagateReadFailedExceptionCause(invoker.invoke(transactionProxy));
}
Also used : PrimaryNotFoundException(org.opendaylight.controller.cluster.datastore.exceptions.PrimaryNotFoundException) ActorSelection(akka.actor.ActorSelection) DoNothingActor(org.opendaylight.controller.cluster.raft.utils.DoNothingActor) ActorRef(akka.actor.ActorRef) Timeout(akka.util.Timeout)

Example 3 with PrimaryNotFoundException

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

the class ShardManagerTest method testRemoveShardReplicaForNonExistentShard.

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

        {
            ActorRef shardManager = actorFactory.createActor(newShardMgrProps(new ConfigurationImpl(new EmptyModuleShardConfigProvider())).withDispatcher(Dispatchers.DefaultDispatcherId()));
            shardManager.tell(new RemoveShardReplica("model-inventory", MEMBER_1), getRef());
            Status.Failure resp = expectMsgClass(duration("10 seconds"), Status.Failure.class);
            assertEquals("Failure obtained", true, resp.cause() instanceof PrimaryNotFoundException);
        }
    };
}
Also used : EmptyModuleShardConfigProvider(org.opendaylight.controller.cluster.datastore.config.EmptyModuleShardConfigProvider) 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) PrimaryNotFoundException(org.opendaylight.controller.cluster.datastore.exceptions.PrimaryNotFoundException) ActorRef(akka.actor.ActorRef) TestActorRef(akka.testkit.TestActorRef) TestKit(akka.testkit.javadsl.TestKit) ConfigurationImpl(org.opendaylight.controller.cluster.datastore.config.ConfigurationImpl) RemoveShardReplica(org.opendaylight.controller.cluster.datastore.messages.RemoveShardReplica) Failure(akka.actor.Status.Failure) Test(org.junit.Test) AbstractShardManagerTest(org.opendaylight.controller.cluster.datastore.AbstractShardManagerTest)

Example 4 with PrimaryNotFoundException

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

the class ShardManager method findPrimary.

private void findPrimary(final FindPrimary message) {
    LOG.debug("{}: In findPrimary: {}", persistenceId(), message);
    final String shardName = message.getShardName();
    final boolean canReturnLocalShardState = !(message instanceof RemoteFindPrimary);
    // First see if the there is a local replica for the shard
    final ShardInformation info = localShards.get(shardName);
    if (info != null && info.isActiveMember()) {
        sendResponse(info, message.isWaitUntilReady(), true, () -> {
            String primaryPath = info.getSerializedLeaderActor();
            Object found = canReturnLocalShardState && info.isLeader() ? new LocalPrimaryShardFound(primaryPath, info.getLocalShardDataTree().get()) : new RemotePrimaryShardFound(primaryPath, info.getLeaderVersion());
            LOG.debug("{}: Found primary for {}: {}", persistenceId(), shardName, found);
            return found;
        });
        return;
    }
    final Collection<String> visitedAddresses;
    if (message instanceof RemoteFindPrimary) {
        visitedAddresses = ((RemoteFindPrimary) message).getVisitedAddresses();
    } else {
        visitedAddresses = new ArrayList<>(1);
    }
    visitedAddresses.add(peerAddressResolver.getShardManagerActorPathBuilder(cluster.getSelfAddress()).toString());
    for (String address : peerAddressResolver.getShardManagerPeerActorAddresses()) {
        if (visitedAddresses.contains(address)) {
            continue;
        }
        LOG.debug("{}: findPrimary for {} forwarding to remote ShardManager {}, visitedAddresses: {}", persistenceId(), shardName, address, visitedAddresses);
        getContext().actorSelection(address).forward(new RemoteFindPrimary(shardName, message.isWaitUntilReady(), visitedAddresses), getContext());
        return;
    }
    LOG.debug("{}: No shard found for {}", persistenceId(), shardName);
    getSender().tell(new PrimaryNotFoundException(String.format("No primary shard found for %s.", shardName)), getSelf());
}
Also used : PrimaryNotFoundException(org.opendaylight.controller.cluster.datastore.exceptions.PrimaryNotFoundException) LocalPrimaryShardFound(org.opendaylight.controller.cluster.datastore.messages.LocalPrimaryShardFound) RemotePrimaryShardFound(org.opendaylight.controller.cluster.datastore.messages.RemotePrimaryShardFound) RemoteFindPrimary(org.opendaylight.controller.cluster.datastore.messages.RemoteFindPrimary)

Example 5 with PrimaryNotFoundException

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

the class TransactionProxyTest method completeOperation.

private void completeOperation(final TransactionProxyOperation operation, final boolean shardFound) {
    ActorSystem actorSystem = getSystem();
    ActorRef shardActorRef = actorSystem.actorOf(Props.create(DoNothingActor.class));
    doReturn(actorSystem.actorSelection(shardActorRef.path())).when(mockActorContext).actorSelection(shardActorRef.path().toString());
    if (shardFound) {
        doReturn(Futures.successful(newPrimaryShardInfo(shardActorRef))).when(mockActorContext).findPrimaryShardAsync(eq(DefaultShardStrategy.DEFAULT_SHARD));
    } else {
        doReturn(Futures.failed(new PrimaryNotFoundException("test"))).when(mockActorContext).findPrimaryShardAsync(eq(DefaultShardStrategy.DEFAULT_SHARD));
    }
    ActorRef txActorRef = actorSystem.actorOf(Props.create(DoNothingActor.class));
    String actorPath = txActorRef.path().toString();
    CreateTransactionReply createTransactionReply = new CreateTransactionReply(actorPath, nextTransactionId(), DataStoreVersions.CURRENT_VERSION);
    doReturn(actorSystem.actorSelection(actorPath)).when(mockActorContext).actorSelection(actorPath);
    doReturn(Futures.successful(createTransactionReply)).when(mockActorContext).executeOperationAsync(eq(actorSystem.actorSelection(shardActorRef.path())), eqCreateTransaction(memberName, READ_WRITE), any(Timeout.class));
    TransactionProxy transactionProxy = new TransactionProxy(mockComponentFactory, READ_WRITE);
    long start = System.nanoTime();
    operation.run(transactionProxy);
    long end = System.nanoTime();
    long expected = TimeUnit.MILLISECONDS.toNanos(mockActorContext.getDatastoreContext().getOperationTimeoutInMillis());
    Assert.assertTrue(String.format("Expected elapsed time: %s. Actual: %s", expected, end - start), end - start <= expected);
}
Also used : ActorSystem(akka.actor.ActorSystem) PrimaryNotFoundException(org.opendaylight.controller.cluster.datastore.exceptions.PrimaryNotFoundException) DoNothingActor(org.opendaylight.controller.cluster.raft.utils.DoNothingActor) ActorRef(akka.actor.ActorRef) Timeout(akka.util.Timeout) CreateTransactionReply(org.opendaylight.controller.cluster.datastore.messages.CreateTransactionReply) Matchers.anyString(org.mockito.Matchers.anyString)

Aggregations

PrimaryNotFoundException (org.opendaylight.controller.cluster.datastore.exceptions.PrimaryNotFoundException)5 ActorRef (akka.actor.ActorRef)3 Timeout (akka.util.Timeout)2 LocalPrimaryShardFound (org.opendaylight.controller.cluster.datastore.messages.LocalPrimaryShardFound)2 RemotePrimaryShardFound (org.opendaylight.controller.cluster.datastore.messages.RemotePrimaryShardFound)2 DoNothingActor (org.opendaylight.controller.cluster.raft.utils.DoNothingActor)2 ActorSelection (akka.actor.ActorSelection)1 ActorSystem (akka.actor.ActorSystem)1 Status (akka.actor.Status)1 Failure (akka.actor.Status.Failure)1 TestActorRef (akka.testkit.TestActorRef)1 TestKit (akka.testkit.javadsl.TestKit)1 Test (org.junit.Test)1 Matchers.anyString (org.mockito.Matchers.anyString)1 AbstractShardManagerTest (org.opendaylight.controller.cluster.datastore.AbstractShardManagerTest)1 ConfigurationImpl (org.opendaylight.controller.cluster.datastore.config.ConfigurationImpl)1 EmptyModuleShardConfigProvider (org.opendaylight.controller.cluster.datastore.config.EmptyModuleShardConfigProvider)1 NoShardLeaderException (org.opendaylight.controller.cluster.datastore.exceptions.NoShardLeaderException)1 NotInitializedException (org.opendaylight.controller.cluster.datastore.exceptions.NotInitializedException)1 UnknownMessageException (org.opendaylight.controller.cluster.datastore.exceptions.UnknownMessageException)1