Search in sources :

Example 46 with CommandContext

use of org.openkilda.wfm.CommandContext in project open-kilda by telstra.

the class PingProducer method emit.

private void emit(Tuple input, PingContext pingContext) throws PipelineException {
    CommandContext commandContext = pullContext(input);
    Values output = new Values(pingContext, commandContext);
    getOutput().emit(input, output);
}
Also used : CommandContext(org.openkilda.wfm.CommandContext) Values(org.apache.storm.tuple.Values)

Example 47 with CommandContext

use of org.openkilda.wfm.CommandContext in project open-kilda by telstra.

the class WorkerBoltTest method multipleRequestsArePossible.

@Test
public void multipleRequestsArePossible() {
    String key = "key";
    String payload = "payload";
    Tuple request = new TupleImpl(topologyContext, new Values(key, payload, new CommandContext()), HUB_TASK_ID, Utils.DEFAULT_STREAM_ID);
    worker.execute(request);
    worker.emitHubResponse = false;
    reset(output);
    Tuple response = new TupleImpl(topologyContext, new Values(key, payload, new CommandContext()), SPOUT_TASK_ID, Utils.DEFAULT_STREAM_ID);
    worker.execute(response);
    verify(output).ack(response);
    verifyNoMoreInteractions(output);
    reset(output);
    worker.emitHubResponse = true;
    worker.execute(response);
    // cancel timeout
    verify(output).emit(eq(CoordinatorBolt.INCOME_STREAM), eq(response), Mockito.any());
    // hub response
    verify(output).emitDirect(eq(HUB_TASK_ID), eq(WORKER_TO_HUB_STREAM_ID), eq(response), Mockito.any());
    verify(output).ack(response);
    verifyNoMoreInteractions(output);
}
Also used : CommandContext(org.openkilda.wfm.CommandContext) Values(org.apache.storm.tuple.Values) TupleImpl(org.apache.storm.tuple.TupleImpl) Tuple(org.apache.storm.tuple.Tuple) Test(org.junit.Test)

Example 48 with CommandContext

use of org.openkilda.wfm.CommandContext in project open-kilda by telstra.

the class LoggerContextInitializer method aroundAdvice.

/**
 * Wraps "execute" method of storm bolts to inject/cleanup fields in logger MDC.
 */
@Around("execution(* org.apache.storm.topology.IRichBolt+.execute(org.apache.storm.tuple.Tuple)) && args(input)" + "|| execution(* org.apache.storm.topology.IStatefulBolt+.execute(org.apache.storm.tuple.Tuple)) " + "&& args(input)")
public Object aroundAdvice(ProceedingJoinPoint joinPoint, Tuple input) throws Throwable {
    CommandContext context = extract(input).orElseGet(() -> {
        LOGGER.debug("CorrelationId was not sent or can't be extracted for tuple {}", input);
        return new CommandContext(DEFAULT_CORRELATION_ID);
    });
    Map<String, String> fields = prepareFields(context);
    fields.put(TOPOLOGY_NAME, stormId);
    Map<String, String> current = inject(fields);
    try {
        return joinPoint.proceed(joinPoint.getArgs());
    } finally {
        revert(current);
    }
}
Also used : CommandContext(org.openkilda.wfm.CommandContext) Around(org.aspectj.lang.annotation.Around)

Example 49 with CommandContext

use of org.openkilda.wfm.CommandContext in project open-kilda by telstra.

the class CoordinatorSpout method nextTuple.

@Override
public void nextTuple() {
    if (emit) {
        collector.emit(new Values(System.currentTimeMillis(), new CommandContext()), messageId++);
        emit = false;
    } else {
        org.apache.storm.utils.Utils.sleep(1L);
    }
}
Also used : CommandContext(org.openkilda.wfm.CommandContext) Values(org.apache.storm.tuple.Values)

Example 50 with CommandContext

use of org.openkilda.wfm.CommandContext in project open-kilda by telstra.

the class SpeakerToNetworkProxyBoltTest method verifySpeakerToConsumerTupleConsistency.

@Test
public void verifySpeakerToConsumerTupleConsistency() throws Exception {
    injectLifecycleEventUpdate(START_SIGNAL);
    ArgumentCaptor<Values> outputCaptor = ArgumentCaptor.forClass(Values.class);
    verify(outputCollector).emit(anyString(), any(Tuple.class), outputCaptor.capture());
    Values output = outputCaptor.getValue();
    assertEquals(START_SIGNAL, ((LifecycleEvent) output.get(0)).getSignal());
    InfoMessage discoveryConfirmation = new InfoMessage(new DiscoPacketSendingConfirmation(new NetworkEndpoint(switchAlpha, 1), 1L), 3L, "discovery-confirmation", REGION_ONE);
    Tuple tuple = new TupleImpl(generalTopologyContext, new Values(switchAlpha.toString(), discoveryConfirmation, new CommandContext(discoveryConfirmation)), TASK_ID_SPOUT, STREAM_SPOUT_DEFAULT);
    subject.execute(tuple);
    ArgumentCaptor<Values> discoReplyValuesCaptor = ArgumentCaptor.forClass(Values.class);
    verify(outputCollector).emit(eq(SpeakerToNetworkProxyBolt.STREAM_ALIVE_EVIDENCE_ID), eq(tuple), discoReplyValuesCaptor.capture());
    assertEquals(REGION_ONE, discoReplyValuesCaptor.getValue().get(0));
    assertEquals(discoveryConfirmation.getTimestamp(), discoReplyValuesCaptor.getValue().get(1));
    ArgumentCaptor<Values> topoDiscoCaptor = ArgumentCaptor.forClass(Values.class);
    verify(outputCollector).emit(eq(tuple), topoDiscoCaptor.capture());
    assertEquals(switchAlpha.toString(), topoDiscoCaptor.getValue().get(0));
    assertEquals(discoveryConfirmation, topoDiscoCaptor.getValue().get(1));
}
Also used : DiscoPacketSendingConfirmation(org.openkilda.messaging.info.discovery.DiscoPacketSendingConfirmation) NetworkEndpoint(org.openkilda.messaging.model.NetworkEndpoint) CommandContext(org.openkilda.wfm.CommandContext) InfoMessage(org.openkilda.messaging.info.InfoMessage) Values(org.apache.storm.tuple.Values) TupleImpl(org.apache.storm.tuple.TupleImpl) Tuple(org.apache.storm.tuple.Tuple) Test(org.junit.Test)

Aggregations

CommandContext (org.openkilda.wfm.CommandContext)95 Test (org.junit.Test)28 Values (org.apache.storm.tuple.Values)27 FlowSegmentRequest (org.openkilda.floodlight.api.request.FlowSegmentRequest)15 Flow (org.openkilda.model.Flow)15 AbstractYFlowTest (org.openkilda.wfm.topology.flowhs.service.AbstractYFlowTest)14 Tuple (org.apache.storm.tuple.Tuple)12 SwitchId (org.openkilda.model.SwitchId)11 YFlow (org.openkilda.model.YFlow)11 BaseSpeakerCommandsRequest (org.openkilda.floodlight.api.request.rulemanager.BaseSpeakerCommandsRequest)9 SpeakerResponse (org.openkilda.floodlight.api.response.SpeakerResponse)9 YFlowRequest (org.openkilda.messaging.command.yflow.YFlowRequest)9 InfoMessage (org.openkilda.messaging.info.InfoMessage)9 TupleImpl (org.apache.storm.tuple.TupleImpl)8 FlowPath (org.openkilda.model.FlowPath)8 ArrayList (java.util.ArrayList)7 FlowRerouteRequest (org.openkilda.messaging.command.flow.FlowRerouteRequest)7 FlowProcessingException (org.openkilda.wfm.topology.flowhs.exception.FlowProcessingException)7 UnknownKeyException (org.openkilda.wfm.topology.flowhs.exception.UnknownKeyException)7 List (java.util.List)6