use of org.openkilda.wfm.CommandContext in project open-kilda by telstra.
the class OnSubFlowRemovedAction method perform.
@Override
protected void perform(State from, State to, Event event, YFlowDeleteContext context, YFlowDeleteFsm stateMachine) {
String subFlowId = context.getSubFlowId();
if (!stateMachine.isDeletingSubFlow(subFlowId)) {
throw new IllegalStateException("Received an event for non-pending sub-flow " + subFlowId);
}
String yFlowId = stateMachine.getYFlowId();
stateMachine.saveActionToHistory("Removed a sub-flow", format("Removed sub-flow %s of y-flow %s", subFlowId, yFlowId));
stateMachine.removeDeletingSubFlow(subFlowId);
stateMachine.notifyEventListeners(listener -> listener.onSubFlowProcessingFinished(yFlowId, subFlowId));
// TODO: refactor to concurrent deleting once https://github.com/telstra/open-kilda/issues/3411 is fixed.
YFlow yFlow = getYFlow(yFlowId);
yFlow.getSubFlows().stream().filter(subFlow -> !stateMachine.getSubFlows().contains(subFlow.getSubFlowId())).findFirst().ifPresent(subFlow -> {
String nextSubFlowId = subFlow.getSubFlowId();
stateMachine.addSubFlow(nextSubFlowId);
stateMachine.addDeletingSubFlow(nextSubFlowId);
stateMachine.notifyEventListeners(listener -> listener.onSubFlowProcessingStart(yFlowId, nextSubFlowId));
CommandContext flowContext = stateMachine.getCommandContext().fork(nextSubFlowId);
flowDeleteService.startFlowDeletion(flowContext, nextSubFlowId);
});
if (stateMachine.getDeletingSubFlows().isEmpty()) {
stateMachine.fire(Event.ALL_SUB_FLOWS_REMOVED);
}
}
use of org.openkilda.wfm.CommandContext in project open-kilda by telstra.
the class RemoveSubFlowsAction method perform.
@Override
public void perform(State from, State to, Event event, YFlowCreateContext context, YFlowCreateFsm stateMachine) {
String yFlowId = stateMachine.getYFlowId();
log.debug("Start removing {} sub-flows of y-flow {}", stateMachine.getSubFlows().size(), yFlowId);
stateMachine.clearDeletingSubFlows();
stateMachine.getSubFlows().forEach(subFlowId -> {
stateMachine.addDeletingSubFlow(subFlowId);
stateMachine.notifyEventListeners(listener -> listener.onSubFlowProcessingStart(yFlowId, subFlowId));
CommandContext flowContext = stateMachine.getCommandContext().fork(subFlowId);
flowDeleteService.startFlowDeletion(flowContext, subFlowId);
});
}
use of org.openkilda.wfm.CommandContext in project open-kilda by telstra.
the class OnSubFlowReroutedAction method perform.
@Override
protected void perform(State from, State to, Event event, YFlowRerouteContext context, YFlowRerouteFsm stateMachine) {
String subFlowId = context.getSubFlowId();
if (!stateMachine.isReroutingSubFlow(subFlowId)) {
throw new IllegalStateException("Received an event for non-pending sub-flow " + subFlowId);
}
stateMachine.saveActionToHistory("Rerouted a sub-flow", format("Rerouted sub-flow %s of y-flow %s", subFlowId, stateMachine.getYFlowId()));
stateMachine.removeReroutingSubFlow(subFlowId);
String yFlowId = stateMachine.getYFlowId();
if (subFlowId.equals(stateMachine.getMainAffinityFlowId())) {
stateMachine.getRerouteRequests().forEach(rerouteRequest -> {
String requestedFlowId = rerouteRequest.getFlowId();
if (!requestedFlowId.equals(subFlowId)) {
// clear to avoid the 'path has no affected ISLs' exception
rerouteRequest.getAffectedIsl().clear();
stateMachine.addReroutingSubFlow(requestedFlowId);
stateMachine.notifyEventListeners(listener -> listener.onSubFlowProcessingStart(yFlowId, requestedFlowId));
CommandContext flowContext = stateMachine.getCommandContext().fork(requestedFlowId);
flowRerouteService.startFlowRerouting(rerouteRequest, flowContext, yFlowId);
}
});
}
if (stateMachine.getReroutingSubFlows().isEmpty()) {
if (stateMachine.getFailedSubFlows().isEmpty()) {
stateMachine.fire(Event.ALL_SUB_FLOWS_REROUTED);
} else {
stateMachine.fire(Event.FAILED_TO_REROUTE_SUB_FLOWS);
stateMachine.setErrorReason(format("Failed to reroute sub-flows %s of y-flow %s", stateMachine.getFailedSubFlows(), stateMachine.getYFlowId()));
}
}
}
use of org.openkilda.wfm.CommandContext in project open-kilda by telstra.
the class RemoveSubFlowsAction method perform.
@Override
public void perform(State from, State to, Event event, YFlowDeleteContext context, YFlowDeleteFsm stateMachine) {
String yFlowId = stateMachine.getYFlowId();
YFlow yFlow = getYFlow(yFlowId);
log.debug("Start removing 1 of {} sub-flows of y-flow {}", yFlow.getSubFlows().size(), yFlowId);
stateMachine.clearDeletingSubFlows();
// TODO: refactor to concurrent deleting once https://github.com/telstra/open-kilda/issues/3411 is fixed.
yFlow.getSubFlows().stream().findFirst().ifPresent(subFlow -> {
String subFlowId = subFlow.getSubFlowId();
stateMachine.addSubFlow(subFlowId);
stateMachine.addDeletingSubFlow(subFlowId);
stateMachine.notifyEventListeners(listener -> listener.onSubFlowProcessingStart(yFlowId, subFlowId));
CommandContext flowContext = stateMachine.getCommandContext().fork(subFlowId);
flowDeleteService.startFlowDeletion(flowContext, subFlowId);
});
}
use of org.openkilda.wfm.CommandContext in project open-kilda by telstra.
the class OnSubFlowUpdatedAction 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(requestedFlow -> {
String requestedFlowId = requestedFlow.getFlowId();
if (!requestedFlowId.equals(subFlowId)) {
stateMachine.addUpdatingSubFlow(requestedFlowId);
stateMachine.notifyEventListeners(listener -> listener.onSubFlowProcessingStart(yFlowId, requestedFlowId));
CommandContext flowContext = stateMachine.getCommandContext().fork(requestedFlowId);
flowUpdateService.startFlowUpdating(flowContext, requestedFlow, yFlowId);
}
});
}
if (stateMachine.getUpdatingSubFlows().isEmpty()) {
if (stateMachine.getFailedSubFlows().isEmpty()) {
stateMachine.fire(Event.ALL_SUB_FLOWS_UPDATED);
} else {
stateMachine.fire(Event.FAILED_TO_UPDATE_SUB_FLOWS);
}
}
}
Aggregations