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