Search in sources :

Example 1 with FlowCreateFsm

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

the class ResourcesDeallocationAction method perform.

@Override
protected void perform(State from, State to, Event event, FlowCreateContext context, FlowCreateFsm stateMachine) {
    try {
        transactionManager.doInTransaction(() -> {
            Flow flow = getFlow(stateMachine.getFlowId());
            flow.resetPaths();
        });
    } catch (FlowProcessingException e) {
        stateMachine.saveActionToHistory("Skip resources deallocation", format("Skip resources deallocation. Flow %s has already been deleted: %s", stateMachine.getFlowId(), e.getMessage()));
        return;
    }
    Collection<FlowResources> flowResources = stateMachine.getFlowResources();
    for (FlowResources resources : flowResources) {
        List<PathSegment> removedSegments = new ArrayList<>();
        Stream.of(resources.getForward().getPathId(), resources.getReverse().getPathId()).forEach(pathId -> flowPathRepository.remove(pathId).ifPresent(path -> removedSegments.addAll(path.getSegments())));
        updateIslsForSegments(removedSegments);
        transactionManager.doInTransaction(() -> resourcesManager.deallocatePathResources(resources));
    }
    if (!stateMachine.isPathsBeenAllocated()) {
        flowRepository.remove(stateMachine.getFlowId());
    }
    stateMachine.saveActionToHistory("The resources have been deallocated");
}
Also used : PathSegment(org.openkilda.model.PathSegment) FlowProcessingWithHistorySupportAction(org.openkilda.wfm.topology.flowhs.fsm.common.actions.FlowProcessingWithHistorySupportAction) Event(org.openkilda.wfm.topology.flowhs.fsm.create.FlowCreateFsm.Event) Collection(java.util.Collection) FlowCreateFsm(org.openkilda.wfm.topology.flowhs.fsm.create.FlowCreateFsm) FlowResources(org.openkilda.wfm.share.flow.resources.FlowResources) String.format(java.lang.String.format) ArrayList(java.util.ArrayList) FlowProcessingException(org.openkilda.wfm.topology.flowhs.exception.FlowProcessingException) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) Stream(java.util.stream.Stream) Flow(org.openkilda.model.Flow) State(org.openkilda.wfm.topology.flowhs.fsm.create.FlowCreateFsm.State) IslRepository(org.openkilda.persistence.repositories.IslRepository) FlowCreateContext(org.openkilda.wfm.topology.flowhs.fsm.create.FlowCreateContext) FlowResourcesManager(org.openkilda.wfm.share.flow.resources.FlowResourcesManager) PersistenceManager(org.openkilda.persistence.PersistenceManager) FlowProcessingException(org.openkilda.wfm.topology.flowhs.exception.FlowProcessingException) FlowResources(org.openkilda.wfm.share.flow.resources.FlowResources) ArrayList(java.util.ArrayList) PathSegment(org.openkilda.model.PathSegment) Flow(org.openkilda.model.Flow)

Example 2 with FlowCreateFsm

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

the class FlowCreateService method startFlowCreation.

private void startFlowCreation(String key, CommandContext commandContext, RequestedFlow requestedFlow, String sharedBandwidthGroupId) throws DuplicateKeyException {
    String flowId = requestedFlow.getFlowId();
    log.debug("Handling flow create request with key {} and flow ID: {}", key, flowId);
    if (fsmRegister.hasRegisteredFsmWithKey(key)) {
        throw new DuplicateKeyException(key, "There's another active FSM with the same key");
    }
    if (fsmRegister.hasRegisteredFsmWithFlowId(flowId)) {
        sendErrorResponseToNorthbound(ErrorType.ALREADY_EXISTS, "Could not create flow", format("Flow %s is already creating now", flowId), commandContext);
        throw new DuplicateKeyException(key, "There's another active FSM for the same flowId " + flowId);
    }
    FlowCreateFsm fsm = fsmFactory.newInstance(commandContext, flowId, eventListeners);
    fsm.setSharedBandwidthGroupId(sharedBandwidthGroupId);
    fsmRegister.registerFsm(key, fsm);
    if (requestedFlow.getFlowEncapsulationType() == null) {
        requestedFlow.setFlowEncapsulationType(kildaConfigurationRepository.getOrDefault().getFlowEncapsulationType());
    }
    if (requestedFlow.getPathComputationStrategy() == null) {
        requestedFlow.setPathComputationStrategy(kildaConfigurationRepository.getOrDefault().getPathComputationStrategy());
    }
    FlowCreateContext context = FlowCreateContext.builder().targetFlow(requestedFlow).build();
    fsm.start(context);
    fsmExecutor.fire(fsm, Event.NEXT, context);
    removeIfFinished(fsm, key);
}
Also used : FlowCreateContext(org.openkilda.wfm.topology.flowhs.fsm.create.FlowCreateContext) FlowCreateFsm(org.openkilda.wfm.topology.flowhs.fsm.create.FlowCreateFsm) DuplicateKeyException(org.openkilda.wfm.topology.flowhs.exception.DuplicateKeyException)

Example 3 with FlowCreateFsm

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

the class FlowCreateService method handleTimeout.

/**
 * Handles timeout case.
 *
 * @param key command identifier.
 */
public void handleTimeout(@NonNull String key) throws UnknownKeyException {
    log.debug("Handling timeout for {}", key);
    FlowCreateFsm fsm = fsmRegister.getFsmByKey(key).orElseThrow(() -> new UnknownKeyException(key));
    fsm.setTimedOut(true);
    fsmExecutor.fire(fsm, Event.TIMEOUT);
    removeIfFinished(fsm, key);
}
Also used : FlowCreateFsm(org.openkilda.wfm.topology.flowhs.fsm.create.FlowCreateFsm) UnknownKeyException(org.openkilda.wfm.topology.flowhs.exception.UnknownKeyException)

Example 4 with FlowCreateFsm

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

the class FlowCreateService 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);
    FlowCreateFsm fsm = fsmRegister.getFsmByKey(key).orElseThrow(() -> new UnknownKeyException(key));
    FlowCreateContext context = FlowCreateContext.builder().speakerFlowResponse(flowResponse).build();
    fsmExecutor.fire(fsm, Event.RESPONSE_RECEIVED, context);
    removeIfFinished(fsm, key);
}
Also used : FlowCreateContext(org.openkilda.wfm.topology.flowhs.fsm.create.FlowCreateContext) FlowCreateFsm(org.openkilda.wfm.topology.flowhs.fsm.create.FlowCreateFsm) UnknownKeyException(org.openkilda.wfm.topology.flowhs.exception.UnknownKeyException)

Aggregations

FlowCreateFsm (org.openkilda.wfm.topology.flowhs.fsm.create.FlowCreateFsm)4 FlowCreateContext (org.openkilda.wfm.topology.flowhs.fsm.create.FlowCreateContext)3 UnknownKeyException (org.openkilda.wfm.topology.flowhs.exception.UnknownKeyException)2 String.format (java.lang.String.format)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 List (java.util.List)1 Stream (java.util.stream.Stream)1 Slf4j (lombok.extern.slf4j.Slf4j)1 Flow (org.openkilda.model.Flow)1 PathSegment (org.openkilda.model.PathSegment)1 PersistenceManager (org.openkilda.persistence.PersistenceManager)1 IslRepository (org.openkilda.persistence.repositories.IslRepository)1 FlowResources (org.openkilda.wfm.share.flow.resources.FlowResources)1 FlowResourcesManager (org.openkilda.wfm.share.flow.resources.FlowResourcesManager)1 DuplicateKeyException (org.openkilda.wfm.topology.flowhs.exception.DuplicateKeyException)1 FlowProcessingException (org.openkilda.wfm.topology.flowhs.exception.FlowProcessingException)1 FlowProcessingWithHistorySupportAction (org.openkilda.wfm.topology.flowhs.fsm.common.actions.FlowProcessingWithHistorySupportAction)1 Event (org.openkilda.wfm.topology.flowhs.fsm.create.FlowCreateFsm.Event)1 State (org.openkilda.wfm.topology.flowhs.fsm.create.FlowCreateFsm.State)1