Search in sources :

Example 6 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 7 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)

Example 8 with FlowResources

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

the class BaseResourceAllocationAction method allocateFlowResources.

@SneakyThrows
protected FlowResources allocateFlowResources(Flow flow, PathId forwardPathId, PathId reversePathId) throws ResourceAllocationException {
    RetryPolicy<FlowResources> resourceAllocationRetryPolicy = transactionManager.<FlowResources>getDefaultRetryPolicy().handle(ResourceAllocationException.class).handle(ConstraintViolationException.class).onRetry(e -> log.warn("Failure in resource allocation. Retrying #{}...", e.getAttemptCount(), e.getLastFailure())).onRetriesExceeded(e -> log.warn("Failure in resource allocation. No more retries", e.getFailure())).withMaxRetries(resourceAllocationRetriesLimit);
    FlowResources flowResources = transactionManager.doInTransaction(resourceAllocationRetryPolicy, () -> resourcesManager.allocateFlowResources(flow, forwardPathId, reversePathId));
    log.debug("Resources have been allocated: {}", flowResources);
    return flowResources;
}
Also used : FlowPath(org.openkilda.model.FlowPath) HistoryMapper(org.openkilda.wfm.share.mappers.HistoryMapper) SneakyThrows(lombok.SneakyThrows) ResourceAllocationException(org.openkilda.wfm.share.flow.resources.ResourceAllocationException) FlowPathStatus(org.openkilda.model.FlowPathStatus) UnroutableFlowException(org.openkilda.pce.exception.UnroutableFlowException) FlowPathSwappingFsm(org.openkilda.wfm.topology.flowhs.fsm.common.FlowPathSwappingFsm) FailsafeException(net.jodah.failsafe.FailsafeException) Flow(org.openkilda.model.Flow) Duration(java.time.Duration) Map(java.util.Map) FlowPathPair(org.openkilda.wfm.topology.flow.model.FlowPathPair) DumpType(org.openkilda.wfm.share.history.model.FlowDumpData.DumpType) Path(org.openkilda.pce.Path) SwitchProperties(org.openkilda.model.SwitchProperties) IslEndpoints(org.openkilda.persistence.repositories.IslRepository.IslEndpoints) Predicate(java.util.function.Predicate) Collection(java.util.Collection) RetryPolicy(net.jodah.failsafe.RetryPolicy) PersistenceException(org.openkilda.persistence.exceptions.PersistenceException) FlowResources(org.openkilda.wfm.share.flow.resources.FlowResources) String.format(java.lang.String.format) Objects(java.util.Objects) SwitchPropertiesRepository(org.openkilda.persistence.repositories.SwitchPropertiesRepository) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) FlowDumpData(org.openkilda.wfm.share.history.model.FlowDumpData) PathComputer(org.openkilda.pce.PathComputer) Optional(java.util.Optional) ConstraintViolationException(org.openkilda.persistence.exceptions.ConstraintViolationException) SwitchRepository(org.openkilda.persistence.repositories.SwitchRepository) FlowSegmentCookieBuilder(org.openkilda.model.cookie.FlowSegmentCookie.FlowSegmentCookieBuilder) Message(org.openkilda.messaging.Message) PathSegment(org.openkilda.model.PathSegment) KildaConfigurationRepository(org.openkilda.persistence.repositories.KildaConfigurationRepository) HashMap(java.util.HashMap) Supplier(java.util.function.Supplier) RecoverableException(org.openkilda.pce.exception.RecoverableException) ArrayList(java.util.ArrayList) FlowPathDirection(org.openkilda.model.FlowPathDirection) PathSegmentRepository(org.openkilda.persistence.repositories.PathSegmentRepository) IslRepository(org.openkilda.persistence.repositories.IslRepository) Suppliers(com.google.common.base.Suppliers) FlowSegmentCookie(org.openkilda.model.cookie.FlowSegmentCookie) PersistenceManager(org.openkilda.persistence.PersistenceManager) PathId(org.openkilda.model.PathId) DetectConnectedDevices(org.openkilda.model.DetectConnectedDevices) FlowOperationsDashboardLogger(org.openkilda.wfm.share.logger.FlowOperationsDashboardLogger) ErrorType(org.openkilda.messaging.error.ErrorType) IslStatus(org.openkilda.model.IslStatus) Failsafe(net.jodah.failsafe.Failsafe) RepositoryFactory(org.openkilda.persistence.repositories.RepositoryFactory) FlowPathBuilder(org.openkilda.wfm.topology.flowhs.service.FlowPathBuilder) SwitchId(org.openkilda.model.SwitchId) FlowResourcesManager(org.openkilda.wfm.share.flow.resources.FlowResourcesManager) GetPathsResult(org.openkilda.pce.GetPathsResult) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Isl(org.openkilda.model.Isl) LazyMap(org.apache.commons.collections4.map.LazyMap) FlowResources(org.openkilda.wfm.share.flow.resources.FlowResources) ConstraintViolationException(org.openkilda.persistence.exceptions.ConstraintViolationException) SneakyThrows(lombok.SneakyThrows)

Example 9 with FlowResources

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

the class ResourcesAllocationAction method allocateMainPath.

private void allocateMainPath(FlowCreateFsm stateMachine) throws UnroutableFlowException, RecoverableException, ResourceAllocationException {
    GetPathsResult paths = pathComputer.getPath(getFlow(stateMachine.getFlowId()));
    stateMachine.setBackUpPrimaryPathComputationWayUsed(paths.isBackUpPathComputationWayUsed());
    log.debug("Creating the primary path {} for flow {}", paths, stateMachine.getFlowId());
    transactionManager.doInTransaction(() -> {
        Flow flow = getFlow(stateMachine.getFlowId());
        FlowResources flowResources = resourcesManager.allocateFlowResources(flow);
        final FlowSegmentCookieBuilder cookieBuilder = FlowSegmentCookie.builder().flowEffectiveId(flowResources.getUnmaskedCookie());
        updateSwitchRelatedFlowProperties(flow);
        FlowPath forward = flowPathBuilder.buildFlowPath(flow, flowResources.getForward(), paths.getForward(), cookieBuilder.direction(FlowPathDirection.FORWARD).build(), false, stateMachine.getSharedBandwidthGroupId());
        forward.setStatus(FlowPathStatus.IN_PROGRESS);
        flowPathRepository.add(forward);
        flow.setForwardPath(forward);
        FlowPath reverse = flowPathBuilder.buildFlowPath(flow, flowResources.getReverse(), paths.getReverse(), cookieBuilder.direction(FlowPathDirection.REVERSE).build(), false, stateMachine.getSharedBandwidthGroupId());
        reverse.setStatus(FlowPathStatus.IN_PROGRESS);
        flowPathRepository.add(reverse);
        flow.setReversePath(reverse);
        updateIslsForFlowPath(forward.getPathId());
        updateIslsForFlowPath(reverse.getPathId());
        stateMachine.setForwardPathId(forward.getPathId());
        stateMachine.setReversePathId(reverse.getPathId());
        log.debug("Allocated resources for the flow {}: {}", flow.getFlowId(), flowResources);
        stateMachine.getFlowResources().add(flowResources);
    });
}
Also used : FlowResources(org.openkilda.wfm.share.flow.resources.FlowResources) FlowSegmentCookieBuilder(org.openkilda.model.cookie.FlowSegmentCookie.FlowSegmentCookieBuilder) FlowPath(org.openkilda.model.FlowPath) GetPathsResult(org.openkilda.pce.GetPathsResult) Flow(org.openkilda.model.Flow) YSubFlow(org.openkilda.model.YSubFlow) RequestedFlow(org.openkilda.wfm.topology.flowhs.model.RequestedFlow) YFlow(org.openkilda.model.YFlow)

Example 10 with FlowResources

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

the class SwapFlowPathsAction method swapProtectedPaths.

private void swapProtectedPaths(FlowRerouteFsm stateMachine) {
    PathId newForward = stateMachine.getNewProtectedForwardPath();
    PathId newReverse = stateMachine.getNewProtectedReversePath();
    if (newForward != null && newReverse != null) {
        transactionManager.doInTransaction(() -> {
            Flow flow = getFlow(stateMachine.getFlowId());
            FlowPath oldForward = flow.getProtectedForwardPath();
            if (oldForward != null) {
                stateMachine.setOldProtectedForwardPath(oldForward.getPathId());
                stateMachine.setOldProtectedForwardPathStatus(oldForward.getStatus());
                oldForward.setStatus(FlowPathStatus.IN_PROGRESS);
            }
            FlowPath oldReverse = flow.getProtectedReversePath();
            if (oldReverse != null) {
                stateMachine.setOldProtectedReversePath(oldReverse.getPathId());
                stateMachine.setOldProtectedReversePathStatus(oldReverse.getStatus());
                oldReverse.setStatus(FlowPathStatus.IN_PROGRESS);
            }
            if (oldForward != null || oldReverse != null) {
                FlowResources oldResources = getResources(flow, oldForward != null ? oldForward : oldReverse, oldReverse != null ? oldReverse : oldForward);
                stateMachine.getOldResources().add(oldResources);
            }
            flow.setProtectedForwardPathId(newForward);
            flow.setProtectedReversePathId(newReverse);
            log.debug("Swapping the protected 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) FlowPath(org.openkilda.model.FlowPath) Flow(org.openkilda.model.Flow)

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