Search in sources :

Example 16 with FlowResources

use of org.openkilda.wfm.share.flow.resources.FlowResources 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

FlowResources (org.openkilda.wfm.share.flow.resources.FlowResources)16 Flow (org.openkilda.model.Flow)14 FlowPath (org.openkilda.model.FlowPath)9 PathId (org.openkilda.model.PathId)9 GetPathsResult (org.openkilda.pce.GetPathsResult)7 Slf4j (lombok.extern.slf4j.Slf4j)6 PersistenceManager (org.openkilda.persistence.PersistenceManager)6 FlowResourcesManager (org.openkilda.wfm.share.flow.resources.FlowResourcesManager)6 FlowPathPair (org.openkilda.wfm.topology.flow.model.FlowPathPair)5 String.format (java.lang.String.format)4 ArrayList (java.util.ArrayList)4 List (java.util.List)4 UnroutableFlowException (org.openkilda.pce.exception.UnroutableFlowException)4 ResourceAllocationException (org.openkilda.wfm.share.flow.resources.ResourceAllocationException)4 Objects (java.util.Objects)3 Predicate (java.util.function.Predicate)3 Stream (java.util.stream.Stream)3 ErrorType (org.openkilda.messaging.error.ErrorType)3 FlowSegmentCookieBuilder (org.openkilda.model.cookie.FlowSegmentCookie.FlowSegmentCookieBuilder)3 PathComputer (org.openkilda.pce.PathComputer)3