Search in sources :

Example 1 with FlowNotFoundException

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

the class ResourcesAllocationAction method allocateProtectedPath.

private void allocateProtectedPath(FlowCreateFsm stateMachine) throws UnroutableFlowException, RecoverableException, ResourceAllocationException, FlowNotFoundException {
    String flowId = stateMachine.getFlowId();
    Flow tmpFlow = getFlow(flowId);
    if (!tmpFlow.isAllocateProtectedPath()) {
        return;
    }
    tmpFlow.setDiverseGroupId(getFlowDiverseGroupFromContext(flowId).orElseThrow(() -> new FlowNotFoundException(flowId)));
    GetPathsResult protectedPath = pathComputer.getPath(tmpFlow);
    stateMachine.setBackUpProtectedPathComputationWayUsed(protectedPath.isBackUpPathComputationWayUsed());
    boolean overlappingProtectedPathFound = flowPathBuilder.arePathsOverlapped(protectedPath.getForward(), tmpFlow.getForwardPath()) || flowPathBuilder.arePathsOverlapped(protectedPath.getReverse(), tmpFlow.getReversePath());
    if (overlappingProtectedPathFound) {
        log.info("Couldn't find non overlapping protected path. Result flow state: {}", tmpFlow);
        throw new UnroutableFlowException("Couldn't find non overlapping protected path", tmpFlow.getFlowId());
    }
    log.debug("Creating the protected path {} for flow {}", protectedPath, tmpFlow);
    transactionManager.doInTransaction(() -> {
        Flow flow = getFlow(flowId);
        FlowResources flowResources = resourcesManager.allocateFlowResources(flow);
        final FlowSegmentCookieBuilder cookieBuilder = FlowSegmentCookie.builder().flowEffectiveId(flowResources.getUnmaskedCookie());
        FlowPath forward = flowPathBuilder.buildFlowPath(flow, flowResources.getForward(), protectedPath.getForward(), cookieBuilder.direction(FlowPathDirection.FORWARD).build(), false, stateMachine.getSharedBandwidthGroupId());
        forward.setStatus(FlowPathStatus.IN_PROGRESS);
        flowPathRepository.add(forward);
        flow.setProtectedForwardPath(forward);
        FlowPath reverse = flowPathBuilder.buildFlowPath(flow, flowResources.getReverse(), protectedPath.getReverse(), cookieBuilder.direction(FlowPathDirection.REVERSE).build(), false, stateMachine.getSharedBandwidthGroupId());
        reverse.setStatus(FlowPathStatus.IN_PROGRESS);
        flowPathRepository.add(reverse);
        flow.setProtectedReversePath(reverse);
        updateIslsForFlowPath(forward.getPathId());
        updateIslsForFlowPath(reverse.getPathId());
        stateMachine.setProtectedForwardPathId(forward.getPathId());
        stateMachine.setProtectedReversePathId(reverse.getPathId());
        log.debug("Allocated resources for the flow {}: {}", flow.getFlowId(), flowResources);
        stateMachine.getFlowResources().add(flowResources);
    });
}
Also used : FlowNotFoundException(org.openkilda.wfm.error.FlowNotFoundException) FlowResources(org.openkilda.wfm.share.flow.resources.FlowResources) UnroutableFlowException(org.openkilda.pce.exception.UnroutableFlowException) FlowSegmentCookieBuilder(org.openkilda.model.cookie.FlowSegmentCookie.FlowSegmentCookieBuilder) FlowPath(org.openkilda.model.FlowPath) Flow(org.openkilda.model.Flow) YSubFlow(org.openkilda.model.YSubFlow) RequestedFlow(org.openkilda.wfm.topology.flowhs.model.RequestedFlow) YFlow(org.openkilda.model.YFlow) GetPathsResult(org.openkilda.pce.GetPathsResult)

Example 2 with FlowNotFoundException

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

the class ResourcesAllocationAction method performWithResponse.

@Override
protected Optional<Message> performWithResponse(State from, State to, Event event, FlowCreateContext context, FlowCreateFsm stateMachine) throws FlowProcessingException {
    try {
        String flowId = stateMachine.getFlowId();
        log.debug("Allocation resources has been started");
        stateMachine.setPathsBeenAllocated(false);
        if (context != null && context.getTargetFlow() != null) {
            createFlow(context.getTargetFlow());
        } else if (!flowRepository.exists(flowId)) {
            log.warn("Flow {} has been deleted while creation was in progress", flowId);
            return Optional.empty();
        }
        createPaths(stateMachine);
        log.debug("Resources allocated successfully for the flow {}", flowId);
        stateMachine.setPathsBeenAllocated(true);
        Flow resultFlow = getFlow(flowId);
        createSpeakerRequestFactories(stateMachine, resultFlow);
        saveHistory(stateMachine, resultFlow);
        if (resultFlow.isOneSwitchFlow()) {
            stateMachine.fire(Event.SKIP_NON_INGRESS_RULES_INSTALL);
        } else {
            stateMachine.fireNext(context);
        }
        // Notify about successful allocation.
        stateMachine.notifyEventListeners(listener -> listener.onResourcesAllocated(flowId));
        return Optional.of(buildResponseMessage(resultFlow, stateMachine.getCommandContext()));
    } catch (UnroutableFlowException | RecoverableException e) {
        throw new FlowProcessingException(ErrorType.NOT_FOUND, "Not enough bandwidth or no path found. " + e.getMessage(), e);
    } catch (ResourceAllocationException e) {
        throw new FlowProcessingException(ErrorType.INTERNAL_ERROR, "Failed to allocate flow resources. " + e.getMessage(), e);
    } catch (FlowNotFoundException e) {
        throw new FlowProcessingException(ErrorType.NOT_FOUND, "Couldn't find the diverse flow. " + e.getMessage(), e);
    } catch (FlowAlreadyExistException e) {
        if (!stateMachine.retryIfAllowed()) {
            throw new FlowProcessingException(ErrorType.INTERNAL_ERROR, e.getMessage(), e);
        } else {
            // we have retried the operation, no need to respond.
            log.debug(e.getMessage(), e);
            return Optional.empty();
        }
    }
}
Also used : FlowNotFoundException(org.openkilda.wfm.error.FlowNotFoundException) FlowProcessingException(org.openkilda.wfm.topology.flowhs.exception.FlowProcessingException) FlowAlreadyExistException(org.openkilda.wfm.error.FlowAlreadyExistException) UnroutableFlowException(org.openkilda.pce.exception.UnroutableFlowException) ResourceAllocationException(org.openkilda.wfm.share.flow.resources.ResourceAllocationException) RecoverableException(org.openkilda.pce.exception.RecoverableException) Flow(org.openkilda.model.Flow) YSubFlow(org.openkilda.model.YSubFlow) RequestedFlow(org.openkilda.wfm.topology.flowhs.model.RequestedFlow) YFlow(org.openkilda.model.YFlow)

Example 3 with FlowNotFoundException

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

the class FlowValidationFsm method receiveData.

protected void receiveData(State from, State to, Event event, Object context) {
    Flow flow;
    try {
        flow = service.checkFlowStatusAndGetFlow(flowId);
    } catch (FlowNotFoundException e) {
        log.error("Flow {} not found when sending commands to SpeakerWorkerBolt", flowId, e);
        sendException(e.getMessage(), "Receiving rules operation in FlowValidationFsm", ErrorType.NOT_FOUND);
        return;
    } catch (IllegalFlowStateException e) {
        log.error("Could not validate flow: Flow {} is in DOWN state", flowId, e);
        sendException("Could not validate flow", format("Could not validate flow: Flow %s is in DOWN state", flowId), ErrorType.UNPROCESSABLE_REQUEST);
        return;
    }
    List<SwitchId> switchIds = service.getSwitchIdListByFlowId(flowId);
    awaitingRules = switchIds.size();
    log.debug("Send commands to get rules on the switches");
    switchIds.forEach(switchId -> getCarrier().sendSpeakerRequest(flowId, new DumpRulesForFlowHsRequest(switchId)));
    log.debug("Send commands to get meters on the termination switches");
    awaitingMeters = TERMINATION_SWITCHES_COUNT;
    getCarrier().sendSpeakerRequest(flowId, new DumpMetersForFlowHsRequest(flow.getSrcSwitchId()));
    getCarrier().sendSpeakerRequest(flowId, new DumpMetersForFlowHsRequest(flow.getDestSwitchId()));
    log.debug("Send commands to get groups on the termination switches");
    awaitingGroups = TERMINATION_SWITCHES_COUNT;
    getCarrier().sendSpeakerRequest(flowId, new DumpGroupsForFlowHsRequest(flow.getSrcSwitchId()));
    getCarrier().sendSpeakerRequest(flowId, new DumpGroupsForFlowHsRequest(flow.getDestSwitchId()));
}
Also used : FlowNotFoundException(org.openkilda.wfm.error.FlowNotFoundException) DumpGroupsForFlowHsRequest(org.openkilda.messaging.command.switches.DumpGroupsForFlowHsRequest) DumpMetersForFlowHsRequest(org.openkilda.messaging.command.switches.DumpMetersForFlowHsRequest) IllegalFlowStateException(org.openkilda.wfm.error.IllegalFlowStateException) DumpRulesForFlowHsRequest(org.openkilda.messaging.command.switches.DumpRulesForFlowHsRequest) SwitchId(org.openkilda.model.SwitchId) Flow(org.openkilda.model.Flow)

Example 4 with FlowNotFoundException

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

the class FlowValidationService method validateFlow.

/**
 * Validate flow.
 */
public List<FlowValidationResponse> validateFlow(String flowId, List<SwitchFlowEntries> switchFlowEntries, List<SwitchMeterEntries> switchMeterEntries, List<SwitchGroupEntries> switchGroupEntries) throws FlowNotFoundException, SwitchNotFoundException {
    Map<SwitchId, List<SimpleSwitchRule>> switchRules = new HashMap<>();
    int rulesCount = 0;
    int metersCount = 0;
    for (SwitchFlowEntries switchRulesEntries : switchFlowEntries) {
        SwitchMeterEntries switchMeters = switchMeterEntries.stream().filter(meterEntries -> switchRulesEntries.getSwitchId().equals(meterEntries.getSwitchId())).findFirst().orElse(null);
        SwitchGroupEntries switchGroup = switchGroupEntries.stream().filter(groupEntries -> switchRulesEntries.getSwitchId().equals(groupEntries.getSwitchId())).findFirst().orElse(null);
        List<SimpleSwitchRule> simpleSwitchRules = simpleSwitchRuleConverter.convertSwitchFlowEntriesToSimpleSwitchRules(switchRulesEntries, switchMeters, switchGroup);
        switchRules.put(switchRulesEntries.getSwitchId(), simpleSwitchRules);
        rulesCount += Optional.ofNullable(switchRulesEntries.getFlowEntries()).map(List::size).orElse(0);
        metersCount += Optional.ofNullable(switchMeters).map(SwitchMeterEntries::getMeterEntries).map(List::size).orElse(0);
    }
    Optional<Flow> foundFlow = flowRepository.findById(flowId);
    if (!foundFlow.isPresent()) {
        throw new FlowNotFoundException(flowId);
    }
    Flow flow = foundFlow.get();
    if (flow.getForwardPath() == null) {
        throw new InvalidPathException(flowId, "Forward path was not returned.");
    }
    if (flow.getReversePath() == null) {
        throw new InvalidPathException(flowId, "Reverse path was not returned.");
    }
    List<FlowValidationResponse> flowValidationResponse = new ArrayList<>();
    List<SimpleSwitchRule> forwardRules = getSimpleSwitchRules(flow, flow.getForwardPath(), flow.getReversePath());
    flowValidationResponse.add(compare(switchRules, forwardRules, flowId, rulesCount, metersCount));
    List<SimpleSwitchRule> reverseRules = getSimpleSwitchRules(flow, flow.getReversePath(), flow.getForwardPath());
    flowValidationResponse.add(compare(switchRules, reverseRules, flowId, rulesCount, metersCount));
    if (flow.getProtectedForwardPath() != null) {
        List<SimpleSwitchRule> forwardProtectedRules = getSimpleSwitchRules(flow, flow.getProtectedForwardPath(), flow.getProtectedReversePath());
        flowValidationResponse.add(compare(switchRules, forwardProtectedRules, flowId, rulesCount, metersCount));
    }
    if (flow.getProtectedReversePath() != null) {
        List<SimpleSwitchRule> reverseProtectedRules = getSimpleSwitchRules(flow, flow.getProtectedReversePath(), flow.getProtectedForwardPath());
        flowValidationResponse.add(compare(switchRules, reverseProtectedRules, flowId, rulesCount, metersCount));
    }
    return flowValidationResponse;
}
Also used : FlowNotFoundException(org.openkilda.wfm.error.FlowNotFoundException) SwitchFlowEntries(org.openkilda.messaging.info.rule.SwitchFlowEntries) HashMap(java.util.HashMap) SwitchMeterEntries(org.openkilda.messaging.info.meter.SwitchMeterEntries) ArrayList(java.util.ArrayList) SwitchId(org.openkilda.model.SwitchId) FlowValidationResponse(org.openkilda.messaging.info.flow.FlowValidationResponse) InvalidPathException(java.nio.file.InvalidPathException) Flow(org.openkilda.model.Flow) SimpleSwitchRule(org.openkilda.wfm.share.utils.rule.validation.SimpleSwitchRule) SwitchGroupEntries(org.openkilda.messaging.info.rule.SwitchGroupEntries) ArrayList(java.util.ArrayList) List(java.util.List)

Example 5 with FlowNotFoundException

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

the class YFlowReadService method getYFlowPaths.

/**
 * Gets y-flow paths.
 */
public YFlowPathsResponse getYFlowPaths(@NonNull String yFlowId) throws FlowNotFoundException {
    return transactionManager.doInTransaction(getReadOperationRetryPolicy(), () -> {
        Set<YSubFlow> subFlows = yFlowRepository.findById(yFlowId).orElseThrow(() -> new FlowNotFoundException(yFlowId)).getSubFlows();
        Set<FlowPath> mainPaths = new HashSet<>();
        Set<FlowPath> protectedPaths = new HashSet<>();
        for (YSubFlow subFlow : subFlows) {
            Flow flow = subFlow.getFlow();
            mainPaths.add(flow.getForwardPath());
            if (flow.isAllocateProtectedPath() && flow.getProtectedForwardPath() != null) {
                protectedPaths.add(flow.getProtectedForwardPath());
            }
        }
        List<PathSegment> sharedPathSegments = IntersectionComputer.calculatePathIntersectionFromSource(mainPaths);
        PathInfoData sharedPath = FlowPathMapper.INSTANCE.map(sharedPathSegments);
        PathInfoData sharedProtectedPath;
        // At least 2 paths required to calculate Y-point.
        if (protectedPaths.size() < 2) {
            sharedProtectedPath = new PathInfoData();
        } else {
            List<PathSegment> pathSegments = IntersectionComputer.calculatePathIntersectionFromSource(protectedPaths);
            sharedProtectedPath = FlowPathMapper.INSTANCE.map(pathSegments);
        }
        List<SubFlowPathDto> subFlowPathDtos = mainPaths.stream().map(flowPath -> new SubFlowPathDto(flowPath.getFlowId(), FlowPathMapper.INSTANCE.map(flowPath))).collect(Collectors.toList());
        List<SubFlowPathDto> subFlowProtectedPathDtos = protectedPaths.stream().map(flowPath -> new SubFlowPathDto(flowPath.getFlowId(), FlowPathMapper.INSTANCE.map(flowPath))).collect(Collectors.toList());
        return new YFlowPathsResponse(sharedPath, subFlowPathDtos, sharedProtectedPath, subFlowProtectedPathDtos);
    });
}
Also used : TransactionManager(org.openkilda.persistence.tx.TransactionManager) PathSegment(org.openkilda.model.PathSegment) FlowPath(org.openkilda.model.FlowPath) SubFlowDto(org.openkilda.messaging.command.yflow.SubFlowDto) YFlowResponse(org.openkilda.messaging.command.yflow.YFlowResponse) FlowPathMapper(org.openkilda.wfm.share.mappers.FlowPathMapper) YFlowDto(org.openkilda.messaging.command.yflow.YFlowDto) PathInfoData(org.openkilda.messaging.info.event.PathInfoData) HashSet(java.util.HashSet) Flow(org.openkilda.model.Flow) IntersectionComputer(org.openkilda.wfm.share.service.IntersectionComputer) Duration(java.time.Duration) SubFlowsResponse(org.openkilda.messaging.command.yflow.SubFlowsResponse) YFlow(org.openkilda.model.YFlow) FlowRepository(org.openkilda.persistence.repositories.FlowRepository) PersistenceManager(org.openkilda.persistence.PersistenceManager) YFlowPathsResponse(org.openkilda.messaging.command.yflow.YFlowPathsResponse) FlowNotFoundException(org.openkilda.wfm.error.FlowNotFoundException) YSubFlow(org.openkilda.model.YSubFlow) ErrorType(org.openkilda.messaging.error.ErrorType) NonNull(lombok.NonNull) Collection(java.util.Collection) Set(java.util.Set) RetryPolicy(net.jodah.failsafe.RetryPolicy) PersistenceException(org.openkilda.persistence.exceptions.PersistenceException) Collectors(java.util.stream.Collectors) YFlowRepository(org.openkilda.persistence.repositories.YFlowRepository) YFlowMapper(org.openkilda.wfm.topology.flowhs.mapper.YFlowMapper) Objects(java.util.Objects) FlowProcessingException(org.openkilda.wfm.topology.flowhs.exception.FlowProcessingException) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) SubFlowPathDto(org.openkilda.messaging.command.yflow.SubFlowPathDto) Collections(java.util.Collections) FlowNotFoundException(org.openkilda.wfm.error.FlowNotFoundException) PathSegment(org.openkilda.model.PathSegment) YSubFlow(org.openkilda.model.YSubFlow) Flow(org.openkilda.model.Flow) YFlow(org.openkilda.model.YFlow) YSubFlow(org.openkilda.model.YSubFlow) PathInfoData(org.openkilda.messaging.info.event.PathInfoData) FlowPath(org.openkilda.model.FlowPath) HashSet(java.util.HashSet) SubFlowPathDto(org.openkilda.messaging.command.yflow.SubFlowPathDto) YFlowPathsResponse(org.openkilda.messaging.command.yflow.YFlowPathsResponse)

Aggregations

FlowNotFoundException (org.openkilda.wfm.error.FlowNotFoundException)13 Flow (org.openkilda.model.Flow)9 List (java.util.List)6 SwitchId (org.openkilda.model.SwitchId)6 YFlow (org.openkilda.model.YFlow)6 YSubFlow (org.openkilda.model.YSubFlow)6 SwitchNotFoundException (org.openkilda.wfm.error.SwitchNotFoundException)6 ArrayList (java.util.ArrayList)5 Slf4j (lombok.extern.slf4j.Slf4j)4 MessageException (org.openkilda.messaging.error.MessageException)4 Duration (java.time.Duration)3 Collection (java.util.Collection)3 Collections (java.util.Collections)3 HashSet (java.util.HashSet)3 Objects (java.util.Objects)3 Optional (java.util.Optional)3 Set (java.util.Set)3 Collectors (java.util.stream.Collectors)3 RetryPolicy (net.jodah.failsafe.RetryPolicy)3 FlowResponse (org.openkilda.messaging.info.flow.FlowResponse)3