Search in sources :

Example 1 with FlowRerouteContext

use of org.openkilda.wfm.topology.flowhs.fsm.reroute.FlowRerouteContext in project open-kilda by telstra.

the class RevertResourceAllocationAction method perform.

@Override
protected void perform(State from, State to, Event event, FlowRerouteContext context, FlowRerouteFsm stateMachine) {
    Flow flow = getFlow(stateMachine.getFlowId());
    Stream.of(stateMachine.getNewPrimaryResources(), stateMachine.getNewProtectedResources()).filter(Objects::nonNull).forEach(resources -> {
        transactionManager.doInTransaction(() -> resourcesManager.deallocatePathResources(resources));
        saveHistory(stateMachine, flow, resources);
    });
    stateMachine.getRejectedResources().forEach(flowResources -> {
        transactionManager.doInTransaction(() -> resourcesManager.deallocatePathResources(flowResources));
        saveHistory(stateMachine, flow, flowResources);
    });
    Stream.of(stateMachine.getNewPrimaryForwardPath(), stateMachine.getNewPrimaryReversePath(), stateMachine.getNewProtectedForwardPath(), stateMachine.getNewProtectedReversePath()).forEach(pathId -> flowPathRepository.remove(pathId).ifPresent(flowPath -> {
        updateIslsForFlowPath(flowPath);
        saveRemovalActionWithDumpToHistory(stateMachine, flow, flowPath);
    }));
    stateMachine.getRejectedPaths().stream().forEach(pathId -> flowPathRepository.remove(pathId).ifPresent(flowPath -> {
        updateIslsForFlowPath(flowPath);
        saveRemovalActionWithDumpToHistory(stateMachine, flow, flowPath);
    }));
    stateMachine.setNewPrimaryResources(null);
    stateMachine.setNewPrimaryForwardPath(null);
    stateMachine.setNewPrimaryReversePath(null);
    stateMachine.setNewProtectedResources(null);
    stateMachine.setNewProtectedForwardPath(null);
    stateMachine.setNewProtectedReversePath(null);
}
Also used : FlowRerouteContext(org.openkilda.wfm.topology.flowhs.fsm.reroute.FlowRerouteContext) HistoryMapper(org.openkilda.wfm.share.mappers.HistoryMapper) FlowRerouteFsm(org.openkilda.wfm.topology.flowhs.fsm.reroute.FlowRerouteFsm) FlowResources(org.openkilda.wfm.share.flow.resources.FlowResources) String.format(java.lang.String.format) Event(org.openkilda.wfm.topology.flowhs.fsm.reroute.FlowRerouteFsm.Event) Objects(java.util.Objects) BaseFlowPathRemovalAction(org.openkilda.wfm.topology.flowhs.fsm.common.actions.BaseFlowPathRemovalAction) Slf4j(lombok.extern.slf4j.Slf4j) State(org.openkilda.wfm.topology.flowhs.fsm.reroute.FlowRerouteFsm.State) Stream(java.util.stream.Stream) Flow(org.openkilda.model.Flow) FlowDumpData(org.openkilda.wfm.share.history.model.FlowDumpData) FlowResourcesManager(org.openkilda.wfm.share.flow.resources.FlowResourcesManager) DumpType(org.openkilda.wfm.share.history.model.FlowDumpData.DumpType) PersistenceManager(org.openkilda.persistence.PersistenceManager) Flow(org.openkilda.model.Flow)

Example 2 with FlowRerouteContext

use of org.openkilda.wfm.topology.flowhs.fsm.reroute.FlowRerouteContext in project open-kilda by telstra.

the class FlowRerouteService method startFlowRerouting.

private void startFlowRerouting(String key, FlowRerouteRequest reroute, CommandContext commandContext, String sharedBandwidthGroupId) {
    String flowId = reroute.getFlowId();
    log.debug("Handling flow reroute request with key {} and flow ID: {}", key, flowId);
    try {
        checkRequestsCollision(key, flowId);
    } catch (Exception e) {
        log.error(e.getMessage());
        fsmRegister.getFsmByKey(key).ifPresent(fsm -> removeIfFinished(fsm, key));
        return;
    }
    if (fsmRegister.hasRegisteredFsmWithFlowId(flowId)) {
        carrier.sendRerouteResultStatus(flowId, new RerouteInProgressError(), commandContext.getCorrelationId());
        return;
    }
    FlowRerouteFsm fsm = fsmFactory.newInstance(flowId, commandContext, eventListeners);
    fsm.setSharedBandwidthGroupId(sharedBandwidthGroupId);
    fsmRegister.registerFsm(key, fsm);
    FlowRerouteContext context = FlowRerouteContext.builder().flowId(flowId).affectedIsl(reroute.getAffectedIsl()).forceReroute(reroute.isForce()).ignoreBandwidth(reroute.isIgnoreBandwidth()).effectivelyDown(reroute.isEffectivelyDown()).rerouteReason(reroute.getReason()).build();
    fsmExecutor.fire(fsm, Event.NEXT, context);
    removeIfFinished(fsm, key);
}
Also used : RerouteInProgressError(org.openkilda.messaging.info.reroute.error.RerouteInProgressError) FlowRerouteContext(org.openkilda.wfm.topology.flowhs.fsm.reroute.FlowRerouteContext) SpeakerFlowSegmentResponse(org.openkilda.floodlight.api.response.SpeakerFlowSegmentResponse) FlowErrorResponse(org.openkilda.floodlight.flow.response.FlowErrorResponse) FlowProcessingFsmRegister(org.openkilda.wfm.topology.flowhs.service.common.FlowProcessingFsmRegister) NonNull(lombok.NonNull) Config(org.openkilda.wfm.topology.flowhs.fsm.reroute.FlowRerouteFsm.Config) CommandContext(org.openkilda.wfm.CommandContext) FlowRerouteFsm(org.openkilda.wfm.topology.flowhs.fsm.reroute.FlowRerouteFsm) Event(org.openkilda.wfm.topology.flowhs.fsm.reroute.FlowRerouteFsm.Event) FlowRerouteRequest(org.openkilda.messaging.command.flow.FlowRerouteRequest) Slf4j(lombok.extern.slf4j.Slf4j) FlowProcessingService(org.openkilda.wfm.topology.flowhs.service.common.FlowProcessingService) PathComputer(org.openkilda.pce.PathComputer) UnknownKeyException(org.openkilda.wfm.topology.flowhs.exception.UnknownKeyException) FlowResourcesManager(org.openkilda.wfm.share.flow.resources.FlowResourcesManager) FsmExecutor(org.openkilda.wfm.share.utils.FsmExecutor) PersistenceManager(org.openkilda.persistence.PersistenceManager) FlowRerouteFsm(org.openkilda.wfm.topology.flowhs.fsm.reroute.FlowRerouteFsm) FlowRerouteContext(org.openkilda.wfm.topology.flowhs.fsm.reroute.FlowRerouteContext) UnknownKeyException(org.openkilda.wfm.topology.flowhs.exception.UnknownKeyException) RerouteInProgressError(org.openkilda.messaging.info.reroute.error.RerouteInProgressError)

Example 3 with FlowRerouteContext

use of org.openkilda.wfm.topology.flowhs.fsm.reroute.FlowRerouteContext in project open-kilda by telstra.

the class FlowRerouteService method handleAsyncResponse.

/**
 * Handles async response from worker.
 *
 * @param key command identifier.
 */
public void handleAsyncResponse(@NonNull String key, @NonNull SpeakerFlowSegmentResponse flowResponse) throws UnknownKeyException {
    log.debug("Received flow command response {}", flowResponse);
    FlowRerouteFsm fsm = fsmRegister.getFsmByKey(key).orElseThrow(() -> new UnknownKeyException(key));
    FlowRerouteContext context = FlowRerouteContext.builder().speakerFlowResponse(flowResponse).build();
    if (flowResponse instanceof FlowErrorResponse) {
        fsmExecutor.fire(fsm, Event.ERROR_RECEIVED, context);
    } else {
        fsmExecutor.fire(fsm, Event.RESPONSE_RECEIVED, context);
    }
    removeIfFinished(fsm, key);
}
Also used : FlowRerouteFsm(org.openkilda.wfm.topology.flowhs.fsm.reroute.FlowRerouteFsm) FlowRerouteContext(org.openkilda.wfm.topology.flowhs.fsm.reroute.FlowRerouteContext) FlowErrorResponse(org.openkilda.floodlight.flow.response.FlowErrorResponse) UnknownKeyException(org.openkilda.wfm.topology.flowhs.exception.UnknownKeyException)

Aggregations

FlowRerouteContext (org.openkilda.wfm.topology.flowhs.fsm.reroute.FlowRerouteContext)3 FlowRerouteFsm (org.openkilda.wfm.topology.flowhs.fsm.reroute.FlowRerouteFsm)3 Slf4j (lombok.extern.slf4j.Slf4j)2 FlowErrorResponse (org.openkilda.floodlight.flow.response.FlowErrorResponse)2 PersistenceManager (org.openkilda.persistence.PersistenceManager)2 FlowResourcesManager (org.openkilda.wfm.share.flow.resources.FlowResourcesManager)2 UnknownKeyException (org.openkilda.wfm.topology.flowhs.exception.UnknownKeyException)2 Event (org.openkilda.wfm.topology.flowhs.fsm.reroute.FlowRerouteFsm.Event)2 String.format (java.lang.String.format)1 Objects (java.util.Objects)1 Stream (java.util.stream.Stream)1 NonNull (lombok.NonNull)1 SpeakerFlowSegmentResponse (org.openkilda.floodlight.api.response.SpeakerFlowSegmentResponse)1 FlowRerouteRequest (org.openkilda.messaging.command.flow.FlowRerouteRequest)1 RerouteInProgressError (org.openkilda.messaging.info.reroute.error.RerouteInProgressError)1 Flow (org.openkilda.model.Flow)1 PathComputer (org.openkilda.pce.PathComputer)1 CommandContext (org.openkilda.wfm.CommandContext)1 FlowResources (org.openkilda.wfm.share.flow.resources.FlowResources)1 FlowDumpData (org.openkilda.wfm.share.history.model.FlowDumpData)1