Search in sources :

Example 6 with ClientIdentifier

use of org.opendaylight.controller.cluster.access.concepts.ClientIdentifier in project controller by opendaylight.

the class ActorBehaviorTest method testRecoveryAfterRestartFrontendIdMismatch.

@Test
public void testRecoveryAfterRestartFrontendIdMismatch() throws Exception {
    system.stop(mockedActor);
    // start actor again
    mockedActor = system.actorOf(MockedActor.props(id, initialBehavior));
    probe.expectMsgClass(MockedSnapshotStore.LoadRequest.class);
    // offer snapshot with incorrect client id
    final SnapshotMetadata metadata = saveRequest.getMetadata();
    final FrontendIdentifier anotherFrontend = FrontendIdentifier.create(MemberName.forName("another"), FrontendType.forName("type-2"));
    final ClientIdentifier incorrectClientId = ClientIdentifier.create(anotherFrontend, 0);
    probe.watch(mockedActor);
    probe.reply(Optional.of(new SelectedSnapshot(metadata, incorrectClientId)));
    // actor should be stopped
    probe.expectTerminated(mockedActor, TIMEOUT);
}
Also used : ClientIdentifier(org.opendaylight.controller.cluster.access.concepts.ClientIdentifier) SelectedSnapshot(akka.persistence.SelectedSnapshot) SnapshotMetadata(akka.persistence.SnapshotMetadata) FrontendIdentifier(org.opendaylight.controller.cluster.access.concepts.FrontendIdentifier) Test(org.junit.Test)

Example 7 with ClientIdentifier

use of org.opendaylight.controller.cluster.access.concepts.ClientIdentifier in project controller by opendaylight.

the class Shard method handleRequest.

@Nullable
private RequestSuccess<?, ?> handleRequest(final RequestEnvelope envelope, final long now) throws RequestException {
    // We are not the leader, hence we want to fail-fast.
    if (!isLeader() || paused || !isLeaderActive()) {
        LOG.debug("{}: not currently active leader, rejecting request {}. isLeader: {}, isLeaderActive: {}," + "isLeadershipTransferInProgress: {}, paused: {}", persistenceId(), envelope, isLeader(), isLeaderActive(), isLeadershipTransferInProgress(), paused);
        throw new NotLeaderException(getSelf());
    }
    final Request<?, ?> request = envelope.getMessage();
    if (request instanceof TransactionRequest) {
        final TransactionRequest<?> txReq = (TransactionRequest<?>) request;
        final ClientIdentifier clientId = txReq.getTarget().getHistoryId().getClientId();
        return getFrontend(clientId).handleTransactionRequest(txReq, envelope, now);
    } else if (request instanceof LocalHistoryRequest) {
        final LocalHistoryRequest<?> lhReq = (LocalHistoryRequest<?>) request;
        final ClientIdentifier clientId = lhReq.getTarget().getClientId();
        return getFrontend(clientId).handleLocalHistoryRequest(lhReq, envelope, now);
    } else {
        LOG.warn("{}: rejecting unsupported request {}", persistenceId(), request);
        throw new UnsupportedRequestException(request);
    }
}
Also used : NotLeaderException(org.opendaylight.controller.cluster.access.commands.NotLeaderException) ClientIdentifier(org.opendaylight.controller.cluster.access.concepts.ClientIdentifier) LocalHistoryRequest(org.opendaylight.controller.cluster.access.commands.LocalHistoryRequest) UnsupportedRequestException(org.opendaylight.controller.cluster.access.concepts.UnsupportedRequestException) TransactionRequest(org.opendaylight.controller.cluster.access.commands.TransactionRequest) Nullable(javax.annotation.Nullable)

Example 8 with ClientIdentifier

use of org.opendaylight.controller.cluster.access.concepts.ClientIdentifier in project controller by opendaylight.

the class RecoveringClientActorBehavior method onReceiveRecover.

@Override
AbstractClientActorBehavior<?> onReceiveRecover(final Object recover) {
    if (recover instanceof RecoveryCompleted) {
        final ClientIdentifier nextId;
        if (lastId != null) {
            if (!currentFrontend.equals(lastId.getFrontendId())) {
                LOG.error("{}: Mismatched frontend identifier, shutting down. Current: {} Saved: {}", persistenceId(), currentFrontend, lastId.getFrontendId());
                return null;
            }
            nextId = ClientIdentifier.create(currentFrontend, lastId.getGeneration() + 1);
        } else {
            nextId = ClientIdentifier.create(currentFrontend, 0);
        }
        LOG.debug("{}: persisting new identifier {}", persistenceId(), nextId);
        context().saveSnapshot(nextId);
        return new SavingClientActorBehavior(context(), nextId);
    } else if (recover instanceof SnapshotOffer) {
        lastId = (ClientIdentifier) ((SnapshotOffer) recover).snapshot();
        LOG.debug("{}: recovered identifier {}", persistenceId(), lastId);
    } else {
        LOG.warn("{}: ignoring recovery message {}", persistenceId(), recover);
    }
    return this;
}
Also used : RecoveryCompleted(akka.persistence.RecoveryCompleted) ClientIdentifier(org.opendaylight.controller.cluster.access.concepts.ClientIdentifier) SnapshotOffer(akka.persistence.SnapshotOffer)

Example 9 with ClientIdentifier

use of org.opendaylight.controller.cluster.access.concepts.ClientIdentifier in project controller by opendaylight.

the class ClientBackedTransactionChainTest method setUp.

@Before
public void setUp() throws Exception {
    MockitoAnnotations.initMocks(this);
    final FrontendIdentifier frontendId = FrontendIdentifier.create(MemberName.forName("member"), FrontendType.forName("frontend"));
    final ClientIdentifier clientId = ClientIdentifier.create(frontendId, 0);
    final LocalHistoryIdentifier historyId = new LocalHistoryIdentifier(clientId, 0);
    final TransactionIdentifier transactionId = new TransactionIdentifier(historyId, 0);
    Mockito.when(history.getIdentifier()).thenReturn(historyId);
    Mockito.when(transaction.getIdentifier()).thenReturn(transactionId);
    Mockito.when(snapshot.getIdentifier()).thenReturn(transactionId);
    Mockito.when(history.takeSnapshot()).thenReturn(snapshot);
    Mockito.when(history.createTransaction()).thenReturn(transaction);
    chain = new ClientBackedTransactionChain(history, false);
}
Also used : ClientIdentifier(org.opendaylight.controller.cluster.access.concepts.ClientIdentifier) TransactionIdentifier(org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier) LocalHistoryIdentifier(org.opendaylight.controller.cluster.access.concepts.LocalHistoryIdentifier) FrontendIdentifier(org.opendaylight.controller.cluster.access.concepts.FrontendIdentifier) Before(org.junit.Before)

Example 10 with ClientIdentifier

use of org.opendaylight.controller.cluster.access.concepts.ClientIdentifier in project controller by opendaylight.

the class AbstractTransactionProxyTest method setUp.

@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);
    schemaContext = TestModel.createTestContext();
    doReturn(getSystem()).when(mockActorContext).getActorSystem();
    doReturn(getSystem().dispatchers().defaultGlobalDispatcher()).when(mockActorContext).getClientDispatcher();
    doReturn(MemberName.forName(memberName)).when(mockActorContext).getCurrentMemberName();
    doReturn(new ShardStrategyFactory(configuration, LogicalDatastoreType.CONFIGURATION)).when(mockActorContext).getShardStrategyFactory();
    doReturn(schemaContext).when(mockActorContext).getSchemaContext();
    doReturn(new Timeout(operationTimeoutInSeconds, TimeUnit.SECONDS)).when(mockActorContext).getOperationTimeout();
    doReturn(mockClusterWrapper).when(mockActorContext).getClusterWrapper();
    doReturn(mockClusterWrapper).when(mockActorContext).getClusterWrapper();
    doReturn(dataStoreContextBuilder.build()).when(mockActorContext).getDatastoreContext();
    final ClientIdentifier mockClientId = MockIdentifiers.clientIdentifier(getClass(), memberName);
    mockComponentFactory = new TransactionContextFactory(mockActorContext, mockClientId);
    Timer timer = new MetricRegistry().timer("test");
    doReturn(timer).when(mockActorContext).getOperationTimer(any(String.class));
}
Also used : ClientIdentifier(org.opendaylight.controller.cluster.access.concepts.ClientIdentifier) Timer(com.codahale.metrics.Timer) Timeout(akka.util.Timeout) MetricRegistry(com.codahale.metrics.MetricRegistry) ShardStrategyFactory(org.opendaylight.controller.cluster.datastore.shardstrategy.ShardStrategyFactory) Before(org.junit.Before)

Aggregations

ClientIdentifier (org.opendaylight.controller.cluster.access.concepts.ClientIdentifier)10 FrontendIdentifier (org.opendaylight.controller.cluster.access.concepts.FrontendIdentifier)5 Before (org.junit.Before)3 UnsignedLong (com.google.common.primitives.UnsignedLong)2 NotLeaderException (org.opendaylight.controller.cluster.access.commands.NotLeaderException)2 LocalHistoryIdentifier (org.opendaylight.controller.cluster.access.concepts.LocalHistoryIdentifier)2 UnsupportedRequestException (org.opendaylight.controller.cluster.access.concepts.UnsupportedRequestException)2 Failure (akka.actor.Status.Failure)1 RecoveryCompleted (akka.persistence.RecoveryCompleted)1 SelectedSnapshot (akka.persistence.SelectedSnapshot)1 SnapshotMetadata (akka.persistence.SnapshotMetadata)1 SnapshotOffer (akka.persistence.SnapshotOffer)1 Timeout (akka.util.Timeout)1 MetricRegistry (com.codahale.metrics.MetricRegistry)1 Timer (com.codahale.metrics.Timer)1 ArrayList (java.util.ArrayList)1 Nullable (javax.annotation.Nullable)1 Test (org.junit.Test)1 ABIVersion (org.opendaylight.controller.cluster.access.ABIVersion)1 ConnectClientSuccess (org.opendaylight.controller.cluster.access.commands.ConnectClientSuccess)1