Search in sources :

Example 1 with HeartBeat

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

Example 2 with HeartBeat

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

the class HeartBeatTest method got_heart_beat_event.

@Then("^got at least (\\d+) heart beat event$")
public void got_heart_beat_event(int expect) throws Throwable {
    int beatsCount = 0;
    for (ConsumerRecord<String, String> record : heartBeatConsumer.poll(500)) {
        Message raw = MAPPER.readValue(record.value(), Message.class);
        if (raw instanceof HeartBeat) {
            beatsCount += 1;
        }
    }
    System.out.println(String.format("Got %d heart beats.", beatsCount));
    assertTrue(String.format("Actual heart beats count is %d, expect more than %d", beatsCount, expect), expect <= beatsCount);
}
Also used : HeartBeat(org.openkilda.messaging.HeartBeat) Message(org.openkilda.messaging.Message) Then(cucumber.api.java.en.Then)

Aggregations

HeartBeat (org.openkilda.messaging.HeartBeat)2 Then (cucumber.api.java.en.Then)1 IOException (java.io.IOException)1 BaseMessage (org.openkilda.messaging.BaseMessage)1 Message (org.openkilda.messaging.Message)1 InfoData (org.openkilda.messaging.info.InfoData)1 InfoMessage (org.openkilda.messaging.info.InfoMessage)1 NetworkInfoData (org.openkilda.messaging.info.discovery.NetworkInfoData)1 IslInfoData (org.openkilda.messaging.info.event.IslInfoData)1 PortInfoData (org.openkilda.messaging.info.event.PortInfoData)1 SwitchInfoData (org.openkilda.messaging.info.event.SwitchInfoData)1