Search in sources :

Example 6 with InvalidFlowException

use of org.openkilda.wfm.topology.flowhs.validation.InvalidFlowException in project open-kilda by telstra.

the class FlowValidateAction method performWithResponse.

@Override
protected Optional<Message> performWithResponse(State from, State to, Event event, FlowCreateContext context, FlowCreateFsm stateMachine) throws FlowProcessingException {
    RequestedFlow request = context.getTargetFlow();
    dashboardLogger.onFlowCreate(request.getFlowId(), request.getSrcSwitch(), request.getSrcPort(), request.getSrcVlan(), request.getDestSwitch(), request.getDestPort(), request.getDestVlan(), request.getDiverseFlowId(), request.getBandwidth());
    boolean isOperationAllowed = featureTogglesRepository.getOrDefault().getCreateFlowEnabled();
    if (!isOperationAllowed) {
        throw new FlowProcessingException(ErrorType.NOT_PERMITTED, "Flow create feature is disabled");
    }
    if (flowRepository.exists(request.getFlowId())) {
        throw new FlowProcessingException(ErrorType.ALREADY_EXISTS, format("Flow %s already exists", request.getFlowId()));
    }
    if (yFlowRepository.exists(request.getFlowId())) {
        throw new FlowProcessingException(ErrorType.ALREADY_EXISTS, format("Y-flow %s already exists", request.getFlowId()));
    }
    try {
        flowValidator.validate(request);
    } catch (InvalidFlowException e) {
        throw new FlowProcessingException(e.getType(), e.getMessage(), e);
    } catch (UnavailableFlowEndpointException e) {
        throw new FlowProcessingException(ErrorType.DATA_INVALID, e.getMessage(), e);
    }
    stateMachine.setTargetFlow(request);
    if (event != Event.RETRY) {
        stateMachine.saveNewEventToHistory("Flow was validated successfully", FlowEventData.Event.CREATE);
    } else {
        // no need to save a new event into DB, it should already exist there.
        stateMachine.saveActionToHistory("Flow was validated successfully");
    }
    return Optional.empty();
}
Also used : UnavailableFlowEndpointException(org.openkilda.wfm.topology.flowhs.validation.UnavailableFlowEndpointException) FlowProcessingException(org.openkilda.wfm.topology.flowhs.exception.FlowProcessingException) RequestedFlow(org.openkilda.wfm.topology.flowhs.model.RequestedFlow) InvalidFlowException(org.openkilda.wfm.topology.flowhs.validation.InvalidFlowException)

Aggregations

FlowProcessingException (org.openkilda.wfm.topology.flowhs.exception.FlowProcessingException)6 InvalidFlowException (org.openkilda.wfm.topology.flowhs.validation.InvalidFlowException)6 UnavailableFlowEndpointException (org.openkilda.wfm.topology.flowhs.validation.UnavailableFlowEndpointException)6 Flow (org.openkilda.model.Flow)3 RequestedFlow (org.openkilda.wfm.topology.flowhs.model.RequestedFlow)3 YFlowRequest (org.openkilda.messaging.command.yflow.YFlowRequest)2 FlowEndpoint (org.openkilda.model.FlowEndpoint)2 ErrorData (org.openkilda.messaging.error.ErrorData)1 PathId (org.openkilda.model.PathId)1 PhysicalPort (org.openkilda.model.PhysicalPort)1 YFlow (org.openkilda.model.YFlow)1 YSubFlow (org.openkilda.model.YSubFlow)1 RequestedFlowMirrorPoint (org.openkilda.wfm.topology.flowhs.model.RequestedFlowMirrorPoint)1