Search in sources :

Example 6 with PingContext

use of org.openkilda.wfm.topology.ping.model.PingContext in project open-kilda by telstra.

the class TimeoutManager method emitTimeout.

private void emitTimeout(Tuple input, TimeoutDescriptor descriptor, long timestamp) {
    PingContext pingTimeout = descriptor.getPingContext().toBuilder().timestamp(timestamp).error(Errors.TIMEOUT).build();
    log.debug("{} is timed out", pingTimeout);
    Values output = new Values(pingTimeout.getFlowId(), pingTimeout, descriptor.getCommandContext());
    getOutput().emit(STREAM_RESPONSE_ID, input, output);
}
Also used : Values(org.apache.storm.tuple.Values) PingContext(org.openkilda.wfm.topology.ping.model.PingContext)

Example 7 with PingContext

use of org.openkilda.wfm.topology.ping.model.PingContext 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 8 with PingContext

use of org.openkilda.wfm.topology.ping.model.PingContext in project open-kilda by telstra.

the class FlowFetcher method handleOnDemandRequest.

private void handleOnDemandRequest(Tuple input) throws PipelineException {
    log.debug("Handle on demand ping request");
    FlowPingRequest request = pullOnDemandRequest(input);
    Optional<Flow> optionalFlow = flowRepository.findById(request.getFlowId());
    if (optionalFlow.isPresent()) {
        Flow flow = optionalFlow.get();
        flowRepository.detach(flow);
        if (!flow.isOneSwitchFlow()) {
            Optional<FlowTransitEncapsulation> transitEncapsulation = getTransitEncapsulation(flow);
            if (transitEncapsulation.isPresent()) {
                PingContext pingContext = PingContext.builder().group(new GroupId(DIRECTION_COUNT_PER_FLOW)).kind(Kinds.ON_DEMAND).flow(flow).transitEncapsulation(transitEncapsulation.get()).timeout(request.getTimeout()).build();
                emit(input, pingContext, pullContext(input));
            } else {
                emitOnDemandResponse(input, request, format("Encapsulation resource not found for flow %s", request.getFlowId()));
            }
        } else {
            emitOnDemandResponse(input, request, format("Flow %s should not be one switch flow", request.getFlowId()));
        }
    } else {
        emitOnDemandResponse(input, request, format("Flow %s does not exist", request.getFlowId()));
    }
}
Also used : FlowTransitEncapsulation(org.openkilda.model.FlowTransitEncapsulation) PingContext(org.openkilda.wfm.topology.ping.model.PingContext) FlowPingRequest(org.openkilda.messaging.command.flow.FlowPingRequest) YFlowPingRequest(org.openkilda.messaging.command.flow.YFlowPingRequest) Flow(org.openkilda.model.Flow) YFlow(org.openkilda.model.YFlow) YSubFlow(org.openkilda.model.YSubFlow) GroupId(org.openkilda.wfm.topology.ping.model.GroupId)

Example 9 with PingContext

use of org.openkilda.wfm.topology.ping.model.PingContext 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 10 with PingContext

use of org.openkilda.wfm.topology.ping.model.PingContext in project open-kilda by telstra.

the class GroupCollector method saveCurrentRecord.

private CollectorDescriptor saveCurrentRecord(Tuple input) throws Exception {
    final PingContext pingContext = pullPingContext(input);
    // expiring is only a memory leakage protection in this place
    // waiting ping command timeout + storm internal processing delay milliseconds
    long expireAt = System.currentTimeMillis() + pingContext.getTimeout() + expireDelay;
    CollectorDescriptor descriptor = new CollectorDescriptor(expireAt, pingContext.getGroup());
    descriptor = cache.addIfAbsent(descriptor);
    try {
        int size = descriptor.add(pingContext);
        GroupId group = descriptor.getGroupId();
        log.debug("Group {} add {} of {} response {}", group.getId(), size, group.getSize(), pingContext);
    } catch (IllegalArgumentException e) {
        throw new WorkflowException(this, input, e.toString());
    }
    return descriptor;
}
Also used : WorkflowException(org.openkilda.wfm.error.WorkflowException) CollectorDescriptor(org.openkilda.wfm.topology.ping.model.CollectorDescriptor) PingContext(org.openkilda.wfm.topology.ping.model.PingContext) GroupId(org.openkilda.wfm.topology.ping.model.GroupId)

Aggregations

PingContext (org.openkilda.wfm.topology.ping.model.PingContext)19 Values (org.apache.storm.tuple.Values)5 GroupId (org.openkilda.wfm.topology.ping.model.GroupId)4 HashSet (java.util.HashSet)3 YFlowPingResponse (org.openkilda.messaging.info.flow.YFlowPingResponse)3 CommandContext (org.openkilda.wfm.CommandContext)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 YFlowPingRequest (org.openkilda.messaging.command.flow.YFlowPingRequest)2 Flow (org.openkilda.model.Flow)2 FlowTransitEncapsulation (org.openkilda.model.FlowTransitEncapsulation)2 YFlow (org.openkilda.model.YFlow)2 YSubFlow (org.openkilda.model.YSubFlow)2 FlowPingRequest (org.openkilda.messaging.command.flow.FlowPingRequest)1 FlowPingResponse (org.openkilda.messaging.info.flow.FlowPingResponse)1 FlowPingResponseBuilder (org.openkilda.messaging.info.flow.FlowPingResponse.FlowPingResponseBuilder)1 SubFlowPingPayload (org.openkilda.messaging.info.flow.SubFlowPingPayload)1 UniFlowPingResponse (org.openkilda.messaging.info.flow.UniFlowPingResponse)1 UniSubFlowPingPayload (org.openkilda.messaging.info.flow.UniSubFlowPingPayload)1 WorkflowException (org.openkilda.wfm.error.WorkflowException)1