use of org.openkilda.wfm.topology.flowhs.model.RequestedFlow in project open-kilda by telstra.
the class FlowValidator method checkAffinityFlow.
@VisibleForTesting
void checkAffinityFlow(RequestedFlow targetFlow) throws InvalidFlowException {
if (targetFlow.getSrcSwitch().equals(targetFlow.getDestSwitch())) {
throw new InvalidFlowException("Couldn't add one-switch flow into affinity group", ErrorType.PARAMETERS_INVALID);
}
Flow affinityFlow = flowRepository.findById(targetFlow.getAffinityFlowId()).orElseThrow(() -> new InvalidFlowException(format("Failed to find affinity flow id %s", targetFlow.getAffinityFlowId()), ErrorType.PARAMETERS_INVALID));
if (affinityFlow.isOneSwitchFlow()) {
throw new InvalidFlowException("Couldn't create affinity group with one-switch flow", ErrorType.PARAMETERS_INVALID);
}
if (StringUtils.isNotBlank(affinityFlow.getAffinityGroupId())) {
String mainAffinityFlowId = affinityFlow.getAffinityGroupId();
Flow mainAffinityFlow = flowRepository.findById(mainAffinityFlowId).orElseThrow(() -> new InvalidFlowException(format("Failed to find main affinity flow id %s", mainAffinityFlowId), ErrorType.PARAMETERS_INVALID));
if (StringUtils.isNotBlank(mainAffinityFlow.getDiverseGroupId())) {
Collection<String> diverseFlowIds = flowRepository.findFlowsIdByAffinityGroupId(mainAffinityFlow.getDiverseGroupId()).stream().filter(Objects::nonNull).collect(Collectors.toSet());
if (!diverseFlowIds.contains(targetFlow.getDiverseFlowId())) {
throw new InvalidFlowException("Couldn't create a diverse group with flow " + "in a different diverse group than main affinity flow", ErrorType.PARAMETERS_INVALID);
}
}
}
}
use of org.openkilda.wfm.topology.flowhs.model.RequestedFlow in project open-kilda by telstra.
the class FlowValidator method checkDiverseFlow.
@VisibleForTesting
void checkDiverseFlow(RequestedFlow targetFlow) throws InvalidFlowException {
if (targetFlow.getSrcSwitch().equals(targetFlow.getDestSwitch())) {
throw new InvalidFlowException("Couldn't add one-switch flow into diverse group", ErrorType.PARAMETERS_INVALID);
}
Flow diverseFlow = flowRepository.findById(targetFlow.getDiverseFlowId()).orElse(null);
if (diverseFlow == null) {
YFlow diverseYFlow = yFlowRepository.findById(targetFlow.getDiverseFlowId()).orElseThrow(() -> new InvalidFlowException(format("Failed to find diverse flow id %s", targetFlow.getDiverseFlowId()), ErrorType.PARAMETERS_INVALID));
diverseFlow = diverseYFlow.getSubFlows().stream().map(YSubFlow::getFlow).filter(flow -> flow.getFlowId().equals(flow.getAffinityGroupId())).findFirst().orElseThrow(() -> new InvalidFlowException(format("Failed to find main affinity flow for diverse y-flow id %s", targetFlow.getDiverseFlowId()), ErrorType.INTERNAL_ERROR));
}
if (StringUtils.isNotBlank(diverseFlow.getAffinityGroupId())) {
String diverseFlowId = diverseFlow.getAffinityGroupId();
diverseFlow = flowRepository.findById(diverseFlowId).orElseThrow(() -> new InvalidFlowException(format("Failed to find diverse flow id %s", diverseFlowId), ErrorType.PARAMETERS_INVALID));
Collection<String> affinityFlowIds = flowRepository.findFlowsIdByAffinityGroupId(diverseFlow.getAffinityGroupId()).stream().filter(Objects::nonNull).collect(Collectors.toSet());
if (affinityFlowIds.contains(targetFlow.getAffinityFlowId())) {
throw new InvalidFlowException("Couldn't create diverse group with flow in the same affinity group", ErrorType.PARAMETERS_INVALID);
}
}
if (diverseFlow.isOneSwitchFlow()) {
throw new InvalidFlowException("Couldn't create diverse group with one-switch flow", ErrorType.PARAMETERS_INVALID);
}
}
use of org.openkilda.wfm.topology.flowhs.model.RequestedFlow in project open-kilda by telstra.
the class FlowValidatorTest method shouldFailOnSwapWhenEqualsEndpointsOnSecondFlow.
@Test(expected = InvalidFlowException.class)
public void shouldFailOnSwapWhenEqualsEndpointsOnSecondFlow() throws InvalidFlowException {
RequestedFlow firstFlow = RequestedFlow.builder().flowId("firstFlow").srcSwitch(SWITCH_ID_2).srcPort(10).srcVlan(11).destSwitch(SWITCH_ID_2).destPort(12).detectConnectedDevices(new DetectConnectedDevices()).build();
RequestedFlow secondFlow = RequestedFlow.builder().flowId("secondFlow").srcSwitch(SWITCH_ID_1).srcPort(10).srcVlan(11).destSwitch(SWITCH_ID_1).destPort(10).destVlan(11).detectConnectedDevices(new DetectConnectedDevices()).build();
flowValidator.checkForEqualsEndpoints(firstFlow, secondFlow);
}
use of org.openkilda.wfm.topology.flowhs.model.RequestedFlow in project open-kilda by telstra.
the class FlowValidatorTest method shouldFailOnSwapWhenEqualsEndpointsOnFirstFlow.
@Test(expected = InvalidFlowException.class)
public void shouldFailOnSwapWhenEqualsEndpointsOnFirstFlow() throws InvalidFlowException {
RequestedFlow firstFlow = RequestedFlow.builder().flowId("firstFlow").srcSwitch(SWITCH_ID_1).srcPort(10).srcVlan(11).destSwitch(SWITCH_ID_2).destPort(10).destVlan(11).detectConnectedDevices(new DetectConnectedDevices()).build();
RequestedFlow secondFlow = RequestedFlow.builder().flowId("secondFlow").srcSwitch(SWITCH_ID_2).destSwitch(SWITCH_ID_2).detectConnectedDevices(new DetectConnectedDevices()).build();
flowValidator.checkForEqualsEndpoints(firstFlow, secondFlow);
}
use of org.openkilda.wfm.topology.flowhs.model.RequestedFlow in project open-kilda by telstra.
the class RevertSubFlowsAction method perform.
@Override
public void perform(State from, State to, Event event, YFlowUpdateContext context, YFlowUpdateFsm stateMachine) {
stateMachine.clearUpdatingSubFlows();
stateMachine.clearAllocatedSubFlows();
stateMachine.clearFailedSubFlows();
String yFlowId = stateMachine.getYFlowId();
Collection<RequestedFlow> originalFlows = YFlowRequestMapper.INSTANCE.toRequestedFlows(stateMachine.getOriginalFlow());
stateMachine.setRequestedFlows(originalFlows);
log.debug("Start reverting {} sub-flows for y-flow {}", originalFlows.size(), stateMachine.getYFlowId());
originalFlows.stream().filter(originalFlow -> originalFlow.getFlowId().equals(stateMachine.getMainAffinityFlowId())).forEach(originalFlow -> {
String subFlowId = originalFlow.getFlowId();
CommandContext flowContext = stateMachine.getCommandContext().fork(subFlowId);
stateMachine.addUpdatingSubFlow(subFlowId);
stateMachine.notifyEventListeners(listener -> listener.onSubFlowProcessingStart(yFlowId, subFlowId));
flowUpdateService.startFlowUpdating(flowContext, originalFlow, yFlowId);
});
}
Aggregations