Search in sources :

Example 16 with FlowProcessingException

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

the class ValidateYFlowAction method performWithResponse.

@Override
protected Optional<Message> performWithResponse(State from, State to, Event event, YFlowCreateContext context, YFlowCreateFsm stateMachine) {
    YFlowRequest targetFlow = context.getTargetFlow();
    String yFlowId = targetFlow.getYFlowId();
    boolean isOperationAllowed = featureTogglesRepository.getOrDefault().getModifyYFlowEnabled();
    if (!isOperationAllowed) {
        throw new FlowProcessingException(ErrorType.NOT_PERMITTED, "Y-flow create feature is disabled");
    }
    if (flowRepository.exists(yFlowId)) {
        throw new FlowProcessingException(ErrorType.ALREADY_EXISTS, format("Flow %s already exists", yFlowId));
    }
    if (yFlowRepository.exists(yFlowId)) {
        throw new FlowProcessingException(ErrorType.ALREADY_EXISTS, format("Y-flow %s already exists", yFlowId));
    }
    try {
        yFlowValidator.validate(targetFlow);
    } 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(targetFlow);
    List<FlowEndpoint> subFlowEndpoints = targetFlow.getSubFlows().stream().map(SubFlowDto::getEndpoint).collect(Collectors.toList());
    dashboardLogger.onYFlowCreate(yFlowId, targetFlow.getSharedEndpoint(), subFlowEndpoints, targetFlow.getMaximumBandwidth());
    stateMachine.saveNewEventToHistory("Y-flow was validated successfully", FlowEventData.Event.CREATE);
    return Optional.empty();
}
Also used : UnavailableFlowEndpointException(org.openkilda.wfm.topology.flowhs.validation.UnavailableFlowEndpointException) FlowEndpoint(org.openkilda.model.FlowEndpoint) FlowProcessingException(org.openkilda.wfm.topology.flowhs.exception.FlowProcessingException) InvalidFlowException(org.openkilda.wfm.topology.flowhs.validation.InvalidFlowException) YFlowRequest(org.openkilda.messaging.command.yflow.YFlowRequest)

Example 17 with FlowProcessingException

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

the class OnSubFlowAllocatedAction method convertToYFlowDto.

private YFlowDto convertToYFlowDto(YFlow yFlow) {
    Flow mainAffinityFlow = yFlow.getSubFlows().stream().map(YSubFlow::getFlow).filter(flow -> flow.getFlowId().equals(flow.getAffinityGroupId())).findFirst().orElseThrow(() -> new FlowProcessingException(ErrorType.INTERNAL_ERROR, "Main affinity flow not found"));
    Collection<Flow> diverseWithFlow = getDiverseWithFlow(mainAffinityFlow);
    Set<String> diverseFlows = diverseWithFlow.stream().filter(flow -> flow.getYFlowId() == null).map(Flow::getFlowId).collect(Collectors.toSet());
    Set<String> diverseYFlows = diverseWithFlow.stream().map(Flow::getYFlowId).filter(Objects::nonNull).collect(Collectors.toSet());
    return YFlowMapper.INSTANCE.toYFlowDto(yFlow, diverseFlows, diverseYFlows);
}
Also used : FlowProcessingException(org.openkilda.wfm.topology.flowhs.exception.FlowProcessingException) Flow(org.openkilda.model.Flow) YFlow(org.openkilda.model.YFlow) YSubFlow(org.openkilda.model.YSubFlow)

Example 18 with FlowProcessingException

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

the class OnRevertSubFlowAllocatedAction method perform.

@Override
protected void perform(State from, State to, Event event, YFlowUpdateContext context, YFlowUpdateFsm stateMachine) {
    String subFlowId = context.getSubFlowId();
    if (!stateMachine.isUpdatingSubFlow(subFlowId)) {
        throw new IllegalStateException("Received an event for non-pending sub-flow " + subFlowId);
    }
    String yFlowId = stateMachine.getYFlowId();
    stateMachine.saveActionToHistory("Reverting a sub-flow", format("Allocated resources for sub-flow %s of y-flow %s", subFlowId, yFlowId));
    stateMachine.addAllocatedSubFlow(subFlowId);
    SubFlowDto subFlowDto = stateMachine.getOriginalFlow().getSubFlows().stream().filter(f -> f.getFlowId().equals(subFlowId)).findAny().orElseThrow(() -> new FlowProcessingException(ErrorType.INTERNAL_ERROR, format("Can't find definition of updated sub-flow %s", subFlowId)));
    SubFlowSharedEndpointEncapsulation sharedEndpoint = subFlowDto.getSharedEndpoint();
    FlowEndpoint endpoint = subFlowDto.getEndpoint();
    log.debug("Start updating sub-flow references from {} to y-flow {}", subFlowId, stateMachine.getYFlowId());
    transactionManager.doInTransaction(() -> {
        YFlow yFlow = yFlowRepository.findById(yFlowId).orElseThrow(() -> new FlowProcessingException(ErrorType.INTERNAL_ERROR, format("Y-flow %s not found", yFlowId)));
        Flow flow = flowRepository.findById(subFlowId).orElseThrow(() -> new FlowProcessingException(ErrorType.INTERNAL_ERROR, format("Flow %s not found", subFlowId)));
        YSubFlow subFlow = YSubFlow.builder().yFlow(yFlow).flow(flow).sharedEndpointVlan(sharedEndpoint.getVlanId()).sharedEndpointInnerVlan(sharedEndpoint.getInnerVlanId()).endpointSwitchId(endpoint.getSwitchId()).endpointPort(endpoint.getPortNumber()).endpointVlan(endpoint.getOuterVlanId()).endpointInnerVlan(endpoint.getInnerVlanId()).build();
        yFlow.updateSubFlow(subFlow);
        return yFlow;
    });
}
Also used : YFlow(org.openkilda.model.YFlow) FlowEndpoint(org.openkilda.model.FlowEndpoint) FlowProcessingException(org.openkilda.wfm.topology.flowhs.exception.FlowProcessingException) SubFlowSharedEndpointEncapsulation(org.openkilda.messaging.command.yflow.SubFlowSharedEndpointEncapsulation) SubFlowDto(org.openkilda.messaging.command.yflow.SubFlowDto) YSubFlow(org.openkilda.model.YSubFlow) YSubFlow(org.openkilda.model.YSubFlow) Flow(org.openkilda.model.Flow) YFlow(org.openkilda.model.YFlow)

Example 19 with FlowProcessingException

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

the class CreateDraftYFlowAction method performWithResponse.

@Override
protected Optional<Message> performWithResponse(State from, State to, Event event, YFlowCreateContext context, YFlowCreateFsm stateMachine) {
    YFlowRequest targetFlow = stateMachine.getTargetFlow();
    stateMachine.setDiverseFlowId(targetFlow.getDiverseFlowId());
    String yFlowId = targetFlow.getYFlowId();
    if (yFlowRepository.exists(yFlowId)) {
        throw new FlowProcessingException(ErrorType.ALREADY_EXISTS, format("Y-flow %s already exists", yFlowId));
    }
    YFlow result = transactionManager.doInTransaction(() -> {
        YFlow yFlow = YFlowRequestMapper.INSTANCE.toYFlow(targetFlow);
        yFlow.setStatus(FlowStatus.IN_PROGRESS);
        yFlowRepository.add(yFlow);
        return yFlow;
    });
    stateMachine.saveActionToHistory(format("Draft y-flow was created with status %s", result.getStatus()));
    return Optional.empty();
}
Also used : YFlow(org.openkilda.model.YFlow) FlowProcessingException(org.openkilda.wfm.topology.flowhs.exception.FlowProcessingException) YFlowRequest(org.openkilda.messaging.command.yflow.YFlowRequest)

Example 20 with FlowProcessingException

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

the class YFlowReadService method convertToYFlowDto.

private YFlowDto convertToYFlowDto(YFlow yFlow) {
    Flow mainAffinityFlow = yFlow.getSubFlows().stream().map(YSubFlow::getFlow).filter(flow -> flow.getFlowId().equals(flow.getAffinityGroupId())).findFirst().orElseThrow(() -> new FlowProcessingException(ErrorType.INTERNAL_ERROR, "Main affinity flow not found"));
    Collection<Flow> diverseWithFlow = getDiverseWithFlow(mainAffinityFlow);
    Set<String> diverseFlows = diverseWithFlow.stream().filter(flow -> flow.getYFlowId() == null).map(Flow::getFlowId).collect(Collectors.toSet());
    Set<String> diverseYFlows = diverseWithFlow.stream().map(Flow::getYFlowId).filter(Objects::nonNull).collect(Collectors.toSet());
    return YFlowMapper.INSTANCE.toYFlowDto(yFlow, diverseFlows, diverseYFlows);
}
Also used : FlowProcessingException(org.openkilda.wfm.topology.flowhs.exception.FlowProcessingException) Flow(org.openkilda.model.Flow) YFlow(org.openkilda.model.YFlow) YSubFlow(org.openkilda.model.YSubFlow)

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