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