use of org.openkilda.messaging.ctrl.RequestData 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.RequestData 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.RequestData 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.RequestData in project open-kilda by telstra.
the class CtrlAction method handle.
@Override
protected void handle() throws MessageFormatException, UnsupportedActionException {
String source = getTuple().getSourceComponent();
if (!source.equals(AbstractTopology.BOLT_ID_CTRL_ROUTE)) {
return;
}
isHandled = true;
AbstractAction action;
RouteMessage message = new RouteMessage(getTuple());
RequestData payload = message.getPayload();
switch(payload.getAction()) {
case "list":
action = new ListAction(this, message);
break;
case "dump":
action = new DumpStateAction(this, message);
break;
case "clearState":
action = new ClearStateAction(this, message);
break;
case "dumpBySwitch":
action = new DumpBySwitchStateAction(this, message);
break;
case "dumpResorceCache":
action = new DumpByResorceCacheAction(this, message);
break;
default:
throw new UnsupportedActionException(payload.getAction());
}
action.run();
}
use of org.openkilda.messaging.ctrl.RequestData 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