Search in sources :

Example 1 with ChunkedInfoMessage

use of org.openkilda.messaging.info.ChunkedInfoMessage in project open-kilda by telstra.

the class YFlowReadBolt method emitMessages.

private void emitMessages(Tuple input, String requestId, List<? extends InfoData> messageData) {
    if (messageData.isEmpty()) {
        Message message = new ChunkedInfoMessage(null, System.currentTimeMillis(), requestId, requestId, 0);
        emit(input, new Values(requestId, message));
    } else {
        int idx = 0;
        for (InfoData data : messageData) {
            Message message = new ChunkedInfoMessage(data, System.currentTimeMillis(), requestId, idx++, messageData.size());
            emit(input, new Values(requestId, message));
        }
    }
}
Also used : InfoMessage(org.openkilda.messaging.info.InfoMessage) Message(org.openkilda.messaging.Message) ChunkedInfoMessage(org.openkilda.messaging.info.ChunkedInfoMessage) ErrorMessage(org.openkilda.messaging.error.ErrorMessage) ChunkedInfoMessage(org.openkilda.messaging.info.ChunkedInfoMessage) InfoData(org.openkilda.messaging.info.InfoData) Values(org.apache.storm.tuple.Values)

Example 2 with ChunkedInfoMessage

use of org.openkilda.messaging.info.ChunkedInfoMessage in project open-kilda by telstra.

the class ResponseSplitterBolt method sendChunkedResponse.

private void sendChunkedResponse(List<InfoData> responses, Tuple input, String requestId) {
    List<Message> messages = new ArrayList<>(responses.size());
    if (CollectionUtils.isEmpty(responses)) {
        log.debug("No records found in the database");
        Message message = new ChunkedInfoMessage(null, System.currentTimeMillis(), requestId, requestId, responses.size());
        messages.add(message);
    } else {
        int i = 0;
        for (InfoData data : responses) {
            Message message = new ChunkedInfoMessage(data, System.currentTimeMillis(), requestId, i++, responses.size());
            messages.add(message);
        }
        log.debug("Response is divided into {} messages", messages.size());
    }
    // emit all found messages
    messages.forEach(message -> getOutput().emit(input, new Values(requestId, message)));
}
Also used : Message(org.openkilda.messaging.Message) ChunkedInfoMessage(org.openkilda.messaging.info.ChunkedInfoMessage) ChunkedInfoMessage(org.openkilda.messaging.info.ChunkedInfoMessage) InfoData(org.openkilda.messaging.info.InfoData) ArrayList(java.util.ArrayList) Values(org.apache.storm.tuple.Values)

Example 3 with ChunkedInfoMessage

use of org.openkilda.messaging.info.ChunkedInfoMessage in project open-kilda by telstra.

the class KafkaMessagingChannel method onResponse.

/**
 * Processes messages that come back to NB topics, usually messages come as a response to some request.
 * If this response is for pended request then such request will be marked as completed.
 * Messages might be chunked and not chunked. If chunked we need to wait until we receive the last one
 * and only then collect all responses and complete the request.
 *
 * @param message received message.
 */
void onResponse(Message message) {
    if (!isValid(message)) {
        logger.warn("Skipping invalid message: {}", message);
        return;
    }
    if (message instanceof ErrorMessage) {
        ErrorMessage error = (ErrorMessage) message;
        String errorMessage = String.format("Response message is error: %s", error);
        if (message instanceof ClientErrorMessage) {
            logger.warn(errorMessage);
        } else {
            logger.error(errorMessage);
        }
        completeWithError(error);
    } else if (message instanceof InfoMessage) {
        if (isChunkedPendingResponse(message)) {
            processChunkedMessage((ChunkedInfoMessage) message);
        } else if (pendingRequests.containsKey(message.getCorrelationId())) {
            InfoMessage infoMessage = (InfoMessage) message;
            CompletableFuture<InfoData> request = pendingRequests.remove(message.getCorrelationId());
            if (request != null) {
                request.complete(infoMessage.getData());
            }
        } else {
            logger.trace("Received non-pending message");
        }
    }
}
Also used : ClientErrorMessage(org.openkilda.messaging.error.ClientErrorMessage) InfoMessage(org.openkilda.messaging.info.InfoMessage) ChunkedInfoMessage(org.openkilda.messaging.info.ChunkedInfoMessage) ChunkedInfoMessage(org.openkilda.messaging.info.ChunkedInfoMessage) InfoData(org.openkilda.messaging.info.InfoData) ClientErrorMessage(org.openkilda.messaging.error.ClientErrorMessage) ErrorMessage(org.openkilda.messaging.error.ErrorMessage)

Example 4 with ChunkedInfoMessage

use of org.openkilda.messaging.info.ChunkedInfoMessage in project open-kilda by telstra.

the class KafkaMessagingChannelTest method shouldReturnEmptyList.

@Test
public void shouldReturnEmptyList() throws Exception {
    String requestId = UUID.randomUUID().toString();
    long timestamp = System.currentTimeMillis();
    ChunkedInfoMessage emptyResponse = new ChunkedInfoMessage(null, timestamp, requestId, requestId, 0);
    CHUNKED_RESPONSES.add(emptyResponse);
    Message request = new Message(timestamp, requestId);
    CompletableFuture<List<InfoData>> future = messagingChannel.sendAndGetChunked(CHUNKED_TOPIC, request);
    prepareResponses(CHUNKED_TOPIC);
    List<InfoData> result = future.get(1, TimeUnit.SECONDS);
    assertTrue(result.isEmpty());
    assertTrue(messagingChannel.getPendingChunkedRequests().isEmpty());
}
Also used : InfoMessage(org.openkilda.messaging.info.InfoMessage) Message(org.openkilda.messaging.Message) ChunkedInfoMessage(org.openkilda.messaging.info.ChunkedInfoMessage) ErrorMessage(org.openkilda.messaging.error.ErrorMessage) ChunkedInfoMessage(org.openkilda.messaging.info.ChunkedInfoMessage) SwitchInfoData(org.openkilda.messaging.info.event.SwitchInfoData) InfoData(org.openkilda.messaging.info.InfoData) List(java.util.List) Test(org.junit.Test)

Example 5 with ChunkedInfoMessage

use of org.openkilda.messaging.info.ChunkedInfoMessage in project open-kilda by telstra.

the class FlowValidationHubBolt method buildResponseMessages.

private List<Message> buildResponseMessages(List<? extends InfoData> responseData, String requestId) {
    List<Message> messages = new ArrayList<>(responseData.size());
    if (CollectionUtils.isEmpty(responseData)) {
        messages.add(new ChunkedInfoMessage(null, System.currentTimeMillis(), requestId, requestId, 0));
    } else {
        int i = 0;
        for (InfoData data : responseData) {
            Message message = new ChunkedInfoMessage(data, System.currentTimeMillis(), requestId, i++, responseData.size());
            messages.add(message);
        }
    }
    return messages;
}
Also used : Message(org.openkilda.messaging.Message) CommandMessage(org.openkilda.messaging.command.CommandMessage) ChunkedInfoMessage(org.openkilda.messaging.info.ChunkedInfoMessage) ChunkedInfoMessage(org.openkilda.messaging.info.ChunkedInfoMessage) InfoData(org.openkilda.messaging.info.InfoData) ArrayList(java.util.ArrayList)

Aggregations

ChunkedInfoMessage (org.openkilda.messaging.info.ChunkedInfoMessage)6 InfoData (org.openkilda.messaging.info.InfoData)6 Message (org.openkilda.messaging.Message)4 ErrorMessage (org.openkilda.messaging.error.ErrorMessage)3 InfoMessage (org.openkilda.messaging.info.InfoMessage)3 ArrayList (java.util.ArrayList)2 Values (org.apache.storm.tuple.Values)2 SwitchInfoData (org.openkilda.messaging.info.event.SwitchInfoData)2 List (java.util.List)1 Test (org.junit.Test)1 CommandMessage (org.openkilda.messaging.command.CommandMessage)1 ClientErrorMessage (org.openkilda.messaging.error.ClientErrorMessage)1 SwitchId (org.openkilda.model.SwitchId)1