Search in sources :

Example 1 with YFlowPingRequest

use of org.openkilda.messaging.command.flow.YFlowPingRequest 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 2 with YFlowPingRequest

use of org.openkilda.messaging.command.flow.YFlowPingRequest in project open-kilda by telstra.

the class YFlowServiceImpl method pingYFlow.

@Override
public CompletableFuture<YFlowPingResult> pingYFlow(String yFlowId, YFlowPingPayload payload) {
    log.debug("Processing y-flow ping: {} {}", yFlowId, payload);
    CommandMessage command = new CommandMessage(new YFlowPingRequest(yFlowId, payload.getTimeoutMillis()), System.currentTimeMillis(), RequestCorrelationId.getId());
    return messagingChannel.sendAndGet(pingTopic, command).thenApply(YFlowPingResponse.class::cast).thenApply(flowMapper::toPingResult);
}
Also used : CommandMessage(org.openkilda.messaging.command.CommandMessage) YFlowPingRequest(org.openkilda.messaging.command.flow.YFlowPingRequest)

Aggregations

YFlowPingRequest (org.openkilda.messaging.command.flow.YFlowPingRequest)2 ArrayList (java.util.ArrayList)1 CommandMessage (org.openkilda.messaging.command.CommandMessage)1 Flow (org.openkilda.model.Flow)1 FlowTransitEncapsulation (org.openkilda.model.FlowTransitEncapsulation)1 YFlow (org.openkilda.model.YFlow)1 YSubFlow (org.openkilda.model.YSubFlow)1 CommandContext (org.openkilda.wfm.CommandContext)1 GroupId (org.openkilda.wfm.topology.ping.model.GroupId)1 PingContext (org.openkilda.wfm.topology.ping.model.PingContext)1