Search in sources :

Example 1 with LifecycleEvent

use of org.openkilda.bluegreen.LifecycleEvent in project open-kilda by telstra.

the class ControllerToSpeakerProxyBoltTest method injectLifecycleEventUpdate.

private void injectLifecycleEventUpdate(Signal signal) {
    LifecycleEvent event = LifecycleEvent.builder().signal(signal).build();
    Tuple input = new TupleImpl(generalTopologyContext, new Values(event, new CommandContext()), ZOOKEEPER_SPOUT, STREAM_SPOUT_DEFAULT);
    subject.execute(input);
    verify(outputCollector).ack(eq(input));
}
Also used : CommandContext(org.openkilda.wfm.CommandContext) Values(org.apache.storm.tuple.Values) LifecycleEvent(org.openkilda.bluegreen.LifecycleEvent) TupleImpl(org.apache.storm.tuple.TupleImpl) Tuple(org.apache.storm.tuple.Tuple)

Example 2 with LifecycleEvent

use of org.openkilda.bluegreen.LifecycleEvent in project open-kilda by telstra.

the class SpeakerToNetworkProxyBoltTest method injectLifecycleEventUpdate.

private void injectLifecycleEventUpdate(Signal signal) {
    LifecycleEvent event = LifecycleEvent.builder().signal(signal).build();
    Tuple input = new TupleImpl(generalTopologyContext, new Values(event, new CommandContext()), ZOOKEEPER_SPOUT, STREAM_SPOUT_DEFAULT);
    subject.execute(input);
    verify(outputCollector).ack(eq(input));
}
Also used : CommandContext(org.openkilda.wfm.CommandContext) Values(org.apache.storm.tuple.Values) LifecycleEvent(org.openkilda.bluegreen.LifecycleEvent) TupleImpl(org.apache.storm.tuple.TupleImpl) Tuple(org.apache.storm.tuple.Tuple)

Example 3 with LifecycleEvent

use of org.openkilda.bluegreen.LifecycleEvent in project open-kilda by telstra.

the class DatapointParseBolt method execute.

@Override
public void execute(Tuple tuple) {
    if (ZooKeeperSpout.SPOUT_ID.equals(tuple.getSourceComponent())) {
        LifecycleEvent event = (LifecycleEvent) tuple.getValueByField(FIELD_ID_LIFECYCLE_EVENT);
        if (event != null && shouldHandleLifeCycleEvent(event.getSignal())) {
            handleLifeCycleEvent(tuple, event);
        }
        collector.ack(tuple);
    } else if (active) {
        InfoData data = (InfoData) tuple.getValueByField(MessageKafkaTranslator.FIELD_ID_PAYLOAD);
        LOGGER.debug("Processing datapoint: {}", data);
        try {
            List<Datapoint> datapoints;
            Object payload = tuple.getValueByField(MessageKafkaTranslator.FIELD_ID_PAYLOAD);
            if (payload instanceof Datapoint) {
                LOGGER.debug("Processing datapoint: {}", payload);
                datapoints = Collections.singletonList((Datapoint) payload);
            } else if (payload instanceof DatapointEntries) {
                LOGGER.debug("Processing datapoints: {}", payload);
                datapoints = ((DatapointEntries) payload).getDatapointEntries();
            } else {
                LOGGER.error("Unhandled input tuple from {} with data {}", getClass().getName(), payload);
                return;
            }
            for (Datapoint datapoint : datapoints) {
                collector.emit(asList(datapoint.simpleHashCode(), datapoint));
            }
        } catch (Exception e) {
            LOGGER.error("Failed process data: {}", data, e);
        } finally {
            collector.ack(tuple);
        }
    } else {
        LOGGER.debug("DatapointParseBolt is inactive");
        collector.ack(tuple);
    }
}
Also used : Datapoint(org.openkilda.messaging.info.Datapoint) InfoData(org.openkilda.messaging.info.InfoData) LifecycleEvent(org.openkilda.bluegreen.LifecycleEvent) DatapointEntries(org.openkilda.messaging.info.DatapointEntries) Arrays.asList(java.util.Arrays.asList) List(java.util.List)

Example 4 with LifecycleEvent

use of org.openkilda.bluegreen.LifecycleEvent in project open-kilda by telstra.

the class AbstractBolt method dispatch.

protected void dispatch(Tuple input) throws Exception {
    if (input.getSourceComponent().equals(lifeCycleEventSourceComponent)) {
        LifecycleEvent event = (LifecycleEvent) input.getValueByField(FIELD_ID_LIFECYCLE_EVENT);
        log.info("Received lifecycle event {}", event);
        if (shouldHandleLifeCycleEvent(event.getSignal())) {
            handleLifeCycleEvent(event);
        }
    } else {
        if (meterRegistry != null) {
            MeterRegistryHolder.setRegistry(meterRegistry);
        }
        try {
            handleInput(input);
        } finally {
            MeterRegistryHolder.removeRegistry();
            if (meterRegistry != null && meterOutputStream != null) {
                log.debug("Pushing MeterRegistry data to {} stream", meterOutputStream);
                meterRegistry.pushMeters(getOutput(), meterOutputStream);
            }
        }
    }
}
Also used : LifecycleEvent(org.openkilda.bluegreen.LifecycleEvent)

Example 5 with LifecycleEvent

use of org.openkilda.bluegreen.LifecycleEvent in project open-kilda by telstra.

the class ZooKeeperBolt method handleInput.

@Override
protected void handleInput(Tuple input) throws Exception {
    if (!zkWriter.isConnectedAndValidated()) {
        if (isZooKeeperConnectTimeoutPassed()) {
            zkWriter.safeRefreshConnection();
            zooKeeperConnectionTimestamp = Instant.now();
        }
    }
    try {
        LifecycleEvent event = (LifecycleEvent) input.getValueByField(FIELD_ID_STATE);
        if (event != null) {
            log.info("Handling lifecycle event {} for component {} with id {} from {}", event, serviceName, id, input.getSourceComponent());
            zkStateTracker.processLifecycleEvent(event);
        } else {
            log.error("Received null value as a lifecycle-event");
        }
    } catch (Exception e) {
        log.error("Failed to process event: {}", e.getMessage(), e);
    }
}
Also used : LifecycleEvent(org.openkilda.bluegreen.LifecycleEvent)

Aggregations

LifecycleEvent (org.openkilda.bluegreen.LifecycleEvent)6 Values (org.apache.storm.tuple.Values)3 CommandContext (org.openkilda.wfm.CommandContext)3 Tuple (org.apache.storm.tuple.Tuple)2 TupleImpl (org.apache.storm.tuple.TupleImpl)2 Arrays.asList (java.util.Arrays.asList)1 List (java.util.List)1 Signal (org.openkilda.bluegreen.Signal)1 Datapoint (org.openkilda.messaging.info.Datapoint)1 DatapointEntries (org.openkilda.messaging.info.DatapointEntries)1 InfoData (org.openkilda.messaging.info.InfoData)1