use of org.openkilda.messaging.ctrl.CtrlRequest in project open-kilda by telstra.
the class CacheTopologyTest method ctrlSpecificRoute.
@Test
public void ctrlSpecificRoute() throws Exception {
CtrlRequest request = new CtrlRequest("cachetopology/cache", new RequestData("dump"), 1, "route-correlation-id", Destination.WFM_CTRL);
sendMessage(request, topology.getConfig().getKafkaCtrlTopic());
ConsumerRecord<String, String> raw = ctrlConsumer.pollMessage();
// TODO: FAILED
assertNotNull(raw);
assertNotNull(raw.value());
Message responseGeneric = objectMapper.readValue(raw.value(), Message.class);
CtrlResponse response = (CtrlResponse) responseGeneric;
assertEquals(request.getCorrelationId(), response.getCorrelationId());
}
use of org.openkilda.messaging.ctrl.CtrlRequest in project open-kilda by telstra.
the class CacheTopologyTest method sendClearState.
private static void sendClearState() throws IOException, InterruptedException {
CtrlRequest request = new CtrlRequest("cachetopology/cache", new RequestData("clearState"), 1, "route-correlation-id", Destination.WFM_CTRL);
sendMessage(request, topology.getConfig().getKafkaCtrlTopic());
ConsumerRecord<String, String> raw = ctrlConsumer.pollMessage();
assertNotNull(raw);
CtrlResponse response = (CtrlResponse) objectMapper.readValue(raw.value(), Message.class);
assertEquals(request.getCorrelationId(), response.getCorrelationId());
}
use of org.openkilda.messaging.ctrl.CtrlRequest in project open-kilda by telstra.
the class KafkaUtils method getStateDumpsFromBolts.
public DumpStateManager getStateDumpsFromBolts() {
long timestamp = System.currentTimeMillis();
String correlationId = String.format("atdd-%d", timestamp);
CtrlRequest dumpRequest = new CtrlRequest("*", new RequestData("dump"), timestamp, correlationId, WFM_CTRL);
try {
RecordMetadata postedMessage = postMessage(settings.getControlTopic(), dumpRequest);
KafkaConsumer<String, String> consumer = createConsumer();
try {
consumer.subscribe(Collections.singletonList(settings.getControlTopic()), new NoOpConsumerRebalanceListener() {
@Override
public void onPartitionsAssigned(Collection<TopicPartition> partitions) {
System.out.println("Seek to offset: " + postedMessage.offset());
for (TopicPartition topicPartition : partitions) {
consumer.seek(topicPartition, postedMessage.offset());
}
}
});
List<CtrlResponse> buffer = new ArrayList<>();
final int BOLT_COUNT = 4;
final int NUMBER_OF_ATTEMPTS = 5;
int attempt = 0;
while (buffer.size() < BOLT_COUNT && attempt++ < NUMBER_OF_ATTEMPTS) {
for (ConsumerRecord<String, String> record : consumer.poll(1000)) {
System.out.println("Received message: (" + record.key() + ", " + record.value() + ") at offset " + record.offset());
Message message = MAPPER.readValue(record.value(), Message.class);
if (message.getDestination() == CTRL_CLIENT && message.getCorrelationId().equals(correlationId)) {
buffer.add((CtrlResponse) message);
}
}
}
return DumpStateManager.fromResponsesList(buffer);
} finally {
consumer.close();
}
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
use of org.openkilda.messaging.ctrl.CtrlRequest in project open-kilda by telstra.
the class RouteAction method handle.
@Override
protected void handle() throws MessageFormatException, JsonProcessingException {
KafkaMessage input = new KafkaMessage(getTuple());
Message payload = input.getPayload();
if (!(payload instanceof CtrlRequest)) {
getLogger().debug(String.format("Skip foreign message (correlation-id: %s timestamp: %s)", payload.getCorrelationId(), payload.getTimestamp()));
return;
}
handleMessage((CtrlRequest) payload);
}
use of org.openkilda.messaging.ctrl.CtrlRequest in project open-kilda by telstra.
the class CacheTopologyTest method sendNetworkDumpRequest.
private static void sendNetworkDumpRequest() throws IOException, InterruptedException {
CtrlRequest request = new CtrlRequest("cachetopology/cache", new RequestData("dump"), System.currentTimeMillis(), UUID.randomUUID().toString(), Destination.WFM_CTRL);
sendMessage(request, topology.getConfig().getKafkaCtrlTopic());
}
Aggregations