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