Search in sources :

Example 1 with FlowValidationFsm

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

the class FlowValidationHubService method handleTimeout.

/**
 * Handles timeout case.
 *
 * @param key command identifier.
 */
public void handleTimeout(@NonNull String key) throws UnknownKeyException {
    log.debug("Handling timeout for {}", key);
    FlowValidationFsm fsm = fsmRegister.getFsmByKey(key).orElseThrow(() -> new UnknownKeyException(key));
    ErrorData errorData = new ErrorData(ErrorType.OPERATION_TIMED_OUT, "Flow validation failed by timeout", "Error in FlowValidationHubService");
    fsmExecutor.fire(fsm, Event.ERROR, errorData);
    removeIfFinished(fsm, key);
}
Also used : FlowValidationFsm(org.openkilda.wfm.topology.flowhs.fsm.validation.FlowValidationFsm) ErrorData(org.openkilda.messaging.error.ErrorData) UnknownKeyException(org.openkilda.wfm.topology.flowhs.exception.UnknownKeyException)

Example 2 with FlowValidationFsm

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

the class FlowValidationHubService method handleAsyncResponse.

/**
 * Handles async response from worker.
 *
 * @param key command identifier.
 */
public void handleAsyncResponse(@NonNull String key, @NonNull MessageData data) throws UnknownKeyException {
    log.debug("Received command response {}", data);
    FlowValidationFsm fsm = fsmRegister.getFsmByKey(key).orElseThrow(() -> new UnknownKeyException(key));
    if (data instanceof SwitchFlowEntries) {
        fsmExecutor.fire(fsm, Event.RULES_RECEIVED, data);
    } else if (data instanceof SwitchMeterEntries) {
        fsmExecutor.fire(fsm, Event.METERS_RECEIVED, data);
    } else if (data instanceof SwitchMeterUnsupported) {
        SwitchMeterUnsupported meterUnsupported = (SwitchMeterUnsupported) data;
        log.info("Key: {}; Meters unsupported for switch '{};", key, meterUnsupported.getSwitchId());
        fsmExecutor.fire(fsm, Event.METERS_RECEIVED, SwitchMeterEntries.builder().switchId(meterUnsupported.getSwitchId()).meterEntries(Collections.emptyList()).build());
    } else if (data instanceof SwitchGroupEntries) {
        fsmExecutor.fire(fsm, Event.GROUPS_RECEIVED, data);
    } else if (data instanceof ErrorData) {
        fsmExecutor.fire(fsm, Event.ERROR, data);
    } else {
        log.warn("Key: {}; Unhandled message {}", key, data);
    }
    removeIfFinished(fsm, key);
}
Also used : SwitchFlowEntries(org.openkilda.messaging.info.rule.SwitchFlowEntries) SwitchMeterUnsupported(org.openkilda.messaging.info.meter.SwitchMeterUnsupported) SwitchMeterEntries(org.openkilda.messaging.info.meter.SwitchMeterEntries) SwitchGroupEntries(org.openkilda.messaging.info.rule.SwitchGroupEntries) FlowValidationFsm(org.openkilda.wfm.topology.flowhs.fsm.validation.FlowValidationFsm) ErrorData(org.openkilda.messaging.error.ErrorData) UnknownKeyException(org.openkilda.wfm.topology.flowhs.exception.UnknownKeyException)

Example 3 with FlowValidationFsm

use of org.openkilda.wfm.topology.flowhs.fsm.validation.FlowValidationFsm 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

FlowValidationFsm (org.openkilda.wfm.topology.flowhs.fsm.validation.FlowValidationFsm)3 ErrorData (org.openkilda.messaging.error.ErrorData)2 UnknownKeyException (org.openkilda.wfm.topology.flowhs.exception.UnknownKeyException)2 SwitchMeterEntries (org.openkilda.messaging.info.meter.SwitchMeterEntries)1 SwitchMeterUnsupported (org.openkilda.messaging.info.meter.SwitchMeterUnsupported)1 SwitchFlowEntries (org.openkilda.messaging.info.rule.SwitchFlowEntries)1 SwitchGroupEntries (org.openkilda.messaging.info.rule.SwitchGroupEntries)1 DuplicateKeyException (org.openkilda.wfm.topology.flowhs.exception.DuplicateKeyException)1