Search in sources :

Example 11 with CommandContext

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);
    }
}
Also used : YFlow(org.openkilda.model.YFlow) CommandContext(org.openkilda.wfm.CommandContext)

Example 12 with CommandContext

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);
    });
}
Also used : CommandContext(org.openkilda.wfm.CommandContext)

Example 13 with CommandContext

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()));
        }
    }
}
Also used : CommandContext(org.openkilda.wfm.CommandContext)

Example 14 with CommandContext

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);
    });
}
Also used : YFlow(org.openkilda.model.YFlow) CommandContext(org.openkilda.wfm.CommandContext)

Example 15 with CommandContext

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);
        }
    }
}
Also used : CommandContext(org.openkilda.wfm.CommandContext)

Aggregations

CommandContext (org.openkilda.wfm.CommandContext)95 Test (org.junit.Test)28 Values (org.apache.storm.tuple.Values)27 FlowSegmentRequest (org.openkilda.floodlight.api.request.FlowSegmentRequest)15 Flow (org.openkilda.model.Flow)15 AbstractYFlowTest (org.openkilda.wfm.topology.flowhs.service.AbstractYFlowTest)14 Tuple (org.apache.storm.tuple.Tuple)12 SwitchId (org.openkilda.model.SwitchId)11 YFlow (org.openkilda.model.YFlow)11 BaseSpeakerCommandsRequest (org.openkilda.floodlight.api.request.rulemanager.BaseSpeakerCommandsRequest)9 SpeakerResponse (org.openkilda.floodlight.api.response.SpeakerResponse)9 YFlowRequest (org.openkilda.messaging.command.yflow.YFlowRequest)9 InfoMessage (org.openkilda.messaging.info.InfoMessage)9 TupleImpl (org.apache.storm.tuple.TupleImpl)8 FlowPath (org.openkilda.model.FlowPath)8 ArrayList (java.util.ArrayList)7 FlowRerouteRequest (org.openkilda.messaging.command.flow.FlowRerouteRequest)7 FlowProcessingException (org.openkilda.wfm.topology.flowhs.exception.FlowProcessingException)7 UnknownKeyException (org.openkilda.wfm.topology.flowhs.exception.UnknownKeyException)7 List (java.util.List)6