use of org.openkilda.wfm.topology.flowhs.model.RequestedFlow in project open-kilda by telstra.
the class ResourcesAllocationAction method createFlow.
private void createFlow(RequestedFlow targetFlow) throws FlowNotFoundException, FlowAlreadyExistException {
try {
transactionManager.doInTransaction(() -> {
Flow flow = RequestedFlowMapper.INSTANCE.toFlow(targetFlow);
flow.setStatus(FlowStatus.IN_PROGRESS);
getFlowDiverseGroupFromContext(targetFlow.getDiverseFlowId()).ifPresent(flow::setDiverseGroupId);
getFlowAffinityGroupFromContext(targetFlow.getAffinityFlowId()).ifPresent(flow::setAffinityGroupId);
flowRepository.add(flow);
});
} catch (ConstraintViolationException e) {
throw new FlowAlreadyExistException(format("Failed to save flow with id %s", targetFlow.getFlowId()), e);
}
}
use of org.openkilda.wfm.topology.flowhs.model.RequestedFlow in project open-kilda by telstra.
the class OnFinishedAction method perform.
@Override
public void perform(State from, State to, Event event, FlowCreateContext context, FlowCreateFsm stateMachine) {
RequestedFlow requestedFlow = stateMachine.getTargetFlow();
stateMachine.getCarrier().sendPeriodicPingNotification(requestedFlow.getFlowId(), requestedFlow.isPeriodicPings());
if (!requestedFlow.getSrcSwitch().equals(requestedFlow.getDestSwitch())) {
stateMachine.getCarrier().sendActivateFlowMonitoring(requestedFlow);
}
dashboardLogger.onSuccessfulFlowCreate(stateMachine.getFlowId());
stateMachine.saveActionToHistory("Flow was created successfully");
}
use of org.openkilda.wfm.topology.flowhs.model.RequestedFlow in project open-kilda by telstra.
the class CreateSubFlowsAction method perform.
@Override
public void perform(State from, State to, Event event, YFlowCreateContext context, YFlowCreateFsm stateMachine) {
String yFlowId = stateMachine.getYFlowId();
Collection<RequestedFlow> requestedFlows = YFlowRequestMapper.INSTANCE.toRequestedFlows(stateMachine.getTargetFlow());
stateMachine.setRequestedFlows(requestedFlows);
log.debug("Start creating {} sub-flows for y-flow {}", requestedFlows.size(), yFlowId);
stateMachine.clearCreatingSubFlows();
requestedFlows.stream().findFirst().ifPresent(requestedFlow -> {
String subFlowId = requestedFlow.getFlowId();
stateMachine.setMainAffinityFlowId(subFlowId);
stateMachine.addSubFlow(subFlowId);
stateMachine.addCreatingSubFlow(subFlowId);
stateMachine.notifyEventListeners(listener -> listener.onSubFlowProcessingStart(yFlowId, subFlowId));
CommandContext flowContext = stateMachine.getCommandContext().fork(subFlowId);
requestedFlow.setDiverseFlowId(stateMachine.getDiverseFlowId());
flowCreateService.startFlowCreation(flowContext, requestedFlow, yFlowId);
});
}
use of org.openkilda.wfm.topology.flowhs.model.RequestedFlow in project open-kilda by telstra.
the class UpdateFlowAction method performWithResponse.
@Override
protected Optional<Message> performWithResponse(State from, State to, Event event, FlowUpdateContext context, FlowUpdateFsm stateMachine) {
RequestedFlow targetFlow = stateMachine.getTargetFlow();
String flowId = targetFlow.getFlowId();
transactionManager.doInTransaction(() -> {
Flow flow = getFlow(flowId);
log.debug("Updating the flow {} with properties: {}", flowId, targetFlow);
RequestedFlow originalFlow = RequestedFlowMapper.INSTANCE.toRequestedFlow(flow);
stateMachine.setOldTargetPathComputationStrategy(flow.getTargetPathComputationStrategy());
stateMachine.setOriginalFlow(originalFlow);
stateMachine.setOriginalDiverseFlowGroup(flow.getDiverseGroupId());
stateMachine.setOriginalAffinityFlowGroup(flow.getAffinityGroupId());
// Complete target flow in FSM with values from original flow
stateMachine.setTargetFlow(updateFlow(flow, targetFlow));
EndpointUpdate endpointUpdate = updateEndpointRulesOnly(originalFlow, targetFlow, stateMachine.getOriginalDiverseFlowGroup(), flow.getDiverseGroupId(), stateMachine.getOriginalAffinityFlowGroup(), flow.getAffinityGroupId());
stateMachine.setEndpointUpdate(endpointUpdate);
if (endpointUpdate.isPartialUpdate()) {
FlowLoopOperation flowLoopOperation = detectFlowLoopOperation(originalFlow, targetFlow);
stateMachine.setFlowLoopOperation(flowLoopOperation);
stateMachine.setNewPrimaryForwardPath(flow.getForwardPathId());
stateMachine.setNewPrimaryReversePath(flow.getReversePathId());
stateMachine.setNewProtectedForwardPath(flow.getProtectedForwardPathId());
stateMachine.setNewProtectedReversePath(flow.getProtectedReversePathId());
FlowDumpData dumpData = HistoryMapper.INSTANCE.map(flow, flow.getForwardPath(), flow.getReversePath(), DumpType.STATE_AFTER);
stateMachine.saveActionWithDumpToHistory("New endpoints were stored for flow", format("The flow endpoints were updated for: %s / %s", flow.getSrcSwitch(), flow.getDestSwitch()), dumpData);
}
});
stateMachine.saveActionToHistory("The flow properties were updated");
if (stateMachine.getEndpointUpdate().isPartialUpdate()) {
stateMachine.saveActionToHistory("Skip paths and resources allocation");
stateMachine.fire(Event.UPDATE_ENDPOINT_RULES_ONLY);
}
return Optional.empty();
}
use of org.openkilda.wfm.topology.flowhs.model.RequestedFlow in project open-kilda by telstra.
the class ValidateFlowAction method performWithResponse.
@Override
protected Optional<Message> performWithResponse(State from, State to, Event event, FlowUpdateContext context, FlowUpdateFsm stateMachine) {
String flowId = stateMachine.getFlowId();
RequestedFlow targetFlow = context.getTargetFlow();
String diverseFlowId = targetFlow.getDiverseFlowId();
dashboardLogger.onFlowUpdate(flowId, targetFlow.getSrcSwitch(), targetFlow.getSrcPort(), targetFlow.getSrcVlan(), targetFlow.getDestSwitch(), targetFlow.getDestPort(), targetFlow.getDestVlan(), diverseFlowId, targetFlow.getBandwidth());
boolean isOperationAllowed = featureTogglesRepository.getOrDefault().getUpdateFlowEnabled();
if (!isOperationAllowed) {
throw new FlowProcessingException(ErrorType.NOT_PERMITTED, "Flow update feature is disabled");
}
stateMachine.setTargetFlow(targetFlow);
stateMachine.setBulkUpdateFlowIds(context.getBulkUpdateFlowIds());
stateMachine.setDoNotRevert(context.isDoNotRevert());
Flow flow = getFlow(flowId);
try {
flowValidator.validate(targetFlow, stateMachine.getBulkUpdateFlowIds());
} catch (InvalidFlowException e) {
throw new FlowProcessingException(e.getType(), e.getMessage(), e);
} catch (UnavailableFlowEndpointException e) {
throw new FlowProcessingException(ErrorType.DATA_INVALID, e.getMessage(), e);
}
if ((!targetFlow.getSrcSwitch().equals(flow.getSrcSwitchId()) || !targetFlow.getDestSwitch().equals(flow.getDestSwitchId())) && (!flow.getForwardPath().getFlowMirrorPointsSet().isEmpty() || !flow.getReversePath().getFlowMirrorPointsSet().isEmpty())) {
throw new FlowProcessingException(ErrorType.REQUEST_INVALID, "The current implementation of flow mirror points does not allow allocating paths. " + "Therefore, remove the flow mirror points before changing the endpoint switch.");
}
if (diverseFlowId != null && targetFlow.getSrcSwitch().equals(targetFlow.getDestSwitch())) {
throw new FlowProcessingException(ErrorType.DATA_INVALID, "Couldn't add one-switch flow into diverse group");
}
transactionManager.doInTransaction(() -> {
if (diverseFlowId != null && !diverseFlowId.isEmpty()) {
Flow diverseFlow = getFlow(diverseFlowId);
if (diverseFlow.isOneSwitchFlow()) {
throw new FlowProcessingException(ErrorType.PARAMETERS_INVALID, "Couldn't create diverse group with one-switch flow");
}
}
Flow foundFlow = getFlow(flowId);
if (foundFlow.getStatus() == FlowStatus.IN_PROGRESS && stateMachine.getBulkUpdateFlowIds().isEmpty()) {
throw new FlowProcessingException(ErrorType.REQUEST_INVALID, format("Flow %s is in progress now", flowId));
}
// Keep it, just in case we have to revert it.
stateMachine.setOriginalFlowStatus(foundFlow.getStatus());
stateMachine.setOriginalFlowStatusInfo(foundFlow.getStatusInfo());
foundFlow.setStatus(FlowStatus.IN_PROGRESS);
foundFlow.setStatusInfo("");
return foundFlow;
});
stateMachine.saveNewEventToHistory("Flow was validated successfully", FlowEventData.Event.UPDATE);
return Optional.empty();
}
Aggregations