Search in sources :

Example 6 with InfoMessage

use of org.openkilda.messaging.info.InfoMessage 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 7 with InfoMessage

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

the class CrudBolt method handleCreateRequest.

private void handleCreateRequest(CommandMessage message, Tuple tuple) throws IOException {
    Flow requestedFlow = ((FlowCreateRequest) message.getData()).getPayload();
    ImmutablePair<PathInfoData, PathInfoData> path;
    try {
        new FlowValidator(flowCache).checkFlowForEndpointConflicts(requestedFlow);
        path = pathComputer.getPath(requestedFlow, Strategy.COST);
        logger.info("Created flow path: {}", path);
    } catch (FlowValidationException e) {
        throw new MessageException(message.getCorrelationId(), System.currentTimeMillis(), ErrorType.CREATION_FAILURE, "Could not create flow", e.getMessage());
    } catch (UnroutablePathException e) {
        throw new MessageException(message.getCorrelationId(), System.currentTimeMillis(), ErrorType.CREATION_FAILURE, "Could not create flow", "Path was not found");
    }
    ImmutablePair<Flow, Flow> flow = flowCache.createFlow(requestedFlow, path);
    logger.info("Created flow: {}", flow);
    FlowInfoData data = new FlowInfoData(requestedFlow.getFlowId(), flow, FlowOperation.CREATE, message.getCorrelationId());
    InfoMessage infoMessage = new InfoMessage(data, System.currentTimeMillis(), message.getCorrelationId());
    Values topology = new Values(MAPPER.writeValueAsString(infoMessage));
    outputCollector.emit(StreamType.CREATE.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 : FlowCreateRequest(org.openkilda.messaging.command.flow.FlowCreateRequest) 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 8 with InfoMessage

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

the class CrudBolt method handleDeleteRequest.

private void handleDeleteRequest(String flowId, CommandMessage message, Tuple tuple) throws IOException {
    ImmutablePair<Flow, Flow> flow = flowCache.deleteFlow(flowId);
    logger.info("Deleted flow: {}", flow);
    FlowInfoData data = new FlowInfoData(flowId, flow, FlowOperation.DELETE, message.getCorrelationId());
    InfoMessage infoMessage = new InfoMessage(data, System.currentTimeMillis(), message.getCorrelationId());
    Values topology = new Values(MAPPER.writeValueAsString(infoMessage));
    outputCollector.emit(StreamType.DELETE.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 : InfoMessage(org.openkilda.messaging.info.InfoMessage) Values(org.apache.storm.tuple.Values) Flow(org.openkilda.messaging.model.Flow)

Example 9 with InfoMessage

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

the class CrudBolt method handleRerouteRequest.

private void handleRerouteRequest(CommandMessage message, Tuple tuple) throws IOException {
    FlowRerouteRequest request = (FlowRerouteRequest) message.getData();
    Flow requestedFlow = request.getPayload();
    final String flowId = requestedFlow.getFlowId();
    ImmutablePair<Flow, Flow> flow;
    logger.debug("Handling reroute request with correlationId {}", message.getCorrelationId());
    switch(request.getOperation()) {
        case UPDATE:
            flow = flowCache.getFlow(flowId);
            try {
                ImmutablePair<PathInfoData, PathInfoData> path = pathComputer.getPath(flow.getLeft(), Strategy.COST);
                logger.info("Rerouted flow path: {}", path);
                // no need to emit changes if path wasn't changed and flow is active.
                if (!path.getLeft().equals(flow.getLeft().getFlowPath()) || !isFlowActive(flow)) {
                    flow.getLeft().setState(FlowState.DOWN);
                    flow.getRight().setState(FlowState.DOWN);
                    flow = flowCache.updateFlow(flow.getLeft(), path);
                    logger.info("Rerouted flow: {}", flow);
                    FlowInfoData data = new FlowInfoData(flowId, 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);
                } else {
                    logger.debug("Reroute was unsuccessful: can't find new path");
                }
                logger.debug("Sending response to NB. Correlation id {}", message.getCorrelationId());
                Values response = new Values(new InfoMessage(new FlowPathResponse(flow.left.getFlowPath()), message.getTimestamp(), message.getCorrelationId(), Destination.NORTHBOUND));
                outputCollector.emit(StreamType.RESPONSE.toString(), tuple, response);
            } catch (UnroutablePathException e) {
                flow.getLeft().setState(FlowState.DOWN);
                flow.getRight().setState(FlowState.DOWN);
                throw new MessageException(message.getCorrelationId(), System.currentTimeMillis(), ErrorType.UPDATE_FAILURE, "Could not reroute flow", "Path was not found");
            }
            break;
        case CREATE:
            flow = flowCache.getFlow(flowId);
            logger.info("State flow: {}={}", flow.getLeft().getFlowId(), FlowState.UP);
            flow.getLeft().setState(FlowState.UP);
            flow.getRight().setState(FlowState.UP);
            break;
        case DELETE:
            flow = flowCache.getFlow(flowId);
            logger.info("State flow: {}={}", flow.getLeft().getFlowId(), FlowState.DOWN);
            flow.getLeft().setState(FlowState.DOWN);
            flow.getRight().setState(FlowState.DOWN);
            break;
        default:
            logger.warn("Flow {} undefined reroute operation", request.getOperation());
            break;
    }
}
Also used : PathInfoData(org.openkilda.messaging.info.event.PathInfoData) MessageException(org.openkilda.messaging.error.MessageException) InfoMessage(org.openkilda.messaging.info.InfoMessage) Values(org.apache.storm.tuple.Values) FlowRerouteRequest(org.openkilda.messaging.command.flow.FlowRerouteRequest) UnroutablePathException(org.openkilda.pce.provider.UnroutablePathException) Flow(org.openkilda.messaging.model.Flow)

Example 10 with InfoMessage

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

the class CrudBolt method execute.

/**
 * {@inheritDoc}
 */
@Override
public void execute(Tuple tuple) {
    if (CtrlAction.boltHandlerEntrance(this, tuple))
        return;
    logger.trace("Flow Cache before: {}", flowCache);
    ComponentType componentId = ComponentType.valueOf(tuple.getSourceComponent());
    StreamType streamId = StreamType.valueOf(tuple.getSourceStreamId());
    String flowId = tuple.getStringByField(Utils.FLOW_ID);
    String correlationId = Utils.DEFAULT_CORRELATION_ID;
    try {
        logger.debug("Request tuple={}", tuple);
        switch(componentId) {
            case SPLITTER_BOLT:
                Message msg = (Message) tuple.getValueByField(AbstractTopology.MESSAGE_FIELD);
                correlationId = msg.getCorrelationId();
                CommandMessage cmsg = (msg instanceof CommandMessage) ? (CommandMessage) msg : null;
                InfoMessage imsg = (msg instanceof InfoMessage) ? (InfoMessage) msg : null;
                logger.info("Flow request: {}={}, {}={}, component={}, stream={}", Utils.CORRELATION_ID, correlationId, Utils.FLOW_ID, flowId, componentId, streamId);
                switch(streamId) {
                    case CREATE:
                        handleCreateRequest(cmsg, tuple);
                        break;
                    case UPDATE:
                        handleUpdateRequest(cmsg, tuple);
                        break;
                    case DELETE:
                        handleDeleteRequest(flowId, cmsg, tuple);
                        break;
                    case PUSH:
                        handlePushRequest(flowId, imsg, tuple);
                        break;
                    case UNPUSH:
                        handleUnpushRequest(flowId, imsg, tuple);
                        break;
                    case PATH:
                        handlePathRequest(flowId, cmsg, tuple);
                        break;
                    case RESTORE:
                        handleRestoreRequest(cmsg, tuple);
                        break;
                    case REROUTE:
                        handleRerouteRequest(cmsg, tuple);
                        break;
                    case STATUS:
                        handleStatusRequest(flowId, cmsg, tuple);
                        break;
                    case CACHE_SYNC:
                        handleCacheSyncRequest(cmsg, tuple);
                        break;
                    case READ:
                        if (flowId != null) {
                            handleReadRequest(flowId, cmsg, tuple);
                        } else {
                            handleDumpRequest(cmsg, tuple);
                        }
                        break;
                    default:
                        logger.debug("Unexpected stream: component={}, stream={}", componentId, streamId);
                        break;
                }
                break;
            case SPEAKER_BOLT:
            case TRANSACTION_BOLT:
                FlowState newStatus = (FlowState) tuple.getValueByField(FlowTopology.STATUS_FIELD);
                logger.info("Flow {} status {}: component={}, stream={}", flowId, newStatus, componentId, streamId);
                switch(streamId) {
                    case STATUS:
                        handleStateRequest(flowId, newStatus, tuple);
                        break;
                    default:
                        logger.debug("Unexpected stream: component={}, stream={}", componentId, streamId);
                        break;
                }
                break;
            case TOPOLOGY_ENGINE_BOLT:
                ErrorMessage errorMessage = (ErrorMessage) tuple.getValueByField(AbstractTopology.MESSAGE_FIELD);
                logger.info("Flow {} error: component={}, stream={}", flowId, componentId, streamId);
                switch(streamId) {
                    case STATUS:
                        handleErrorRequest(flowId, errorMessage, tuple);
                        break;
                    default:
                        logger.debug("Unexpected stream: component={}, stream={}", componentId, streamId);
                        break;
                }
                break;
            default:
                logger.debug("Unexpected component: {}", componentId);
                break;
        }
    } catch (CacheException exception) {
        String logMessage = format("%s: %s", exception.getErrorMessage(), exception.getErrorDescription());
        logger.error("{}, {}={}, {}={}, component={}, stream={}", logMessage, Utils.CORRELATION_ID, correlationId, Utils.FLOW_ID, flowId, componentId, streamId, exception);
        ErrorMessage errorMessage = buildErrorMessage(correlationId, exception.getErrorType(), logMessage, componentId.toString().toLowerCase());
        Values error = new Values(errorMessage, exception.getErrorType());
        outputCollector.emit(StreamType.ERROR.toString(), tuple, error);
    } catch (IOException exception) {
        logger.error("Could not deserialize message {}", tuple, exception);
    } finally {
        logger.debug("Command message ack: component={}, stream={}, tuple={}", tuple.getSourceComponent(), tuple.getSourceStreamId(), tuple);
        outputCollector.ack(tuple);
    }
    logger.trace("Flow Cache after: {}", flowCache);
}
Also used : StreamType(org.openkilda.wfm.topology.flow.StreamType) ComponentType(org.openkilda.wfm.topology.flow.ComponentType) FlowState(org.openkilda.messaging.payload.flow.FlowState) InfoMessage(org.openkilda.messaging.info.InfoMessage) CommandMessage(org.openkilda.messaging.command.CommandMessage) Message(org.openkilda.messaging.Message) ErrorMessage(org.openkilda.messaging.error.ErrorMessage) CacheException(org.openkilda.messaging.error.CacheException) InfoMessage(org.openkilda.messaging.info.InfoMessage) Values(org.apache.storm.tuple.Values) IOException(java.io.IOException) ErrorMessage(org.openkilda.messaging.error.ErrorMessage) CommandMessage(org.openkilda.messaging.command.CommandMessage)

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