Search in sources :

Example 1 with FlowSwapEndpointsFsm

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

the class FlowSwapEndpointsHubService method handleTaskTimeout.

/**
 * Handles timeout case.
 */
public void handleTaskTimeout(String key) {
    log.debug("Handling timeout for {}", key);
    FlowSwapEndpointsFsm fsm = fsmRegister.getFsmByKey(key).orElse(null);
    if (fsm == null) {
        log.warn("Failed to find a FSM: timeout event for non pending FSM with key {}", key);
        return;
    }
    fsm.fire(Event.TIMEOUT);
    removeIfFinished(fsm, key);
}
Also used : FlowSwapEndpointsFsm(org.openkilda.wfm.topology.flowhs.fsm.swapendpoints.FlowSwapEndpointsFsm)

Example 2 with FlowSwapEndpointsFsm

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

the class FlowSwapEndpointsHubService method handleRequest.

/**
 * Handles request for swap flow endpoints.
 */
public void handleRequest(String key, CommandContext commandContext, SwapFlowEndpointRequest request) {
    if (yFlowRepository.isSubFlow(request.getFirstFlow().getFlowId())) {
        sendForbiddenSubFlowOperationToNorthbound(request.getFirstFlow().getFlowId(), commandContext);
        return;
    }
    if (yFlowRepository.isSubFlow(request.getSecondFlow().getFlowId())) {
        sendForbiddenSubFlowOperationToNorthbound(request.getSecondFlow().getFlowId(), commandContext);
        return;
    }
    log.debug("Handling swap flow endpoints request with key {} and flow IDs: {}, {}", key, request.getFirstFlow().getFlowId(), request.getSecondFlow().getFlowId());
    if (fsmRegister.hasRegisteredFsmWithKey(key)) {
        log.error("Attempt to create a FSM with key {}, while there's another active FSM with the same key.", key);
        return;
    }
    RequestedFlow firstFlow = RequestedFlowMapper.INSTANCE.toRequestedFlow(request.getFirstFlow());
    RequestedFlow secondFlow = RequestedFlowMapper.INSTANCE.toRequestedFlow(request.getSecondFlow());
    FlowSwapEndpointsFsm fsm = fsmFactory.newInstance(commandContext, firstFlow, secondFlow);
    fsmRegister.registerFsm(key, fsm);
    fsm.fire(Event.NEXT);
    removeIfFinished(fsm, key);
}
Also used : FlowSwapEndpointsFsm(org.openkilda.wfm.topology.flowhs.fsm.swapendpoints.FlowSwapEndpointsFsm) RequestedFlow(org.openkilda.wfm.topology.flowhs.model.RequestedFlow)

Example 3 with FlowSwapEndpointsFsm

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

the class FlowSwapEndpointsHubService method handleAsyncResponse.

/**
 * Handles async response.
 */
public void handleAsyncResponse(String key, Message message) {
    log.debug("Received response {}", message);
    FlowSwapEndpointsFsm fsm = fsmRegister.getFsmByKey(key).orElse(null);
    if (fsm == null) {
        log.warn("Failed to find a FSM: received response with key {} for non pending FSM", key);
        return;
    }
    if (message instanceof InfoMessage && ((InfoMessage) message).getData() instanceof FlowResponse) {
        fsm.fire(Event.RESPONSE_RECEIVED, new FlowSwapEndpointsContext(((InfoMessage) message).getData()));
    } else if (message instanceof ErrorMessage) {
        fsm.fire(Event.ERROR_RECEIVED, new FlowSwapEndpointsContext(((ErrorMessage) message).getData()));
    } else {
        log.warn("Key: {}; Unhandled message {}", key, message);
    }
    removeIfFinished(fsm, key);
}
Also used : FlowSwapEndpointsFsm(org.openkilda.wfm.topology.flowhs.fsm.swapendpoints.FlowSwapEndpointsFsm) InfoMessage(org.openkilda.messaging.info.InfoMessage) FlowResponse(org.openkilda.messaging.info.flow.FlowResponse) ErrorMessage(org.openkilda.messaging.error.ErrorMessage) FlowSwapEndpointsContext(org.openkilda.wfm.topology.flowhs.fsm.swapendpoints.FlowSwapEndpointsContext)

Aggregations

FlowSwapEndpointsFsm (org.openkilda.wfm.topology.flowhs.fsm.swapendpoints.FlowSwapEndpointsFsm)3 ErrorMessage (org.openkilda.messaging.error.ErrorMessage)1 InfoMessage (org.openkilda.messaging.info.InfoMessage)1 FlowResponse (org.openkilda.messaging.info.flow.FlowResponse)1 FlowSwapEndpointsContext (org.openkilda.wfm.topology.flowhs.fsm.swapendpoints.FlowSwapEndpointsContext)1 RequestedFlow (org.openkilda.wfm.topology.flowhs.model.RequestedFlow)1