Search in sources :

Example 21 with RequestedFlow

use of org.openkilda.wfm.topology.flowhs.model.RequestedFlow in project open-kilda by telstra.

the class UpdateSubFlowsAction method perform.

@Override
public void perform(State from, State to, Event event, YFlowUpdateContext context, YFlowUpdateFsm stateMachine) {
    Collection<RequestedFlow> requestedFlows = YFlowRequestMapper.INSTANCE.toRequestedFlows(stateMachine.getTargetFlow());
    stateMachine.setRequestedFlows(requestedFlows);
    log.debug("Start updating {} sub-flows for y-flow {}", requestedFlows.size(), stateMachine.getYFlowId());
    stateMachine.clearUpdatingSubFlows();
    String yFlowId = stateMachine.getYFlowId();
    requestedFlows.forEach(requestedFlow -> {
        String subFlowId = requestedFlow.getFlowId();
        stateMachine.addSubFlow(subFlowId);
        if (requestedFlow.getFlowId().equals(stateMachine.getMainAffinityFlowId())) {
            stateMachine.addUpdatingSubFlow(subFlowId);
            stateMachine.notifyEventListeners(listener -> listener.onSubFlowProcessingStart(yFlowId, subFlowId));
            CommandContext flowContext = stateMachine.getCommandContext().fork(subFlowId);
            requestedFlow.setDiverseFlowId(stateMachine.getDiverseFlowId());
            flowUpdateService.startFlowUpdating(flowContext, requestedFlow, yFlowId);
        }
    });
}
Also used : CommandContext(org.openkilda.wfm.CommandContext) RequestedFlow(org.openkilda.wfm.topology.flowhs.model.RequestedFlow)

Example 22 with RequestedFlow

use of org.openkilda.wfm.topology.flowhs.model.RequestedFlow in project open-kilda by telstra.

the class PathSwappingRuleRemovalAction method getOriginalFlowWithPaths.

protected Flow getOriginalFlowWithPaths(FlowPathSwappingFsm<T, S, E, C, ?, ?> stateMachine, RequestedFlow originalFlow) {
    Flow flow = RequestedFlowMapper.INSTANCE.toFlow(originalFlow);
    flow.setForwardPathId(stateMachine.getOldPrimaryForwardPath());
    flow.setReversePathId(stateMachine.getOldPrimaryReversePath());
    if (flow.isAllocateProtectedPath()) {
        flow.setProtectedForwardPathId(stateMachine.getOldProtectedForwardPath());
        flow.setProtectedReversePathId(stateMachine.getOldProtectedReversePath());
    }
    flow.addPaths(getFlow(stateMachine.getFlowId()).getPaths().toArray(new FlowPath[0]));
    return flow;
}
Also used : FlowPath(org.openkilda.model.FlowPath) Flow(org.openkilda.model.Flow) RequestedFlow(org.openkilda.wfm.topology.flowhs.model.RequestedFlow)

Example 23 with RequestedFlow

use of org.openkilda.wfm.topology.flowhs.model.RequestedFlow 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)

Example 24 with RequestedFlow

use of org.openkilda.wfm.topology.flowhs.model.RequestedFlow in project open-kilda by telstra.

the class FlowSwapEndpointsHubService method handleRequest.

/**
 * Handles request for swap flow endpoints.
 */
public void handleRequest(String key, CommandContext commandContext, SwapFlowEndpointRequest request) {
    if (yFlowRepository.isSubFlow(request.getFirstFlow().getFlowId())) {
        sendForbiddenSubFlowOperationToNorthbound(request.getFirstFlow().getFlowId(), commandContext);
        return;
    }
    if (yFlowRepository.isSubFlow(request.getSecondFlow().getFlowId())) {
        sendForbiddenSubFlowOperationToNorthbound(request.getSecondFlow().getFlowId(), commandContext);
        return;
    }
    log.debug("Handling swap flow endpoints request with key {} and flow IDs: {}, {}", key, request.getFirstFlow().getFlowId(), request.getSecondFlow().getFlowId());
    if (fsmRegister.hasRegisteredFsmWithKey(key)) {
        log.error("Attempt to create a FSM with key {}, while there's another active FSM with the same key.", key);
        return;
    }
    RequestedFlow firstFlow = RequestedFlowMapper.INSTANCE.toRequestedFlow(request.getFirstFlow());
    RequestedFlow secondFlow = RequestedFlowMapper.INSTANCE.toRequestedFlow(request.getSecondFlow());
    FlowSwapEndpointsFsm fsm = fsmFactory.newInstance(commandContext, firstFlow, secondFlow);
    fsmRegister.registerFsm(key, fsm);
    fsm.fire(Event.NEXT);
    removeIfFinished(fsm, key);
}
Also used : FlowSwapEndpointsFsm(org.openkilda.wfm.topology.flowhs.fsm.swapendpoints.FlowSwapEndpointsFsm) RequestedFlow(org.openkilda.wfm.topology.flowhs.model.RequestedFlow)

Example 25 with RequestedFlow

use of org.openkilda.wfm.topology.flowhs.model.RequestedFlow in project open-kilda by telstra.

the class FlowCreateService method handleRequest.

/**
 * Handles request for flow creation.
 *
 * @param key command identifier.
 * @param request request data.
 */
public void handleRequest(@NonNull String key, @NonNull CommandContext commandContext, @NonNull FlowRequest request) throws DuplicateKeyException {
    RequestedFlow requestedFlow = RequestedFlowMapper.INSTANCE.toRequestedFlow(request);
    startFlowCreation(key, commandContext, requestedFlow, requestedFlow.getFlowId());
}
Also used : RequestedFlow(org.openkilda.wfm.topology.flowhs.model.RequestedFlow)

Aggregations

RequestedFlow (org.openkilda.wfm.topology.flowhs.model.RequestedFlow)34 Flow (org.openkilda.model.Flow)12 Test (org.junit.Test)10 DetectConnectedDevices (org.openkilda.wfm.topology.flowhs.model.DetectConnectedDevices)8 YFlow (org.openkilda.model.YFlow)4 YSubFlow (org.openkilda.model.YSubFlow)4 FlowProcessingException (org.openkilda.wfm.topology.flowhs.exception.FlowProcessingException)4 FlowPath (org.openkilda.model.FlowPath)3 InvalidFlowException (org.openkilda.wfm.topology.flowhs.validation.InvalidFlowException)3 UnavailableFlowEndpointException (org.openkilda.wfm.topology.flowhs.validation.UnavailableFlowEndpointException)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 FlowSegmentRequestFactory (org.openkilda.floodlight.api.request.factory.FlowSegmentRequestFactory)2 Switch (org.openkilda.model.Switch)2 CommandContext (org.openkilda.wfm.CommandContext)2 FlowCommandBuilder (org.openkilda.wfm.topology.flowhs.service.FlowCommandBuilder)2 Sets (com.google.common.collect.Sets)1 String.format (java.lang.String.format)1 HashSet (java.util.HashSet)1