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();
}
Aggregations