Search in sources :

Example 86 with InfoMessage

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

the class KafkaHealthCheckMessageConsumer method receive.

/**
 * Receives messages from WorkFlowManager queue.
 *
 * @param record the message object instance
 */
@KafkaListener(id = "northbound-listener-health-check", topics = Topic.HEALTH_CHECK)
public void receive(final String record) {
    try {
        logger.trace("message received");
        Message message = MAPPER.readValue(record, Message.class);
        if (Destination.NORTHBOUND.equals(message.getDestination())) {
            logger.debug("message received: {}", record);
            InfoMessage info = (InfoMessage) message;
            HealthCheckInfoData healthCheck = (HealthCheckInfoData) info.getData();
            messages.put(healthCheck.getId(), healthCheck);
        } else {
            logger.trace("Skip message: {}", message);
        }
    } catch (IOException exception) {
        logger.error("Could not deserialize message: {}", record, exception);
    }
}
Also used : HealthCheckInfoData(org.openkilda.messaging.info.discovery.HealthCheckInfoData) InfoMessage(org.openkilda.messaging.info.InfoMessage) Message(org.openkilda.messaging.Message) InfoMessage(org.openkilda.messaging.info.InfoMessage) IOException(java.io.IOException) KafkaListener(org.springframework.kafka.annotation.KafkaListener)

Example 87 with InfoMessage

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

the class FlowServiceImpl method flowPushUnpush.

/**
 * There are only minor differences between push and unpush .. this utility function helps
 */
private BatchResults flowPushUnpush(List<FlowInfoData> externalFlows, String correlationId, FlowOperation op) {
    LOGGER.debug("Flow {}: {}={}", op, CORRELATION_ID, correlationId);
    LOGGER.debug("Size of list: {}", externalFlows.size());
    // First, send them all, then wait for all the responses.
    // Send the command to both Flow Topology and to TE
    messageConsumer.clear();
    // used for error reporting, if needed
    ArrayList<InfoMessage> flowRequests = new ArrayList<>();
    // used for error reporting, if needed
    ArrayList<InfoMessage> teRequests = new ArrayList<>();
    for (int i = 0; i < externalFlows.size(); i++) {
        FlowInfoData data = externalFlows.get(i);
        // <-- this is what determines PUSH / UNPUSH
        data.setOperation(op);
        String flowCorrelation = correlationId + "-FLOW-" + i;
        InfoMessage flowRequest = new InfoMessage(data, System.currentTimeMillis(), flowCorrelation, Destination.WFM);
        flowRequests.add(flowRequest);
        messageProducer.send(topic, flowRequest);
        String teCorrelation = correlationId + "-TE-" + i;
        InfoMessage teRequest = new InfoMessage(data, System.currentTimeMillis(), teCorrelation, Destination.TOPOLOGY_ENGINE);
        teRequests.add(teRequest);
        messageProducer.send(topoEngTopic, teRequest);
    }
    int flow_success = 0;
    int flow_failure = 0;
    int te_success = 0;
    int te_failure = 0;
    List<String> msgs = new ArrayList<>();
    msgs.add("Total Flows Received: " + externalFlows.size());
    for (int i = 0; i < externalFlows.size(); i++) {
        String flowCorrelation = correlationId + "-FLOW-" + i;
        String teCorrelation = correlationId + "-TE-" + i;
        FlowState expectedState = (op == FlowOperation.PUSH) ? FlowState.UP : FlowState.DOWN;
        try {
            Message flowMessage = (Message) messageConsumer.poll(flowCorrelation);
            FlowStatusResponse response = (FlowStatusResponse) validateInfoMessage(flowRequests.get(i), flowMessage, correlationId);
            FlowIdStatusPayload status = response.getPayload();
            if (status.getStatus() == expectedState) {
                flow_success++;
            } else {
                msgs.add("FAILURE (FlowTopo): Flow " + status.getId() + " NOT in " + expectedState + " state: state = " + status.getStatus());
                flow_failure++;
            }
        } catch (Exception e) {
            msgs.add("EXCEPTION in Flow Topology Response: " + e.getMessage());
            flow_failure++;
        }
        try {
            // TODO: this code block is mostly the same as the previous: consolidate.
            Message teMessage = (Message) messageConsumer.poll(teCorrelation);
            FlowStatusResponse response = (FlowStatusResponse) validateInfoMessage(flowRequests.get(i), teMessage, correlationId);
            FlowIdStatusPayload status = response.getPayload();
            if (status.getStatus() == expectedState) {
                te_success++;
            } else {
                msgs.add("FAILURE (TE): Flow " + status.getId() + " NOT in " + expectedState + " state: state = " + status.getStatus());
                te_failure++;
            }
        } catch (Exception e) {
            msgs.add("EXCEPTION in Topology Engine Response: " + e.getMessage());
            te_failure++;
        }
    }
    BatchResults result = new BatchResults(flow_failure + te_failure, flow_success + te_success, msgs.stream().toArray(String[]::new));
    LOGGER.debug("Returned: ", result);
    return result;
}
Also used : FlowInfoData(org.openkilda.messaging.info.flow.FlowInfoData) FlowState(org.openkilda.messaging.payload.flow.FlowState) FlowStatusResponse(org.openkilda.messaging.info.flow.FlowStatusResponse) InfoMessage(org.openkilda.messaging.info.InfoMessage) Message(org.openkilda.messaging.Message) CommandMessage(org.openkilda.messaging.command.CommandMessage) FlowIdStatusPayload(org.openkilda.messaging.payload.flow.FlowIdStatusPayload) ArrayList(java.util.ArrayList) BatchResults(org.openkilda.northbound.service.BatchResults) InfoMessage(org.openkilda.messaging.info.InfoMessage)

Aggregations

InfoMessage (org.openkilda.messaging.info.InfoMessage)87 Test (org.junit.Test)34 Values (org.apache.storm.tuple.Values)27 CommandMessage (org.openkilda.messaging.command.CommandMessage)21 Flow (org.openkilda.messaging.model.Flow)21 Message (org.openkilda.messaging.Message)20 ErrorMessage (org.openkilda.messaging.error.ErrorMessage)19 AbstractStormTest (org.openkilda.wfm.AbstractStormTest)19 RemoveFlow (org.openkilda.messaging.command.flow.RemoveFlow)13 InstallOneSwitchFlow (org.openkilda.messaging.command.flow.InstallOneSwitchFlow)12 FlowIdStatusPayload (org.openkilda.messaging.payload.flow.FlowIdStatusPayload)12 IOException (java.io.IOException)9 SwitchInfoData (org.openkilda.messaging.info.event.SwitchInfoData)9 ErrorData (org.openkilda.messaging.error.ErrorData)8 InfoData (org.openkilda.messaging.info.InfoData)8 PortInfoData (org.openkilda.messaging.info.event.PortInfoData)8 FlowResponse (org.openkilda.messaging.info.flow.FlowResponse)8 FlowStatusResponse (org.openkilda.messaging.info.flow.FlowStatusResponse)8 NetworkInfoData (org.openkilda.messaging.info.discovery.NetworkInfoData)7 IslInfoData (org.openkilda.messaging.info.event.IslInfoData)7