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