Search in sources :

Example 16 with CommandContext

use of org.openkilda.wfm.CommandContext in project open-kilda by telstra.

the class ValidateSubFlowsAction method perform.

@Override
protected void perform(State from, State to, Event event, YFlowValidationContext context, YFlowValidationFsm stateMachine) {
    String yFlowId = stateMachine.getYFlowId();
    YFlow yFlow = yFlowRepository.findById(yFlowId).orElseThrow(() -> new FlowProcessingException(ErrorType.NOT_FOUND, format("Y-flow %s not found", yFlowId)));
    if (yFlow.getStatus() == FlowStatus.DOWN) {
        throw new FlowProcessingException(ErrorType.UNPROCESSABLE_REQUEST, format("Could not validate y-flow: y-flow %s in in DOWN state", yFlowId));
    }
    log.debug("Start validating {} sub-flows of y-flow {}", yFlow.getSubFlows().size(), yFlowId);
    stateMachine.clearValidatingSubFlows();
    yFlow.getSubFlows().forEach(subFlow -> {
        String subFlowId = subFlow.getSubFlowId();
        stateMachine.addSubFlow(subFlowId);
        stateMachine.addValidatingSubFlow(subFlowId);
        stateMachine.notifyEventListeners(listener -> listener.onSubFlowProcessingStart(yFlowId, subFlowId));
        CommandContext flowContext = stateMachine.getCommandContext().fork(subFlowId);
        flowValidationHubService.startFlowValidation(flowContext, subFlowId);
    });
}
Also used : YFlow(org.openkilda.model.YFlow) CommandContext(org.openkilda.wfm.CommandContext) FlowProcessingException(org.openkilda.wfm.topology.flowhs.exception.FlowProcessingException)

Example 17 with CommandContext

use of org.openkilda.wfm.CommandContext in project open-kilda by telstra.

the class FlowRerouteService method startFlowRerouting.

private void startFlowRerouting(String key, FlowRerouteRequest reroute, CommandContext commandContext, String sharedBandwidthGroupId) {
    String flowId = reroute.getFlowId();
    log.debug("Handling flow reroute request with key {} and flow ID: {}", key, flowId);
    try {
        checkRequestsCollision(key, flowId);
    } catch (Exception e) {
        log.error(e.getMessage());
        fsmRegister.getFsmByKey(key).ifPresent(fsm -> removeIfFinished(fsm, key));
        return;
    }
    if (fsmRegister.hasRegisteredFsmWithFlowId(flowId)) {
        carrier.sendRerouteResultStatus(flowId, new RerouteInProgressError(), commandContext.getCorrelationId());
        return;
    }
    FlowRerouteFsm fsm = fsmFactory.newInstance(flowId, commandContext, eventListeners);
    fsm.setSharedBandwidthGroupId(sharedBandwidthGroupId);
    fsmRegister.registerFsm(key, fsm);
    FlowRerouteContext context = FlowRerouteContext.builder().flowId(flowId).affectedIsl(reroute.getAffectedIsl()).forceReroute(reroute.isForce()).ignoreBandwidth(reroute.isIgnoreBandwidth()).effectivelyDown(reroute.isEffectivelyDown()).rerouteReason(reroute.getReason()).build();
    fsmExecutor.fire(fsm, Event.NEXT, context);
    removeIfFinished(fsm, key);
}
Also used : RerouteInProgressError(org.openkilda.messaging.info.reroute.error.RerouteInProgressError) FlowRerouteContext(org.openkilda.wfm.topology.flowhs.fsm.reroute.FlowRerouteContext) SpeakerFlowSegmentResponse(org.openkilda.floodlight.api.response.SpeakerFlowSegmentResponse) FlowErrorResponse(org.openkilda.floodlight.flow.response.FlowErrorResponse) FlowProcessingFsmRegister(org.openkilda.wfm.topology.flowhs.service.common.FlowProcessingFsmRegister) NonNull(lombok.NonNull) Config(org.openkilda.wfm.topology.flowhs.fsm.reroute.FlowRerouteFsm.Config) CommandContext(org.openkilda.wfm.CommandContext) FlowRerouteFsm(org.openkilda.wfm.topology.flowhs.fsm.reroute.FlowRerouteFsm) Event(org.openkilda.wfm.topology.flowhs.fsm.reroute.FlowRerouteFsm.Event) FlowRerouteRequest(org.openkilda.messaging.command.flow.FlowRerouteRequest) Slf4j(lombok.extern.slf4j.Slf4j) FlowProcessingService(org.openkilda.wfm.topology.flowhs.service.common.FlowProcessingService) PathComputer(org.openkilda.pce.PathComputer) UnknownKeyException(org.openkilda.wfm.topology.flowhs.exception.UnknownKeyException) FlowResourcesManager(org.openkilda.wfm.share.flow.resources.FlowResourcesManager) FsmExecutor(org.openkilda.wfm.share.utils.FsmExecutor) PersistenceManager(org.openkilda.persistence.PersistenceManager) FlowRerouteFsm(org.openkilda.wfm.topology.flowhs.fsm.reroute.FlowRerouteFsm) FlowRerouteContext(org.openkilda.wfm.topology.flowhs.fsm.reroute.FlowRerouteContext) UnknownKeyException(org.openkilda.wfm.topology.flowhs.exception.UnknownKeyException) RerouteInProgressError(org.openkilda.messaging.info.reroute.error.RerouteInProgressError)

Example 18 with CommandContext

use of org.openkilda.wfm.CommandContext in project open-kilda by telstra.

the class FlowRerouteServiceTest method shouldFailRerouteOnErrorDuringCompletingFlowPathInstallation.

@Test
public void shouldFailRerouteOnErrorDuringCompletingFlowPathInstallation() throws RecoverableException, UnroutableFlowException, UnknownKeyException {
    Flow origin = makeFlow();
    preparePathComputation(origin.getFlowId(), make3SwitchesPathPair());
    FlowPathRepository repository = setupFlowPathRepositorySpy();
    Set<PathId> originalPaths = origin.getPaths().stream().map(FlowPath::getPathId).collect(toSet());
    doThrow(new RuntimeException(injectedErrorMessage)).when(repository).updateStatus(ArgumentMatchers.argThat(argument -> !originalPaths.contains(argument)), eq(FlowPathStatus.ACTIVE));
    FlowRerouteService service = makeService();
    FlowRerouteRequest request = new FlowRerouteRequest(origin.getFlowId(), false, false, false, Collections.emptySet(), null, false);
    service.handleRequest(currentRequestKey, request, commandContext);
    verifyFlowStatus(origin.getFlowId(), FlowStatus.IN_PROGRESS);
    verifyNorthboundSuccessResponse(carrier);
    FlowSegmentRequest speakerRequest;
    while ((speakerRequest = requests.poll()) != null) {
        if (speakerRequest.isVerifyRequest()) {
            service.handleAsyncResponse(currentRequestKey, buildResponseOnVerifyRequest(speakerRequest));
        } else {
            produceAsyncResponse(service, speakerRequest);
        }
    }
    Flow result = verifyFlowStatus(origin.getFlowId(), FlowStatus.UP);
    verifyNoPathReplace(origin, result);
}
Also used : PathId(org.openkilda.model.PathId) MAX_LATENCY(org.openkilda.model.PathComputationStrategy.MAX_LATENCY) ArgumentMatchers(org.mockito.ArgumentMatchers) FlowPath(org.openkilda.model.FlowPath) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) FlowStatus(org.openkilda.model.FlowStatus) ResourceAllocationException(org.openkilda.wfm.share.flow.resources.ResourceAllocationException) Mockito.doThrow(org.mockito.Mockito.doThrow) FlowPathStatus(org.openkilda.model.FlowPathStatus) UnroutableFlowException(org.openkilda.pce.exception.UnroutableFlowException) Flow(org.openkilda.model.Flow) MockitoHamcrest.argThat(org.mockito.hamcrest.MockitoHamcrest.argThat) Mockito.doAnswer(org.mockito.Mockito.doAnswer) Mockito.doReturn(org.mockito.Mockito.doReturn) Collectors.toSet(java.util.stream.Collectors.toSet) IslEndpoint(org.openkilda.model.IslEndpoint) FlowErrorResponse(org.openkilda.floodlight.flow.response.FlowErrorResponse) FlowPathRepository(org.openkilda.persistence.repositories.FlowPathRepository) Collection(java.util.Collection) Set(java.util.Set) CommandContext(org.openkilda.wfm.CommandContext) FlowRerouteRequest(org.openkilda.messaging.command.flow.FlowRerouteRequest) List(java.util.List) Assert.assertFalse(org.junit.Assert.assertFalse) Matchers.equalTo(org.hamcrest.Matchers.equalTo) ErrorCode(org.openkilda.floodlight.flow.response.FlowErrorResponse.ErrorCode) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) RerouteResultInfoData(org.openkilda.messaging.info.reroute.RerouteResultInfoData) PathSegment(org.openkilda.model.PathSegment) Mock(org.mockito.Mock) RunWith(org.junit.runner.RunWith) RecoverableException(org.openkilda.pce.exception.RecoverableException) Matchers.hasProperty(org.hamcrest.Matchers.hasProperty) IslRepository(org.openkilda.persistence.repositories.IslRepository) UnknownKeyException(org.openkilda.wfm.topology.flowhs.exception.UnknownKeyException) ArgumentMatchers.anyInt(org.mockito.ArgumentMatchers.anyInt) FlowRerouteResponse(org.openkilda.messaging.info.flow.FlowRerouteResponse) PathId(org.openkilda.model.PathId) FlowSegmentRequest(org.openkilda.floodlight.api.request.FlowSegmentRequest) Before(org.junit.Before) ArgumentMatchers.isNull(org.mockito.ArgumentMatchers.isNull) Assert.assertNotNull(org.junit.Assert.assertNotNull) ErrorType(org.openkilda.messaging.error.ErrorType) Mockito.times(org.mockito.Mockito.times) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) LATENCY(org.openkilda.model.PathComputationStrategy.LATENCY) Mockito.verify(org.mockito.Mockito.verify) Assert.assertNull(org.junit.Assert.assertNull) Ignore(org.junit.Ignore) GetPathsResult(org.openkilda.pce.GetPathsResult) Assert(org.junit.Assert) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) FlowPathRepository(org.openkilda.persistence.repositories.FlowPathRepository) FlowSegmentRequest(org.openkilda.floodlight.api.request.FlowSegmentRequest) FlowRerouteRequest(org.openkilda.messaging.command.flow.FlowRerouteRequest) Flow(org.openkilda.model.Flow) Test(org.junit.Test)

Example 19 with CommandContext

use of org.openkilda.wfm.CommandContext in project open-kilda by telstra.

the class FlowValidationHubServiceTest method testMainPath.

@Test
public void testMainPath() throws DuplicateKeyException, UnknownKeyException {
    FlowValidationHubCarrier carrier = new FlowValidationHubCarrier() {

        @Override
        public void sendSpeakerRequest(String flowId, CommandData commandData) {
            assertTrue(commandData instanceof DumpRulesForFlowHsRequest || commandData instanceof DumpMetersForFlowHsRequest || commandData instanceof DumpGroupsForFlowHsRequest);
            List<SwitchId> switchIds = Lists.newArrayList(TEST_SWITCH_ID_A, TEST_SWITCH_ID_B, TEST_SWITCH_ID_C, TEST_SWITCH_ID_E);
            if (commandData instanceof DumpRulesForFlowHsRequest) {
                assertTrue(switchIds.contains(((DumpRulesForFlowHsRequest) commandData).getSwitchId()));
            } else if (commandData instanceof DumpMetersForFlowHsRequest) {
                assertTrue(switchIds.contains(((DumpMetersForFlowHsRequest) commandData).getSwitchId()));
            } else {
                assertTrue(switchIds.contains(((DumpGroupsForFlowHsRequest) commandData).getSwitchId()));
            }
        }

        @Override
        public void sendNorthboundResponse(List<? extends InfoData> message) {
            assertEquals(4, message.size());
            try {
                assertEquals(flowValidationService.validateFlow(TEST_FLOW_ID_A, getSwitchFlowEntriesWithTransitVlan(), getSwitchMeterEntries(), getSwitchGroupEntries()), message);
            } catch (FlowNotFoundException | SwitchNotFoundException e) {
            // tested in the FlowValidationServiceTest
            }
        }

        @Override
        public void sendNorthboundResponse(Message message) {
            fail();
        }

        @Override
        public void cancelTimeoutCallback(String key) {
            assertEquals(TEST_KEY, key);
        }

        @Override
        public void sendInactive() {
        }
    };
    flowValidationHubService = new FlowValidationHubService(carrier, persistenceManager, flowResourcesManager, MIN_BURST_SIZE_IN_KBITS, BURST_COEFFICIENT);
    buildTransitVlanFlow("");
    flowValidationHubService.handleFlowValidationRequest(TEST_KEY, new CommandContext(), new FlowValidationRequest(TEST_FLOW_ID_A));
    for (SwitchFlowEntries switchFlowEntries : getSwitchFlowEntriesWithTransitVlan()) {
        flowValidationHubService.handleAsyncResponse(TEST_KEY, switchFlowEntries);
    }
    for (SwitchMeterEntries switchMeterEntries : getSwitchMeterEntries()) {
        flowValidationHubService.handleAsyncResponse(TEST_KEY, switchMeterEntries);
    }
    for (SwitchGroupEntries switchGroupEntries : getSwitchGroupEntries()) {
        flowValidationHubService.handleAsyncResponse(TEST_KEY, switchGroupEntries);
    }
}
Also used : DumpGroupsForFlowHsRequest(org.openkilda.messaging.command.switches.DumpGroupsForFlowHsRequest) FlowNotFoundException(org.openkilda.wfm.error.FlowNotFoundException) SwitchFlowEntries(org.openkilda.messaging.info.rule.SwitchFlowEntries) Message(org.openkilda.messaging.Message) ErrorMessage(org.openkilda.messaging.error.ErrorMessage) CommandContext(org.openkilda.wfm.CommandContext) SwitchMeterEntries(org.openkilda.messaging.info.meter.SwitchMeterEntries) SwitchId(org.openkilda.model.SwitchId) SwitchNotFoundException(org.openkilda.wfm.error.SwitchNotFoundException) DumpMetersForFlowHsRequest(org.openkilda.messaging.command.switches.DumpMetersForFlowHsRequest) FlowValidationRequest(org.openkilda.messaging.command.flow.FlowValidationRequest) InfoData(org.openkilda.messaging.info.InfoData) DumpRulesForFlowHsRequest(org.openkilda.messaging.command.switches.DumpRulesForFlowHsRequest) SwitchGroupEntries(org.openkilda.messaging.info.rule.SwitchGroupEntries) List(java.util.List) CommandData(org.openkilda.messaging.command.CommandData) Test(org.junit.Test)

Example 20 with CommandContext

use of org.openkilda.wfm.CommandContext in project open-kilda by telstra.

the class YFlowDeleteServiceTest method shouldDeleteOnTimeoutDuringMeterRemoval.

@Test
public void shouldDeleteOnTimeoutDuringMeterRemoval() throws DuplicateKeyException {
    // given
    String yFlowId = "test_y_flow_11";
    createYFlowViaTransit(yFlowId);
    YFlowDeleteService service = makeYFlowDeleteService(0);
    // when
    service.handleRequest(yFlowId, new CommandContext(), new YFlowDeleteRequest(yFlowId));
    verifyYFlowStatus(yFlowId, FlowStatus.IN_PROGRESS);
    // and
    handleSpeakerCommandsAndTimeoutRemove(service, yFlowId);
    // then
    verifyNorthboundSuccessResponse(yFlowDeleteHubCarrier, YFlowResponse.class);
    verifyYFlowIsAbsent(yFlowId);
}
Also used : CommandContext(org.openkilda.wfm.CommandContext) YFlowDeleteRequest(org.openkilda.messaging.command.yflow.YFlowDeleteRequest) Test(org.junit.Test) AbstractYFlowTest(org.openkilda.wfm.topology.flowhs.service.AbstractYFlowTest)

Aggregations

CommandContext (org.openkilda.wfm.CommandContext)95 Test (org.junit.Test)28 Values (org.apache.storm.tuple.Values)27 FlowSegmentRequest (org.openkilda.floodlight.api.request.FlowSegmentRequest)15 Flow (org.openkilda.model.Flow)15 AbstractYFlowTest (org.openkilda.wfm.topology.flowhs.service.AbstractYFlowTest)14 Tuple (org.apache.storm.tuple.Tuple)12 SwitchId (org.openkilda.model.SwitchId)11 YFlow (org.openkilda.model.YFlow)11 BaseSpeakerCommandsRequest (org.openkilda.floodlight.api.request.rulemanager.BaseSpeakerCommandsRequest)9 SpeakerResponse (org.openkilda.floodlight.api.response.SpeakerResponse)9 YFlowRequest (org.openkilda.messaging.command.yflow.YFlowRequest)9 InfoMessage (org.openkilda.messaging.info.InfoMessage)9 TupleImpl (org.apache.storm.tuple.TupleImpl)8 FlowPath (org.openkilda.model.FlowPath)8 ArrayList (java.util.ArrayList)7 FlowRerouteRequest (org.openkilda.messaging.command.flow.FlowRerouteRequest)7 FlowProcessingException (org.openkilda.wfm.topology.flowhs.exception.FlowProcessingException)7 UnknownKeyException (org.openkilda.wfm.topology.flowhs.exception.UnknownKeyException)7 List (java.util.List)6