use of org.openkilda.wfm.topology.flowhs.fsm.reroute.FlowRerouteContext in project open-kilda by telstra.
the class RevertResourceAllocationAction method perform.
@Override
protected void perform(State from, State to, Event event, FlowRerouteContext context, FlowRerouteFsm 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.reroute.FlowRerouteContext in project open-kilda by telstra.
the class FlowRerouteService method startFlowRerouting.
private void startFlowRerouting(String key, FlowRerouteRequest reroute, CommandContext commandContext, String sharedBandwidthGroupId) {
String flowId = reroute.getFlowId();
log.debug("Handling flow reroute request with key {} and flow ID: {}", key, flowId);
try {
checkRequestsCollision(key, flowId);
} catch (Exception e) {
log.error(e.getMessage());
fsmRegister.getFsmByKey(key).ifPresent(fsm -> removeIfFinished(fsm, key));
return;
}
if (fsmRegister.hasRegisteredFsmWithFlowId(flowId)) {
carrier.sendRerouteResultStatus(flowId, new RerouteInProgressError(), commandContext.getCorrelationId());
return;
}
FlowRerouteFsm fsm = fsmFactory.newInstance(flowId, commandContext, eventListeners);
fsm.setSharedBandwidthGroupId(sharedBandwidthGroupId);
fsmRegister.registerFsm(key, fsm);
FlowRerouteContext context = FlowRerouteContext.builder().flowId(flowId).affectedIsl(reroute.getAffectedIsl()).forceReroute(reroute.isForce()).ignoreBandwidth(reroute.isIgnoreBandwidth()).effectivelyDown(reroute.isEffectivelyDown()).rerouteReason(reroute.getReason()).build();
fsmExecutor.fire(fsm, Event.NEXT, context);
removeIfFinished(fsm, key);
}
use of org.openkilda.wfm.topology.flowhs.fsm.reroute.FlowRerouteContext in project open-kilda by telstra.
the class FlowRerouteService 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);
FlowRerouteFsm fsm = fsmRegister.getFsmByKey(key).orElseThrow(() -> new UnknownKeyException(key));
FlowRerouteContext context = FlowRerouteContext.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