use of org.openkilda.wfm.topology.flowhs.model.RequestedFlow in project open-kilda by telstra.
the class UpdateSubFlowsAction method perform.
@Override
public void perform(State from, State to, Event event, YFlowUpdateContext context, YFlowUpdateFsm stateMachine) {
Collection<RequestedFlow> requestedFlows = YFlowRequestMapper.INSTANCE.toRequestedFlows(stateMachine.getTargetFlow());
stateMachine.setRequestedFlows(requestedFlows);
log.debug("Start updating {} sub-flows for y-flow {}", requestedFlows.size(), stateMachine.getYFlowId());
stateMachine.clearUpdatingSubFlows();
String yFlowId = stateMachine.getYFlowId();
requestedFlows.forEach(requestedFlow -> {
String subFlowId = requestedFlow.getFlowId();
stateMachine.addSubFlow(subFlowId);
if (requestedFlow.getFlowId().equals(stateMachine.getMainAffinityFlowId())) {
stateMachine.addUpdatingSubFlow(subFlowId);
stateMachine.notifyEventListeners(listener -> listener.onSubFlowProcessingStart(yFlowId, subFlowId));
CommandContext flowContext = stateMachine.getCommandContext().fork(subFlowId);
requestedFlow.setDiverseFlowId(stateMachine.getDiverseFlowId());
flowUpdateService.startFlowUpdating(flowContext, requestedFlow, yFlowId);
}
});
}
use of org.openkilda.wfm.topology.flowhs.model.RequestedFlow in project open-kilda by telstra.
the class PathSwappingRuleRemovalAction method getOriginalFlowWithPaths.
protected Flow getOriginalFlowWithPaths(FlowPathSwappingFsm<T, S, E, C, ?, ?> stateMachine, RequestedFlow originalFlow) {
Flow flow = RequestedFlowMapper.INSTANCE.toFlow(originalFlow);
flow.setForwardPathId(stateMachine.getOldPrimaryForwardPath());
flow.setReversePathId(stateMachine.getOldPrimaryReversePath());
if (flow.isAllocateProtectedPath()) {
flow.setProtectedForwardPathId(stateMachine.getOldProtectedForwardPath());
flow.setProtectedReversePathId(stateMachine.getOldProtectedReversePath());
}
flow.addPaths(getFlow(stateMachine.getFlowId()).getPaths().toArray(new FlowPath[0]));
return flow;
}
use of org.openkilda.wfm.topology.flowhs.model.RequestedFlow in project open-kilda by telstra.
the class FlowValidateAction method performWithResponse.
@Override
protected Optional<Message> performWithResponse(State from, State to, Event event, FlowCreateContext context, FlowCreateFsm stateMachine) throws FlowProcessingException {
RequestedFlow request = context.getTargetFlow();
dashboardLogger.onFlowCreate(request.getFlowId(), request.getSrcSwitch(), request.getSrcPort(), request.getSrcVlan(), request.getDestSwitch(), request.getDestPort(), request.getDestVlan(), request.getDiverseFlowId(), request.getBandwidth());
boolean isOperationAllowed = featureTogglesRepository.getOrDefault().getCreateFlowEnabled();
if (!isOperationAllowed) {
throw new FlowProcessingException(ErrorType.NOT_PERMITTED, "Flow create feature is disabled");
}
if (flowRepository.exists(request.getFlowId())) {
throw new FlowProcessingException(ErrorType.ALREADY_EXISTS, format("Flow %s already exists", request.getFlowId()));
}
if (yFlowRepository.exists(request.getFlowId())) {
throw new FlowProcessingException(ErrorType.ALREADY_EXISTS, format("Y-flow %s already exists", request.getFlowId()));
}
try {
flowValidator.validate(request);
} catch (InvalidFlowException e) {
throw new FlowProcessingException(e.getType(), e.getMessage(), e);
} catch (UnavailableFlowEndpointException e) {
throw new FlowProcessingException(ErrorType.DATA_INVALID, e.getMessage(), e);
}
stateMachine.setTargetFlow(request);
if (event != Event.RETRY) {
stateMachine.saveNewEventToHistory("Flow was validated successfully", FlowEventData.Event.CREATE);
} else {
// no need to save a new event into DB, it should already exist there.
stateMachine.saveActionToHistory("Flow was validated successfully");
}
return Optional.empty();
}
use of org.openkilda.wfm.topology.flowhs.model.RequestedFlow in project open-kilda by telstra.
the class FlowSwapEndpointsHubService method handleRequest.
/**
* Handles request for swap flow endpoints.
*/
public void handleRequest(String key, CommandContext commandContext, SwapFlowEndpointRequest request) {
if (yFlowRepository.isSubFlow(request.getFirstFlow().getFlowId())) {
sendForbiddenSubFlowOperationToNorthbound(request.getFirstFlow().getFlowId(), commandContext);
return;
}
if (yFlowRepository.isSubFlow(request.getSecondFlow().getFlowId())) {
sendForbiddenSubFlowOperationToNorthbound(request.getSecondFlow().getFlowId(), commandContext);
return;
}
log.debug("Handling swap flow endpoints request with key {} and flow IDs: {}, {}", key, request.getFirstFlow().getFlowId(), request.getSecondFlow().getFlowId());
if (fsmRegister.hasRegisteredFsmWithKey(key)) {
log.error("Attempt to create a FSM with key {}, while there's another active FSM with the same key.", key);
return;
}
RequestedFlow firstFlow = RequestedFlowMapper.INSTANCE.toRequestedFlow(request.getFirstFlow());
RequestedFlow secondFlow = RequestedFlowMapper.INSTANCE.toRequestedFlow(request.getSecondFlow());
FlowSwapEndpointsFsm fsm = fsmFactory.newInstance(commandContext, firstFlow, secondFlow);
fsmRegister.registerFsm(key, fsm);
fsm.fire(Event.NEXT);
removeIfFinished(fsm, key);
}
use of org.openkilda.wfm.topology.flowhs.model.RequestedFlow in project open-kilda by telstra.
the class FlowCreateService method handleRequest.
/**
* Handles request for flow creation.
*
* @param key command identifier.
* @param request request data.
*/
public void handleRequest(@NonNull String key, @NonNull CommandContext commandContext, @NonNull FlowRequest request) throws DuplicateKeyException {
RequestedFlow requestedFlow = RequestedFlowMapper.INSTANCE.toRequestedFlow(request);
startFlowCreation(key, commandContext, requestedFlow, requestedFlow.getFlowId());
}
Aggregations