Search in sources :

Example 1 with YFlowValidationContext

use of org.openkilda.wfm.topology.flowhs.fsm.yflow.validation.YFlowValidationContext 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 2 with YFlowValidationContext

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

the class YFlowValidationHubService method handleRequest.

/**
 * Handles request for y-flow validating.
 *
 * @param key command identifier.
 * @param yFlowId requested y-flow to validate.
 */
public void handleRequest(@NonNull String key, @NonNull CommandContext commandContext, @NonNull String yFlowId) throws DuplicateKeyException {
    log.debug("Handling y-flow validation request with key {} and y-flow ID: {}", key, yFlowId);
    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 validate y-flow", format("Y-flow %s is already validating now", yFlowId), commandContext);
        log.error("Attempt to create a FSM with key {}, while there's another active FSM for the same yFlowId {}.", key, yFlowId);
        return;
    }
    YFlowValidationFsm fsm = fsmFactory.newInstance(commandContext, yFlowId, eventListeners);
    fsmRegister.registerFsm(key, fsm);
    YFlowValidationContext context = YFlowValidationContext.builder().build();
    fsm.start(context);
    fsmExecutor.fire(fsm, Event.NEXT, context);
    removeIfFinished(fsm, key);
}
Also used : YFlowValidationFsm(org.openkilda.wfm.topology.flowhs.fsm.yflow.validation.YFlowValidationFsm) DuplicateKeyException(org.openkilda.wfm.topology.flowhs.exception.DuplicateKeyException) YFlowValidationContext(org.openkilda.wfm.topology.flowhs.fsm.yflow.validation.YFlowValidationContext)

Example 3 with YFlowValidationContext

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

the class CompleteYFlowValidationAction method performWithResponse.

@Override
public Optional<Message> performWithResponse(State from, State to, Event event, YFlowValidationContext context, YFlowValidationFsm stateMachine) throws FlowNotFoundException, SwitchNotFoundException {
    YFlowDiscrepancyDto resourcesValidationResult = validationService.validateYFlowResources(stateMachine.getYFlowId(), stateMachine.getReceivedRules(), stateMachine.getReceivedMeters());
    YFlowValidationResponse result = new YFlowValidationResponse();
    result.setYFlowValidationResult(resourcesValidationResult);
    result.setSubFlowValidationResults(stateMachine.getSubFlowValidationResults());
    boolean notAsExpected = !resourcesValidationResult.isAsExpected() || stateMachine.getSubFlowValidationResults().stream().map(FlowValidationResponse::getAsExpected).anyMatch(n -> !n);
    result.setAsExpected(!notAsExpected);
    CommandContext commandContext = stateMachine.getCommandContext();
    InfoMessage message = new InfoMessage(result, commandContext.getCreateTime(), commandContext.getCorrelationId());
    return Optional.of(message);
}
Also used : InfoMessage(org.openkilda.messaging.info.InfoMessage) Message(org.openkilda.messaging.Message) FlowValidationResponse(org.openkilda.messaging.info.flow.FlowValidationResponse) YFlowValidationFsm(org.openkilda.wfm.topology.flowhs.fsm.yflow.validation.YFlowValidationFsm) CommandContext(org.openkilda.wfm.CommandContext) YFlowValidationContext(org.openkilda.wfm.topology.flowhs.fsm.yflow.validation.YFlowValidationContext) SwitchNotFoundException(org.openkilda.wfm.error.SwitchNotFoundException) Slf4j(lombok.extern.slf4j.Slf4j) NbTrackableAction(org.openkilda.wfm.topology.flowhs.fsm.common.actions.NbTrackableAction) YFlowDiscrepancyDto(org.openkilda.messaging.command.yflow.YFlowDiscrepancyDto) Event(org.openkilda.wfm.topology.flowhs.fsm.yflow.validation.YFlowValidationFsm.Event) Optional(java.util.Optional) YFlowValidationResponse(org.openkilda.messaging.command.yflow.YFlowValidationResponse) YFlowValidationService(org.openkilda.wfm.topology.flowhs.fsm.yflow.validation.YFlowValidationService) State(org.openkilda.wfm.topology.flowhs.fsm.yflow.validation.YFlowValidationFsm.State) FlowNotFoundException(org.openkilda.wfm.error.FlowNotFoundException) YFlowValidationResponse(org.openkilda.messaging.command.yflow.YFlowValidationResponse) CommandContext(org.openkilda.wfm.CommandContext) InfoMessage(org.openkilda.messaging.info.InfoMessage) YFlowDiscrepancyDto(org.openkilda.messaging.command.yflow.YFlowDiscrepancyDto) FlowValidationResponse(org.openkilda.messaging.info.flow.FlowValidationResponse) YFlowValidationResponse(org.openkilda.messaging.command.yflow.YFlowValidationResponse)

Aggregations

YFlowValidationContext (org.openkilda.wfm.topology.flowhs.fsm.yflow.validation.YFlowValidationContext)3 YFlowValidationFsm (org.openkilda.wfm.topology.flowhs.fsm.yflow.validation.YFlowValidationFsm)3 Optional (java.util.Optional)1 Slf4j (lombok.extern.slf4j.Slf4j)1 Message (org.openkilda.messaging.Message)1 YFlowDiscrepancyDto (org.openkilda.messaging.command.yflow.YFlowDiscrepancyDto)1 YFlowValidationResponse (org.openkilda.messaging.command.yflow.YFlowValidationResponse)1 ErrorData (org.openkilda.messaging.error.ErrorData)1 InfoMessage (org.openkilda.messaging.info.InfoMessage)1 FlowValidationResponse (org.openkilda.messaging.info.flow.FlowValidationResponse)1 CommandContext (org.openkilda.wfm.CommandContext)1 FlowNotFoundException (org.openkilda.wfm.error.FlowNotFoundException)1 SwitchNotFoundException (org.openkilda.wfm.error.SwitchNotFoundException)1 DuplicateKeyException (org.openkilda.wfm.topology.flowhs.exception.DuplicateKeyException)1 UnknownKeyException (org.openkilda.wfm.topology.flowhs.exception.UnknownKeyException)1 NbTrackableAction (org.openkilda.wfm.topology.flowhs.fsm.common.actions.NbTrackableAction)1 Event (org.openkilda.wfm.topology.flowhs.fsm.yflow.validation.YFlowValidationFsm.Event)1 State (org.openkilda.wfm.topology.flowhs.fsm.yflow.validation.YFlowValidationFsm.State)1 YFlowValidationService (org.openkilda.wfm.topology.flowhs.fsm.yflow.validation.YFlowValidationService)1