Search in sources :

Example 6 with DuplicateKeyException

use of org.openkilda.wfm.topology.flowhs.exception.DuplicateKeyException in project open-kilda by telstra.

the class FlowUpdateService method startFlowUpdating.

private void startFlowUpdating(String key, CommandContext commandContext, RequestedFlow request, boolean doNotRevert, Set<String> bulkUpdateFlowIds, String sharedBandwidthGroupId) throws DuplicateKeyException {
    String flowId = request.getFlowId();
    log.debug("Handling flow update request with key {} and flow ID: {}", key, request.getFlowId());
    if (fsmRegister.hasRegisteredFsmWithKey(key)) {
        throw new DuplicateKeyException(key, "There's another active FSM with the same key");
    }
    if (fsmRegister.hasRegisteredFsmWithFlowId(flowId)) {
        sendErrorResponseToNorthbound(ErrorType.REQUEST_INVALID, "Could not update flow", format("Flow %s is updating now", flowId), commandContext);
        log.error("Attempt to create a FSM with key {}, while there's another active FSM for the same flowId {}.", key, flowId);
        return;
    }
    FlowUpdateFsm fsm = fsmFactory.newInstance(request.getFlowId(), commandContext, eventListeners);
    fsm.setSharedBandwidthGroupId(sharedBandwidthGroupId);
    fsmRegister.registerFsm(key, fsm);
    if (request.getFlowEncapsulationType() == null) {
        request.setFlowEncapsulationType(kildaConfigurationRepository.getOrDefault().getFlowEncapsulationType());
    }
    FlowUpdateContext context = FlowUpdateContext.builder().targetFlow(request).doNotRevert(doNotRevert).bulkUpdateFlowIds(bulkUpdateFlowIds).build();
    fsmExecutor.fire(fsm, Event.NEXT, context);
    removeIfFinished(fsm, key);
}
Also used : FlowUpdateFsm(org.openkilda.wfm.topology.flowhs.fsm.update.FlowUpdateFsm) FlowUpdateContext(org.openkilda.wfm.topology.flowhs.fsm.update.FlowUpdateContext) DuplicateKeyException(org.openkilda.wfm.topology.flowhs.exception.DuplicateKeyException)

Example 7 with DuplicateKeyException

use of org.openkilda.wfm.topology.flowhs.exception.DuplicateKeyException in project open-kilda by telstra.

the class FlowCreateService method startFlowCreation.

private void startFlowCreation(String key, CommandContext commandContext, RequestedFlow requestedFlow, String sharedBandwidthGroupId) throws DuplicateKeyException {
    String flowId = requestedFlow.getFlowId();
    log.debug("Handling flow create request with key {} and flow ID: {}", key, flowId);
    if (fsmRegister.hasRegisteredFsmWithKey(key)) {
        throw new DuplicateKeyException(key, "There's another active FSM with the same key");
    }
    if (fsmRegister.hasRegisteredFsmWithFlowId(flowId)) {
        sendErrorResponseToNorthbound(ErrorType.ALREADY_EXISTS, "Could not create flow", format("Flow %s is already creating now", flowId), commandContext);
        throw new DuplicateKeyException(key, "There's another active FSM for the same flowId " + flowId);
    }
    FlowCreateFsm fsm = fsmFactory.newInstance(commandContext, flowId, eventListeners);
    fsm.setSharedBandwidthGroupId(sharedBandwidthGroupId);
    fsmRegister.registerFsm(key, fsm);
    if (requestedFlow.getFlowEncapsulationType() == null) {
        requestedFlow.setFlowEncapsulationType(kildaConfigurationRepository.getOrDefault().getFlowEncapsulationType());
    }
    if (requestedFlow.getPathComputationStrategy() == null) {
        requestedFlow.setPathComputationStrategy(kildaConfigurationRepository.getOrDefault().getPathComputationStrategy());
    }
    FlowCreateContext context = FlowCreateContext.builder().targetFlow(requestedFlow).build();
    fsm.start(context);
    fsmExecutor.fire(fsm, Event.NEXT, context);
    removeIfFinished(fsm, key);
}
Also used : FlowCreateContext(org.openkilda.wfm.topology.flowhs.fsm.create.FlowCreateContext) FlowCreateFsm(org.openkilda.wfm.topology.flowhs.fsm.create.FlowCreateFsm) DuplicateKeyException(org.openkilda.wfm.topology.flowhs.exception.DuplicateKeyException)

Example 8 with DuplicateKeyException

use of org.openkilda.wfm.topology.flowhs.exception.DuplicateKeyException in project open-kilda by telstra.

the class FlowDeleteService method startFlowDeletion.

private void startFlowDeletion(String key, CommandContext commandContext, String flowId) throws DuplicateKeyException {
    log.debug("Handling flow deletion request with key {} and flow ID: {}", key, flowId);
    if (fsmRegister.hasRegisteredFsmWithKey(key)) {
        throw new DuplicateKeyException(key, "There's another active FSM with the same key");
    }
    if (fsmRegister.hasRegisteredFsmWithFlowId(flowId)) {
        sendErrorResponseToNorthbound(ErrorType.REQUEST_INVALID, "Could not delete flow", format("Flow %s is already deleting now", flowId), commandContext);
        throw new DuplicateKeyException(key, "There's another active FSM for the same flowId " + flowId);
    }
    FlowDeleteFsm fsm = fsmFactory.newInstance(commandContext, flowId, eventListeners);
    fsmRegister.registerFsm(key, fsm);
    fsm.start();
    fsmExecutor.fire(fsm, Event.NEXT, FlowDeleteContext.builder().build());
    removeIfFinished(fsm, key);
}
Also used : FlowDeleteFsm(org.openkilda.wfm.topology.flowhs.fsm.delete.FlowDeleteFsm) DuplicateKeyException(org.openkilda.wfm.topology.flowhs.exception.DuplicateKeyException)

Example 9 with DuplicateKeyException

use of org.openkilda.wfm.topology.flowhs.exception.DuplicateKeyException in project open-kilda by telstra.

the class FlowUpdateServiceTest method shouldFailUpdateOnErrorDuringCompletingFlowPathInstallation.

@Test
public void shouldFailUpdateOnErrorDuringCompletingFlowPathInstallation() throws RecoverableException, UnroutableFlowException, DuplicateKeyException, UnknownKeyException {
    Flow origin = makeFlow();
    preparePathComputation(origin.getFlowId(), make3SwitchesPathPair());
    FlowRequest request = makeRequest().flowId(origin.getFlowId()).build();
    FlowPathRepository repository = setupFlowPathRepositorySpy();
    Set<PathId> originalPaths = origin.getPaths().stream().map(FlowPath::getPathId).collect(Collectors.toSet());
    doThrow(new RuntimeException(injectedErrorMessage)).when(repository).updateStatus(ArgumentMatchers.argThat(argument -> !originalPaths.contains(argument)), eq(FlowPathStatus.ACTIVE));
    FlowUpdateService service = makeService();
    service.handleUpdateRequest(dummyRequestKey, commandContext, request);
    verifyFlowStatus(origin.getFlowId(), FlowStatus.IN_PROGRESS);
    verifyNorthboundSuccessResponse(carrier);
    FlowSegmentRequest speakerRequest;
    while ((speakerRequest = requests.poll()) != null) {
        if (speakerRequest.isVerifyRequest()) {
            service.handleAsyncResponse(dummyRequestKey, buildResponseOnVerifyRequest(speakerRequest));
        } else {
            service.handleAsyncResponse(dummyRequestKey, SpeakerFlowSegmentResponse.builder().messageContext(speakerRequest.getMessageContext()).commandId(speakerRequest.getCommandId()).metadata(speakerRequest.getMetadata()).switchId(speakerRequest.getSwitchId()).success(true).build());
        }
    }
    Flow result = verifyFlowStatus(origin.getFlowId(), FlowStatus.UP);
    verifyNoPathReplace(origin, result);
}
Also used : PathId(org.openkilda.model.PathId) ArgumentMatchers(org.mockito.ArgumentMatchers) FlowPath(org.openkilda.model.FlowPath) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) IngressFlowLoopSegmentRemoveRequest(org.openkilda.floodlight.api.request.IngressFlowLoopSegmentRemoveRequest) FlowStatus(org.openkilda.model.FlowStatus) ResourceAllocationException(org.openkilda.wfm.share.flow.resources.ResourceAllocationException) TransitFlowLoopSegmentInstallRequest(org.openkilda.floodlight.api.request.TransitFlowLoopSegmentInstallRequest) 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) FlowErrorResponse(org.openkilda.floodlight.flow.response.FlowErrorResponse) FlowPathRepository(org.openkilda.persistence.repositories.FlowPathRepository) Set(java.util.Set) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) 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) SpeakerFlowSegmentResponse(org.openkilda.floodlight.api.response.SpeakerFlowSegmentResponse) Mock(org.mockito.Mock) CreateFlowLoopRequest(org.openkilda.messaging.command.flow.CreateFlowLoopRequest) 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) PathId(org.openkilda.model.PathId) FlowSegmentRequest(org.openkilda.floodlight.api.request.FlowSegmentRequest) Before(org.junit.Before) FlowRequest(org.openkilda.messaging.command.flow.FlowRequest) DuplicateKeyException(org.openkilda.wfm.topology.flowhs.exception.DuplicateKeyException) DeleteFlowLoopRequest(org.openkilda.messaging.command.flow.DeleteFlowLoopRequest) ErrorType(org.openkilda.messaging.error.ErrorType) IngressFlowLoopSegmentVerifyRequest(org.openkilda.floodlight.api.request.IngressFlowLoopSegmentVerifyRequest) Assert.assertTrue(org.junit.Assert.assertTrue) Mockito.times(org.mockito.Mockito.times) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) Mockito.verify(org.mockito.Mockito.verify) ArgumentMatchers.anyCollection(org.mockito.ArgumentMatchers.anyCollection) Assert.assertNull(org.junit.Assert.assertNull) Ignore(org.junit.Ignore) GetPathsResult(org.openkilda.pce.GetPathsResult) TransitFlowLoopSegmentRemoveRequest(org.openkilda.floodlight.api.request.TransitFlowLoopSegmentRemoveRequest) Assert(org.junit.Assert) IngressFlowLoopSegmentInstallRequest(org.openkilda.floodlight.api.request.IngressFlowLoopSegmentInstallRequest) TransitFlowLoopSegmentVerifyRequest(org.openkilda.floodlight.api.request.TransitFlowLoopSegmentVerifyRequest) Assert.assertEquals(org.junit.Assert.assertEquals) FlowPathRepository(org.openkilda.persistence.repositories.FlowPathRepository) FlowRequest(org.openkilda.messaging.command.flow.FlowRequest) FlowSegmentRequest(org.openkilda.floodlight.api.request.FlowSegmentRequest) Flow(org.openkilda.model.Flow) Test(org.junit.Test)

Example 10 with DuplicateKeyException

use of org.openkilda.wfm.topology.flowhs.exception.DuplicateKeyException in project open-kilda by telstra.

the class YFlowDeleteHubBolt method onRequest.

@Override
protected void onRequest(Tuple input) throws PipelineException {
    currentKey = pullKey(input);
    YFlowDeleteRequest payload = pullValue(input, FIELD_ID_PAYLOAD, YFlowDeleteRequest.class);
    try {
        yFlowDeleteService.handleRequest(currentKey, getCommandContext(), payload);
    } catch (DuplicateKeyException e) {
        log.error("Failed to handle a request with key {}. {}", currentKey, e.getMessage());
    }
}
Also used : YFlowDeleteRequest(org.openkilda.messaging.command.yflow.YFlowDeleteRequest) DuplicateKeyException(org.openkilda.wfm.topology.flowhs.exception.DuplicateKeyException)

Aggregations

DuplicateKeyException (org.openkilda.wfm.topology.flowhs.exception.DuplicateKeyException)21 Before (org.junit.Before)3 Test (org.junit.Test)3 RunWith (org.junit.runner.RunWith)3 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)3 Mock (org.mockito.Mock)3 Mockito.doAnswer (org.mockito.Mockito.doAnswer)3 Mockito.times (org.mockito.Mockito.times)3 Mockito.verify (org.mockito.Mockito.verify)3 MockitoJUnitRunner (org.mockito.junit.MockitoJUnitRunner)3 YFlowRequest (org.openkilda.messaging.command.yflow.YFlowRequest)3 CommandContext (org.openkilda.wfm.CommandContext)3 Assert.assertEquals (org.junit.Assert.assertEquals)2 Assert.assertFalse (org.junit.Assert.assertFalse)2 Assert.assertTrue (org.junit.Assert.assertTrue)2 Ignore (org.junit.Ignore)2 ArgumentMatchers (org.mockito.ArgumentMatchers)2 ArgumentMatchers.eq (org.mockito.ArgumentMatchers.eq)2 Mockito.doThrow (org.mockito.Mockito.doThrow)2 Mockito.when (org.mockito.Mockito.when)2