Search in sources :

Example 1 with RequestedFlow

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

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

the class OnFinishedAction method perform.

@Override
public void perform(State from, State to, Event event, FlowCreateContext context, FlowCreateFsm stateMachine) {
    RequestedFlow requestedFlow = stateMachine.getTargetFlow();
    stateMachine.getCarrier().sendPeriodicPingNotification(requestedFlow.getFlowId(), requestedFlow.isPeriodicPings());
    if (!requestedFlow.getSrcSwitch().equals(requestedFlow.getDestSwitch())) {
        stateMachine.getCarrier().sendActivateFlowMonitoring(requestedFlow);
    }
    dashboardLogger.onSuccessfulFlowCreate(stateMachine.getFlowId());
    stateMachine.saveActionToHistory("Flow was created successfully");
}
Also used : RequestedFlow(org.openkilda.wfm.topology.flowhs.model.RequestedFlow)

Example 3 with RequestedFlow

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

the class CreateSubFlowsAction method perform.

@Override
public void perform(State from, State to, Event event, YFlowCreateContext context, YFlowCreateFsm stateMachine) {
    String yFlowId = stateMachine.getYFlowId();
    Collection<RequestedFlow> requestedFlows = YFlowRequestMapper.INSTANCE.toRequestedFlows(stateMachine.getTargetFlow());
    stateMachine.setRequestedFlows(requestedFlows);
    log.debug("Start creating {} sub-flows for y-flow {}", requestedFlows.size(), yFlowId);
    stateMachine.clearCreatingSubFlows();
    requestedFlows.stream().findFirst().ifPresent(requestedFlow -> {
        String subFlowId = requestedFlow.getFlowId();
        stateMachine.setMainAffinityFlowId(subFlowId);
        stateMachine.addSubFlow(subFlowId);
        stateMachine.addCreatingSubFlow(subFlowId);
        stateMachine.notifyEventListeners(listener -> listener.onSubFlowProcessingStart(yFlowId, subFlowId));
        CommandContext flowContext = stateMachine.getCommandContext().fork(subFlowId);
        requestedFlow.setDiverseFlowId(stateMachine.getDiverseFlowId());
        flowCreateService.startFlowCreation(flowContext, requestedFlow, yFlowId);
    });
}
Also used : CommandContext(org.openkilda.wfm.CommandContext) RequestedFlow(org.openkilda.wfm.topology.flowhs.model.RequestedFlow)

Example 4 with RequestedFlow

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

the class UpdateFlowAction method performWithResponse.

@Override
protected Optional<Message> performWithResponse(State from, State to, Event event, FlowUpdateContext context, FlowUpdateFsm stateMachine) {
    RequestedFlow targetFlow = stateMachine.getTargetFlow();
    String flowId = targetFlow.getFlowId();
    transactionManager.doInTransaction(() -> {
        Flow flow = getFlow(flowId);
        log.debug("Updating the flow {} with properties: {}", flowId, targetFlow);
        RequestedFlow originalFlow = RequestedFlowMapper.INSTANCE.toRequestedFlow(flow);
        stateMachine.setOldTargetPathComputationStrategy(flow.getTargetPathComputationStrategy());
        stateMachine.setOriginalFlow(originalFlow);
        stateMachine.setOriginalDiverseFlowGroup(flow.getDiverseGroupId());
        stateMachine.setOriginalAffinityFlowGroup(flow.getAffinityGroupId());
        // Complete target flow in FSM with values from original flow
        stateMachine.setTargetFlow(updateFlow(flow, targetFlow));
        EndpointUpdate endpointUpdate = updateEndpointRulesOnly(originalFlow, targetFlow, stateMachine.getOriginalDiverseFlowGroup(), flow.getDiverseGroupId(), stateMachine.getOriginalAffinityFlowGroup(), flow.getAffinityGroupId());
        stateMachine.setEndpointUpdate(endpointUpdate);
        if (endpointUpdate.isPartialUpdate()) {
            FlowLoopOperation flowLoopOperation = detectFlowLoopOperation(originalFlow, targetFlow);
            stateMachine.setFlowLoopOperation(flowLoopOperation);
            stateMachine.setNewPrimaryForwardPath(flow.getForwardPathId());
            stateMachine.setNewPrimaryReversePath(flow.getReversePathId());
            stateMachine.setNewProtectedForwardPath(flow.getProtectedForwardPathId());
            stateMachine.setNewProtectedReversePath(flow.getProtectedReversePathId());
            FlowDumpData dumpData = HistoryMapper.INSTANCE.map(flow, flow.getForwardPath(), flow.getReversePath(), DumpType.STATE_AFTER);
            stateMachine.saveActionWithDumpToHistory("New endpoints were stored for flow", format("The flow endpoints were updated for: %s / %s", flow.getSrcSwitch(), flow.getDestSwitch()), dumpData);
        }
    });
    stateMachine.saveActionToHistory("The flow properties were updated");
    if (stateMachine.getEndpointUpdate().isPartialUpdate()) {
        stateMachine.saveActionToHistory("Skip paths and resources allocation");
        stateMachine.fire(Event.UPDATE_ENDPOINT_RULES_ONLY);
    }
    return Optional.empty();
}
Also used : FlowDumpData(org.openkilda.wfm.share.history.model.FlowDumpData) EndpointUpdate(org.openkilda.wfm.topology.flowhs.fsm.update.FlowUpdateFsm.EndpointUpdate) FlowLoopOperation(org.openkilda.wfm.topology.flowhs.fsm.update.FlowUpdateFsm.FlowLoopOperation) RequestedFlow(org.openkilda.wfm.topology.flowhs.model.RequestedFlow) Flow(org.openkilda.model.Flow) YFlow(org.openkilda.model.YFlow) YSubFlow(org.openkilda.model.YSubFlow) RequestedFlow(org.openkilda.wfm.topology.flowhs.model.RequestedFlow)

Example 5 with RequestedFlow

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

the class ValidateFlowAction method performWithResponse.

@Override
protected Optional<Message> performWithResponse(State from, State to, Event event, FlowUpdateContext context, FlowUpdateFsm stateMachine) {
    String flowId = stateMachine.getFlowId();
    RequestedFlow targetFlow = context.getTargetFlow();
    String diverseFlowId = targetFlow.getDiverseFlowId();
    dashboardLogger.onFlowUpdate(flowId, targetFlow.getSrcSwitch(), targetFlow.getSrcPort(), targetFlow.getSrcVlan(), targetFlow.getDestSwitch(), targetFlow.getDestPort(), targetFlow.getDestVlan(), diverseFlowId, targetFlow.getBandwidth());
    boolean isOperationAllowed = featureTogglesRepository.getOrDefault().getUpdateFlowEnabled();
    if (!isOperationAllowed) {
        throw new FlowProcessingException(ErrorType.NOT_PERMITTED, "Flow update feature is disabled");
    }
    stateMachine.setTargetFlow(targetFlow);
    stateMachine.setBulkUpdateFlowIds(context.getBulkUpdateFlowIds());
    stateMachine.setDoNotRevert(context.isDoNotRevert());
    Flow flow = getFlow(flowId);
    try {
        flowValidator.validate(targetFlow, stateMachine.getBulkUpdateFlowIds());
    } catch (InvalidFlowException e) {
        throw new FlowProcessingException(e.getType(), e.getMessage(), e);
    } catch (UnavailableFlowEndpointException e) {
        throw new FlowProcessingException(ErrorType.DATA_INVALID, e.getMessage(), e);
    }
    if ((!targetFlow.getSrcSwitch().equals(flow.getSrcSwitchId()) || !targetFlow.getDestSwitch().equals(flow.getDestSwitchId())) && (!flow.getForwardPath().getFlowMirrorPointsSet().isEmpty() || !flow.getReversePath().getFlowMirrorPointsSet().isEmpty())) {
        throw new FlowProcessingException(ErrorType.REQUEST_INVALID, "The current implementation of flow mirror points does not allow allocating paths. " + "Therefore, remove the flow mirror points before changing the endpoint switch.");
    }
    if (diverseFlowId != null && targetFlow.getSrcSwitch().equals(targetFlow.getDestSwitch())) {
        throw new FlowProcessingException(ErrorType.DATA_INVALID, "Couldn't add one-switch flow into diverse group");
    }
    transactionManager.doInTransaction(() -> {
        if (diverseFlowId != null && !diverseFlowId.isEmpty()) {
            Flow diverseFlow = getFlow(diverseFlowId);
            if (diverseFlow.isOneSwitchFlow()) {
                throw new FlowProcessingException(ErrorType.PARAMETERS_INVALID, "Couldn't create diverse group with one-switch flow");
            }
        }
        Flow foundFlow = getFlow(flowId);
        if (foundFlow.getStatus() == FlowStatus.IN_PROGRESS && stateMachine.getBulkUpdateFlowIds().isEmpty()) {
            throw new FlowProcessingException(ErrorType.REQUEST_INVALID, format("Flow %s is in progress now", flowId));
        }
        // Keep it, just in case we have to revert it.
        stateMachine.setOriginalFlowStatus(foundFlow.getStatus());
        stateMachine.setOriginalFlowStatusInfo(foundFlow.getStatusInfo());
        foundFlow.setStatus(FlowStatus.IN_PROGRESS);
        foundFlow.setStatusInfo("");
        return foundFlow;
    });
    stateMachine.saveNewEventToHistory("Flow was validated successfully", FlowEventData.Event.UPDATE);
    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) Flow(org.openkilda.model.Flow) 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