Search in sources :

Example 11 with DuplicateKeyException

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

the class YFlowValidationHubBolt method onRequest.

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

Example 12 with DuplicateKeyException

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

the class YFlowDeleteService method handleRequest.

/**
 * Handles request for y-flow deletion.
 *
 * @param key command identifier.
 * @param request request data.
 */
public void handleRequest(@NonNull String key, @NonNull CommandContext commandContext, @NonNull YFlowDeleteRequest request) throws DuplicateKeyException {
    String yFlowId = request.getYFlowId();
    log.debug("Handling y-flow delete request with key {} and yFlowId {}", key, yFlowId);
    if (fsmRegister.hasRegisteredFsmWithKey(key)) {
        throw new DuplicateKeyException(key, "There's another active FSM with the same key");
    }
    if (fsmRegister.hasRegisteredFsmWithFlowId(yFlowId)) {
        sendErrorResponseToNorthbound(ErrorType.ALREADY_EXISTS, "Could not delete y-flow", format("Y-flow %s is already creating now", yFlowId), commandContext);
        return;
    }
    YFlowDeleteFsm fsm = fsmFactory.newInstance(commandContext, yFlowId, eventListeners);
    fsmRegister.registerFsm(key, fsm);
    YFlowDeleteContext context = YFlowDeleteContext.builder().build();
    fsm.start(context);
    fsmExecutor.fire(fsm, Event.NEXT, context);
    removeIfFinished(fsm, key);
}
Also used : YFlowDeleteFsm(org.openkilda.wfm.topology.flowhs.fsm.yflow.delete.YFlowDeleteFsm) YFlowDeleteContext(org.openkilda.wfm.topology.flowhs.fsm.yflow.delete.YFlowDeleteContext) DuplicateKeyException(org.openkilda.wfm.topology.flowhs.exception.DuplicateKeyException)

Example 13 with DuplicateKeyException

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

the class YFlowUpdateService method handleRequest.

/**
 * Handles request for y-flow updating.
 *
 * @param key command identifier.
 * @param request request data.
 */
public void handleRequest(@NonNull String key, @NonNull CommandContext commandContext, @NonNull YFlowRequest request) throws DuplicateKeyException {
    String yFlowId = request.getYFlowId();
    log.debug("Handling y-flow update request with key {} and flow ID: {}", key, request.getYFlowId());
    if (fsmRegister.hasRegisteredFsmWithKey(key)) {
        throw new DuplicateKeyException(key, "There's another active FSM with the same key");
    }
    if (fsmRegister.hasRegisteredFsmWithFlowId(yFlowId)) {
        sendErrorResponseToNorthbound(ErrorType.ALREADY_EXISTS, "Could not update y-flow", format("Y-flow %s is already updating now", yFlowId), commandContext);
        log.error("Attempt to create a FSM with key {}, while there's another active FSM for the same yFlowId {}.", key, yFlowId);
        return;
    }
    if (yFlowId == null) {
        yFlowId = generateFlowId(prefixForGeneratedYFlowId);
        request.setYFlowId(yFlowId);
    }
    request.getSubFlows().forEach(subFlow -> {
        if (subFlow.getFlowId() == null) {
            subFlow.setFlowId(generateFlowId(prefixForGeneratedSubFlowId));
        }
    });
    if (request.getEncapsulationType() == null) {
        request.setEncapsulationType(kildaConfigurationRepository.getOrDefault().getFlowEncapsulationType());
    }
    if (request.getPathComputationStrategy() == null) {
        request.setPathComputationStrategy(kildaConfigurationRepository.getOrDefault().getPathComputationStrategy());
    }
    YFlowUpdateFsm fsm = fsmFactory.newInstance(commandContext, yFlowId, eventListeners);
    fsmRegister.registerFsm(key, fsm);
    YFlowUpdateContext context = YFlowUpdateContext.builder().targetFlow(request).build();
    fsm.start(context);
    fsmExecutor.fire(fsm, Event.NEXT, context);
    removeIfFinished(fsm, key);
}
Also used : YFlowUpdateFsm(org.openkilda.wfm.topology.flowhs.fsm.yflow.update.YFlowUpdateFsm) YFlowUpdateContext(org.openkilda.wfm.topology.flowhs.fsm.yflow.update.YFlowUpdateContext) DuplicateKeyException(org.openkilda.wfm.topology.flowhs.exception.DuplicateKeyException)

Example 14 with DuplicateKeyException

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

the class YFlowCreateService method handleRequest.

/**
 * Handles request for y-flow creation.
 *
 * @param key command identifier.
 * @param request request data.
 */
public void handleRequest(@NonNull String key, @NonNull CommandContext commandContext, @NonNull YFlowRequest request) throws DuplicateKeyException {
    String yFlowId = request.getYFlowId();
    log.debug("Handling y-flow create request with key {} and yFlowId {}", key, yFlowId);
    if (fsmRegister.hasRegisteredFsmWithKey(key)) {
        throw new DuplicateKeyException(key, "There's another active FSM with the same key");
    }
    if (yFlowId == null) {
        yFlowId = generateFlowId(prefixForGeneratedYFlowId);
        request.setYFlowId(yFlowId);
    } else if (fsmRegister.hasRegisteredFsmWithFlowId(yFlowId)) {
        sendErrorResponseToNorthbound(ErrorType.ALREADY_EXISTS, "Could not create y-flow", format("Y-flow %s is already creating now", yFlowId), commandContext);
        return;
    }
    request.getSubFlows().forEach(subFlow -> {
        if (subFlow.getFlowId() == null) {
            subFlow.setFlowId(generateFlowId(prefixForGeneratedSubFlowId));
        }
    });
    if (request.getEncapsulationType() == null) {
        request.setEncapsulationType(kildaConfigurationRepository.getOrDefault().getFlowEncapsulationType());
    }
    if (request.getPathComputationStrategy() == null) {
        request.setPathComputationStrategy(kildaConfigurationRepository.getOrDefault().getPathComputationStrategy());
    }
    YFlowCreateFsm fsm = fsmFactory.newInstance(commandContext, yFlowId, eventListeners);
    fsmRegister.registerFsm(key, fsm);
    YFlowCreateContext context = YFlowCreateContext.builder().targetFlow(request).build();
    fsm.start(context);
    fsmExecutor.fire(fsm, Event.NEXT, context);
    removeIfFinished(fsm, key);
}
Also used : YFlowCreateContext(org.openkilda.wfm.topology.flowhs.fsm.yflow.create.YFlowCreateContext) YFlowCreateFsm(org.openkilda.wfm.topology.flowhs.fsm.yflow.create.YFlowCreateFsm) DuplicateKeyException(org.openkilda.wfm.topology.flowhs.exception.DuplicateKeyException)

Example 15 with DuplicateKeyException

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

the class FlowValidationHubService method startFlowValidation.

private void startFlowValidation(@NonNull String key, @NonNull CommandContext commandContext, @NonNull String flowId) throws DuplicateKeyException {
    log.debug("Handling flow validation 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");
    }
    FlowValidationFsm fsm = fsmFactory.newInstance(flowId, commandContext, eventListeners);
    fsmRegister.registerFsm(key, fsm);
    fsm.start();
    fsmExecutor.fire(fsm, Event.NEXT, flowId);
    removeIfFinished(fsm, key);
}
Also used : FlowValidationFsm(org.openkilda.wfm.topology.flowhs.fsm.validation.FlowValidationFsm) 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