Search in sources :

Example 1 with FlowResources

use of org.openkilda.wfm.share.flow.resources.FlowResources in project open-kilda by telstra.

the class RevertResourceAllocationAction method perform.

@Override
protected void perform(State from, State to, Event event, FlowUpdateContext context, FlowUpdateFsm stateMachine) {
    Flow flow = getFlow(stateMachine.getFlowId());
    Stream.of(stateMachine.getNewPrimaryResources(), stateMachine.getNewProtectedResources()).filter(Objects::nonNull).forEach(resources -> {
        transactionManager.doInTransaction(() -> resourcesManager.deallocatePathResources(resources));
        saveHistory(stateMachine, flow, resources);
    });
    stateMachine.getRejectedResources().forEach(flowResources -> {
        transactionManager.doInTransaction(() -> resourcesManager.deallocatePathResources(flowResources));
        saveHistory(stateMachine, flow, flowResources);
    });
    Stream.of(stateMachine.getNewPrimaryForwardPath(), stateMachine.getNewPrimaryReversePath(), stateMachine.getNewProtectedForwardPath(), stateMachine.getNewProtectedReversePath()).forEach(pathId -> flowPathRepository.remove(pathId).ifPresent(flowPath -> {
        updateIslsForFlowPath(flowPath);
        saveRemovalActionWithDumpToHistory(stateMachine, flow, flowPath);
    }));
    stateMachine.getRejectedPaths().stream().forEach(pathId -> flowPathRepository.remove(pathId).ifPresent(flowPath -> {
        updateIslsForFlowPath(flowPath);
        saveRemovalActionWithDumpToHistory(stateMachine, flow, flowPath);
    }));
    stateMachine.setNewPrimaryResources(null);
    stateMachine.setNewPrimaryForwardPath(null);
    stateMachine.setNewPrimaryReversePath(null);
    stateMachine.setNewProtectedResources(null);
    stateMachine.setNewProtectedForwardPath(null);
    stateMachine.setNewProtectedReversePath(null);
}
Also used : HistoryMapper(org.openkilda.wfm.share.mappers.HistoryMapper) FlowUpdateFsm(org.openkilda.wfm.topology.flowhs.fsm.update.FlowUpdateFsm) State(org.openkilda.wfm.topology.flowhs.fsm.update.FlowUpdateFsm.State) FlowResources(org.openkilda.wfm.share.flow.resources.FlowResources) String.format(java.lang.String.format) Event(org.openkilda.wfm.topology.flowhs.fsm.update.FlowUpdateFsm.Event) Objects(java.util.Objects) BaseFlowPathRemovalAction(org.openkilda.wfm.topology.flowhs.fsm.common.actions.BaseFlowPathRemovalAction) Slf4j(lombok.extern.slf4j.Slf4j) Stream(java.util.stream.Stream) Flow(org.openkilda.model.Flow) FlowUpdateContext(org.openkilda.wfm.topology.flowhs.fsm.update.FlowUpdateContext) FlowDumpData(org.openkilda.wfm.share.history.model.FlowDumpData) FlowResourcesManager(org.openkilda.wfm.share.flow.resources.FlowResourcesManager) DumpType(org.openkilda.wfm.share.history.model.FlowDumpData.DumpType) PersistenceManager(org.openkilda.persistence.PersistenceManager) Flow(org.openkilda.model.Flow)

Example 2 with FlowResources

use of org.openkilda.wfm.share.flow.resources.FlowResources in project open-kilda by telstra.

the class SwapFlowPathsAction method swapPrimaryPaths.

private void swapPrimaryPaths(FlowUpdateFsm stateMachine) {
    PathId newForward = stateMachine.getNewPrimaryForwardPath();
    PathId newReverse = stateMachine.getNewPrimaryReversePath();
    if (newForward != null && newReverse != null) {
        transactionManager.doInTransaction(() -> {
            Flow flow = getFlow(stateMachine.getFlowId());
            FlowPath oldForward = flow.getForwardPath();
            if (oldForward != null) {
                stateMachine.setOldPrimaryForwardPath(oldForward.getPathId());
                stateMachine.setOldPrimaryForwardPathStatus(oldForward.getStatus());
                oldForward.setStatus(FlowPathStatus.IN_PROGRESS);
            }
            FlowPath oldReverse = flow.getReversePath();
            if (oldReverse != null) {
                stateMachine.setOldPrimaryReversePath(oldReverse.getPathId());
                stateMachine.setOldPrimaryReversePathStatus(oldReverse.getStatus());
                oldReverse.setStatus(FlowPathStatus.IN_PROGRESS);
            }
            if (oldForward != null || oldReverse != null) {
                FlowEncapsulationType oldFlowEncapsulationType = stateMachine.getOriginalFlow().getFlowEncapsulationType();
                FlowResources oldResources = getResources(oldForward != null ? oldForward : oldReverse, oldReverse != null ? oldReverse : oldForward, oldFlowEncapsulationType);
                stateMachine.getOldResources().add(oldResources);
            }
            flow.setForwardPathId(newForward);
            flow.setReversePathId(newReverse);
            log.debug("Swapping the primary paths {}/{} with {}/{}", oldForward != null ? oldForward.getPathId() : null, oldReverse != null ? oldReverse.getPathId() : null, newForward, newReverse);
        });
        saveHistory(stateMachine, stateMachine.getFlowId(), newForward, newReverse);
    }
}
Also used : PathId(org.openkilda.model.PathId) FlowResources(org.openkilda.wfm.share.flow.resources.FlowResources) FlowEncapsulationType(org.openkilda.model.FlowEncapsulationType) FlowPath(org.openkilda.model.FlowPath) Flow(org.openkilda.model.Flow)

Example 3 with FlowResources

use of org.openkilda.wfm.share.flow.resources.FlowResources in project open-kilda by telstra.

the class RevertResourceAllocationAction method perform.

@Override
protected void perform(State from, State to, Event event, FlowRerouteContext context, FlowRerouteFsm stateMachine) {
    Flow flow = getFlow(stateMachine.getFlowId());
    Stream.of(stateMachine.getNewPrimaryResources(), stateMachine.getNewProtectedResources()).filter(Objects::nonNull).forEach(resources -> {
        transactionManager.doInTransaction(() -> resourcesManager.deallocatePathResources(resources));
        saveHistory(stateMachine, flow, resources);
    });
    stateMachine.getRejectedResources().forEach(flowResources -> {
        transactionManager.doInTransaction(() -> resourcesManager.deallocatePathResources(flowResources));
        saveHistory(stateMachine, flow, flowResources);
    });
    Stream.of(stateMachine.getNewPrimaryForwardPath(), stateMachine.getNewPrimaryReversePath(), stateMachine.getNewProtectedForwardPath(), stateMachine.getNewProtectedReversePath()).forEach(pathId -> flowPathRepository.remove(pathId).ifPresent(flowPath -> {
        updateIslsForFlowPath(flowPath);
        saveRemovalActionWithDumpToHistory(stateMachine, flow, flowPath);
    }));
    stateMachine.getRejectedPaths().stream().forEach(pathId -> flowPathRepository.remove(pathId).ifPresent(flowPath -> {
        updateIslsForFlowPath(flowPath);
        saveRemovalActionWithDumpToHistory(stateMachine, flow, flowPath);
    }));
    stateMachine.setNewPrimaryResources(null);
    stateMachine.setNewPrimaryForwardPath(null);
    stateMachine.setNewPrimaryReversePath(null);
    stateMachine.setNewProtectedResources(null);
    stateMachine.setNewProtectedForwardPath(null);
    stateMachine.setNewProtectedReversePath(null);
}
Also used : FlowRerouteContext(org.openkilda.wfm.topology.flowhs.fsm.reroute.FlowRerouteContext) HistoryMapper(org.openkilda.wfm.share.mappers.HistoryMapper) FlowRerouteFsm(org.openkilda.wfm.topology.flowhs.fsm.reroute.FlowRerouteFsm) FlowResources(org.openkilda.wfm.share.flow.resources.FlowResources) String.format(java.lang.String.format) Event(org.openkilda.wfm.topology.flowhs.fsm.reroute.FlowRerouteFsm.Event) Objects(java.util.Objects) BaseFlowPathRemovalAction(org.openkilda.wfm.topology.flowhs.fsm.common.actions.BaseFlowPathRemovalAction) Slf4j(lombok.extern.slf4j.Slf4j) State(org.openkilda.wfm.topology.flowhs.fsm.reroute.FlowRerouteFsm.State) Stream(java.util.stream.Stream) Flow(org.openkilda.model.Flow) FlowDumpData(org.openkilda.wfm.share.history.model.FlowDumpData) FlowResourcesManager(org.openkilda.wfm.share.flow.resources.FlowResourcesManager) DumpType(org.openkilda.wfm.share.history.model.FlowDumpData.DumpType) PersistenceManager(org.openkilda.persistence.PersistenceManager) Flow(org.openkilda.model.Flow)

Example 4 with FlowResources

use of org.openkilda.wfm.share.flow.resources.FlowResources in project open-kilda by telstra.

the class HandleNotRevertedResourceAllocationAction method perform.

@Override
public void perform(State from, State to, Event event, FlowUpdateContext context, FlowUpdateFsm stateMachine) {
    FlowResources newPrimaryResources = stateMachine.getNewPrimaryResources();
    if (newPrimaryResources != null) {
        stateMachine.saveErrorToHistory("Failed to revert resource allocation", format("Failed to revert resource allocation: %s", newPrimaryResources));
    }
    FlowResources newProtectedResources = stateMachine.getNewProtectedResources();
    if (newProtectedResources != null) {
        stateMachine.saveErrorToHistory("Failed to revert resource allocation", format("Failed to revert resource allocation: %s", newProtectedResources));
    }
}
Also used : FlowResources(org.openkilda.wfm.share.flow.resources.FlowResources)

Example 5 with FlowResources

use of org.openkilda.wfm.share.flow.resources.FlowResources in project open-kilda by telstra.

the class AllocateProtectedResourcesAction method allocate.

@Override
protected void allocate(FlowUpdateFsm stateMachine) throws RecoverableException, UnroutableFlowException, ResourceAllocationException {
    String flowId = stateMachine.getFlowId();
    Set<String> flowIds = Sets.newHashSet(flowId);
    if (stateMachine.getBulkUpdateFlowIds() != null) {
        flowIds.addAll(stateMachine.getBulkUpdateFlowIds());
    }
    log.debug("Finding protected path ids for flows {}", flowIds);
    List<PathId> pathIdsToReuse = new ArrayList<>(flowPathRepository.findActualPathIdsByFlowIds(flowIds));
    pathIdsToReuse.addAll(stateMachine.getRejectedPaths());
    Flow tmpFlow = getFlow(flowId);
    FlowPathPair oldPaths = new FlowPathPair(tmpFlow.getProtectedForwardPath(), tmpFlow.getProtectedReversePath());
    FlowPath primaryForward = getFlowPath(tmpFlow, stateMachine.getNewPrimaryForwardPath());
    FlowPath primaryReverse = getFlowPath(tmpFlow, stateMachine.getNewPrimaryReversePath());
    Predicate<GetPathsResult> testNonOverlappingPath = path -> (primaryForward == null || !flowPathBuilder.arePathsOverlapped(path.getForward(), primaryForward)) && (primaryReverse == null || !flowPathBuilder.arePathsOverlapped(path.getReverse(), primaryReverse));
    PathId newForwardPathId = resourcesManager.generatePathId(flowId);
    PathId newReversePathId = resourcesManager.generatePathId(flowId);
    log.debug("Finding a new protected path for flow {}", flowId);
    GetPathsResult allocatedPaths = allocatePathPair(tmpFlow, newForwardPathId, newReversePathId, false, pathIdsToReuse, oldPaths, true, stateMachine.getSharedBandwidthGroupId(), testNonOverlappingPath);
    if (allocatedPaths == null) {
        throw new ResourceAllocationException("Unable to allocate a path");
    }
    if (!testNonOverlappingPath.test(allocatedPaths)) {
        stateMachine.saveActionToHistory("Couldn't find non overlapping protected path");
    } else {
        log.debug("New protected paths have been allocated: {}", allocatedPaths);
        stateMachine.setNewProtectedForwardPath(newForwardPathId);
        stateMachine.setNewProtectedReversePath(newReversePathId);
        stateMachine.setBackUpProtectedPathComputationWayUsed(allocatedPaths.isBackUpPathComputationWayUsed());
        log.debug("Allocating resources for a new protected path of flow {}", flowId);
        FlowResources flowResources = allocateFlowResources(tmpFlow, newForwardPathId, newReversePathId);
        stateMachine.setNewProtectedResources(flowResources);
        FlowPathPair createdPaths = createFlowPathPair(flowId, flowResources, allocatedPaths, false, stateMachine.getSharedBandwidthGroupId());
        log.debug("New protected path has been created: {}", createdPaths);
        saveAllocationActionWithDumpsToHistory(stateMachine, tmpFlow, "protected", createdPaths);
    }
}
Also used : BaseResourceAllocationAction(org.openkilda.wfm.topology.flowhs.fsm.common.actions.BaseResourceAllocationAction) FlowPath(org.openkilda.model.FlowPath) ResourceAllocationException(org.openkilda.wfm.share.flow.resources.ResourceAllocationException) RecoverableException(org.openkilda.pce.exception.RecoverableException) ArrayList(java.util.ArrayList) UnroutableFlowException(org.openkilda.pce.exception.UnroutableFlowException) Flow(org.openkilda.model.Flow) FlowPathPair(org.openkilda.wfm.topology.flow.model.FlowPathPair) PersistenceManager(org.openkilda.persistence.PersistenceManager) PathId(org.openkilda.model.PathId) FlowOperationsDashboardLogger(org.openkilda.wfm.share.logger.FlowOperationsDashboardLogger) ErrorType(org.openkilda.messaging.error.ErrorType) Predicate(java.util.function.Predicate) FlowUpdateFsm(org.openkilda.wfm.topology.flowhs.fsm.update.FlowUpdateFsm) Set(java.util.Set) State(org.openkilda.wfm.topology.flowhs.fsm.update.FlowUpdateFsm.State) FlowResources(org.openkilda.wfm.share.flow.resources.FlowResources) Sets(com.google.common.collect.Sets) Event(org.openkilda.wfm.topology.flowhs.fsm.update.FlowUpdateFsm.Event) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) FlowUpdateContext(org.openkilda.wfm.topology.flowhs.fsm.update.FlowUpdateContext) PathComputer(org.openkilda.pce.PathComputer) FlowResourcesManager(org.openkilda.wfm.share.flow.resources.FlowResourcesManager) GetPathsResult(org.openkilda.pce.GetPathsResult) FlowResources(org.openkilda.wfm.share.flow.resources.FlowResources) ArrayList(java.util.ArrayList) Flow(org.openkilda.model.Flow) FlowPathPair(org.openkilda.wfm.topology.flow.model.FlowPathPair) GetPathsResult(org.openkilda.pce.GetPathsResult) PathId(org.openkilda.model.PathId) FlowPath(org.openkilda.model.FlowPath) ResourceAllocationException(org.openkilda.wfm.share.flow.resources.ResourceAllocationException)

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