Search in sources :

Example 1 with FlowProcessingException

use of org.openkilda.wfm.topology.flowhs.exception.FlowProcessingException in project open-kilda by telstra.

the class CompleteFlowCreateAction method perform.

@Override
protected void perform(State from, State to, Event event, FlowCreateContext context, FlowCreateFsm stateMachine) {
    String flowId = stateMachine.getFlowId();
    if (!flowRepository.exists(flowId)) {
        throw new FlowProcessingException(ErrorType.NOT_FOUND, "Couldn't complete flow creation. The flow was deleted");
    }
    FlowStatus flowStatus = transactionManager.doInTransaction(() -> {
        FlowStatus status = FlowStatus.UP;
        FlowPathStatus primaryPathStatus;
        if (stateMachine.isBackUpPrimaryPathComputationWayUsed()) {
            primaryPathStatus = FlowPathStatus.DEGRADED;
            status = FlowStatus.DEGRADED;
        } else {
            primaryPathStatus = FlowPathStatus.ACTIVE;
        }
        flowPathRepository.updateStatus(stateMachine.getForwardPathId(), primaryPathStatus);
        flowPathRepository.updateStatus(stateMachine.getReversePathId(), primaryPathStatus);
        if (stateMachine.getProtectedForwardPathId() != null && stateMachine.getProtectedReversePathId() != null) {
            FlowPathStatus protectedPathStatus;
            if (stateMachine.isBackUpProtectedPathComputationWayUsed()) {
                protectedPathStatus = FlowPathStatus.DEGRADED;
                status = FlowStatus.DEGRADED;
            } else {
                protectedPathStatus = FlowPathStatus.ACTIVE;
            }
            flowPathRepository.updateStatus(stateMachine.getProtectedForwardPathId(), protectedPathStatus);
            flowPathRepository.updateStatus(stateMachine.getProtectedReversePathId(), protectedPathStatus);
        }
        flowRepository.updateStatus(flowId, status);
        if (FlowStatus.DEGRADED.equals(status)) {
            flowRepository.updateStatusInfo(flowId, "An alternative way " + "(back up strategy or max_latency_tier2 value) of building the path was used");
        }
        return status;
    });
    dashboardLogger.onFlowStatusUpdate(flowId, flowStatus);
    stateMachine.saveActionToHistory(format("The flow status was set to %s", flowStatus));
}
Also used : FlowPathStatus(org.openkilda.model.FlowPathStatus) FlowProcessingException(org.openkilda.wfm.topology.flowhs.exception.FlowProcessingException) FlowStatus(org.openkilda.model.FlowStatus)

Example 2 with FlowProcessingException

use of org.openkilda.wfm.topology.flowhs.exception.FlowProcessingException in project open-kilda by telstra.

the class ValidateFlowAction method performWithResponse.

@Override
protected Optional<Message> performWithResponse(State from, State to, Event event, FlowDeleteContext context, FlowDeleteFsm stateMachine) {
    String flowId = stateMachine.getFlowId();
    dashboardLogger.onFlowDelete(flowId);
    boolean isOperationAllowed = featureTogglesRepository.getOrDefault().getDeleteFlowEnabled();
    if (!isOperationAllowed) {
        throw new FlowProcessingException(ErrorType.NOT_PERMITTED, "Flow delete feature is disabled");
    }
    Flow resultFlow = transactionManager.doInTransaction(() -> {
        Flow flow = getFlow(flowId);
        if (flow.getStatus() == FlowStatus.IN_PROGRESS) {
            throw new FlowProcessingException(ErrorType.REQUEST_INVALID, format("Flow %s is in progress now", flowId));
        }
        // Keep it, just in case we have to revert it.
        stateMachine.setOriginalFlowStatus(flow.getStatus());
        flow.setStatus(FlowStatus.IN_PROGRESS);
        return flow;
    });
    stateMachine.setDstSwitchId(resultFlow.getDestSwitchId());
    stateMachine.setSrcSwitchId(resultFlow.getSrcSwitchId());
    stateMachine.saveNewEventToHistory("Flow was validated successfully", FlowEventData.Event.DELETE);
    return Optional.of(buildResponseMessage(resultFlow, stateMachine.getCommandContext()));
}
Also used : FlowProcessingException(org.openkilda.wfm.topology.flowhs.exception.FlowProcessingException) Flow(org.openkilda.model.Flow)

Example 3 with FlowProcessingException

use of org.openkilda.wfm.topology.flowhs.exception.FlowProcessingException in project open-kilda by telstra.

the class EmitUpdateRulesRequestsAction method buildCommands.

private Collection<FlowSegmentRequestFactory> buildCommands(FlowMirrorPointCreateFsm stateMachine, Flow flow) {
    final FlowCommandBuilder commandBuilder = commandBuilderFactory.getBuilder(flow.getEncapsulationType());
    PathId flowPathId = stateMachine.getFlowPathId();
    FlowPath path = flow.getPath(flowPathId).orElseThrow(() -> new FlowProcessingException(ErrorType.NOT_FOUND, format("Flow path %s not found", flowPathId)));
    PathId oppositePathId = flow.getOppositePathId(flowPathId).orElseThrow(() -> new FlowProcessingException(ErrorType.NOT_FOUND, format("Opposite flow path id for path %s not found", flowPathId)));
    FlowPath oppositePath = flow.getPath(oppositePathId).orElse(null);
    RequestedFlowMirrorPoint mirrorPoint = stateMachine.getRequestedFlowMirrorPoint();
    CommandContext context = stateMachine.getCommandContext();
    SpeakerRequestBuildContext speakerContext = buildBaseSpeakerContextForInstall(path.getSrcSwitchId(), path.getDestSwitchId());
    if (mirrorPoint.getMirrorPointSwitchId().equals(path.getSrcSwitchId())) {
        return new ArrayList<>(commandBuilder.buildIngressOnlyOneDirection(context, flow, path, oppositePath, speakerContext.getForward(), MirrorContext.builder().buildMirrorFactoryOnly(true).addNewGroup(stateMachine.isAddNewGroup()).build()));
    } else if (mirrorPoint.getMirrorPointSwitchId().equals(path.getDestSwitchId())) {
        return new ArrayList<>(commandBuilder.buildEgressOnlyOneDirection(context, flow, path, oppositePath, MirrorContext.builder().buildMirrorFactoryOnly(true).addNewGroup(stateMachine.isAddNewGroup()).build()));
    }
    return Collections.emptyList();
}
Also used : PathId(org.openkilda.model.PathId) RequestedFlowMirrorPoint(org.openkilda.wfm.topology.flowhs.model.RequestedFlowMirrorPoint) CommandContext(org.openkilda.wfm.CommandContext) FlowProcessingException(org.openkilda.wfm.topology.flowhs.exception.FlowProcessingException) ArrayList(java.util.ArrayList) FlowCommandBuilder(org.openkilda.wfm.topology.flowhs.service.FlowCommandBuilder) FlowPath(org.openkilda.model.FlowPath) SpeakerRequestBuildContext(org.openkilda.wfm.share.model.SpeakerRequestBuildContext)

Example 4 with FlowProcessingException

use of org.openkilda.wfm.topology.flowhs.exception.FlowProcessingException in project open-kilda by telstra.

the class ResourceAllocationAction method createFlowMirrorPoints.

private FlowMirrorPoints createFlowMirrorPoints(RequestedFlowMirrorPoint mirrorPoint, FlowPath flowPath) throws ResourceAllocationException {
    Switch mirrorSwitch = switchRepository.findById(mirrorPoint.getMirrorPointSwitchId()).orElseThrow(() -> new FlowProcessingException(ErrorType.NOT_FOUND, format("Switch %s not found", mirrorPoint.getMirrorPointSwitchId())));
    MirrorDirection direction = mirrorPoint.getMirrorPointSwitchId().equals(flowPath.getSrcSwitchId()) ? MirrorDirection.INGRESS : MirrorDirection.EGRESS;
    MirrorGroup mirrorGroup = resourcesManager.getAllocatedMirrorGroup(mirrorPoint.getMirrorPointSwitchId(), mirrorPoint.getFlowId(), flowPath.getPathId(), MirrorGroupType.TRAFFIC_INTEGRITY, direction);
    FlowMirrorPoints flowMirrorPoints = FlowMirrorPoints.builder().mirrorSwitch(mirrorSwitch).mirrorGroup(mirrorGroup).build();
    flowMirrorPointsRepository.add(flowMirrorPoints);
    flowPath.addFlowMirrorPoints(flowMirrorPoints);
    return flowMirrorPoints;
}
Also used : MirrorGroup(org.openkilda.model.MirrorGroup) Switch(org.openkilda.model.Switch) FlowProcessingException(org.openkilda.wfm.topology.flowhs.exception.FlowProcessingException) FlowMirrorPoints(org.openkilda.model.FlowMirrorPoints) MirrorDirection(org.openkilda.model.MirrorDirection)

Example 5 with FlowProcessingException

use of org.openkilda.wfm.topology.flowhs.exception.FlowProcessingException in project open-kilda by telstra.

the class ValidateRequestAction method performWithResponse.

@Override
protected Optional<Message> performWithResponse(State from, State to, Event event, FlowMirrorPointCreateContext context, FlowMirrorPointCreateFsm stateMachine) {
    String flowId = stateMachine.getFlowId();
    RequestedFlowMirrorPoint mirrorPoint = context.getMirrorPoint();
    PathId mirrorPathId = new PathId(mirrorPoint.getMirrorPointId());
    stateMachine.setMirrorPathId(mirrorPathId);
    stateMachine.setMirrorSwitchId(mirrorPoint.getMirrorPointSwitchId());
    dashboardLogger.onFlowMirrorPointCreate(flowId, mirrorPoint.getMirrorPointSwitchId(), mirrorPoint.getMirrorPointDirection().toString(), mirrorPoint.getSinkEndpoint().getSwitchId(), mirrorPoint.getSinkEndpoint().getPortNumber(), mirrorPoint.getSinkEndpoint().getOuterVlanId());
    stateMachine.setRequestedFlowMirrorPoint(mirrorPoint);
    Flow flow = transactionManager.doInTransaction(() -> {
        Flow foundFlow = getFlow(flowId);
        if (foundFlow.getStatus() == FlowStatus.IN_PROGRESS) {
            throw new FlowProcessingException(ErrorType.REQUEST_INVALID, format("Flow %s is in progress now", flowId));
        }
        stateMachine.setFlowStatus(foundFlow.getStatus());
        flowRepository.updateStatus(flowId, FlowStatus.IN_PROGRESS);
        return foundFlow;
    });
    if (!mirrorPoint.getMirrorPointSwitchId().equals(mirrorPoint.getSinkEndpoint().getSwitchId())) {
        throw new FlowProcessingException(ErrorType.REQUEST_INVALID, format("Invalid sink endpoint switch id: %s. In the current implementation, " + "the sink switch id cannot differ from the mirror point switch id.", mirrorPoint.getSinkEndpoint().getSwitchId()));
    }
    if (!mirrorPoint.getMirrorPointSwitchId().equals(flow.getSrcSwitchId()) && !mirrorPoint.getMirrorPointSwitchId().equals(flow.getDestSwitchId())) {
        throw new FlowProcessingException(ErrorType.REQUEST_INVALID, format("Invalid mirror point switch id: %s", mirrorPoint.getMirrorPointSwitchId()));
    }
    if (flowMirrorPathRepository.exists(mirrorPathId)) {
        throw new FlowProcessingException(ErrorType.ALREADY_EXISTS, format("Flow mirror point %s already exists", mirrorPathId));
    }
    Optional<PhysicalPort> physicalPort = physicalPortRepository.findBySwitchIdAndPortNumber(mirrorPoint.getSinkEndpoint().getSwitchId(), mirrorPoint.getSinkEndpoint().getPortNumber());
    if (physicalPort.isPresent()) {
        throw new FlowProcessingException(ErrorType.REQUEST_INVALID, format("Invalid sink port %d on switch %s. This port is part of LAG %d. Please delete LAG port " + "or choose another sink port.", mirrorPoint.getSinkEndpoint().getPortNumber(), mirrorPoint.getSinkEndpoint().getSwitchId(), physicalPort.get().getLagLogicalPort().getLogicalPortNumber()));
    }
    try {
        flowValidator.flowMirrorPointValidate(mirrorPoint);
    } catch (InvalidFlowException e) {
        throw new FlowProcessingException(e.getType(), e.getMessage(), e);
    } catch (UnavailableFlowEndpointException e) {
        throw new FlowProcessingException(ErrorType.DATA_INVALID, e.getMessage(), e);
    }
    stateMachine.saveNewEventToHistory("Flow was validated successfully", FlowEventData.Event.FLOW_MIRROR_POINT_CREATE);
    return Optional.empty();
}
Also used : PathId(org.openkilda.model.PathId) UnavailableFlowEndpointException(org.openkilda.wfm.topology.flowhs.validation.UnavailableFlowEndpointException) RequestedFlowMirrorPoint(org.openkilda.wfm.topology.flowhs.model.RequestedFlowMirrorPoint) FlowProcessingException(org.openkilda.wfm.topology.flowhs.exception.FlowProcessingException) PhysicalPort(org.openkilda.model.PhysicalPort) InvalidFlowException(org.openkilda.wfm.topology.flowhs.validation.InvalidFlowException) Flow(org.openkilda.model.Flow)

Aggregations

FlowProcessingException (org.openkilda.wfm.topology.flowhs.exception.FlowProcessingException)40 Flow (org.openkilda.model.Flow)24 YFlow (org.openkilda.model.YFlow)20 YSubFlow (org.openkilda.model.YSubFlow)11 SwitchId (org.openkilda.model.SwitchId)7 CommandContext (org.openkilda.wfm.CommandContext)7 FlowEndpoint (org.openkilda.model.FlowEndpoint)6 PathId (org.openkilda.model.PathId)6 RequestedFlow (org.openkilda.wfm.topology.flowhs.model.RequestedFlow)6 InvalidFlowException (org.openkilda.wfm.topology.flowhs.validation.InvalidFlowException)6 UnavailableFlowEndpointException (org.openkilda.wfm.topology.flowhs.validation.UnavailableFlowEndpointException)6 ArrayList (java.util.ArrayList)5 YFlowRequest (org.openkilda.messaging.command.yflow.YFlowRequest)5 Switch (org.openkilda.model.Switch)5 SubFlowDto (org.openkilda.messaging.command.yflow.SubFlowDto)4 SubFlowSharedEndpointEncapsulation (org.openkilda.messaging.command.yflow.SubFlowSharedEndpointEncapsulation)4 FlowMirrorPath (org.openkilda.model.FlowMirrorPath)4 FlowMirrorPoints (org.openkilda.model.FlowMirrorPoints)4 FlowPath (org.openkilda.model.FlowPath)4 InfoMessage (org.openkilda.messaging.info.InfoMessage)3