Search in sources :

Example 51 with CommandContext

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

Example 52 with CommandContext

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);
    });
}
Also used : YFlowRequestMapper(org.openkilda.wfm.topology.flowhs.mapper.YFlowRequestMapper) Slf4j(lombok.extern.slf4j.Slf4j) HistoryRecordingAction(org.openkilda.wfm.topology.flowhs.fsm.common.actions.HistoryRecordingAction) Collection(java.util.Collection) YFlowUpdateFsm(org.openkilda.wfm.topology.flowhs.fsm.yflow.update.YFlowUpdateFsm) Event(org.openkilda.wfm.topology.flowhs.fsm.yflow.update.YFlowUpdateFsm.Event) CommandContext(org.openkilda.wfm.CommandContext) RequestedFlow(org.openkilda.wfm.topology.flowhs.model.RequestedFlow) State(org.openkilda.wfm.topology.flowhs.fsm.yflow.update.YFlowUpdateFsm.State) YFlowUpdateContext(org.openkilda.wfm.topology.flowhs.fsm.yflow.update.YFlowUpdateContext) FlowUpdateService(org.openkilda.wfm.topology.flowhs.service.FlowUpdateService) CommandContext(org.openkilda.wfm.CommandContext) RequestedFlow(org.openkilda.wfm.topology.flowhs.model.RequestedFlow)

Example 53 with CommandContext

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

Example 54 with CommandContext

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

Example 55 with CommandContext

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