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