Search in sources :

Example 1 with RequestEnvelope

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

the class AbstractClientHandleTest method backendRespondToRequest.

/**
 * Checks, whether backend actor has received request of expected class wrapped in RequestEnvelope.
 * Then given response wrapped in ResponseEnvelope is sent.
 *
 * @param expectedRequestClass expected request class
 * @param response             response
 * @param <R>                  expected request type
 * @return request message
 */
protected <R extends Request<?, R>> R backendRespondToRequest(final Class<R> expectedRequestClass, final Response<?, ?> response) {
    final RequestEnvelope envelope = backendProbe.expectMsgClass(RequestEnvelope.class);
    Assert.assertEquals(expectedRequestClass, envelope.getMessage().getClass());
    final AbstractClientConnection<ShardBackendInfo> connection = client.getConnection(0L);
    final long sessionId = envelope.getSessionId();
    final long txSequence = envelope.getTxSequence();
    final long executionTime = 0L;
    if (response instanceof RequestSuccess) {
        final RequestSuccess<?, ?> success = (RequestSuccess<?, ?>) response;
        final SuccessEnvelope responseEnvelope = new SuccessEnvelope(success, sessionId, txSequence, executionTime);
        AccessClientUtil.completeRequest(connection, responseEnvelope);
    } else if (response instanceof RequestFailure) {
        final RequestFailure<?, ?> fail = (RequestFailure<?, ?>) response;
        final FailureEnvelope responseEnvelope = new FailureEnvelope(fail, sessionId, txSequence, executionTime);
        AccessClientUtil.completeRequest(connection, responseEnvelope);
    }
    return expectedRequestClass.cast(envelope.getMessage());
}
Also used : SuccessEnvelope(org.opendaylight.controller.cluster.access.concepts.SuccessEnvelope) FailureEnvelope(org.opendaylight.controller.cluster.access.concepts.FailureEnvelope) RequestEnvelope(org.opendaylight.controller.cluster.access.concepts.RequestEnvelope) RequestFailure(org.opendaylight.controller.cluster.access.concepts.RequestFailure) RequestSuccess(org.opendaylight.controller.cluster.access.concepts.RequestSuccess)

Example 2 with RequestEnvelope

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

the class AbstractProxyTransactionTest method testHandleForwardedRemoteRequest.

protected <R extends TransactionRequest<R>> R testHandleForwardedRemoteRequest(final R request) throws Exception {
    transaction.handleReplayedRemoteRequest(request, createCallbackMock(), Ticker.systemTicker().read());
    final RequestEnvelope envelope = backendProbe.expectMsgClass(RequestEnvelope.class);
    final R received = (R) envelope.getMessage();
    Assert.assertTrue(received.getClass().equals(request.getClass()));
    Assert.assertEquals(TRANSACTION_ID, received.getTarget());
    Assert.assertEquals(clientContextProbe.ref(), received.getReplyTo());
    return received;
}
Also used : RequestEnvelope(org.opendaylight.controller.cluster.access.concepts.RequestEnvelope)

Example 3 with RequestEnvelope

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

the class Shard method handleNonRaftCommand.

@Override
protected void handleNonRaftCommand(final Object message) {
    try (MessageTracker.Context context = appendEntriesReplyTracker.received(message)) {
        final Optional<Error> maybeError = context.error();
        if (maybeError.isPresent()) {
            LOG.trace("{} : AppendEntriesReply failed to arrive at the expected interval {}", persistenceId(), maybeError.get());
        }
        store.resetTransactionBatch();
        if (message instanceof RequestEnvelope) {
            handleRequestEnvelope((RequestEnvelope) message);
        } else if (MessageAssembler.isHandledMessage(message)) {
            handleRequestAssemblerMessage(message);
        } else if (message instanceof ConnectClientRequest) {
            handleConnectClient((ConnectClientRequest) message);
        } else if (CreateTransaction.isSerializedType(message)) {
            handleCreateTransaction(message);
        } else if (message instanceof BatchedModifications) {
            handleBatchedModifications((BatchedModifications) message);
        } else if (message instanceof ForwardedReadyTransaction) {
            handleForwardedReadyTransaction((ForwardedReadyTransaction) message);
        } else if (message instanceof ReadyLocalTransaction) {
            handleReadyLocalTransaction((ReadyLocalTransaction) message);
        } else if (CanCommitTransaction.isSerializedType(message)) {
            handleCanCommitTransaction(CanCommitTransaction.fromSerializable(message));
        } else if (CommitTransaction.isSerializedType(message)) {
            handleCommitTransaction(CommitTransaction.fromSerializable(message));
        } else if (AbortTransaction.isSerializedType(message)) {
            handleAbortTransaction(AbortTransaction.fromSerializable(message));
        } else if (CloseTransactionChain.isSerializedType(message)) {
            closeTransactionChain(CloseTransactionChain.fromSerializable(message));
        } else if (message instanceof RegisterChangeListener) {
            changeSupport.onMessage((RegisterChangeListener) message, isLeader(), hasLeader());
        } else if (message instanceof RegisterDataTreeChangeListener) {
            treeChangeSupport.onMessage((RegisterDataTreeChangeListener) message, isLeader(), hasLeader());
        } else if (message instanceof UpdateSchemaContext) {
            updateSchemaContext((UpdateSchemaContext) message);
        } else if (message instanceof PeerAddressResolved) {
            PeerAddressResolved resolved = (PeerAddressResolved) message;
            setPeerAddress(resolved.getPeerId(), resolved.getPeerAddress());
        } else if (TX_COMMIT_TIMEOUT_CHECK_MESSAGE.equals(message)) {
            commitTimeoutCheck();
        } else if (message instanceof DatastoreContext) {
            onDatastoreContext((DatastoreContext) message);
        } else if (message instanceof RegisterRoleChangeListener) {
            roleChangeNotifier.get().forward(message, context());
        } else if (message instanceof FollowerInitialSyncUpStatus) {
            shardMBean.setFollowerInitialSyncStatus(((FollowerInitialSyncUpStatus) message).isInitialSyncDone());
            context().parent().tell(message, self());
        } else if (GET_SHARD_MBEAN_MESSAGE.equals(message)) {
            sender().tell(getShardMBean(), self());
        } else if (message instanceof GetShardDataTree) {
            sender().tell(store.getDataTree(), self());
        } else if (message instanceof ServerRemoved) {
            context().parent().forward(message, context());
        } else if (ShardTransactionMessageRetrySupport.TIMER_MESSAGE_CLASS.isInstance(message)) {
            messageRetrySupport.onTimerMessage(message);
        } else if (message instanceof DataTreeCohortActorRegistry.CohortRegistryCommand) {
            store.processCohortRegistryCommand(getSender(), (DataTreeCohortActorRegistry.CohortRegistryCommand) message);
        } else if (message instanceof PersistAbortTransactionPayload) {
            final TransactionIdentifier txId = ((PersistAbortTransactionPayload) message).getTransactionId();
            persistPayload(txId, AbortTransactionPayload.create(txId), true);
        } else if (message instanceof MakeLeaderLocal) {
            onMakeLeaderLocal();
        } else if (RESUME_NEXT_PENDING_TRANSACTION.equals(message)) {
            store.resumeNextPendingTransaction();
        } else if (!responseMessageSlicer.handleMessage(message)) {
            super.handleNonRaftCommand(message);
        }
    }
}
Also used : UpdateSchemaContext(org.opendaylight.controller.cluster.datastore.messages.UpdateSchemaContext) RegisterRoleChangeListener(org.opendaylight.controller.cluster.notifications.RegisterRoleChangeListener) RegisterChangeListener(org.opendaylight.controller.cluster.datastore.messages.RegisterChangeListener) ServerRemoved(org.opendaylight.controller.cluster.raft.messages.ServerRemoved) Error(org.opendaylight.controller.cluster.common.actor.MessageTracker.Error) PeerAddressResolved(org.opendaylight.controller.cluster.datastore.messages.PeerAddressResolved) MessageTracker(org.opendaylight.controller.cluster.common.actor.MessageTracker) RegisterDataTreeChangeListener(org.opendaylight.controller.cluster.datastore.messages.RegisterDataTreeChangeListener) FollowerInitialSyncUpStatus(org.opendaylight.controller.cluster.raft.base.messages.FollowerInitialSyncUpStatus) BatchedModifications(org.opendaylight.controller.cluster.datastore.messages.BatchedModifications) GetShardDataTree(org.opendaylight.controller.cluster.datastore.messages.GetShardDataTree) MakeLeaderLocal(org.opendaylight.controller.cluster.datastore.messages.MakeLeaderLocal) ConnectClientRequest(org.opendaylight.controller.cluster.access.commands.ConnectClientRequest) ReadyLocalTransaction(org.opendaylight.controller.cluster.datastore.messages.ReadyLocalTransaction) TransactionIdentifier(org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier) RequestEnvelope(org.opendaylight.controller.cluster.access.concepts.RequestEnvelope) ForwardedReadyTransaction(org.opendaylight.controller.cluster.datastore.messages.ForwardedReadyTransaction) PersistAbortTransactionPayload(org.opendaylight.controller.cluster.datastore.messages.PersistAbortTransactionPayload)

Example 4 with RequestEnvelope

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

the class ConnectingClientConnectionTest method assertRequestEquals.

private static void assertRequestEquals(final Request<?, ?> expected, final long sequence, final Object obj) {
    assertTrue(obj instanceof RequestEnvelope);
    final RequestEnvelope actual = (RequestEnvelope) obj;
    assertEquals(0, actual.getSessionId());
    assertEquals(sequence, actual.getTxSequence());
    assertSame(expected, actual.getMessage());
}
Also used : RequestEnvelope(org.opendaylight.controller.cluster.access.concepts.RequestEnvelope)

Example 5 with RequestEnvelope

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

the class TransmittingTransmitQueueTest method testRequestSlicingOnTransmit.

@Test
public void testRequestSlicingOnTransmit() throws Exception {
    doReturn(true).when(mockMessageSlicer).slice(any());
    ModifyTransactionRequestBuilder reqBuilder = new ModifyTransactionRequestBuilder(TRANSACTION_IDENTIFIER, probe.ref());
    reqBuilder.setSequence(0L);
    final Request<?, ?> request = reqBuilder.build();
    final long now = now();
    final Consumer<Response<?, ?>> mockConsumer = createConsumerMock();
    Optional<TransmittedConnectionEntry> transmitted = queue.transmit(new ConnectionEntry(request, mockConsumer, now), now);
    assertTrue(transmitted.isPresent());
    ArgumentCaptor<SliceOptions> sliceOptions = ArgumentCaptor.forClass(SliceOptions.class);
    verify(mockMessageSlicer).slice(sliceOptions.capture());
    assertTrue(sliceOptions.getValue().getMessage() instanceof RequestEnvelope);
    RequestEnvelope requestEnvelope = (RequestEnvelope) sliceOptions.getValue().getMessage();
    assertEquals(request, requestEnvelope.getMessage());
    final Request<?, ?> request2 = new TransactionPurgeRequest(TRANSACTION_IDENTIFIER, 1L, probe.ref());
    transmitted = queue.transmit(new ConnectionEntry(request2, mockConsumer, now), now);
    assertFalse(transmitted.isPresent());
}
Also used : TransactionPurgeResponse(org.opendaylight.controller.cluster.access.commands.TransactionPurgeResponse) Response(org.opendaylight.controller.cluster.access.concepts.Response) TransactionPurgeRequest(org.opendaylight.controller.cluster.access.commands.TransactionPurgeRequest) ModifyTransactionRequestBuilder(org.opendaylight.controller.cluster.access.commands.ModifyTransactionRequestBuilder) RequestEnvelope(org.opendaylight.controller.cluster.access.concepts.RequestEnvelope) SliceOptions(org.opendaylight.controller.cluster.messaging.SliceOptions) Test(org.junit.Test)

Aggregations

RequestEnvelope (org.opendaylight.controller.cluster.access.concepts.RequestEnvelope)9 Test (org.junit.Test)5 Response (org.opendaylight.controller.cluster.access.concepts.Response)5 TransactionPurgeRequest (org.opendaylight.controller.cluster.access.commands.TransactionPurgeRequest)4 TransactionPurgeResponse (org.opendaylight.controller.cluster.access.commands.TransactionPurgeResponse)4 ModifyTransactionRequestBuilder (org.opendaylight.controller.cluster.access.commands.ModifyTransactionRequestBuilder)2 FailureEnvelope (org.opendaylight.controller.cluster.access.concepts.FailureEnvelope)2 SuccessEnvelope (org.opendaylight.controller.cluster.access.concepts.SuccessEnvelope)2 TransactionIdentifier (org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier)2 SliceOptions (org.opendaylight.controller.cluster.messaging.SliceOptions)2 ConnectClientRequest (org.opendaylight.controller.cluster.access.commands.ConnectClientRequest)1 TransactionAbortSuccess (org.opendaylight.controller.cluster.access.commands.TransactionAbortSuccess)1 LocalHistoryIdentifier (org.opendaylight.controller.cluster.access.concepts.LocalHistoryIdentifier)1 RequestException (org.opendaylight.controller.cluster.access.concepts.RequestException)1 RequestFailure (org.opendaylight.controller.cluster.access.concepts.RequestFailure)1 RequestSuccess (org.opendaylight.controller.cluster.access.concepts.RequestSuccess)1 MessageTracker (org.opendaylight.controller.cluster.common.actor.MessageTracker)1 Error (org.opendaylight.controller.cluster.common.actor.MessageTracker.Error)1 BatchedModifications (org.opendaylight.controller.cluster.datastore.messages.BatchedModifications)1 ForwardedReadyTransaction (org.opendaylight.controller.cluster.datastore.messages.ForwardedReadyTransaction)1