Search in sources :

Example 1 with Message

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

the class CacheBolt method emitFlowCrudMessage.

private void emitFlowCrudMessage(InfoData data, Tuple tuple, String correlationId) throws IOException {
    Message message = new InfoMessage(data, System.currentTimeMillis(), correlationId, Destination.WFM);
    outputCollector.emit(StreamType.WFM_DUMP.toString(), tuple, new Values(MAPPER.writeValueAsString(message)));
    logger.info("Flow command message sent");
}
Also used : InfoMessage(org.openkilda.messaging.info.InfoMessage) CommandMessage(org.openkilda.messaging.command.CommandMessage) BaseMessage(org.openkilda.messaging.BaseMessage) Message(org.openkilda.messaging.Message) InfoMessage(org.openkilda.messaging.info.InfoMessage) Values(org.apache.storm.tuple.Values)

Example 2 with Message

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

the class CacheBolt method emitFlowMessage.

private void emitFlowMessage(InfoData data, Tuple tuple, String correlationId) throws IOException {
    Message message = new InfoMessage(data, System.currentTimeMillis(), correlationId, Destination.TOPOLOGY_ENGINE);
    outputCollector.emit(StreamType.TPE.toString(), tuple, new Values(MAPPER.writeValueAsString(message)));
    logger.info("Flow command message sent");
}
Also used : InfoMessage(org.openkilda.messaging.info.InfoMessage) CommandMessage(org.openkilda.messaging.command.CommandMessage) BaseMessage(org.openkilda.messaging.BaseMessage) Message(org.openkilda.messaging.Message) InfoMessage(org.openkilda.messaging.info.InfoMessage) Values(org.apache.storm.tuple.Values)

Example 3 with Message

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

the class PopulateIslFilterAction method handle.

@Override
protected void handle() throws MessageFormatException, UnsupportedActionException, JsonProcessingException {
    KafkaMessage input = new KafkaMessage(getTuple());
    Message message = input.getPayload();
    if (message.getDestination() != Destination.WFM_OF_DISCOVERY) {
        return;
    }
    if (!(message instanceof CommandMessage)) {
        return;
    }
    CommandMessage command = (CommandMessage) message;
    if (!(command.getData() instanceof DiscoveryFilterPopulateData)) {
        return;
    }
    DiscoveryFilterPopulateData payload = (DiscoveryFilterPopulateData) command.getData();
    logger.info("Clean ISL filter");
    filter.clear();
    for (DiscoveryFilterEntity entity : payload.getFilter()) {
        logger.info("Add ISL filter record - switcID=\"{}\" portId=\"{}\"", entity.switchId, entity.portId);
        filter.add(entity.switchId, entity.portId);
    }
}
Also used : DiscoveryFilterEntity(org.openkilda.messaging.command.discovery.DiscoveryFilterEntity) Message(org.openkilda.messaging.Message) KafkaMessage(org.openkilda.wfm.protocol.KafkaMessage) CommandMessage(org.openkilda.messaging.command.CommandMessage) KafkaMessage(org.openkilda.wfm.protocol.KafkaMessage) DiscoveryFilterPopulateData(org.openkilda.messaging.command.discovery.DiscoveryFilterPopulateData) CommandMessage(org.openkilda.messaging.command.CommandMessage)

Example 4 with Message

use of org.openkilda.messaging.Message 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 5 with Message

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

the class NorthboundReplyBolt method execute.

/**
 * {@inheritDoc}
 */
@Override
public void execute(Tuple tuple) {
    ComponentType componentId = ComponentType.valueOf(tuple.getSourceComponent());
    StreamType streamId = StreamType.valueOf(tuple.getSourceStreamId());
    Message message = (Message) tuple.getValueByField(AbstractTopology.MESSAGE_FIELD);
    Values values = null;
    try {
        logger.debug("Request tuple={}", tuple);
        switch(componentId) {
            case TOPOLOGY_ENGINE_BOLT:
            case CRUD_BOLT:
            case ERROR_BOLT:
                logger.debug("Flow response: {}={}, component={}, stream={}, message={}", Utils.CORRELATION_ID, message.getCorrelationId(), componentId, streamId, message);
                message.setDestination(Destination.NORTHBOUND);
                values = new Values(MAPPER.writeValueAsString(message));
                outputCollector.emit(StreamType.RESPONSE.toString(), tuple, values);
                break;
            default:
                logger.debug("Flow unknown response: {}={}, component={}, stream={}, message={}", Utils.CORRELATION_ID, message.getCorrelationId(), componentId, streamId, message);
                break;
        }
    } catch (JsonProcessingException exception) {
        logger.error("Could not serialize message: component={}, stream={}, message={}", componentId, streamId, message);
    } finally {
        logger.debug("Northbound-Reply message ack: component={}, stream={}, tuple={}, values={}", tuple.getSourceComponent(), tuple.getSourceStreamId(), tuple, values);
        outputCollector.ack(tuple);
    }
}
Also used : StreamType(org.openkilda.wfm.topology.flow.StreamType) ComponentType(org.openkilda.wfm.topology.flow.ComponentType) Message(org.openkilda.messaging.Message) Values(org.apache.storm.tuple.Values) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Aggregations

Message (org.openkilda.messaging.Message)71 CommandMessage (org.openkilda.messaging.command.CommandMessage)55 InfoMessage (org.openkilda.messaging.info.InfoMessage)55 ErrorMessage (org.openkilda.messaging.error.ErrorMessage)29 Test (org.junit.Test)25 IOException (java.io.IOException)11 Values (org.apache.storm.tuple.Values)10 CtrlRequest (org.openkilda.messaging.ctrl.CtrlRequest)6 CtrlResponse (org.openkilda.messaging.ctrl.CtrlResponse)6 FlowIdStatusPayload (org.openkilda.messaging.payload.flow.FlowIdStatusPayload)6 CommandData (org.openkilda.messaging.command.CommandData)5 RequestData (org.openkilda.messaging.ctrl.RequestData)5 FlowResponse (org.openkilda.messaging.info.flow.FlowResponse)5 CommandWithReplyToMessage (org.openkilda.messaging.command.CommandWithReplyToMessage)4 DumpStateResponseData (org.openkilda.messaging.ctrl.DumpStateResponseData)4 IslInfoData (org.openkilda.messaging.info.event.IslInfoData)4 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)3 BaseInstallFlow (org.openkilda.messaging.command.flow.BaseInstallFlow)3 FlowCreateRequest (org.openkilda.messaging.command.flow.FlowCreateRequest)3 FlowGetRequest (org.openkilda.messaging.command.flow.FlowGetRequest)3