Search in sources :

Example 11 with ResourceAllocationException

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

the class YFlowUpdateServiceTest method shouldFailIfNoResourcesAvailable.

@Test
public void shouldFailIfNoResourcesAvailable() throws UnroutableFlowException, RecoverableException, ResourceAllocationException, DuplicateKeyException {
    // given
    YFlowRequest request = createYFlow();
    request.setMaximumBandwidth(2000L);
    request.getSubFlows().get(0).setEndpoint(newFirstEndpoint);
    request.getSubFlows().get(1).setEndpoint(newSecondEndpoint);
    preparePathComputationForUpdate("test_flow_1", buildNewFirstSubFlowPathPair(), buildFirstSubFlowPathPair());
    preparePathComputationForUpdate("test_flow_2", buildNewSecondSubFlowPathPair(), buildSecondSubFlowPathPair());
    prepareYPointComputation(SWITCH_SHARED, SWITCH_NEW_FIRST_EP, SWITCH_NEW_SECOND_EP, SWITCH_TRANSIT);
    doThrow(new ResourceAllocationException(injectedErrorMessage)).when(flowResourcesManager).allocateMeter(eq("test_successful_yflow"), eq(SWITCH_TRANSIT));
    // when
    processUpdateRequestAndSpeakerCommands(request);
    verifyYFlowStatus(request.getYFlowId(), FlowStatus.UP);
    // +1 from YFlowCreateFsm
    verify(flowResourcesManager, times(METER_ALLOCATION_RETRIES_LIMIT + 2)).allocateMeter(eq("test_successful_yflow"), eq(SWITCH_TRANSIT));
    YFlow flow = getYFlow(request.getYFlowId());
    assertEquals(1000L, flow.getMaximumBandwidth());
    Set<SwitchId> expectedEndpointSwitchIds = Stream.of(SWITCH_FIRST_EP, SWITCH_SECOND_EP).collect(Collectors.toSet());
    Set<SwitchId> actualEndpointSwitchIds = flow.getSubFlows().stream().map(YSubFlow::getEndpointSwitchId).collect(Collectors.toSet());
    assertEquals(expectedEndpointSwitchIds, actualEndpointSwitchIds);
}
Also used : YFlow(org.openkilda.model.YFlow) SwitchId(org.openkilda.model.SwitchId) ResourceAllocationException(org.openkilda.wfm.share.flow.resources.ResourceAllocationException) YFlowRequest(org.openkilda.messaging.command.yflow.YFlowRequest) Test(org.junit.Test) AbstractYFlowTest(org.openkilda.wfm.topology.flowhs.service.AbstractYFlowTest)

Example 12 with ResourceAllocationException

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

the class FlowRerouteServiceTest method shouldFailRerouteFlowIfNoResourcesAvailable.

@Test
public void shouldFailRerouteFlowIfNoResourcesAvailable() throws RecoverableException, UnroutableFlowException, ResourceAllocationException {
    Flow origin = makeFlow();
    preparePathComputation(origin.getFlowId(), make3SwitchesPathPair());
    doThrow(new ResourceAllocationException(injectedErrorMessage)).when(flowResourcesManager).allocateFlowResources(makeFlowArgumentMatch(origin.getFlowId()), any(), any());
    FlowRerouteRequest request = new FlowRerouteRequest(origin.getFlowId(), false, false, false, Collections.emptySet(), null, false);
    testExpectedFailure(dummyRequestKey, request, commandContext, origin, FlowStatus.UP, ErrorType.INTERNAL_ERROR);
    verify(flowResourcesManager, times(PATH_ALLOCATION_RETRIES_LIMIT + 1)).allocateFlowResources(makeFlowArgumentMatch(origin.getFlowId()), any(), any());
}
Also used : FlowRerouteRequest(org.openkilda.messaging.command.flow.FlowRerouteRequest) ResourceAllocationException(org.openkilda.wfm.share.flow.resources.ResourceAllocationException) Flow(org.openkilda.model.Flow) Test(org.junit.Test)

Example 13 with ResourceAllocationException

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

the class AllocateProtectedResourcesAction method allocate.

@TimedExecution("fsm.resource_allocation_protected")
@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.getProtectedForwardPath(), tmpFlowCopy.getProtectedReversePath());
    FlowPath primaryForward = tmpFlowCopy.getPath(stateMachine.getNewPrimaryForwardPath()).orElse(tmpFlowCopy.getForwardPath());
    FlowPath primaryReverse = tmpFlowCopy.getPath(stateMachine.getNewPrimaryReversePath()).orElse(tmpFlowCopy.getReversePath());
    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);
    List<PathId> pathsToReuse = Lists.newArrayList(tmpFlowCopy.getProtectedForwardPathId(), tmpFlowCopy.getProtectedReversePathId());
    pathsToReuse.addAll(stateMachine.getRejectedPaths());
    log.debug("Finding a new protected path for flow {}", flowId);
    GetPathsResult allocatedPaths = allocatePathPair(tmpFlowCopy, newForwardPathId, newReversePathId, stateMachine.isIgnoreBandwidth(), pathsToReuse, oldPaths, stateMachine.isRecreateIfSamePath(), stateMachine.getSharedBandwidthGroupId(), testNonOverlappingPath);
    if (allocatedPaths != null) {
        stateMachine.setBackUpProtectedPathComputationWayUsed(allocatedPaths.isBackUpPathComputationWayUsed());
        if (!testNonOverlappingPath.test(allocatedPaths)) {
            stateMachine.saveActionToHistory("Couldn't find non overlapping protected path. Skipped creating it");
            stateMachine.fireNoPathFound("Couldn't find non overlapping protected path");
        } else {
            log.debug("New protected paths have been allocated: {}", allocatedPaths);
            stateMachine.setNewProtectedForwardPath(newForwardPathId);
            stateMachine.setNewProtectedReversePath(newReversePathId);
            log.debug("Allocating resources for a new protected path of flow {}", flowId);
            FlowResources flowResources = allocateFlowResources(tmpFlowCopy, newForwardPathId, newReversePathId);
            stateMachine.setNewProtectedResources(flowResources);
            FlowPathPair createdPaths = createFlowPathPair(flowId, flowResources, allocatedPaths, stateMachine.isIgnoreBandwidth(), stateMachine.getSharedBandwidthGroupId());
            log.debug("New protected paths have been created: {}", createdPaths);
            saveAllocationActionWithDumpsToHistory(stateMachine, tmpFlowCopy, "protected", createdPaths);
        }
    } else {
        stateMachine.saveActionToHistory("Found the same protected path. Skipped creating of it");
    }
}
Also used : FlowRerouteContext(org.openkilda.wfm.topology.flowhs.fsm.reroute.FlowRerouteContext) BaseResourceAllocationAction(org.openkilda.wfm.topology.flowhs.fsm.common.actions.BaseResourceAllocationAction) FlowOperationsDashboardLogger(org.openkilda.wfm.share.logger.FlowOperationsDashboardLogger) FlowPath(org.openkilda.model.FlowPath) ErrorType(org.openkilda.messaging.error.ErrorType) Predicate(java.util.function.Predicate) ResourceAllocationException(org.openkilda.wfm.share.flow.resources.ResourceAllocationException) FlowRerouteFsm(org.openkilda.wfm.topology.flowhs.fsm.reroute.FlowRerouteFsm) FlowResources(org.openkilda.wfm.share.flow.resources.FlowResources) Event(org.openkilda.wfm.topology.flowhs.fsm.reroute.FlowRerouteFsm.Event) RecoverableException(org.openkilda.pce.exception.RecoverableException) UnroutableFlowException(org.openkilda.pce.exception.UnroutableFlowException) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) State(org.openkilda.wfm.topology.flowhs.fsm.reroute.FlowRerouteFsm.State) Lists(com.google.common.collect.Lists) Flow(org.openkilda.model.Flow) TimedExecution(org.openkilda.wfm.share.metrics.TimedExecution) PathComputer(org.openkilda.pce.PathComputer) FlowPathPair(org.openkilda.wfm.topology.flow.model.FlowPathPair) FlowResourcesManager(org.openkilda.wfm.share.flow.resources.FlowResourcesManager) GetPathsResult(org.openkilda.pce.GetPathsResult) PersistenceManager(org.openkilda.persistence.PersistenceManager) PathId(org.openkilda.model.PathId) PathId(org.openkilda.model.PathId) FlowResources(org.openkilda.wfm.share.flow.resources.FlowResources) FlowPath(org.openkilda.model.FlowPath) 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

ResourceAllocationException (org.openkilda.wfm.share.flow.resources.ResourceAllocationException)13 Flow (org.openkilda.model.Flow)9 ArrayList (java.util.ArrayList)5 Test (org.junit.Test)5 FlowPath (org.openkilda.model.FlowPath)5 PathId (org.openkilda.model.PathId)5 GetPathsResult (org.openkilda.pce.GetPathsResult)5 RecoverableException (org.openkilda.pce.exception.RecoverableException)5 UnroutableFlowException (org.openkilda.pce.exception.UnroutableFlowException)5 FlowResources (org.openkilda.wfm.share.flow.resources.FlowResources)5 FlowPathPair (org.openkilda.wfm.topology.flow.model.FlowPathPair)5 List (java.util.List)4 Predicate (java.util.function.Predicate)4 Slf4j (lombok.extern.slf4j.Slf4j)4 ErrorType (org.openkilda.messaging.error.ErrorType)4 SwitchId (org.openkilda.model.SwitchId)4 PathComputer (org.openkilda.pce.PathComputer)4 PersistenceManager (org.openkilda.persistence.PersistenceManager)4 FlowResourcesManager (org.openkilda.wfm.share.flow.resources.FlowResourcesManager)4 FlowOperationsDashboardLogger (org.openkilda.wfm.share.logger.FlowOperationsDashboardLogger)4