Search in sources :

Example 1 with Event

use of org.openkilda.wfm.topology.flowhs.fsm.create.FlowCreateFsm.Event 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)

Aggregations

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 FlowProcessingException (org.openkilda.wfm.topology.flowhs.exception.FlowProcessingException)1 FlowProcessingWithHistorySupportAction (org.openkilda.wfm.topology.flowhs.fsm.common.actions.FlowProcessingWithHistorySupportAction)1 FlowCreateContext (org.openkilda.wfm.topology.flowhs.fsm.create.FlowCreateContext)1 FlowCreateFsm (org.openkilda.wfm.topology.flowhs.fsm.create.FlowCreateFsm)1 Event (org.openkilda.wfm.topology.flowhs.fsm.create.FlowCreateFsm.Event)1 State (org.openkilda.wfm.topology.flowhs.fsm.create.FlowCreateFsm.State)1