Search in sources :

Example 1 with DuplicateKeyException

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

the class YFlowRerouteHubBolt method onRequest.

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

Example 2 with DuplicateKeyException

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

the class FlowDeleteHubBolt method onRequest.

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

Example 3 with DuplicateKeyException

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

the class FlowUpdateHubBolt method onRequest.

@Override
protected void onRequest(Tuple input) throws PipelineException {
    currentKey = input.getStringByField(MessageKafkaTranslator.FIELD_ID_KEY);
    Object payload = input.getValueByField(FIELD_ID_PAYLOAD);
    try {
        if (payload instanceof FlowRequest) {
            FlowRequest flowRequest = (FlowRequest) payload;
            service.handleUpdateRequest(currentKey, pullContext(input), flowRequest);
        } else if (payload instanceof CreateFlowLoopRequest) {
            CreateFlowLoopRequest flowLoopRequest = (CreateFlowLoopRequest) payload;
            service.handleCreateFlowLoopRequest(currentKey, pullContext(input), flowLoopRequest);
        } else if (payload instanceof DeleteFlowLoopRequest) {
            DeleteFlowLoopRequest flowLoopRequest = (DeleteFlowLoopRequest) payload;
            service.handleDeleteFlowLoopRequest(currentKey, pullContext(input), flowLoopRequest);
        } else {
            unhandledInput(input);
        }
    } catch (DuplicateKeyException e) {
        log.error("Failed to handle a request with key {}. {}", currentKey, e.getMessage());
    }
}
Also used : FlowRequest(org.openkilda.messaging.command.flow.FlowRequest) DeleteFlowLoopRequest(org.openkilda.messaging.command.flow.DeleteFlowLoopRequest) CreateFlowLoopRequest(org.openkilda.messaging.command.flow.CreateFlowLoopRequest) DuplicateKeyException(org.openkilda.wfm.topology.flowhs.exception.DuplicateKeyException)

Example 4 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 5 with DuplicateKeyException

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

the class YFlowRerouteService method handleRequest.

/**
 * Handles request for y-flow rerouting.
 *
 * @param key command identifier.
 * @param request request data.
 */
public void handleRequest(@NonNull String key, @NonNull CommandContext commandContext, @NonNull YFlowRerouteRequest request) throws DuplicateKeyException {
    String yFlowId = request.getYFlowId();
    log.debug("Handling y-flow reroute 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 reroute y-flow", format("Y-flow %s is already rerouting now", yFlowId), commandContext);
        return;
    }
    YFlowRerouteFsm fsm = fsmFactory.newInstance(commandContext, request.getYFlowId(), eventListeners);
    fsmRegister.registerFsm(key, fsm);
    YFlowRerouteContext context = YFlowRerouteContext.builder().rerouteRequest(request).build();
    fsm.start(context);
    fsmExecutor.fire(fsm, Event.NEXT, context);
    removeIfFinished(fsm, key);
}
Also used : YFlowRerouteFsm(org.openkilda.wfm.topology.flowhs.fsm.yflow.reroute.YFlowRerouteFsm) YFlowRerouteContext(org.openkilda.wfm.topology.flowhs.fsm.yflow.reroute.YFlowRerouteContext) 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