Search in sources :

Example 1 with FlowDeleteFsm

use of org.openkilda.wfm.topology.flowhs.fsm.delete.FlowDeleteFsm in project open-kilda by telstra.

the class FlowDeleteService method handleAsyncResponse.

/**
 * Handles async response from worker.
 *
 * @param key command identifier.
 */
public void handleAsyncResponse(@NonNull String key, @NonNull SpeakerFlowSegmentResponse flowResponse) throws UnknownKeyException {
    log.debug("Received flow command response {}", flowResponse);
    FlowDeleteFsm fsm = fsmRegister.getFsmByKey(key).orElseThrow(() -> new UnknownKeyException(key));
    FlowDeleteContext context = FlowDeleteContext.builder().speakerFlowResponse(flowResponse).build();
    if (flowResponse instanceof FlowErrorResponse) {
        fsmExecutor.fire(fsm, Event.ERROR_RECEIVED, context);
    } else {
        fsmExecutor.fire(fsm, Event.RESPONSE_RECEIVED, context);
    }
    removeIfFinished(fsm, key);
}
Also used : FlowErrorResponse(org.openkilda.floodlight.flow.response.FlowErrorResponse) FlowDeleteFsm(org.openkilda.wfm.topology.flowhs.fsm.delete.FlowDeleteFsm) UnknownKeyException(org.openkilda.wfm.topology.flowhs.exception.UnknownKeyException) FlowDeleteContext(org.openkilda.wfm.topology.flowhs.fsm.delete.FlowDeleteContext)

Example 2 with FlowDeleteFsm

use of org.openkilda.wfm.topology.flowhs.fsm.delete.FlowDeleteFsm 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 3 with FlowDeleteFsm

use of org.openkilda.wfm.topology.flowhs.fsm.delete.FlowDeleteFsm in project open-kilda by telstra.

the class FlowDeleteService method handleTimeout.

/**
 * Handles timeout case.
 *
 * @param key command identifier.
 */
public void handleTimeout(@NonNull String key) throws UnknownKeyException {
    log.debug("Handling timeout for {}", key);
    FlowDeleteFsm fsm = fsmRegister.getFsmByKey(key).orElseThrow(() -> new UnknownKeyException(key));
    fsmExecutor.fire(fsm, Event.TIMEOUT);
    removeIfFinished(fsm, key);
}
Also used : FlowDeleteFsm(org.openkilda.wfm.topology.flowhs.fsm.delete.FlowDeleteFsm) UnknownKeyException(org.openkilda.wfm.topology.flowhs.exception.UnknownKeyException)

Aggregations

FlowDeleteFsm (org.openkilda.wfm.topology.flowhs.fsm.delete.FlowDeleteFsm)3 UnknownKeyException (org.openkilda.wfm.topology.flowhs.exception.UnknownKeyException)2 FlowErrorResponse (org.openkilda.floodlight.flow.response.FlowErrorResponse)1 DuplicateKeyException (org.openkilda.wfm.topology.flowhs.exception.DuplicateKeyException)1 FlowDeleteContext (org.openkilda.wfm.topology.flowhs.fsm.delete.FlowDeleteContext)1