Search in sources :

Example 1 with CtrlRequest

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());
}
Also used : InfoMessage(org.openkilda.messaging.info.InfoMessage) Message(org.openkilda.messaging.Message) CommandMessage(org.openkilda.messaging.command.CommandMessage) CtrlRequest(org.openkilda.messaging.ctrl.CtrlRequest) RequestData(org.openkilda.messaging.ctrl.RequestData) CtrlResponse(org.openkilda.messaging.ctrl.CtrlResponse) AbstractStormTest(org.openkilda.wfm.AbstractStormTest)

Example 2 with CtrlRequest

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());
}
Also used : InfoMessage(org.openkilda.messaging.info.InfoMessage) Message(org.openkilda.messaging.Message) CommandMessage(org.openkilda.messaging.command.CommandMessage) CtrlRequest(org.openkilda.messaging.ctrl.CtrlRequest) RequestData(org.openkilda.messaging.ctrl.RequestData) CtrlResponse(org.openkilda.messaging.ctrl.CtrlResponse)

Example 3 with CtrlRequest

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;
    }
}
Also used : Message(org.openkilda.messaging.Message) CtrlRequest(org.openkilda.messaging.ctrl.CtrlRequest) ArrayList(java.util.ArrayList) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) CtrlResponse(org.openkilda.messaging.ctrl.CtrlResponse) RecordMetadata(org.apache.kafka.clients.producer.RecordMetadata) RequestData(org.openkilda.messaging.ctrl.RequestData) TopicPartition(org.apache.kafka.common.TopicPartition) NoOpConsumerRebalanceListener(org.apache.kafka.clients.consumer.internals.NoOpConsumerRebalanceListener)

Example 4 with CtrlRequest

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);
}
Also used : Message(org.openkilda.messaging.Message) KafkaMessage(org.openkilda.wfm.protocol.KafkaMessage) CtrlRequest(org.openkilda.messaging.ctrl.CtrlRequest) KafkaMessage(org.openkilda.wfm.protocol.KafkaMessage)

Example 5 with CtrlRequest

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());
}
Also used : CtrlRequest(org.openkilda.messaging.ctrl.CtrlRequest) RequestData(org.openkilda.messaging.ctrl.RequestData)

Aggregations

CtrlRequest (org.openkilda.messaging.ctrl.CtrlRequest)9 Message (org.openkilda.messaging.Message)8 RequestData (org.openkilda.messaging.ctrl.RequestData)8 CtrlResponse (org.openkilda.messaging.ctrl.CtrlResponse)7 CommandMessage (org.openkilda.messaging.command.CommandMessage)6 InfoMessage (org.openkilda.messaging.info.InfoMessage)6 AbstractStormTest (org.openkilda.wfm.AbstractStormTest)4 DumpStateResponseData (org.openkilda.messaging.ctrl.DumpStateResponseData)3 ResponseData (org.openkilda.messaging.ctrl.ResponseData)3 ErrorMessage (org.openkilda.messaging.error.ErrorMessage)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 ExecutionException (java.util.concurrent.ExecutionException)1 NoOpConsumerRebalanceListener (org.apache.kafka.clients.consumer.internals.NoOpConsumerRebalanceListener)1 RecordMetadata (org.apache.kafka.clients.producer.RecordMetadata)1 TopicPartition (org.apache.kafka.common.TopicPartition)1 Ignore (org.junit.Ignore)1 Test (org.junit.Test)1 KafkaMessage (org.openkilda.wfm.protocol.KafkaMessage)1