Search in sources :

Example 41 with CommandContext

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

the class RerouteBolt method emitPathSwapCommand.

/**
 * Emit swap command for consumer.
 *
 * @param correlationId correlation id to pass through
 * @param flowId flow
 * @param reason initial reason of path swap
 */
@Override
public void emitPathSwapCommand(String correlationId, String flowId, String reason) {
    CommandContext context = new CommandContext(correlationId).fork(UUID.randomUUID().toString());
    emit(STREAM_OPERATION_QUEUE_ID, getCurrentTuple(), new Values(flowId, new FlowPathSwapRequest(flowId, false), context));
    log.warn("Flow {} swap path command message sent with correlationId {}, reason \"{}\"", flowId, context.getCorrelationId(), reason);
}
Also used : CommandContext(org.openkilda.wfm.CommandContext) FlowPathSwapRequest(org.openkilda.messaging.command.flow.FlowPathSwapRequest) Values(org.apache.storm.tuple.Values)

Example 42 with CommandContext

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

the class DatapointParseBolt method handleLifeCycleEvent.

protected void handleLifeCycleEvent(Tuple tuple, LifecycleEvent event) {
    if (Signal.START.equals(event.getSignal())) {
        active = true;
        collector.emit(ZkStreams.ZK.toString(), tuple, new Values(event, new CommandContext()));
    } else if (Signal.SHUTDOWN.equals(event.getSignal())) {
        active = false;
        collector.emit(ZkStreams.ZK.toString(), tuple, new Values(event, new CommandContext()));
    } else {
        LOGGER.error("Unsupported signal received: {}", event.getSignal());
    }
}
Also used : CommandContext(org.openkilda.wfm.CommandContext) Values(org.apache.storm.tuple.Values)

Example 43 with CommandContext

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

the class FlowFetcher method handleOnDemandYFlowRequest.

private void handleOnDemandYFlowRequest(Tuple input) throws PipelineException {
    log.debug("Handle on demand ping request");
    YFlowPingRequest request = pullOnDemandYFlowRequest(input);
    Optional<YFlow> optionalYFlow = yFlowRepository.findById(request.getYFlowId());
    if (!optionalYFlow.isPresent()) {
        emitOnDemandYFlowResponse(input, request, format("YFlow %s does not exist", request.getYFlowId()));
        return;
    }
    YFlow yFlow = optionalYFlow.get();
    Set<YSubFlow> subFlows = yFlow.getSubFlows();
    if (subFlows.isEmpty()) {
        emitOnDemandYFlowResponse(input, request, format("YFlow %s has no sub flows", request.getYFlowId()));
        return;
    }
    GroupId groupId = new GroupId(subFlows.size() * DIRECTION_COUNT_PER_FLOW);
    List<PingContext> subFlowPingRequests = new ArrayList<>();
    for (YSubFlow subFlow : subFlows) {
        Flow flow = subFlow.getFlow();
        // Load paths to use in PingProducer
        flow.getPaths();
        flowRepository.detach(flow);
        Optional<FlowTransitEncapsulation> transitEncapsulation = getTransitEncapsulation(flow);
        if (transitEncapsulation.isPresent()) {
            subFlowPingRequests.add(PingContext.builder().group(groupId).kind(Kinds.ON_DEMAND_Y_FLOW).flow(flow).yFlowId(yFlow.getYFlowId()).transitEncapsulation(transitEncapsulation.get()).timeout(request.getTimeout()).build());
        } else {
            emitOnDemandYFlowResponse(input, request, format("Encapsulation resource not found for sub flow %s of YFlow %s", subFlow.getSubFlowId(), yFlow.getYFlowId()));
            return;
        }
    }
    CommandContext commandContext = pullContext(input);
    for (PingContext pingContext : subFlowPingRequests) {
        emit(input, pingContext, commandContext);
    }
}
Also used : YFlow(org.openkilda.model.YFlow) CommandContext(org.openkilda.wfm.CommandContext) ArrayList(java.util.ArrayList) FlowTransitEncapsulation(org.openkilda.model.FlowTransitEncapsulation) YSubFlow(org.openkilda.model.YSubFlow) GroupId(org.openkilda.wfm.topology.ping.model.GroupId) Flow(org.openkilda.model.Flow) YFlow(org.openkilda.model.YFlow) YSubFlow(org.openkilda.model.YSubFlow) PingContext(org.openkilda.wfm.topology.ping.model.PingContext) YFlowPingRequest(org.openkilda.messaging.command.flow.YFlowPingRequest)

Example 44 with CommandContext

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

the class FlowFetcher method handlePeriodicRequest.

private void handlePeriodicRequest(Tuple input) throws PipelineException {
    log.debug("Handle periodic ping request");
    if (lastPeriodicPingCacheRefresh + periodicPingCacheExpiryInterval < System.currentTimeMillis()) {
        refreshHeap(input, true);
    }
    final CommandContext commandContext = pullContext(input);
    for (FlowWithTransitEncapsulation flow : flowsSet) {
        PingContext pingContext = PingContext.builder().group(new GroupId(DIRECTION_COUNT_PER_FLOW)).kind(Kinds.PERIODIC).flow(flow.getFlow()).yFlowId(flow.yFlowId).transitEncapsulation(flow.getTransitEncapsulation()).build();
        emit(input, pingContext, commandContext);
    }
}
Also used : CommandContext(org.openkilda.wfm.CommandContext) PingContext(org.openkilda.wfm.topology.ping.model.PingContext) GroupId(org.openkilda.wfm.topology.ping.model.GroupId)

Example 45 with CommandContext

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

the class FlowFetcher method refreshHeap.

private void refreshHeap(Tuple input, boolean emitCacheExpiry) throws PipelineException {
    log.debug("Handle periodic ping request");
    Set<FlowWithTransitEncapsulation> flowsWithTransitEncapsulation = flowRepository.findWithPeriodicPingsEnabled().stream().peek(flowRepository::detach).map(this::getFlowWithTransitEncapsulation).flatMap(o -> o.isPresent() ? Stream.of(o.get()) : Stream.empty()).collect(Collectors.toSet());
    if (emitCacheExpiry) {
        final CommandContext commandContext = pullContext(input);
        emitCacheExpire(input, commandContext, flowsWithTransitEncapsulation);
    }
    flowsSet = flowsWithTransitEncapsulation;
    lastPeriodicPingCacheRefresh = System.currentTimeMillis();
}
Also used : OutputFieldsDeclarer(org.apache.storm.topology.OutputFieldsDeclarer) YFlowPingResponse(org.openkilda.messaging.info.flow.YFlowPingResponse) FlowTransitEncapsulation(org.openkilda.model.FlowTransitEncapsulation) FlowResourcesConfig(org.openkilda.wfm.share.flow.resources.FlowResourcesConfig) Value(lombok.Value) ArrayList(java.util.ArrayList) Values(org.apache.storm.tuple.Values) Tuple(org.apache.storm.tuple.Tuple) FlowPingRequest(org.openkilda.messaging.command.flow.FlowPingRequest) Flow(org.openkilda.model.Flow) OutputCollector(org.apache.storm.task.OutputCollector) PipelineException(org.openkilda.wfm.error.PipelineException) Kinds(org.openkilda.wfm.topology.ping.model.PingContext.Kinds) YFlow(org.openkilda.model.YFlow) FlowRepository(org.openkilda.persistence.repositories.FlowRepository) PersistenceManager(org.openkilda.persistence.PersistenceManager) Utils(org.openkilda.messaging.Utils) YSubFlow(org.openkilda.model.YSubFlow) PersistenceContextRequired(org.openkilda.persistence.context.PersistenceContextRequired) PeriodicPingCommand(org.openkilda.messaging.command.flow.PeriodicPingCommand) Set(java.util.Set) CommandContext(org.openkilda.wfm.CommandContext) Fields(org.apache.storm.tuple.Fields) FlowPingResponse(org.openkilda.messaging.info.flow.FlowPingResponse) EqualsAndHashCode(lombok.EqualsAndHashCode) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) YFlowRepository(org.openkilda.persistence.repositories.YFlowRepository) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) YFlowPingRequest(org.openkilda.messaging.command.flow.YFlowPingRequest) Stream(java.util.stream.Stream) GroupId(org.openkilda.wfm.topology.ping.model.GroupId) PingContext(org.openkilda.wfm.topology.ping.model.PingContext) FlowResourcesManager(org.openkilda.wfm.share.flow.resources.FlowResourcesManager) Optional(java.util.Optional) AllArgsConstructor(lombok.AllArgsConstructor) CommandContext(org.openkilda.wfm.CommandContext)

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