Search in sources :

Example 1 with FlowUpdateContext

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

the class RevertResourceAllocationAction method perform.

@Override
protected void perform(State from, State to, Event event, FlowUpdateContext context, FlowUpdateFsm 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 : HistoryMapper(org.openkilda.wfm.share.mappers.HistoryMapper) FlowUpdateFsm(org.openkilda.wfm.topology.flowhs.fsm.update.FlowUpdateFsm) State(org.openkilda.wfm.topology.flowhs.fsm.update.FlowUpdateFsm.State) FlowResources(org.openkilda.wfm.share.flow.resources.FlowResources) String.format(java.lang.String.format) Event(org.openkilda.wfm.topology.flowhs.fsm.update.FlowUpdateFsm.Event) Objects(java.util.Objects) BaseFlowPathRemovalAction(org.openkilda.wfm.topology.flowhs.fsm.common.actions.BaseFlowPathRemovalAction) Slf4j(lombok.extern.slf4j.Slf4j) Stream(java.util.stream.Stream) Flow(org.openkilda.model.Flow) FlowUpdateContext(org.openkilda.wfm.topology.flowhs.fsm.update.FlowUpdateContext) 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 FlowUpdateContext

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

the class FlowUpdateService method startFlowUpdating.

private void startFlowUpdating(String key, CommandContext commandContext, RequestedFlow request, boolean doNotRevert, Set<String> bulkUpdateFlowIds, String sharedBandwidthGroupId) throws DuplicateKeyException {
    String flowId = request.getFlowId();
    log.debug("Handling flow update request with key {} and flow ID: {}", key, request.getFlowId());
    if (fsmRegister.hasRegisteredFsmWithKey(key)) {
        throw new DuplicateKeyException(key, "There's another active FSM with the same key");
    }
    if (fsmRegister.hasRegisteredFsmWithFlowId(flowId)) {
        sendErrorResponseToNorthbound(ErrorType.REQUEST_INVALID, "Could not update flow", format("Flow %s is updating now", flowId), commandContext);
        log.error("Attempt to create a FSM with key {}, while there's another active FSM for the same flowId {}.", key, flowId);
        return;
    }
    FlowUpdateFsm fsm = fsmFactory.newInstance(request.getFlowId(), commandContext, eventListeners);
    fsm.setSharedBandwidthGroupId(sharedBandwidthGroupId);
    fsmRegister.registerFsm(key, fsm);
    if (request.getFlowEncapsulationType() == null) {
        request.setFlowEncapsulationType(kildaConfigurationRepository.getOrDefault().getFlowEncapsulationType());
    }
    FlowUpdateContext context = FlowUpdateContext.builder().targetFlow(request).doNotRevert(doNotRevert).bulkUpdateFlowIds(bulkUpdateFlowIds).build();
    fsmExecutor.fire(fsm, Event.NEXT, context);
    removeIfFinished(fsm, key);
}
Also used : FlowUpdateFsm(org.openkilda.wfm.topology.flowhs.fsm.update.FlowUpdateFsm) FlowUpdateContext(org.openkilda.wfm.topology.flowhs.fsm.update.FlowUpdateContext) DuplicateKeyException(org.openkilda.wfm.topology.flowhs.exception.DuplicateKeyException)

Example 3 with FlowUpdateContext

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

the class FlowUpdateService 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);
    FlowUpdateFsm fsm = fsmRegister.getFsmByKey(key).orElseThrow(() -> new UnknownKeyException(key));
    FlowUpdateContext context = FlowUpdateContext.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 : FlowErrorResponse(org.openkilda.floodlight.flow.response.FlowErrorResponse) FlowUpdateFsm(org.openkilda.wfm.topology.flowhs.fsm.update.FlowUpdateFsm) FlowUpdateContext(org.openkilda.wfm.topology.flowhs.fsm.update.FlowUpdateContext) UnknownKeyException(org.openkilda.wfm.topology.flowhs.exception.UnknownKeyException)

Aggregations

FlowUpdateContext (org.openkilda.wfm.topology.flowhs.fsm.update.FlowUpdateContext)3 FlowUpdateFsm (org.openkilda.wfm.topology.flowhs.fsm.update.FlowUpdateFsm)3 String.format (java.lang.String.format)1 Objects (java.util.Objects)1 Stream (java.util.stream.Stream)1 Slf4j (lombok.extern.slf4j.Slf4j)1 FlowErrorResponse (org.openkilda.floodlight.flow.response.FlowErrorResponse)1 Flow (org.openkilda.model.Flow)1 PersistenceManager (org.openkilda.persistence.PersistenceManager)1 FlowResources (org.openkilda.wfm.share.flow.resources.FlowResources)1 FlowResourcesManager (org.openkilda.wfm.share.flow.resources.FlowResourcesManager)1 FlowDumpData (org.openkilda.wfm.share.history.model.FlowDumpData)1 DumpType (org.openkilda.wfm.share.history.model.FlowDumpData.DumpType)1 HistoryMapper (org.openkilda.wfm.share.mappers.HistoryMapper)1 DuplicateKeyException (org.openkilda.wfm.topology.flowhs.exception.DuplicateKeyException)1 UnknownKeyException (org.openkilda.wfm.topology.flowhs.exception.UnknownKeyException)1 BaseFlowPathRemovalAction (org.openkilda.wfm.topology.flowhs.fsm.common.actions.BaseFlowPathRemovalAction)1 Event (org.openkilda.wfm.topology.flowhs.fsm.update.FlowUpdateFsm.Event)1 State (org.openkilda.wfm.topology.flowhs.fsm.update.FlowUpdateFsm.State)1