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);
}
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);
}
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);
}
Aggregations