Search in sources :

Example 1 with StreamType

use of org.openkilda.wfm.topology.flow.StreamType 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 StreamType

use of org.openkilda.wfm.topology.flow.StreamType 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)

Example 3 with StreamType

use of org.openkilda.wfm.topology.flow.StreamType in project open-kilda by telstra.

the class ErrorBolt method execute.

/**
 * {@inheritDoc}
 */
@Override
public void execute(Tuple tuple) {
    ComponentType componentId = ComponentType.valueOf(tuple.getSourceComponent());
    StreamType streamId = StreamType.valueOf(tuple.getSourceStreamId());
    ErrorType errorType = (ErrorType) tuple.getValueByField(FlowTopology.ERROR_TYPE_FIELD);
    ErrorMessage error = (ErrorMessage) tuple.getValueByField(AbstractTopology.MESSAGE_FIELD);
    error.setDestination(Destination.NORTHBOUND);
    Values values = new Values(error);
    try {
        logger.debug("Request tuple={}", tuple);
        switch(componentId) {
            case CRUD_BOLT:
            case SPLITTER_BOLT:
                logger.debug("Error message: data={}", error.getData());
                outputCollector.emit(StreamType.RESPONSE.toString(), tuple, values);
                break;
            default:
                logger.debug("Skip message from unknown component: component={}, stream={}, error-type={}", componentId, streamId, errorType);
                break;
        }
    } catch (Exception exception) {
        logger.error("Could not process message: {}", tuple, exception);
    } finally {
        logger.debug("Error 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) ErrorType(org.openkilda.messaging.error.ErrorType) Values(org.apache.storm.tuple.Values) ErrorMessage(org.openkilda.messaging.error.ErrorMessage)

Example 4 with StreamType

use of org.openkilda.wfm.topology.flow.StreamType in project open-kilda by telstra.

the class TransactionBolt method execute.

@Override
public void execute(Tuple tuple) {
    if (CtrlAction.boltHandlerEntrance(this, tuple))
        return;
    logger.trace("States before: {}", transactions);
    ComponentType componentId = ComponentType.valueOf(tuple.getSourceComponent());
    StreamType streamId = StreamType.valueOf(tuple.getSourceStreamId());
    Long transactionId = (Long) tuple.getValueByField(Utils.TRANSACTION_ID);
    String switchId = (String) tuple.getValueByField(FlowTopology.SWITCH_ID_FIELD);
    String flowId = (String) tuple.getValueByField(Utils.FLOW_ID);
    Object message = tuple.getValueByField(FlowTopology.MESSAGE_FIELD);
    Map<String, Set<Long>> flowTransactions;
    Set<Long> flowTransactionIds;
    Values values = null;
    try {
        logger.debug("Request tuple={}", tuple);
        switch(componentId) {
            case TOPOLOGY_ENGINE_BOLT:
                logger.info("Transaction from TopologyEngine: switch-id={}, {}={}, {}={}", switchId, Utils.FLOW_ID, flowId, Utils.TRANSACTION_ID, transactionId);
                flowTransactions = transactions.get(switchId);
                if (flowTransactions == null) {
                    flowTransactions = new ConcurrentHashMap<>();
                    transactions.put(switchId, flowTransactions);
                }
                flowTransactionIds = flowTransactions.get(flowId);
                if (flowTransactionIds == null) {
                    flowTransactionIds = new ConcurrentHashSet<>();
                    flowTransactions.put(flowId, flowTransactionIds);
                }
                if (!flowTransactionIds.add(transactionId)) {
                    throw new RuntimeException(String.format("Transaction adding failure: id %d already exists", transactionId));
                }
                logger.info("Set status {}: switch-id={}, {}={}, {}={}", FlowState.IN_PROGRESS, switchId, Utils.FLOW_ID, flowId, Utils.TRANSACTION_ID, transactionId);
                values = new Values(flowId, FlowState.IN_PROGRESS);
                outputCollector.emit(StreamType.STATUS.toString(), tuple, values);
                values = new Values(message);
                outputCollector.emit(streamId.toString(), tuple, values);
                break;
            case SPEAKER_BOLT:
                logger.info("Transaction from Speaker: switch-id={}, {}={}, {}={}", switchId, Utils.FLOW_ID, flowId, Utils.TRANSACTION_ID, transactionId);
                flowTransactions = transactions.get(switchId);
                if (flowTransactions != null) {
                    flowTransactionIds = flowTransactions.get(flowId);
                    if (flowTransactionIds != null) {
                        if (flowTransactionIds.remove(transactionId)) {
                            if (flowTransactionIds.isEmpty()) {
                                // 
                                // All transactions have been removed .. the Flow
                                // can now be considered "UP"
                                // 
                                logger.info("Set status {}: switch-id={}, {}={}, {}={}", FlowState.UP, switchId, Utils.FLOW_ID, flowId, Utils.TRANSACTION_ID, transactionId);
                                values = new Values(flowId, FlowState.UP);
                                outputCollector.emit(StreamType.STATUS.toString(), tuple, values);
                                flowTransactions.remove(flowId);
                            } else {
                                logger.debug("Transaction {} not empty yet, count = {}", transactionId, flowTransactionIds.size());
                            }
                        } else {
                            logger.warn("Transaction removing: transaction id not found");
                        }
                    } else {
                        logger.warn("Transaction removing failure: flow id not found");
                    }
                    if (flowTransactions.isEmpty()) {
                        transactions.delete(switchId);
                    }
                } else {
                    logger.warn("Transaction removing failure: switch id not found");
                }
                break;
            default:
                logger.debug("Skip undefined message: message={}", tuple);
                break;
        }
    } catch (RuntimeException exception) {
        logger.error("Set status {}: switch-id={}, {}={}, {}={}", FlowState.DOWN, switchId, Utils.FLOW_ID, flowId, Utils.TRANSACTION_ID, transactionId, exception);
        values = new Values(flowId, FlowState.DOWN);
        outputCollector.emit(StreamType.STATUS.toString(), tuple, values);
    } finally {
        logger.debug("Transaction message ack: component={}, stream={}, tuple={}, values={}", tuple.getSourceComponent(), tuple.getSourceStreamId(), tuple, values);
        outputCollector.ack(tuple);
    }
    logger.trace("States after: {}", transactions);
}
Also used : StreamType(org.openkilda.wfm.topology.flow.StreamType) ComponentType(org.openkilda.wfm.topology.flow.ComponentType) Set(java.util.Set) ConcurrentHashSet(org.apache.storm.shade.org.eclipse.jetty.util.ConcurrentHashSet) Values(org.apache.storm.tuple.Values)

Aggregations

Values (org.apache.storm.tuple.Values)4 ComponentType (org.openkilda.wfm.topology.flow.ComponentType)4 StreamType (org.openkilda.wfm.topology.flow.StreamType)4 Message (org.openkilda.messaging.Message)2 ErrorMessage (org.openkilda.messaging.error.ErrorMessage)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 IOException (java.io.IOException)1 Set (java.util.Set)1 ConcurrentHashSet (org.apache.storm.shade.org.eclipse.jetty.util.ConcurrentHashSet)1 CommandMessage (org.openkilda.messaging.command.CommandMessage)1 CacheException (org.openkilda.messaging.error.CacheException)1 ErrorType (org.openkilda.messaging.error.ErrorType)1 InfoMessage (org.openkilda.messaging.info.InfoMessage)1 FlowState (org.openkilda.messaging.payload.flow.FlowState)1