Search in sources :

Example 1 with OnDemandRaftState

use of org.opendaylight.controller.cluster.raft.client.messages.OnDemandRaftState in project controller by opendaylight.

the class ShardManager method onFlipShardMembersVotingStatus.

private void onFlipShardMembersVotingStatus(final FlipShardMembersVotingStatus flipMembersVotingStatus) {
    LOG.debug("{}: onFlipShardMembersVotingStatus: {}", persistenceId(), flipMembersVotingStatus);
    ActorRef sender = getSender();
    final String shardName = flipMembersVotingStatus.getShardName();
    findLocalShard(shardName, sender, localShardFound -> {
        Future<Object> future = ask(localShardFound.getPath(), GetOnDemandRaftState.INSTANCE, Timeout.apply(30, TimeUnit.SECONDS));
        future.onComplete(new OnComplete<Object>() {

            @Override
            public void onComplete(final Throwable failure, final Object response) {
                if (failure != null) {
                    sender.tell(new Status.Failure(new RuntimeException(String.format("Failed to access local shard %s", shardName), failure)), self());
                    return;
                }
                OnDemandRaftState raftState = (OnDemandRaftState) response;
                Map<String, Boolean> serverVotingStatusMap = new HashMap<>();
                for (Entry<String, Boolean> e : raftState.getPeerVotingStates().entrySet()) {
                    serverVotingStatusMap.put(e.getKey(), !e.getValue());
                }
                serverVotingStatusMap.put(getShardIdentifier(cluster.getCurrentMemberName(), shardName).toString(), !raftState.isVoting());
                changeShardMembersVotingStatus(new ChangeServersVotingStatus(serverVotingStatusMap), shardName, localShardFound.getPath(), sender);
            }
        }, new Dispatchers(context().system().dispatchers()).getDispatcher(Dispatchers.DispatcherType.Client));
    });
}
Also used : ActorRef(akka.actor.ActorRef) GetOnDemandRaftState(org.opendaylight.controller.cluster.raft.client.messages.GetOnDemandRaftState) OnDemandRaftState(org.opendaylight.controller.cluster.raft.client.messages.OnDemandRaftState) Entry(java.util.Map.Entry) ChangeServersVotingStatus(org.opendaylight.controller.cluster.raft.messages.ChangeServersVotingStatus) Map(java.util.Map) HashMap(java.util.HashMap) SaveSnapshotFailure(akka.persistence.SaveSnapshotFailure) DeleteSnapshotsFailure(akka.persistence.DeleteSnapshotsFailure) Dispatchers(org.opendaylight.controller.cluster.common.actor.Dispatchers)

Example 2 with OnDemandRaftState

use of org.opendaylight.controller.cluster.raft.client.messages.OnDemandRaftState in project controller by opendaylight.

the class ShardStats method getOnDemandRaftState.

@SuppressWarnings("checkstyle:IllegalCatch")
private OnDemandRaftState getOnDemandRaftState() {
    try {
        final OnDemandRaftState state = stateCache.get();
        statRetrievalError = null;
        return state;
    } catch (Exception e) {
        statRetrievalError = e.getCause().toString();
        return OnDemandRaftState.builder().build();
    }
}
Also used : OnDemandRaftState(org.opendaylight.controller.cluster.raft.client.messages.OnDemandRaftState)

Example 3 with OnDemandRaftState

use of org.opendaylight.controller.cluster.raft.client.messages.OnDemandRaftState in project controller by opendaylight.

the class ShardTest method testPeerAddressResolved.

@Test
public void testPeerAddressResolved() throws Exception {
    new ShardTestKit(getSystem()) {

        {
            final ShardIdentifier peerID = ShardIdentifier.create("inventory", MemberName.forName("member-2"), "config");
            final TestActorRef<Shard> shard = actorFactory.createTestActor(newShardBuilder().peerAddresses(Collections.<String, String>singletonMap(peerID.toString(), null)).props().withDispatcher(Dispatchers.DefaultDispatcherId()), "testPeerAddressResolved");
            final String address = "akka://foobar";
            shard.tell(new PeerAddressResolved(peerID.toString(), address), ActorRef.noSender());
            shard.tell(GetOnDemandRaftState.INSTANCE, getRef());
            final OnDemandRaftState state = expectMsgClass(OnDemandRaftState.class);
            assertEquals("getPeerAddress", address, state.getPeerAddresses().get(peerID.toString()));
        }
    };
}
Also used : ShardIdentifier(org.opendaylight.controller.cluster.datastore.identifiers.ShardIdentifier) GetOnDemandRaftState(org.opendaylight.controller.cluster.raft.client.messages.GetOnDemandRaftState) OnDemandRaftState(org.opendaylight.controller.cluster.raft.client.messages.OnDemandRaftState) PeerAddressResolved(org.opendaylight.controller.cluster.datastore.messages.PeerAddressResolved) Test(org.junit.Test)

Example 4 with OnDemandRaftState

use of org.opendaylight.controller.cluster.raft.client.messages.OnDemandRaftState in project controller by opendaylight.

the class AbstractEntityOwnershipTest method verifyRaftState.

static void verifyRaftState(final TestActorRef<? extends EntityOwnershipShard> shard, final Consumer<OnDemandRaftState> verifier) throws Exception {
    AssertionError lastError = null;
    Stopwatch sw = Stopwatch.createStarted();
    while (sw.elapsed(TimeUnit.SECONDS) <= 5) {
        FiniteDuration operationDuration = Duration.create(5, TimeUnit.SECONDS);
        Future<Object> future = Patterns.ask(shard, GetOnDemandRaftState.INSTANCE, new Timeout(operationDuration));
        OnDemandRaftState raftState = (OnDemandRaftState) Await.result(future, operationDuration);
        try {
            verifier.accept(raftState);
            return;
        } catch (AssertionError e) {
            lastError = e;
            Uninterruptibles.sleepUninterruptibly(50, TimeUnit.MILLISECONDS);
        }
    }
    throw lastError;
}
Also used : Timeout(akka.util.Timeout) Stopwatch(com.google.common.base.Stopwatch) FiniteDuration(scala.concurrent.duration.FiniteDuration) GetOnDemandRaftState(org.opendaylight.controller.cluster.raft.client.messages.GetOnDemandRaftState) OnDemandRaftState(org.opendaylight.controller.cluster.raft.client.messages.OnDemandRaftState)

Example 5 with OnDemandRaftState

use of org.opendaylight.controller.cluster.raft.client.messages.OnDemandRaftState in project controller by opendaylight.

the class AbstractRaftActorIntegrationTest method verifyRaftState.

@SuppressWarnings("checkstyle:IllegalCatch")
static void verifyRaftState(final ActorRef raftActor, final Consumer<OnDemandRaftState> verifier) {
    Timeout timeout = new Timeout(500, TimeUnit.MILLISECONDS);
    AssertionError lastError = null;
    Stopwatch sw = Stopwatch.createStarted();
    while (sw.elapsed(TimeUnit.SECONDS) <= 5) {
        try {
            OnDemandRaftState raftState = (OnDemandRaftState) Await.result(ask(raftActor, GetOnDemandRaftState.INSTANCE, timeout), timeout.duration());
            verifier.accept(raftState);
            return;
        } catch (AssertionError e) {
            lastError = e;
            Uninterruptibles.sleepUninterruptibly(50, TimeUnit.MILLISECONDS);
        } catch (Exception e) {
            lastError = new AssertionError("OnDemandRaftState failed", e);
            Uninterruptibles.sleepUninterruptibly(50, TimeUnit.MILLISECONDS);
        }
    }
    throw lastError;
}
Also used : Timeout(akka.util.Timeout) Stopwatch(com.google.common.base.Stopwatch) OnDemandRaftState(org.opendaylight.controller.cluster.raft.client.messages.OnDemandRaftState) GetOnDemandRaftState(org.opendaylight.controller.cluster.raft.client.messages.GetOnDemandRaftState) InvalidActorNameException(akka.actor.InvalidActorNameException)

Aggregations

OnDemandRaftState (org.opendaylight.controller.cluster.raft.client.messages.OnDemandRaftState)6 GetOnDemandRaftState (org.opendaylight.controller.cluster.raft.client.messages.GetOnDemandRaftState)5 Stopwatch (com.google.common.base.Stopwatch)3 ActorRef (akka.actor.ActorRef)2 Timeout (akka.util.Timeout)2 InvalidActorNameException (akka.actor.InvalidActorNameException)1 DeleteSnapshotsFailure (akka.persistence.DeleteSnapshotsFailure)1 SaveSnapshotFailure (akka.persistence.SaveSnapshotFailure)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 Test (org.junit.Test)1 Dispatchers (org.opendaylight.controller.cluster.common.actor.Dispatchers)1 ShardIdentifier (org.opendaylight.controller.cluster.datastore.identifiers.ShardIdentifier)1 PeerAddressResolved (org.opendaylight.controller.cluster.datastore.messages.PeerAddressResolved)1 ActorContext (org.opendaylight.controller.cluster.datastore.utils.ActorContext)1 ChangeServersVotingStatus (org.opendaylight.controller.cluster.raft.messages.ChangeServersVotingStatus)1 FiniteDuration (scala.concurrent.duration.FiniteDuration)1