Search in sources :

Example 11 with FlowPathPair

use of org.openkilda.wfm.topology.flow.model.FlowPathPair in project open-kilda by telstra.

the class RevertPathsSwapAction method perform.

@Override
protected void perform(State from, State to, Event event, FlowPathSwapContext context, FlowPathSwapFsm stateMachine) {
    FlowPathPair pathPair = transactionManager.doInTransaction(() -> {
        String flowId = stateMachine.getFlowId();
        Flow flow = getFlow(flowId);
        log.debug("Reverting primary and protected paths swap for flow {}", flowId);
        FlowPath oldPrimaryForward = flow.getForwardPath();
        FlowPath oldPrimaryReverse = flow.getReversePath();
        PathId newPrimaryForward = flow.getProtectedForwardPathId();
        PathId newPrimaryReverse = flow.getProtectedReversePathId();
        setMirrorPointsToNewPath(oldPrimaryForward.getPathId(), newPrimaryForward);
        setMirrorPointsToNewPath(oldPrimaryReverse.getPathId(), newPrimaryReverse);
        flow.setForwardPathId(newPrimaryForward);
        flow.setReversePathId(newPrimaryReverse);
        flow.setProtectedForwardPathId(oldPrimaryForward.getPathId());
        flow.setProtectedReversePathId(oldPrimaryReverse.getPathId());
        return new FlowPathPair(oldPrimaryForward, oldPrimaryReverse);
    });
    saveHistory(stateMachine, stateMachine.getFlowId(), pathPair.getForwardPathId(), pathPair.getReversePathId());
}
Also used : PathId(org.openkilda.model.PathId) FlowPath(org.openkilda.model.FlowPath) FlowPathPair(org.openkilda.wfm.topology.flow.model.FlowPathPair) Flow(org.openkilda.model.Flow)

Example 12 with FlowPathPair

use of org.openkilda.wfm.topology.flow.model.FlowPathPair in project open-kilda by telstra.

the class AllocatePrimaryResourcesAction method allocate.

@TimedExecution("fsm.resource_allocation_primary")
@Override
protected void allocate(FlowRerouteFsm stateMachine) throws RecoverableException, UnroutableFlowException, ResourceAllocationException {
    String flowId = stateMachine.getFlowId();
    Flow tmpFlowCopy = getFlow(flowId);
    // Detach the entity to avoid propagation to the database.
    flowRepository.detach(tmpFlowCopy);
    if (stateMachine.getNewEncapsulationType() != null) {
        // This is for PCE to use proper (updated) encapsulation type.
        tmpFlowCopy.setEncapsulationType(stateMachine.getNewEncapsulationType());
    }
    FlowPathPair oldPaths = new FlowPathPair(tmpFlowCopy.getForwardPath(), tmpFlowCopy.getReversePath());
    PathId newForwardPathId = resourcesManager.generatePathId(flowId);
    PathId newReversePathId = resourcesManager.generatePathId(flowId);
    List<PathId> pathsToReuse = Lists.newArrayList(tmpFlowCopy.getForwardPathId(), tmpFlowCopy.getReversePathId());
    pathsToReuse.addAll(stateMachine.getRejectedPaths());
    log.debug("Finding a new primary path for flow {}", flowId);
    GetPathsResult allocatedPaths = allocatePathPair(tmpFlowCopy, newForwardPathId, newReversePathId, stateMachine.isIgnoreBandwidth(), pathsToReuse, oldPaths, stateMachine.isRecreateIfSamePath(), stateMachine.getSharedBandwidthGroupId(), path -> true);
    if (allocatedPaths != null) {
        log.debug("New primary paths have been allocated: {}", allocatedPaths);
        stateMachine.setBackUpPrimaryPathComputationWayUsed(allocatedPaths.isBackUpPathComputationWayUsed());
        stateMachine.setNewPrimaryForwardPath(newForwardPathId);
        stateMachine.setNewPrimaryReversePath(newReversePathId);
        log.debug("Allocating resources for a new primary path of flow {}", flowId);
        FlowResources flowResources = allocateFlowResources(tmpFlowCopy, newForwardPathId, newReversePathId);
        stateMachine.setNewPrimaryResources(flowResources);
        FlowPathPair createdPaths = createFlowPathPair(flowId, flowResources, allocatedPaths, stateMachine.isIgnoreBandwidth(), stateMachine.getSharedBandwidthGroupId());
        log.debug("New primary paths have been created: {}", createdPaths);
        setMirrorPointsToNewPath(oldPaths.getForwardPathId(), newForwardPathId);
        setMirrorPointsToNewPath(oldPaths.getReversePathId(), newReversePathId);
        saveAllocationActionWithDumpsToHistory(stateMachine, tmpFlowCopy, "primary", createdPaths);
    } else {
        stateMachine.saveActionToHistory("Found the same primary path. Skipped creating of it");
    }
}
Also used : PathId(org.openkilda.model.PathId) FlowResources(org.openkilda.wfm.share.flow.resources.FlowResources) Flow(org.openkilda.model.Flow) FlowPathPair(org.openkilda.wfm.topology.flow.model.FlowPathPair) GetPathsResult(org.openkilda.pce.GetPathsResult) TimedExecution(org.openkilda.wfm.share.metrics.TimedExecution)

Aggregations

FlowPathPair (org.openkilda.wfm.topology.flow.model.FlowPathPair)12 PathId (org.openkilda.model.PathId)10 FlowPath (org.openkilda.model.FlowPath)9 Flow (org.openkilda.model.Flow)7 GetPathsResult (org.openkilda.pce.GetPathsResult)5 FlowResources (org.openkilda.wfm.share.flow.resources.FlowResources)5 ResourceAllocationException (org.openkilda.wfm.share.flow.resources.ResourceAllocationException)4 ArrayList (java.util.ArrayList)3 List (java.util.List)3 Predicate (java.util.function.Predicate)3 Slf4j (lombok.extern.slf4j.Slf4j)3 ErrorType (org.openkilda.messaging.error.ErrorType)3 PathComputer (org.openkilda.pce.PathComputer)3 RecoverableException (org.openkilda.pce.exception.RecoverableException)3 UnroutableFlowException (org.openkilda.pce.exception.UnroutableFlowException)3 PersistenceManager (org.openkilda.persistence.PersistenceManager)3 FlowResourcesManager (org.openkilda.wfm.share.flow.resources.FlowResourcesManager)3 FlowOperationsDashboardLogger (org.openkilda.wfm.share.logger.FlowOperationsDashboardLogger)3 TimedExecution (org.openkilda.wfm.share.metrics.TimedExecution)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1