use of org.openkilda.wfm.CommandContext 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);
}
use of org.openkilda.wfm.CommandContext in project open-kilda by telstra.
the class RevertSubFlowsAction method perform.
@Override
public void perform(State from, State to, Event event, YFlowUpdateContext context, YFlowUpdateFsm stateMachine) {
stateMachine.clearUpdatingSubFlows();
stateMachine.clearAllocatedSubFlows();
stateMachine.clearFailedSubFlows();
String yFlowId = stateMachine.getYFlowId();
Collection<RequestedFlow> originalFlows = YFlowRequestMapper.INSTANCE.toRequestedFlows(stateMachine.getOriginalFlow());
stateMachine.setRequestedFlows(originalFlows);
log.debug("Start reverting {} sub-flows for y-flow {}", originalFlows.size(), stateMachine.getYFlowId());
originalFlows.stream().filter(originalFlow -> originalFlow.getFlowId().equals(stateMachine.getMainAffinityFlowId())).forEach(originalFlow -> {
String subFlowId = originalFlow.getFlowId();
CommandContext flowContext = stateMachine.getCommandContext().fork(subFlowId);
stateMachine.addUpdatingSubFlow(subFlowId);
stateMachine.notifyEventListeners(listener -> listener.onSubFlowProcessingStart(yFlowId, subFlowId));
flowUpdateService.startFlowUpdating(flowContext, originalFlow, yFlowId);
});
}
use of org.openkilda.wfm.CommandContext in project open-kilda by telstra.
the class UpdateSubFlowsAction method perform.
@Override
public void perform(State from, State to, Event event, YFlowUpdateContext context, YFlowUpdateFsm stateMachine) {
Collection<RequestedFlow> requestedFlows = YFlowRequestMapper.INSTANCE.toRequestedFlows(stateMachine.getTargetFlow());
stateMachine.setRequestedFlows(requestedFlows);
log.debug("Start updating {} sub-flows for y-flow {}", requestedFlows.size(), stateMachine.getYFlowId());
stateMachine.clearUpdatingSubFlows();
String yFlowId = stateMachine.getYFlowId();
requestedFlows.forEach(requestedFlow -> {
String subFlowId = requestedFlow.getFlowId();
stateMachine.addSubFlow(subFlowId);
if (requestedFlow.getFlowId().equals(stateMachine.getMainAffinityFlowId())) {
stateMachine.addUpdatingSubFlow(subFlowId);
stateMachine.notifyEventListeners(listener -> listener.onSubFlowProcessingStart(yFlowId, subFlowId));
CommandContext flowContext = stateMachine.getCommandContext().fork(subFlowId);
requestedFlow.setDiverseFlowId(stateMachine.getDiverseFlowId());
flowUpdateService.startFlowUpdating(flowContext, requestedFlow, yFlowId);
}
});
}
use of org.openkilda.wfm.CommandContext in project open-kilda by telstra.
the class OnSubFlowRevertedAction method perform.
@Override
protected void perform(State from, State to, Event event, YFlowUpdateContext context, YFlowUpdateFsm stateMachine) {
String subFlowId = context.getSubFlowId();
if (!stateMachine.isUpdatingSubFlow(subFlowId)) {
throw new IllegalStateException("Received an event for non-pending sub-flow " + subFlowId);
}
stateMachine.saveActionToHistory("Updated a sub-flow", format("Updated sub-flow %s of y-flow %s", subFlowId, stateMachine.getYFlowId()));
stateMachine.removeUpdatingSubFlow(subFlowId);
stateMachine.notifyEventListeners(listener -> listener.onSubFlowProcessingFinished(stateMachine.getYFlowId(), subFlowId));
String yFlowId = stateMachine.getYFlowId();
if (subFlowId.equals(stateMachine.getMainAffinityFlowId())) {
stateMachine.getRequestedFlows().forEach(originalFlow -> {
String requestedFlowId = originalFlow.getFlowId();
if (!requestedFlowId.equals(subFlowId)) {
CommandContext flowContext = stateMachine.getCommandContext().fork(requestedFlowId);
stateMachine.addUpdatingSubFlow(requestedFlowId);
stateMachine.notifyEventListeners(listener -> listener.onSubFlowProcessingStart(yFlowId, requestedFlowId));
flowUpdateService.startFlowUpdating(flowContext, originalFlow, yFlowId);
}
});
}
if (stateMachine.getUpdatingSubFlows().isEmpty()) {
stateMachine.fire(Event.ALL_SUB_FLOWS_REVERTED);
}
}
use of org.openkilda.wfm.CommandContext in project open-kilda by telstra.
the class RerouteSubFlowsAction method sendRerouteRequest.
private void sendRerouteRequest(YFlowRerouteFsm stateMachine, FlowRerouteRequest rerouteRequest, String yFlowId) {
String subFlowId = rerouteRequest.getFlowId();
stateMachine.addReroutingSubFlow(subFlowId);
stateMachine.notifyEventListeners(listener -> listener.onSubFlowProcessingStart(yFlowId, subFlowId));
CommandContext flowContext = stateMachine.getCommandContext().fork(subFlowId);
flowRerouteService.startFlowRerouting(rerouteRequest, flowContext, yFlowId);
}
Aggregations