Search in sources :

Example 1 with FlowAlreadyExistException

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

the class ResourcesAllocationAction method createFlow.

private void createFlow(RequestedFlow targetFlow) throws FlowNotFoundException, FlowAlreadyExistException {
    try {
        transactionManager.doInTransaction(() -> {
            Flow flow = RequestedFlowMapper.INSTANCE.toFlow(targetFlow);
            flow.setStatus(FlowStatus.IN_PROGRESS);
            getFlowDiverseGroupFromContext(targetFlow.getDiverseFlowId()).ifPresent(flow::setDiverseGroupId);
            getFlowAffinityGroupFromContext(targetFlow.getAffinityFlowId()).ifPresent(flow::setAffinityGroupId);
            flowRepository.add(flow);
        });
    } catch (ConstraintViolationException e) {
        throw new FlowAlreadyExistException(format("Failed to save flow with id %s", targetFlow.getFlowId()), e);
    }
}
Also used : FlowAlreadyExistException(org.openkilda.wfm.error.FlowAlreadyExistException) ConstraintViolationException(org.openkilda.persistence.exceptions.ConstraintViolationException) Flow(org.openkilda.model.Flow) YSubFlow(org.openkilda.model.YSubFlow) RequestedFlow(org.openkilda.wfm.topology.flowhs.model.RequestedFlow) YFlow(org.openkilda.model.YFlow)

Example 2 with FlowAlreadyExistException

use of org.openkilda.wfm.error.FlowAlreadyExistException 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)

Aggregations

Flow (org.openkilda.model.Flow)2 YFlow (org.openkilda.model.YFlow)2 YSubFlow (org.openkilda.model.YSubFlow)2 FlowAlreadyExistException (org.openkilda.wfm.error.FlowAlreadyExistException)2 RequestedFlow (org.openkilda.wfm.topology.flowhs.model.RequestedFlow)2 RecoverableException (org.openkilda.pce.exception.RecoverableException)1 UnroutableFlowException (org.openkilda.pce.exception.UnroutableFlowException)1 ConstraintViolationException (org.openkilda.persistence.exceptions.ConstraintViolationException)1 FlowNotFoundException (org.openkilda.wfm.error.FlowNotFoundException)1 ResourceAllocationException (org.openkilda.wfm.share.flow.resources.ResourceAllocationException)1 FlowProcessingException (org.openkilda.wfm.topology.flowhs.exception.FlowProcessingException)1