Search in sources :

Example 1 with ErrorMessage

use of org.openkilda.messaging.error.ErrorMessage 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)

Example 2 with ErrorMessage

use of org.openkilda.messaging.error.ErrorMessage in project open-kilda by telstra.

the class SpeakerBolt method execute.

/**
 * {@inheritDoc}
 */
@Override
public void execute(Tuple tuple) {
    String request = tuple.getString(0);
    Values values = null;
    try {
        Message message = MAPPER.readValue(request, Message.class);
        if (!Destination.WFM_TRANSACTION.equals(message.getDestination())) {
            return;
        }
        logger.debug("Request tuple={}", tuple);
        if (message instanceof CommandMessage) {
            CommandData data = ((CommandMessage) message).getData();
            if (data instanceof BaseInstallFlow) {
                Long transactionId = ((BaseInstallFlow) data).getTransactionId();
                String switchId = ((BaseInstallFlow) data).getSwitchId();
                String flowId = ((BaseInstallFlow) data).getId();
                logger.debug("Flow install message: {}={}, switch-id={}, {}={}, {}={}, message={}", Utils.CORRELATION_ID, message.getCorrelationId(), switchId, Utils.FLOW_ID, flowId, Utils.TRANSACTION_ID, transactionId, request);
                message.setDestination(Destination.TOPOLOGY_ENGINE);
                values = new Values(MAPPER.writeValueAsString(message), switchId, flowId, transactionId);
                // FIXME(surabujin): looks like TE ignore this messages
                outputCollector.emit(StreamType.CREATE.toString(), tuple, values);
            } else if (data instanceof RemoveFlow) {
                Long transactionId = ((RemoveFlow) data).getTransactionId();
                String switchId = ((RemoveFlow) data).getSwitchId();
                String flowId = ((RemoveFlow) data).getId();
                logger.debug("Flow remove message: {}={}, switch-id={}, {}={}, {}={}, message={}", Utils.CORRELATION_ID, message.getCorrelationId(), switchId, Utils.FLOW_ID, flowId, Utils.TRANSACTION_ID, transactionId, request);
                message.setDestination(Destination.TOPOLOGY_ENGINE);
                values = new Values(MAPPER.writeValueAsString(message), switchId, flowId, transactionId);
                outputCollector.emit(StreamType.DELETE.toString(), tuple, values);
            } else {
                logger.debug("Skip undefined command message: {}={}, message={}", Utils.CORRELATION_ID, message.getCorrelationId(), request);
            }
        } else if (message instanceof ErrorMessage) {
            String flowId = ((ErrorMessage) message).getData().getErrorDescription();
            FlowState status = FlowState.DOWN;
            // TODO: Should add debug message if receiving ErrorMessage.
            if (flowId != null) {
                logger.error("Flow error message: {}={}, {}={}, message={}", Utils.CORRELATION_ID, message.getCorrelationId(), Utils.FLOW_ID, flowId, request);
                values = new Values(flowId, status);
                outputCollector.emit(StreamType.STATUS.toString(), tuple, values);
            } else {
                logger.debug("Skip error message without flow-id: {}={}, message={}", Utils.CORRELATION_ID, message.getCorrelationId(), request);
            }
        } else {
            // TODO: should this be a warn or error? Probably, after refactored / specific
            // topics
            logger.debug("Skip undefined message: {}={}, message={}", Utils.CORRELATION_ID, message.getCorrelationId(), request);
        }
    } catch (IOException exception) {
        logger.error("\n\nCould not deserialize message={}", request, exception);
    } finally {
        logger.debug("Speaker message ack: component={}, stream={}, tuple={}, values={}", tuple.getSourceComponent(), tuple.getSourceStreamId(), tuple, values);
        outputCollector.ack(tuple);
    }
}
Also used : FlowState(org.openkilda.messaging.payload.flow.FlowState) Message(org.openkilda.messaging.Message) CommandMessage(org.openkilda.messaging.command.CommandMessage) ErrorMessage(org.openkilda.messaging.error.ErrorMessage) RemoveFlow(org.openkilda.messaging.command.flow.RemoveFlow) Values(org.apache.storm.tuple.Values) BaseInstallFlow(org.openkilda.messaging.command.flow.BaseInstallFlow) IOException(java.io.IOException) CommandData(org.openkilda.messaging.command.CommandData) ErrorMessage(org.openkilda.messaging.error.ErrorMessage) CommandMessage(org.openkilda.messaging.command.CommandMessage)

Example 3 with ErrorMessage

use of org.openkilda.messaging.error.ErrorMessage in project open-kilda by telstra.

the class TopologyEngineBolt method execute.

/**
 * {@inheritDoc}
 */
@Override
public void execute(Tuple tuple) {
    String request = tuple.getString(0);
    Values values = null;
    try {
        Message message = MAPPER.readValue(request, Message.class);
        if (!Destination.WFM.equals(message.getDestination())) {
            return;
        }
        logger.debug("Request tuple={}", tuple);
        if (message instanceof CommandMessage) {
            CommandData data = ((CommandMessage) message).getData();
            if (data instanceof BaseInstallFlow) {
                BaseInstallFlow installData = (BaseInstallFlow) data;
                Long transactionId = UUID.randomUUID().getLeastSignificantBits();
                installData.setTransactionId(transactionId);
                String switchId = installData.getSwitchId();
                String flowId = installData.getId();
                logger.debug("Flow install message: {}={}, switch-id={}, {}={}, {}={}, message={}", Utils.CORRELATION_ID, message.getCorrelationId(), switchId, Utils.FLOW_ID, flowId, Utils.TRANSACTION_ID, transactionId, request);
                // FIXME(surabujin): send here and in TE
                message.setDestination(Destination.CONTROLLER);
                values = new Values(MAPPER.writeValueAsString(message), switchId, flowId, transactionId);
                outputCollector.emit(StreamType.CREATE.toString(), tuple, values);
            } else if (data instanceof RemoveFlow) {
                RemoveFlow removeData = (RemoveFlow) data;
                Long transactionId = UUID.randomUUID().getLeastSignificantBits();
                removeData.setTransactionId(transactionId);
                String switchId = removeData.getSwitchId();
                String flowId = removeData.getId();
                logger.debug("Flow remove message: {}={}, switch-id={}, {}={}, {}={}, message={}", Utils.CORRELATION_ID, message.getCorrelationId(), switchId, Utils.FLOW_ID, flowId, Utils.TRANSACTION_ID, transactionId, request);
                message.setDestination(Destination.CONTROLLER);
                values = new Values(MAPPER.writeValueAsString(message), switchId, flowId, transactionId);
                outputCollector.emit(StreamType.DELETE.toString(), tuple, values);
            } else {
                logger.debug("Skip undefined command message: {}={}, message={}", Utils.CORRELATION_ID, message.getCorrelationId(), request);
            }
        } else if (message instanceof InfoMessage) {
            values = new Values(message);
            logger.debug("Flow response message: {}={}, message={}", Utils.CORRELATION_ID, message.getCorrelationId(), request);
            outputCollector.emit(StreamType.RESPONSE.toString(), tuple, values);
        } else if (message instanceof ErrorMessage) {
            String flowId = ((ErrorMessage) message).getData().getErrorDescription();
            logger.error("Flow error message: {}={}, {}={}, message={}", Utils.CORRELATION_ID, message.getCorrelationId(), Utils.FLOW_ID, flowId, request);
            values = new Values(message, flowId);
            outputCollector.emit(StreamType.STATUS.toString(), tuple, values);
        } else {
            logger.debug("Skip undefined message: {}={}, message={}", Utils.CORRELATION_ID, message.getCorrelationId(), request);
        }
    } catch (IOException exception) {
        logger.error("Could not deserialize message={}", request, exception);
    } finally {
        logger.debug("Topology-Engine message ack: component={}, stream={}, tuple={}, values={}", tuple.getSourceComponent(), tuple.getSourceStreamId(), tuple, values);
        outputCollector.ack(tuple);
    }
}
Also used : InfoMessage(org.openkilda.messaging.info.InfoMessage) Message(org.openkilda.messaging.Message) CommandMessage(org.openkilda.messaging.command.CommandMessage) ErrorMessage(org.openkilda.messaging.error.ErrorMessage) RemoveFlow(org.openkilda.messaging.command.flow.RemoveFlow) InfoMessage(org.openkilda.messaging.info.InfoMessage) Values(org.apache.storm.tuple.Values) BaseInstallFlow(org.openkilda.messaging.command.flow.BaseInstallFlow) IOException(java.io.IOException) CommandData(org.openkilda.messaging.command.CommandData) ErrorMessage(org.openkilda.messaging.error.ErrorMessage) CommandMessage(org.openkilda.messaging.command.CommandMessage)

Example 4 with ErrorMessage

use of org.openkilda.messaging.error.ErrorMessage in project open-kilda by telstra.

the class FlowTopologyTest method statusUnknownFlowTest.

@Test
public void statusUnknownFlowTest() throws Exception {
    String flowId = UUID.randomUUID().toString();
    ConsumerRecord<String, String> record;
    statusFlow(flowId);
    record = nbConsumer.pollMessage();
    assertNotNull(record);
    assertNotNull(record.value());
    ErrorMessage errorMessage = objectMapper.readValue(record.value(), ErrorMessage.class);
    assertNotNull(errorMessage);
    ErrorData errorData = errorMessage.getData();
    assertEquals(ErrorType.NOT_FOUND, errorData.getErrorType());
}
Also used : ErrorMessage(org.openkilda.messaging.error.ErrorMessage) ErrorData(org.openkilda.messaging.error.ErrorData) AbstractStormTest(org.openkilda.wfm.AbstractStormTest) Test(org.junit.Test)

Example 5 with ErrorMessage

use of org.openkilda.messaging.error.ErrorMessage in project open-kilda by telstra.

the class FlowTopologyTest method updateUnknownFlowCommandBoltTest.

@Test
public void updateUnknownFlowCommandBoltTest() throws Exception {
    String flowId = UUID.randomUUID().toString();
    ConsumerRecord<String, String> record;
    updateFlow(flowId);
    record = nbConsumer.pollMessage();
    assertNotNull(record);
    assertNotNull(record.value());
    ErrorMessage errorMessage = objectMapper.readValue(record.value(), ErrorMessage.class);
    assertNotNull(errorMessage);
    ErrorData errorData = errorMessage.getData();
    assertEquals(ErrorType.NOT_FOUND, errorData.getErrorType());
}
Also used : ErrorMessage(org.openkilda.messaging.error.ErrorMessage) ErrorData(org.openkilda.messaging.error.ErrorData) AbstractStormTest(org.openkilda.wfm.AbstractStormTest) Test(org.junit.Test)

Aggregations

ErrorMessage (org.openkilda.messaging.error.ErrorMessage)23 ErrorData (org.openkilda.messaging.error.ErrorData)18 Test (org.junit.Test)11 InfoMessage (org.openkilda.messaging.info.InfoMessage)10 AbstractStormTest (org.openkilda.wfm.AbstractStormTest)10 Values (org.apache.storm.tuple.Values)4 Message (org.openkilda.messaging.Message)4 CommandMessage (org.openkilda.messaging.command.CommandMessage)4 RemoveFlow (org.openkilda.messaging.command.flow.RemoveFlow)4 IOException (java.io.IOException)3 SwitchOperationException (org.openkilda.floodlight.switchmanager.SwitchOperationException)3 CommandData (org.openkilda.messaging.command.CommandData)3 ISwitchManager (org.openkilda.floodlight.switchmanager.ISwitchManager)2 BaseInstallFlow (org.openkilda.messaging.command.flow.BaseInstallFlow)2 InstallOneSwitchFlow (org.openkilda.messaging.command.flow.InstallOneSwitchFlow)2 MessageException (org.openkilda.messaging.error.MessageException)2 InfoData (org.openkilda.messaging.info.InfoData)2 FlowStatusResponse (org.openkilda.messaging.info.flow.FlowStatusResponse)2 SwitchRulesResponse (org.openkilda.messaging.info.switches.SwitchRulesResponse)2 Flow (org.openkilda.messaging.model.Flow)2