Search in sources :

Example 1 with CacheException

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

the class CacheBolt method doWork.

/**
 * {@inheritDoc}
 */
@Override
public void doWork(Tuple tuple) {
    if (CtrlAction.boltHandlerEntrance(this, tuple))
        return;
    logger.trace("State before: {}", state);
    String json = tuple.getString(0);
    String source = tuple.getSourceComponent();
    // TODO: Eliminate the inefficiency introduced through the hack
    try {
        logger.info("Received cache data={}", tuple);
        BaseMessage bm = MAPPER.readValue(json, BaseMessage.class);
        if (bm instanceof InfoMessage) {
            InfoMessage message = (InfoMessage) bm;
            InfoData data = message.getData();
            if (data instanceof NetworkInfoData) {
                logger.debug("Storage content message {}", json);
                handleNetworkDump(data, tuple);
                isReceivedCacheInfo = true;
            } else if (!isReceivedCacheInfo) {
                logger.debug("Cache message fail due bolt not initialized: " + "component={}, stream={}, tuple={}", tuple.getSourceComponent(), tuple.getSourceStreamId(), tuple);
            } else if (data instanceof SwitchInfoData) {
                logger.info("Cache update switch info data: {}", data);
                handleSwitchEvent((SwitchInfoData) data, tuple);
            } else if (data instanceof IslInfoData) {
                logger.info("Cache update isl info data: {}", data);
                handleIslEvent((IslInfoData) data, tuple);
            } else if (data instanceof PortInfoData) {
                logger.info("Cache update port info data: {}", data);
                handlePortEvent((PortInfoData) data, tuple);
            } else if (data instanceof FlowInfoData) {
                logger.info("Cache update flow data: {}", data);
                FlowInfoData flowData = (FlowInfoData) data;
                handleFlowEvent(flowData, tuple);
            } else if (data instanceof NetworkTopologyChange) {
                logger.info("Switch flows reroute request");
                NetworkTopologyChange topologyChange = (NetworkTopologyChange) data;
                handleNetworkTopologyChangeEvent(topologyChange, tuple);
            } else {
                logger.error("Skip undefined info data type {}", json);
            }
        } else {
            logger.error("Skip undefined message type {}", json);
        }
    } catch (CacheException exception) {
        logger.error("Could not process message {}", tuple, exception);
    } catch (IOException exception) {
        logger.error("Could not deserialize message {}", tuple, exception);
    } finally {
        if (isReceivedCacheInfo) {
            outputCollector.ack(tuple);
        } else {
            outputCollector.fail(tuple);
        }
    }
    logger.trace("State after: {}", state);
}
Also used : NetworkInfoData(org.openkilda.messaging.info.discovery.NetworkInfoData) FlowInfoData(org.openkilda.messaging.info.flow.FlowInfoData) BaseMessage(org.openkilda.messaging.BaseMessage) CacheException(org.openkilda.messaging.error.CacheException) InfoMessage(org.openkilda.messaging.info.InfoMessage) SwitchInfoData(org.openkilda.messaging.info.event.SwitchInfoData) InfoData(org.openkilda.messaging.info.InfoData) FlowInfoData(org.openkilda.messaging.info.flow.FlowInfoData) IslInfoData(org.openkilda.messaging.info.event.IslInfoData) NetworkInfoData(org.openkilda.messaging.info.discovery.NetworkInfoData) PortInfoData(org.openkilda.messaging.info.event.PortInfoData) IslInfoData(org.openkilda.messaging.info.event.IslInfoData) PortInfoData(org.openkilda.messaging.info.event.PortInfoData) IOException(java.io.IOException) SwitchInfoData(org.openkilda.messaging.info.event.SwitchInfoData) NetworkTopologyChange(org.openkilda.messaging.info.event.NetworkTopologyChange)

Example 2 with CacheException

use of org.openkilda.messaging.error.CacheException 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 3 with CacheException

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

the class NetworkCache method getIsl.

/**
 * Get {@link IslInfoData} instance.
 *
 * @param islId {@link IslInfoData} instance id
 * @return {@link IslInfoData} instance with specified {@link IslInfoData} instance id
 * @throws CacheException if {@link IslInfoData} instance with specified id does not exist
 */
public IslInfoData getIsl(String islId) throws CacheException {
    logger.debug("Get {} isl", islId);
    IslInfoData isl = islPool.get(islId);
    if (isl == null) {
        throw new CacheException(ErrorType.NOT_FOUND, "Can not get isl", String.format("Isl %s not found", islId));
    }
    return islPool.get(islId);
}
Also used : CacheException(org.openkilda.messaging.error.CacheException) IslInfoData(org.openkilda.messaging.info.event.IslInfoData)

Example 4 with CacheException

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

the class NetworkCache method getIslSwitches.

/**
 * Gets {@link SwitchInfoData} instances which are incident nodes for specified {@link IslInfoData} instance.
 *
 * @param isl {@link IslInfoData} instance
 * @return {@link EndpointPair} of {@link SwitchInfoData} instances
 * @throws CacheException if {@link SwitchInfoData} instances for {@link IslInfoData} instance do not exist
 */
private EndpointPair<SwitchInfoData> getIslSwitches(IslInfoData isl) throws CacheException {
    String srcSwitch = isl.getPath().get(0).getSwitchId();
    if (srcSwitch == null) {
        throw new CacheException(ErrorType.PARAMETERS_INVALID, "Can not get isl nodes", "Source switch not specified");
    }
    SwitchInfoData startNode = getSwitch(srcSwitch);
    String dstSwitch = isl.getPath().get(1).getSwitchId();
    if (dstSwitch == null) {
        throw new CacheException(ErrorType.PARAMETERS_INVALID, "Can not get isl nodes", "Destination switch not specified");
    }
    SwitchInfoData endNode = getSwitch(dstSwitch);
    return EndpointPair.ordered(startNode, endNode);
}
Also used : CacheException(org.openkilda.messaging.error.CacheException) SwitchInfoData(org.openkilda.messaging.info.event.SwitchInfoData)

Example 5 with CacheException

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

the class NetworkCache method deleteIsl.

/**
 * Deletes {@link IslInfoData} instance.
 *
 * @param islId {@link IslInfoData} instance id
 * @return removed {@link IslInfoData} instance
 * @throws CacheException if {@link IslInfoData} instance with specified id does not exist
 */
public IslInfoData deleteIsl(String islId) throws CacheException {
    logger.debug("Delete {} isl", islId);
    IslInfoData isl = islPool.remove(islId);
    if (isl == null) {
        throw new CacheException(ErrorType.NOT_FOUND, "Can not delete isl", String.format("Isl %s not found", islId));
    }
    network.removeEdge(isl);
    return isl;
}
Also used : CacheException(org.openkilda.messaging.error.CacheException) IslInfoData(org.openkilda.messaging.info.event.IslInfoData)

Aggregations

CacheException (org.openkilda.messaging.error.CacheException)11 SwitchInfoData (org.openkilda.messaging.info.event.SwitchInfoData)8 IslInfoData (org.openkilda.messaging.info.event.IslInfoData)4 IOException (java.io.IOException)2 InfoMessage (org.openkilda.messaging.info.InfoMessage)2 ImmutablePair (org.openkilda.messaging.model.ImmutablePair)2 MutableNetwork (com.google.common.graph.MutableNetwork)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 Comparator (java.util.Comparator)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 Values (org.apache.storm.tuple.Values)1 BaseMessage (org.openkilda.messaging.BaseMessage)1 Message (org.openkilda.messaging.Message)1