use of org.openkilda.wfm.topology.flowhs.fsm.create.FlowCreateContext 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");
}
use of org.openkilda.wfm.topology.flowhs.fsm.create.FlowCreateContext 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);
}
use of org.openkilda.wfm.topology.flowhs.fsm.create.FlowCreateContext 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);
}
Aggregations