Search in sources :

Example 6 with UnknownKeyException

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

the class YFlowUpdateService method handleAsyncResponse.

/**
 * Handles async response from worker.
 *
 * @param key command identifier.
 */
public void handleAsyncResponse(@NonNull String key, @NonNull SpeakerResponse speakerResponse) throws UnknownKeyException {
    log.debug("Received flow command response {}", speakerResponse);
    YFlowUpdateFsm fsm = fsmRegister.getFsmByKey(key).orElseThrow(() -> new UnknownKeyException(key));
    if (speakerResponse instanceof SpeakerFlowSegmentResponse) {
        SpeakerFlowSegmentResponse response = (SpeakerFlowSegmentResponse) speakerResponse;
        String flowId = response.getMetadata().getFlowId();
        if (fsm.getUpdatingSubFlows().contains(flowId)) {
            flowUpdateService.handleAsyncResponseByFlowId(flowId, response);
        }
    } else if (speakerResponse instanceof SpeakerCommandResponse) {
        SpeakerCommandResponse response = (SpeakerCommandResponse) speakerResponse;
        YFlowUpdateContext context = YFlowUpdateContext.builder().speakerResponse(response).build();
        fsmExecutor.fire(fsm, Event.RESPONSE_RECEIVED, context);
    } else {
        log.debug("Received unexpected speaker response: {}", speakerResponse);
    }
    // After handling an event by FlowUpdate service, we should propagate execution to the FSM.
    if (!fsm.isTerminated()) {
        fsmExecutor.fire(fsm, Event.NEXT);
    }
    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) SpeakerFlowSegmentResponse(org.openkilda.floodlight.api.response.SpeakerFlowSegmentResponse) SpeakerCommandResponse(org.openkilda.floodlight.api.response.rulemanager.SpeakerCommandResponse) UnknownKeyException(org.openkilda.wfm.topology.flowhs.exception.UnknownKeyException)

Example 7 with UnknownKeyException

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

the class YFlowValidationHubService method handleAsyncResponse.

/**
 * Handles async response from worker.
 *
 * @param key command identifier.
 */
public void handleAsyncResponse(@NonNull String key, @NonNull String flowId, @NonNull MessageData data) throws UnknownKeyException {
    log.debug("Received worker response {}", data);
    YFlowValidationFsm fsm = fsmRegister.getFsmByKey(key).orElseThrow(() -> new UnknownKeyException(key));
    if (fsm.getValidatingSubFlows().contains(flowId)) {
        flowValidationService.handleAsyncResponseByFlowId(flowId, data);
        // After handling an event by FlowUpdate service, we should propagate execution to the FSM.
        fsmExecutor.fire(fsm, Event.NEXT);
    } else {
        YFlowValidationContext context = YFlowValidationContext.builder().speakerResponse(data).build();
        if (data instanceof ErrorData) {
            fsmExecutor.fire(fsm, Event.ERROR_RECEIVED, context);
        } else {
            fsmExecutor.fire(fsm, Event.RESPONSE_RECEIVED, context);
        }
    }
    removeIfFinished(fsm, key);
}
Also used : YFlowValidationFsm(org.openkilda.wfm.topology.flowhs.fsm.yflow.validation.YFlowValidationFsm) ErrorData(org.openkilda.messaging.error.ErrorData) YFlowValidationContext(org.openkilda.wfm.topology.flowhs.fsm.yflow.validation.YFlowValidationContext) UnknownKeyException(org.openkilda.wfm.topology.flowhs.exception.UnknownKeyException)

Example 8 with UnknownKeyException

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

the class YFlowCreateService method handleTimeout.

/**
 * Handles timeout case.
 *
 * @param key command identifier.
 */
public void handleTimeout(@NonNull String key) throws UnknownKeyException {
    log.debug("Handling timeout for {}", key);
    YFlowCreateFsm fsm = fsmRegister.getFsmByKey(key).orElseThrow(() -> new UnknownKeyException(key));
    // Propagate timeout event to all sub-flow processing FSMs.
    fsm.getCreatingSubFlows().forEach(flowId -> {
        try {
            flowCreateService.handleTimeoutByFlowId(flowId);
        } catch (UnknownKeyException e) {
            log.error("Failed to handle a timeout event by FlowCreateService for {}.", flowId);
        }
    });
    fsm.getDeletingSubFlows().forEach(flowId -> {
        try {
            flowDeleteService.handleTimeoutByFlowId(flowId);
        } catch (UnknownKeyException e) {
            log.error("Failed to handle a timeout event by FlowDeleteService for {}.", flowId);
        }
    });
    fsmExecutor.fire(fsm, Event.TIMEOUT);
    removeIfFinished(fsm, key);
}
Also used : YFlowCreateFsm(org.openkilda.wfm.topology.flowhs.fsm.yflow.create.YFlowCreateFsm) UnknownKeyException(org.openkilda.wfm.topology.flowhs.exception.UnknownKeyException)

Example 9 with UnknownKeyException

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

the class FlowUpdateService 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);
    FlowUpdateFsm fsm = fsmRegister.getFsmByKey(key).orElseThrow(() -> new UnknownKeyException(key));
    FlowUpdateContext context = FlowUpdateContext.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) FlowUpdateFsm(org.openkilda.wfm.topology.flowhs.fsm.update.FlowUpdateFsm) FlowUpdateContext(org.openkilda.wfm.topology.flowhs.fsm.update.FlowUpdateContext) UnknownKeyException(org.openkilda.wfm.topology.flowhs.exception.UnknownKeyException)

Example 10 with UnknownKeyException

use of org.openkilda.wfm.topology.flowhs.exception.UnknownKeyException 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)

Aggregations

UnknownKeyException (org.openkilda.wfm.topology.flowhs.exception.UnknownKeyException)49 FlowSegmentRequest (org.openkilda.floodlight.api.request.FlowSegmentRequest)9 SpeakerFlowSegmentResponse (org.openkilda.floodlight.api.response.SpeakerFlowSegmentResponse)9 Flow (org.openkilda.model.Flow)7 SpeakerResponse (org.openkilda.floodlight.api.response.SpeakerResponse)6 Test (org.junit.Test)5 FlowErrorResponse (org.openkilda.floodlight.flow.response.FlowErrorResponse)5 SpeakerCommandResponse (org.openkilda.floodlight.api.response.rulemanager.SpeakerCommandResponse)4 FlowRequest (org.openkilda.messaging.command.flow.FlowRequest)4 FlowEndpoint (org.openkilda.model.FlowEndpoint)4 CommandContext (org.openkilda.wfm.CommandContext)4 ErrorData (org.openkilda.messaging.error.ErrorData)3 HashMap (java.util.HashMap)2 Set (java.util.Set)2 UUID (java.util.UUID)2 Matchers.equalTo (org.hamcrest.Matchers.equalTo)2 Matchers.hasProperty (org.hamcrest.Matchers.hasProperty)2 Assert (org.junit.Assert)2 Assert.assertEquals (org.junit.Assert.assertEquals)2 Assert.assertFalse (org.junit.Assert.assertFalse)2