Search in sources :

Example 11 with TimedExecution

use of org.openkilda.wfm.share.metrics.TimedExecution in project open-kilda by telstra.

the class ValidateFlowAction method performWithResponse.

@TimedExecution("fsm.validate_flow")
@Override
protected Optional<Message> performWithResponse(State from, State to, Event event, FlowRerouteContext context, FlowRerouteFsm stateMachine) {
    String flowId = stateMachine.getFlowId();
    Set<IslEndpoint> affectedIsl = new HashSet<>(Optional.ofNullable(context.getAffectedIsl()).orElse(emptySet()));
    dashboardLogger.onFlowPathReroute(flowId, affectedIsl, context.isForceReroute());
    String rerouteReason = context.getRerouteReason();
    stateMachine.saveNewEventToHistory("Started flow validation", FlowEventData.Event.REROUTE, rerouteReason == null ? FlowEventData.Initiator.NB : FlowEventData.Initiator.AUTO, rerouteReason == null ? null : "Reason: " + rerouteReason);
    stateMachine.setRerouteReason(rerouteReason);
    Flow flow = transactionManager.doInTransaction(() -> {
        Flow foundFlow = getFlow(flowId);
        if (foundFlow.getStatus() == FlowStatus.IN_PROGRESS) {
            String message = format("Flow %s is in progress now", flowId);
            stateMachine.setRerouteError(new RerouteError(message));
            throw new FlowProcessingException(ErrorType.REQUEST_INVALID, message);
        }
        if (!foundFlow.getSrcSwitch().isActive()) {
            String message = format("Flow's %s src switch is not active", flowId);
            stateMachine.setRerouteError(new RerouteError(message));
            throw new FlowProcessingException(ErrorType.UNPROCESSABLE_REQUEST, message);
        }
        if (!foundFlow.getDestSwitch().isActive()) {
            String message = format("Flow's %s dest switch is not active", flowId);
            stateMachine.setRerouteError(new RerouteError(message));
            throw new FlowProcessingException(ErrorType.UNPROCESSABLE_REQUEST, message);
        }
        stateMachine.setOriginalFlowStatus(foundFlow.getStatus());
        stateMachine.setOriginalFlowStatusInfo(foundFlow.getStatusInfo());
        stateMachine.setOriginalEncapsulationType(foundFlow.getEncapsulationType());
        stateMachine.setOriginalPathComputationStrategy(foundFlow.getPathComputationStrategy());
        stateMachine.setRecreateIfSamePath(!foundFlow.isActive() || context.isForceReroute());
        stateMachine.setOriginalFlow(RequestedFlowMapper.INSTANCE.toRequestedFlow(foundFlow));
        stateMachine.setPeriodicPingsEnabled(foundFlow.isPeriodicPings());
        if (foundFlow.getTargetPathComputationStrategy() != null) {
            foundFlow.setPathComputationStrategy(foundFlow.getTargetPathComputationStrategy());
            foundFlow.setTargetPathComputationStrategy(null);
        }
        foundFlow.setStatus(FlowStatus.IN_PROGRESS);
        return foundFlow;
    });
    if (featureTogglesRepository.getOrDefault().getFlowsRerouteUsingDefaultEncapType()) {
        stateMachine.setNewEncapsulationType(kildaConfigurationRepository.getOrDefault().getFlowEncapsulationType());
    }
    boolean reroutePrimary;
    boolean rerouteProtected;
    if (affectedIsl.isEmpty()) {
        // no know affected ISLs
        reroutePrimary = true;
        rerouteProtected = true;
    } else {
        reroutePrimary = checkIsPathAffected(flow.getForwardPath(), affectedIsl) || checkIsPathAffected(flow.getReversePath(), affectedIsl);
        rerouteProtected = checkIsPathAffected(flow.getProtectedForwardPath(), affectedIsl) || checkIsPathAffected(flow.getProtectedReversePath(), affectedIsl);
    }
    // check protected path presence
    rerouteProtected &= flow.isAllocateProtectedPath();
    if (!reroutePrimary && !rerouteProtected) {
        throw new FlowProcessingException(ErrorType.NOT_FOUND, format("No paths of the flow %s are affected by failure on %s", flowId, affectedIsl.stream().map(IslEndpoint::toString).collect(Collectors.joining(","))));
    }
    if (reroutePrimary) {
        log.info("Reroute for the flow {} will affect primary paths: {} / {}", flowId, flow.getForwardPathId(), flow.getReversePathId());
    }
    if (rerouteProtected) {
        log.info("Reroute for the flow {} will affect protected paths: {} / {}", flowId, flow.getProtectedForwardPathId(), flow.getProtectedReversePathId());
    }
    stateMachine.setReroutePrimary(reroutePrimary);
    stateMachine.setRerouteProtected(rerouteProtected);
    stateMachine.setEffectivelyDown(context.isEffectivelyDown());
    if (stateMachine.isRerouteProtected() && flow.isPinned()) {
        throw new FlowProcessingException(ErrorType.REQUEST_INVALID, format("Flow %s is pinned, fail to reroute its protected paths", flowId));
    }
    stateMachine.setAffectedIsls(context.getAffectedIsl());
    stateMachine.setForceReroute(context.isForceReroute());
    stateMachine.setIgnoreBandwidth(context.isIgnoreBandwidth());
    stateMachine.saveActionToHistory("Flow was validated successfully");
    return Optional.empty();
}
Also used : IslEndpoint(org.openkilda.model.IslEndpoint) FlowProcessingException(org.openkilda.wfm.topology.flowhs.exception.FlowProcessingException) RerouteError(org.openkilda.messaging.info.reroute.error.RerouteError) HashSet(java.util.HashSet) Flow(org.openkilda.model.Flow) TimedExecution(org.openkilda.wfm.share.metrics.TimedExecution)

Example 12 with TimedExecution

use of org.openkilda.wfm.share.metrics.TimedExecution in project open-kilda by telstra.

the class FlowOperationsBolt method processGetFlowsForSwitchRequest.

@TimedExecution("get_flows_for_switch")
private List<FlowResponse> processGetFlowsForSwitchRequest(GetFlowsForSwitchRequest request) {
    SwitchId srcSwitch = request.getSwitchId();
    Integer srcPort = request.getPort();
    try {
        return flowOperationsService.getFlowsForEndpoint(srcSwitch, srcPort).stream().distinct().map(flowOperationsService::buildFlowResponse).collect(Collectors.toList());
    } catch (SwitchNotFoundException e) {
        throw new MessageException(ErrorType.NOT_FOUND, e.getMessage(), "Switch was not found.");
    }
}
Also used : MessageException(org.openkilda.messaging.error.MessageException) SwitchId(org.openkilda.model.SwitchId) SwitchNotFoundException(org.openkilda.wfm.error.SwitchNotFoundException) TimedExecution(org.openkilda.wfm.share.metrics.TimedExecution)

Example 13 with TimedExecution

use of org.openkilda.wfm.share.metrics.TimedExecution in project open-kilda by telstra.

the class FlowOperationsBolt method processFlowReadRequest.

@TimedExecution("flow_read")
private List<FlowResponse> processFlowReadRequest(FlowReadRequest readRequest) {
    try {
        String flowId = readRequest.getFlowId();
        Flow flow = flowOperationsService.getFlow(flowId);
        FlowStats flowStats = flowOperationsService.getFlowStats(flowId);
        FlowResponse response = flowOperationsService.buildFlowResponse(flow, flowStats);
        return Collections.singletonList(response);
    } catch (FlowNotFoundException e) {
        throw new MessageException(ErrorType.NOT_FOUND, "Can not get flow: " + e.getMessage(), "Flow not found");
    } catch (Exception e) {
        log.error("Can not get flow", e);
        throw new MessageException(ErrorType.INTERNAL_ERROR, "Can not get flow", "Internal Error");
    }
}
Also used : FlowStats(org.openkilda.model.FlowStats) FlowNotFoundException(org.openkilda.wfm.error.FlowNotFoundException) MessageException(org.openkilda.messaging.error.MessageException) FlowResponse(org.openkilda.messaging.info.flow.FlowResponse) IslNotFoundException(org.openkilda.wfm.error.IslNotFoundException) SwitchNotFoundException(org.openkilda.wfm.error.SwitchNotFoundException) MessageException(org.openkilda.messaging.error.MessageException) FlowNotFoundException(org.openkilda.wfm.error.FlowNotFoundException) Flow(org.openkilda.model.Flow) TimedExecution(org.openkilda.wfm.share.metrics.TimedExecution)

Example 14 with TimedExecution

use of org.openkilda.wfm.share.metrics.TimedExecution in project open-kilda by telstra.

the class FlowOperationsBolt method processRerouteFlowsForLinkRequest.

@TimedExecution("reroute_flows_for_link")
private List<FlowsResponse> processRerouteFlowsForLinkRequest(RerouteFlowsForIslRequest message) {
    SwitchId srcSwitch = message.getSource().getDatapath();
    Integer srcPort = message.getSource().getPortNumber();
    SwitchId dstSwitch = message.getDestination().getDatapath();
    Integer dstPort = message.getDestination().getPortNumber();
    Collection<FlowPath> paths;
    try {
        paths = flowOperationsService.getFlowPathsForLink(srcSwitch, srcPort, dstSwitch, dstPort);
    } catch (IslNotFoundException e) {
        throw new MessageException(ErrorType.NOT_FOUND, e.getMessage(), "ISL was not found.");
    }
    Set<IslEndpoint> affectedIslEndpoints = new HashSet<>();
    affectedIslEndpoints.add(new IslEndpoint(srcSwitch, srcPort));
    affectedIslEndpoints.add(new IslEndpoint(dstSwitch, dstPort));
    sendRerouteRequest(paths, affectedIslEndpoints, format("initiated via Northbound, reroute all flows that go over the link %s_%d - %s_%d", srcSwitch, srcPort, dstSwitch, dstPort));
    List<String> flowIds = paths.stream().map(FlowPath::getFlow).map(Flow::getFlowId).distinct().collect(Collectors.toList());
    return Collections.singletonList(new FlowsResponse(flowIds));
}
Also used : IslEndpoint(org.openkilda.model.IslEndpoint) FlowsResponse(org.openkilda.messaging.info.flow.FlowsResponse) SwitchId(org.openkilda.model.SwitchId) Flow(org.openkilda.model.Flow) MessageException(org.openkilda.messaging.error.MessageException) IslNotFoundException(org.openkilda.wfm.error.IslNotFoundException) FlowPath(org.openkilda.model.FlowPath) HashSet(java.util.HashSet) TimedExecution(org.openkilda.wfm.share.metrics.TimedExecution)

Example 15 with TimedExecution

use of org.openkilda.wfm.share.metrics.TimedExecution in project open-kilda by telstra.

the class AllocateProtectedResourcesAction method allocate.

@TimedExecution("fsm.resource_allocation_protected")
@Override
protected void allocate(FlowRerouteFsm stateMachine) throws RecoverableException, UnroutableFlowException, ResourceAllocationException {
    String flowId = stateMachine.getFlowId();
    Flow tmpFlowCopy = getFlow(flowId);
    // Detach the entity to avoid propagation to the database.
    flowRepository.detach(tmpFlowCopy);
    if (stateMachine.getNewEncapsulationType() != null) {
        // This is for PCE to use proper (updated) encapsulation type.
        tmpFlowCopy.setEncapsulationType(stateMachine.getNewEncapsulationType());
    }
    FlowPathPair oldPaths = new FlowPathPair(tmpFlowCopy.getProtectedForwardPath(), tmpFlowCopy.getProtectedReversePath());
    FlowPath primaryForward = tmpFlowCopy.getPath(stateMachine.getNewPrimaryForwardPath()).orElse(tmpFlowCopy.getForwardPath());
    FlowPath primaryReverse = tmpFlowCopy.getPath(stateMachine.getNewPrimaryReversePath()).orElse(tmpFlowCopy.getReversePath());
    Predicate<GetPathsResult> testNonOverlappingPath = path -> (primaryForward == null || !flowPathBuilder.arePathsOverlapped(path.getForward(), primaryForward)) && (primaryReverse == null || !flowPathBuilder.arePathsOverlapped(path.getReverse(), primaryReverse));
    PathId newForwardPathId = resourcesManager.generatePathId(flowId);
    PathId newReversePathId = resourcesManager.generatePathId(flowId);
    List<PathId> pathsToReuse = Lists.newArrayList(tmpFlowCopy.getProtectedForwardPathId(), tmpFlowCopy.getProtectedReversePathId());
    pathsToReuse.addAll(stateMachine.getRejectedPaths());
    log.debug("Finding a new protected path for flow {}", flowId);
    GetPathsResult allocatedPaths = allocatePathPair(tmpFlowCopy, newForwardPathId, newReversePathId, stateMachine.isIgnoreBandwidth(), pathsToReuse, oldPaths, stateMachine.isRecreateIfSamePath(), stateMachine.getSharedBandwidthGroupId(), testNonOverlappingPath);
    if (allocatedPaths != null) {
        stateMachine.setBackUpProtectedPathComputationWayUsed(allocatedPaths.isBackUpPathComputationWayUsed());
        if (!testNonOverlappingPath.test(allocatedPaths)) {
            stateMachine.saveActionToHistory("Couldn't find non overlapping protected path. Skipped creating it");
            stateMachine.fireNoPathFound("Couldn't find non overlapping protected path");
        } else {
            log.debug("New protected paths have been allocated: {}", allocatedPaths);
            stateMachine.setNewProtectedForwardPath(newForwardPathId);
            stateMachine.setNewProtectedReversePath(newReversePathId);
            log.debug("Allocating resources for a new protected path of flow {}", flowId);
            FlowResources flowResources = allocateFlowResources(tmpFlowCopy, newForwardPathId, newReversePathId);
            stateMachine.setNewProtectedResources(flowResources);
            FlowPathPair createdPaths = createFlowPathPair(flowId, flowResources, allocatedPaths, stateMachine.isIgnoreBandwidth(), stateMachine.getSharedBandwidthGroupId());
            log.debug("New protected paths have been created: {}", createdPaths);
            saveAllocationActionWithDumpsToHistory(stateMachine, tmpFlowCopy, "protected", createdPaths);
        }
    } else {
        stateMachine.saveActionToHistory("Found the same protected path. Skipped creating of it");
    }
}
Also used : FlowRerouteContext(org.openkilda.wfm.topology.flowhs.fsm.reroute.FlowRerouteContext) BaseResourceAllocationAction(org.openkilda.wfm.topology.flowhs.fsm.common.actions.BaseResourceAllocationAction) FlowOperationsDashboardLogger(org.openkilda.wfm.share.logger.FlowOperationsDashboardLogger) FlowPath(org.openkilda.model.FlowPath) ErrorType(org.openkilda.messaging.error.ErrorType) Predicate(java.util.function.Predicate) ResourceAllocationException(org.openkilda.wfm.share.flow.resources.ResourceAllocationException) FlowRerouteFsm(org.openkilda.wfm.topology.flowhs.fsm.reroute.FlowRerouteFsm) FlowResources(org.openkilda.wfm.share.flow.resources.FlowResources) Event(org.openkilda.wfm.topology.flowhs.fsm.reroute.FlowRerouteFsm.Event) RecoverableException(org.openkilda.pce.exception.RecoverableException) UnroutableFlowException(org.openkilda.pce.exception.UnroutableFlowException) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) State(org.openkilda.wfm.topology.flowhs.fsm.reroute.FlowRerouteFsm.State) Lists(com.google.common.collect.Lists) Flow(org.openkilda.model.Flow) TimedExecution(org.openkilda.wfm.share.metrics.TimedExecution) PathComputer(org.openkilda.pce.PathComputer) FlowPathPair(org.openkilda.wfm.topology.flow.model.FlowPathPair) FlowResourcesManager(org.openkilda.wfm.share.flow.resources.FlowResourcesManager) GetPathsResult(org.openkilda.pce.GetPathsResult) PersistenceManager(org.openkilda.persistence.PersistenceManager) PathId(org.openkilda.model.PathId) PathId(org.openkilda.model.PathId) FlowResources(org.openkilda.wfm.share.flow.resources.FlowResources) FlowPath(org.openkilda.model.FlowPath) Flow(org.openkilda.model.Flow) FlowPathPair(org.openkilda.wfm.topology.flow.model.FlowPathPair) GetPathsResult(org.openkilda.pce.GetPathsResult) TimedExecution(org.openkilda.wfm.share.metrics.TimedExecution)

Aggregations

TimedExecution (org.openkilda.wfm.share.metrics.TimedExecution)16 Flow (org.openkilda.model.Flow)11 SwitchId (org.openkilda.model.SwitchId)6 FlowPath (org.openkilda.model.FlowPath)5 MessageException (org.openkilda.messaging.error.MessageException)4 IslEndpoint (org.openkilda.model.IslEndpoint)4 HashSet (java.util.HashSet)3 FlowStatus (org.openkilda.model.FlowStatus)3 PathId (org.openkilda.model.PathId)3 IslNotFoundException (org.openkilda.wfm.error.IslNotFoundException)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 PathNode (org.openkilda.messaging.info.event.PathNode)2 YFlow (org.openkilda.model.YFlow)2 GetPathsResult (org.openkilda.pce.GetPathsResult)2 PersistenceManager (org.openkilda.persistence.PersistenceManager)2 SwitchNotFoundException (org.openkilda.wfm.error.SwitchNotFoundException)2 FlowResources (org.openkilda.wfm.share.flow.resources.FlowResources)2 FlowPathPair (org.openkilda.wfm.topology.flow.model.FlowPathPair)2 FlowThrottlingData (org.openkilda.wfm.topology.reroute.model.FlowThrottlingData)2