Search in sources :

Example 1 with BaseMessage

use of org.openkilda.messaging.BaseMessage 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 BaseMessage

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

the class OFELinkBolt method doWork.

@Override
protected void doWork(Tuple tuple) {
    if (CtrlAction.boltHandlerEntrance(this, tuple))
        return;
    // 
    // (crimi) - commenting out the filter code until we re-evaluate the design. Also, this code
    // should probably be embedded in "handleIslEvent"
    // /*
    // * Check whether ISL Filter needs to be engaged.
    // */
    // String source = tuple.getSourceComponent();
    // if (source.equals(OFEventWFMTopology.SPOUT_ID_INPUT)) {
    // PopulateIslFilterAction action = new PopulateIslFilterAction(this, tuple, islFilter);
    // action.run();
    // return;
    // }
    String json = tuple.getString(0);
    try {
        BaseMessage bm = MAPPER.readValue(json, BaseMessage.class);
        watchDog.reset();
        if (bm instanceof InfoMessage) {
            InfoData data = ((InfoMessage) bm).getData();
            if (data instanceof NetworkInfoData) {
                handleNetworkDump(tuple, (NetworkInfoData) data);
                isReceivedCacheInfo = true;
            } else if (!isReceivedCacheInfo) {
                logger.debug("Bolt is not initialized mark tuple as fail");
            } else if (data instanceof SwitchInfoData) {
                handleSwitchEvent(tuple, (SwitchInfoData) data);
                passToTopologyEngine(tuple);
            } else if (data instanceof PortInfoData) {
                handlePortEvent(tuple, (PortInfoData) data);
                passToTopologyEngine(tuple);
            } else if (data instanceof IslInfoData) {
                handleIslEvent(tuple, (IslInfoData) data);
            } else {
                logger.warn("Unknown InfoData type={}", data);
            }
        } else if (bm instanceof HeartBeat) {
            logger.debug("Got speaker's heart beat");
        }
    } catch (IOException e) {
        // All messages should be derived from BaseMessage .. so an exception here
        // means that we found something that isn't. If this criteria changes, then
        // change the logger level.
        logger.error("Unknown Message type={}", json);
    } finally {
        // We mark as fail all tuples while bolt is not initialized
        if (isReceivedCacheInfo) {
            collector.ack(tuple);
        } else {
            collector.fail(tuple);
        }
    }
}
Also used : HeartBeat(org.openkilda.messaging.HeartBeat) NetworkInfoData(org.openkilda.messaging.info.discovery.NetworkInfoData) BaseMessage(org.openkilda.messaging.BaseMessage) InfoMessage(org.openkilda.messaging.info.InfoMessage) IslInfoData(org.openkilda.messaging.info.event.IslInfoData) NetworkInfoData(org.openkilda.messaging.info.discovery.NetworkInfoData) SwitchInfoData(org.openkilda.messaging.info.event.SwitchInfoData) PortInfoData(org.openkilda.messaging.info.event.PortInfoData) InfoData(org.openkilda.messaging.info.InfoData) PortInfoData(org.openkilda.messaging.info.event.PortInfoData) IslInfoData(org.openkilda.messaging.info.event.IslInfoData) IOException(java.io.IOException) SwitchInfoData(org.openkilda.messaging.info.event.SwitchInfoData)

Aggregations

IOException (java.io.IOException)2 BaseMessage (org.openkilda.messaging.BaseMessage)2 InfoData (org.openkilda.messaging.info.InfoData)2 InfoMessage (org.openkilda.messaging.info.InfoMessage)2 NetworkInfoData (org.openkilda.messaging.info.discovery.NetworkInfoData)2 IslInfoData (org.openkilda.messaging.info.event.IslInfoData)2 PortInfoData (org.openkilda.messaging.info.event.PortInfoData)2 SwitchInfoData (org.openkilda.messaging.info.event.SwitchInfoData)2 HeartBeat (org.openkilda.messaging.HeartBeat)1 CacheException (org.openkilda.messaging.error.CacheException)1 NetworkTopologyChange (org.openkilda.messaging.info.event.NetworkTopologyChange)1 FlowInfoData (org.openkilda.messaging.info.flow.FlowInfoData)1