Search in sources :

Example 1 with FlowUpdateRequest

use of org.openkilda.messaging.command.flow.FlowUpdateRequest in project open-kilda by telstra.

the class CrudBolt method handleUpdateRequest.

private void handleUpdateRequest(CommandMessage message, Tuple tuple) throws IOException {
    Flow requestedFlow = ((FlowUpdateRequest) message.getData()).getPayload();
    ImmutablePair<PathInfoData, PathInfoData> path;
    try {
        new FlowValidator(flowCache).checkFlowForEndpointConflicts(requestedFlow);
        path = pathComputer.getPath(requestedFlow, Strategy.COST);
        logger.info("Updated flow path: {}", path);
    } catch (FlowValidationException e) {
        throw new MessageException(message.getCorrelationId(), System.currentTimeMillis(), ErrorType.UPDATE_FAILURE, "Could not update flow", e.getMessage());
    } catch (UnroutablePathException e) {
        throw new MessageException(message.getCorrelationId(), System.currentTimeMillis(), ErrorType.UPDATE_FAILURE, "Could not update flow", "Path was not found");
    }
    ImmutablePair<Flow, Flow> flow = flowCache.updateFlow(requestedFlow, path);
    logger.info("Updated flow: {}", flow);
    FlowInfoData data = new FlowInfoData(requestedFlow.getFlowId(), flow, FlowOperation.UPDATE, message.getCorrelationId());
    InfoMessage infoMessage = new InfoMessage(data, System.currentTimeMillis(), message.getCorrelationId());
    Values topology = new Values(MAPPER.writeValueAsString(infoMessage));
    outputCollector.emit(StreamType.UPDATE.toString(), tuple, topology);
    Values northbound = new Values(new InfoMessage(new FlowResponse(buildFlowResponse(flow)), message.getTimestamp(), message.getCorrelationId(), Destination.NORTHBOUND));
    outputCollector.emit(StreamType.RESPONSE.toString(), tuple, northbound);
}
Also used : FlowUpdateRequest(org.openkilda.messaging.command.flow.FlowUpdateRequest) Values(org.apache.storm.tuple.Values) UnroutablePathException(org.openkilda.pce.provider.UnroutablePathException) Flow(org.openkilda.messaging.model.Flow) PathInfoData(org.openkilda.messaging.info.event.PathInfoData) FlowValidationException(org.openkilda.wfm.topology.flow.validation.FlowValidationException) MessageException(org.openkilda.messaging.error.MessageException) InfoMessage(org.openkilda.messaging.info.InfoMessage) FlowValidator(org.openkilda.wfm.topology.flow.validation.FlowValidator)

Example 2 with FlowUpdateRequest

use of org.openkilda.messaging.command.flow.FlowUpdateRequest in project open-kilda by telstra.

the class SplitterBolt method execute.

/**
 * {@inheritDoc}
 */
@Override
public void execute(Tuple tuple) {
    String request = tuple.getString(0);
    Values values = new Values(request);
    try {
        Message message = tryMessage(request);
        if (message == null || !Destination.WFM.equals(message.getDestination()) || !(message instanceof CommandMessage || message instanceof InfoMessage)) {
            return;
        }
        logger.debug("Request tuple={}", tuple);
        /*
             * First, try to see if this is a PUSH / UNPUSH (smaller code base vs other).
             * NB: InfoMessage was used since it has the relevant attributes/properties for
             * pushing the flow.
             */
        if (message instanceof InfoMessage) {
            InfoData data = ((InfoMessage) message).getData();
            if (data instanceof FlowInfoData) {
                FlowInfoData fid = (FlowInfoData) data;
                String flowId = fid.getFlowId();
                values = new Values(message, flowId);
                logger.info("Flow {} message: operation={} values={}", flowId, fid.getOperation(), values);
                if (fid.getOperation() == FlowOperation.PUSH) {
                    outputCollector.emit(StreamType.PUSH.toString(), tuple, values);
                } else if (fid.getOperation() == FlowOperation.UNPUSH) {
                    outputCollector.emit(StreamType.UNPUSH.toString(), tuple, values);
                } else {
                    logger.warn("Skip undefined FlowInfoData Operation {}: {}={}", fid.getOperation(), Utils.CORRELATION_ID, message.getCorrelationId());
                }
            } else {
                logger.warn("Skip undefined InfoMessage: {}={}", Utils.CORRELATION_ID, message.getCorrelationId());
            }
            return;
        }
        /*
             * Second, it isn't an InfoMessage, so it must be a CommandMessage.
             */
        CommandData data = ((CommandMessage) message).getData();
        if (data instanceof FlowCreateRequest) {
            String flowId = ((FlowCreateRequest) data).getPayload().getFlowId();
            logger.info("Flow {} create message: values={}", flowId, values);
            values = new Values(message, flowId);
            outputCollector.emit(StreamType.CREATE.toString(), tuple, values);
        } else if (data instanceof FlowDeleteRequest) {
            String flowId = ((FlowDeleteRequest) data).getPayload().getFlowId();
            logger.info("Flow {} delete message: values={}", flowId, values);
            values = new Values(message, flowId);
            outputCollector.emit(StreamType.DELETE.toString(), tuple, values);
        } else if (data instanceof FlowUpdateRequest) {
            String flowId = ((FlowUpdateRequest) data).getPayload().getFlowId();
            logger.info("Flow {} update message: values={}", flowId, values);
            values = new Values(message, flowId);
            outputCollector.emit(StreamType.UPDATE.toString(), tuple, values);
        } else if (data instanceof FlowRestoreRequest) {
            String flowId = ((FlowRestoreRequest) data).getPayload().getLeft().getFlowId();
            logger.info("Flow {} restore message: values={}", flowId, values);
            values = new Values(message, flowId);
            outputCollector.emit(StreamType.RESTORE.toString(), tuple, values);
        } else if (data instanceof FlowRerouteRequest) {
            String flowId = ((FlowRerouteRequest) data).getPayload().getFlowId();
            logger.info("Flow {} reroute message: values={}", flowId, values);
            values = new Values(message, flowId);
            outputCollector.emit(StreamType.REROUTE.toString(), tuple, values);
        } else if (data instanceof FlowStatusRequest) {
            String flowId = ((FlowStatusRequest) data).getPayload().getId();
            logger.info("Flow {} status message: values={}", flowId, values);
            values = new Values(message, flowId);
            outputCollector.emit(StreamType.STATUS.toString(), tuple, values);
        } else if (data instanceof FlowGetRequest) {
            String flowId = ((FlowGetRequest) data).getPayload().getId();
            logger.info("Flow {} get message: values={}", flowId, values);
            values = new Values(message, flowId);
            outputCollector.emit(StreamType.READ.toString(), tuple, values);
        } else if (data instanceof FlowsGetRequest) {
            logger.info("Flows get message: values={}", values);
            values = new Values(message, null);
            outputCollector.emit(StreamType.READ.toString(), tuple, values);
        } else if (data instanceof FlowPathRequest) {
            String flowId = ((FlowPathRequest) data).getPayload().getId();
            logger.info("Flow {} path message: values={}", flowId, values);
            values = new Values(message, flowId);
            outputCollector.emit(StreamType.PATH.toString(), tuple, values);
        } else if (data instanceof FlowCacheSyncRequest) {
            logger.info("FlowCacheSyncRequest: values={}", values);
            values = new Values(message, null);
            outputCollector.emit(StreamType.CACHE_SYNC.toString(), tuple, values);
        } else {
            logger.debug("Skip undefined CommandMessage: {}={}", Utils.CORRELATION_ID, message.getCorrelationId());
        }
    /*
 * (crimi) This was commented out since the parsing of the message is handled in tryMessage.
 * Due to refactoring the kafka topics, it appears more messages are coming to the splitter than
 * originally desinged for.
 *
 * TODO: Fix the cause of excess messages coming to the splitter.
 */
    // 
    // } catch (IOException exception) {
    // String message = String.format("Could not deserialize message: %s", request);
    // logger.error("{}", message, exception);
    // 
    // ErrorMessage errorMessage = new ErrorMessage(
    // new ErrorData(ErrorType.REQUEST_INVALID, message, exception.getMessage()),
    // System.currentTimeMillis(), Utils.SYSTEM_CORRELATION_ID, Destination.NORTHBOUND);
    // 
    // values = new Values(errorMessage, ErrorType.INTERNAL_ERROR);
    // outputCollector.emit(StreamType.ERROR.toString(), tuple, values);
    } finally {
        logger.debug("Splitter message ack: component={}, stream={}, tuple={}, values={}", tuple.getSourceComponent(), tuple.getSourceStreamId(), tuple, values);
        outputCollector.ack(tuple);
    }
}
Also used : FlowsGetRequest(org.openkilda.messaging.command.flow.FlowsGetRequest) FlowInfoData(org.openkilda.messaging.info.flow.FlowInfoData) FlowUpdateRequest(org.openkilda.messaging.command.flow.FlowUpdateRequest) InfoMessage(org.openkilda.messaging.info.InfoMessage) Message(org.openkilda.messaging.Message) CommandMessage(org.openkilda.messaging.command.CommandMessage) FlowDeleteRequest(org.openkilda.messaging.command.flow.FlowDeleteRequest) Values(org.apache.storm.tuple.Values) FlowCreateRequest(org.openkilda.messaging.command.flow.FlowCreateRequest) FlowGetRequest(org.openkilda.messaging.command.flow.FlowGetRequest) FlowRestoreRequest(org.openkilda.messaging.command.flow.FlowRestoreRequest) CommandMessage(org.openkilda.messaging.command.CommandMessage) InfoMessage(org.openkilda.messaging.info.InfoMessage) InfoData(org.openkilda.messaging.info.InfoData) FlowInfoData(org.openkilda.messaging.info.flow.FlowInfoData) FlowStatusRequest(org.openkilda.messaging.command.flow.FlowStatusRequest) FlowRerouteRequest(org.openkilda.messaging.command.flow.FlowRerouteRequest) CommandData(org.openkilda.messaging.command.CommandData) FlowPathRequest(org.openkilda.messaging.command.flow.FlowPathRequest) FlowCacheSyncRequest(org.openkilda.messaging.command.flow.FlowCacheSyncRequest)

Example 3 with FlowUpdateRequest

use of org.openkilda.messaging.command.flow.FlowUpdateRequest in project open-kilda by telstra.

the class KafkaMessageConsumer method receive.

/**
 * Receives messages from WorkFlowManager queue.
 *
 * @param record the message object instance
 */
@KafkaListener(topics = "kilda-test")
public void receive(final String record) {
    logger.debug("message received: {}", record);
    try {
        Message message = MAPPER.readValue(record, Message.class);
        if (message.getDestination() == null || Destination.TOPOLOGY_ENGINE.equals(message.getDestination())) {
            if (message instanceof CommandMessage) {
                CommandData data = ((CommandMessage) message).getData();
                if (data instanceof FlowCreateRequest) {
                    FlowPayload payload = ((FlowCreateRequest) data).getPayload();
                    logger.debug("FlowCreateRequest: {}", payload);
                    Set<CommandMessage> commands = flowService.createFlow(payload, message.getCorrelationId());
                    for (CommandMessage response : commands) {
                        kafkaMessageProducer.send(topic, response);
                    }
                    logger.debug("Response send, {}={}", CORRELATION_ID, message.getCorrelationId());
                } else if (data instanceof FlowDeleteRequest) {
                    FlowIdStatusPayload payload = ((FlowDeleteRequest) data).getPayload();
                    logger.debug("FlowDeleteRequest: {}", payload);
                    Set<CommandMessage> commands = flowService.deleteFlow(payload, message.getCorrelationId());
                    for (CommandMessage response : commands) {
                        kafkaMessageProducer.send(topic, response);
                    }
                    logger.debug("Response send, {}={}", CORRELATION_ID, message.getCorrelationId());
                } else if (data instanceof FlowUpdateRequest) {
                    FlowPayload payload = ((FlowUpdateRequest) data).getPayload();
                    logger.debug("FlowUpdateRequest: {}", payload);
                    Set<CommandMessage> commands = flowService.updateFlow(payload, message.getCorrelationId());
                    for (CommandMessage response : commands) {
                        kafkaMessageProducer.send(topic, response);
                    }
                    logger.debug("Response send, {}={}", CORRELATION_ID, message.getCorrelationId());
                } else if (data instanceof FlowGetRequest) {
                    FlowIdStatusPayload payload = ((FlowGetRequest) data).getPayload();
                    logger.debug("FlowGetRequest: {}", payload);
                    InfoMessage response = flowService.getFlow(payload, message.getCorrelationId());
                    kafkaMessageProducer.send(topic, response);
                    logger.debug("Response send, {}={}", CORRELATION_ID, message.getCorrelationId());
                } else if (data instanceof FlowsGetRequest) {
                    FlowIdStatusPayload payload = ((FlowsGetRequest) data).getPayload();
                    logger.debug("FlowsGetRequest: {}", payload);
                    InfoMessage response = flowService.getFlows(payload, message.getCorrelationId());
                    kafkaMessageProducer.send(topic, response);
                    logger.debug("Response send, {}={}", CORRELATION_ID, message.getCorrelationId());
                } else if (data instanceof FlowPathRequest) {
                    FlowIdStatusPayload payload = ((FlowPathRequest) data).getPayload();
                    logger.debug("FlowPathRequest: {}", payload);
                    InfoMessage response = flowService.pathFlow(payload, message.getCorrelationId());
                    kafkaMessageProducer.send(topic, response);
                    logger.debug("Response send, {}={}", CORRELATION_ID, message.getCorrelationId());
                } else {
                    logger.error("Unexpected command message data type: {}", data);
                }
            } else if (message instanceof InfoMessage) {
                InfoData data = ((InfoMessage) message).getData();
                if (data instanceof SwitchInfoData) {
                    SwitchInfoData payload = (SwitchInfoData) data;
                    switch(payload.getState()) {
                        case ADDED:
                            switchService.add(payload);
                            break;
                        case ACTIVATED:
                            switchService.activate(payload);
                            break;
                        case DEACTIVATED:
                            switchService.deactivate(payload);
                            break;
                        case REMOVED:
                            switchService.remove(payload);
                            break;
                        case CHANGED:
                        default:
                            break;
                    }
                } else if (data instanceof IslInfoData) {
                    IslInfoData payload = (IslInfoData) data;
                    islService.discoverLink(payload);
                } else {
                    logger.debug("Unexpected info message data type: {}", data);
                }
            }
        } else {
            logger.debug("Skip message: {}", message);
        }
    } catch (IOException exception) {
        logger.error("Could not deserialize message: {}", record, exception);
    }
}
Also used : FlowsGetRequest(org.openkilda.messaging.command.flow.FlowsGetRequest) Set(java.util.Set) FlowUpdateRequest(org.openkilda.messaging.command.flow.FlowUpdateRequest) InfoMessage(org.openkilda.messaging.info.InfoMessage) Message(org.openkilda.messaging.Message) CommandMessage(org.openkilda.messaging.command.CommandMessage) FlowIdStatusPayload(org.openkilda.messaging.payload.flow.FlowIdStatusPayload) FlowDeleteRequest(org.openkilda.messaging.command.flow.FlowDeleteRequest) FlowCreateRequest(org.openkilda.messaging.command.flow.FlowCreateRequest) FlowGetRequest(org.openkilda.messaging.command.flow.FlowGetRequest) IOException(java.io.IOException) CommandMessage(org.openkilda.messaging.command.CommandMessage) FlowPayload(org.openkilda.messaging.payload.flow.FlowPayload) InfoMessage(org.openkilda.messaging.info.InfoMessage) IslInfoData(org.openkilda.messaging.info.event.IslInfoData) SwitchInfoData(org.openkilda.messaging.info.event.SwitchInfoData) InfoData(org.openkilda.messaging.info.InfoData) IslInfoData(org.openkilda.messaging.info.event.IslInfoData) CommandData(org.openkilda.messaging.command.CommandData) SwitchInfoData(org.openkilda.messaging.info.event.SwitchInfoData) FlowPathRequest(org.openkilda.messaging.command.flow.FlowPathRequest) KafkaListener(org.springframework.kafka.annotation.KafkaListener)

Example 4 with FlowUpdateRequest

use of org.openkilda.messaging.command.flow.FlowUpdateRequest in project open-kilda by telstra.

the class FlowServiceImpl method updateFlow.

/**
 * {@inheritDoc}
 */
@Override
public FlowPayload updateFlow(final FlowPayload flow, final String correlationId) {
    LOGGER.debug("Update flow: {}={}", CORRELATION_ID, correlationId);
    FlowUpdateRequest data = new FlowUpdateRequest(Converter.buildFlowByFlowPayload(flow));
    CommandMessage request = new CommandMessage(data, System.currentTimeMillis(), correlationId, Destination.WFM);
    messageConsumer.clear();
    messageProducer.send(topic, request);
    Message message = (Message) messageConsumer.poll(correlationId);
    FlowResponse response = (FlowResponse) validateInfoMessage(request, message, correlationId);
    return Converter.buildFlowPayloadByFlow(response.getPayload());
}
Also used : FlowUpdateRequest(org.openkilda.messaging.command.flow.FlowUpdateRequest) InfoMessage(org.openkilda.messaging.info.InfoMessage) Message(org.openkilda.messaging.Message) CommandMessage(org.openkilda.messaging.command.CommandMessage) FlowResponse(org.openkilda.messaging.info.flow.FlowResponse) CommandMessage(org.openkilda.messaging.command.CommandMessage)

Example 5 with FlowUpdateRequest

use of org.openkilda.messaging.command.flow.FlowUpdateRequest in project open-kilda by telstra.

the class FlowTopologyTest method updateFlow.

private Flow updateFlow(final String flowId) throws IOException {
    System.out.println("NORTHBOUND: Update flow");
    Flow flowPayload = new Flow(flowId, 10000, false, "", "test-switch", 1, 2, "test-switch", 1, 2);
    FlowUpdateRequest commandData = new FlowUpdateRequest(flowPayload);
    CommandMessage message = new CommandMessage(commandData, 0, "update-flow", Destination.WFM);
    // sendNorthboundMessage(message);
    sendFlowMessage(message);
    return flowPayload;
}
Also used : FlowUpdateRequest(org.openkilda.messaging.command.flow.FlowUpdateRequest) RemoveFlow(org.openkilda.messaging.command.flow.RemoveFlow) Flow(org.openkilda.messaging.model.Flow) InstallOneSwitchFlow(org.openkilda.messaging.command.flow.InstallOneSwitchFlow) CommandMessage(org.openkilda.messaging.command.CommandMessage)

Aggregations

FlowUpdateRequest (org.openkilda.messaging.command.flow.FlowUpdateRequest)5 CommandMessage (org.openkilda.messaging.command.CommandMessage)4 InfoMessage (org.openkilda.messaging.info.InfoMessage)4 Message (org.openkilda.messaging.Message)3 Values (org.apache.storm.tuple.Values)2 CommandData (org.openkilda.messaging.command.CommandData)2 FlowCreateRequest (org.openkilda.messaging.command.flow.FlowCreateRequest)2 FlowDeleteRequest (org.openkilda.messaging.command.flow.FlowDeleteRequest)2 FlowGetRequest (org.openkilda.messaging.command.flow.FlowGetRequest)2 FlowPathRequest (org.openkilda.messaging.command.flow.FlowPathRequest)2 FlowsGetRequest (org.openkilda.messaging.command.flow.FlowsGetRequest)2 InfoData (org.openkilda.messaging.info.InfoData)2 Flow (org.openkilda.messaging.model.Flow)2 IOException (java.io.IOException)1 Set (java.util.Set)1 FlowCacheSyncRequest (org.openkilda.messaging.command.flow.FlowCacheSyncRequest)1 FlowRerouteRequest (org.openkilda.messaging.command.flow.FlowRerouteRequest)1 FlowRestoreRequest (org.openkilda.messaging.command.flow.FlowRestoreRequest)1 FlowStatusRequest (org.openkilda.messaging.command.flow.FlowStatusRequest)1 InstallOneSwitchFlow (org.openkilda.messaging.command.flow.InstallOneSwitchFlow)1