use of org.openkilda.model.YSubFlow in project open-kilda by telstra.
the class ValidateYFlowAction method performWithResponse.
@Override
protected Optional<Message> performWithResponse(State from, State to, Event event, YFlowRerouteContext context, YFlowRerouteFsm stateMachine) {
boolean isOperationAllowed = featureTogglesRepository.getOrDefault().getModifyYFlowEnabled();
if (!isOperationAllowed) {
throw new FlowProcessingException(ErrorType.NOT_PERMITTED, "Y-flow reroute feature is disabled");
}
YFlowRerouteRequest request = context.getRerouteRequest();
String yFlowId = request.getYFlowId();
Set<IslEndpoint> affectedIsls = new HashSet<>(Optional.ofNullable(request.getAffectedIsl()).orElse(emptySet()));
dashboardLogger.onYFlowReroute(yFlowId, affectedIsls, request.isForce());
stateMachine.setAffectedIsls(affectedIsls);
stateMachine.setRerouteReason(request.getReason());
stateMachine.setForceReroute(request.isForce());
stateMachine.setIgnoreBandwidth(request.isIgnoreBandwidth());
YFlow yFlow = transactionManager.doInTransaction(() -> {
YFlow result = yFlowRepository.findById(yFlowId).orElseThrow(() -> new FlowProcessingException(ErrorType.NOT_FOUND, format("Y-flow %s not found", yFlowId)));
if (result.getStatus() == FlowStatus.IN_PROGRESS) {
throw new FlowProcessingException(ErrorType.REQUEST_INVALID, format("Y-flow %s is in progress now", yFlowId));
}
// Keep it, just in case we have to revert it.
stateMachine.setOriginalYFlowStatus(result.getStatus());
result.setStatus(FlowStatus.IN_PROGRESS);
return result;
});
Collection<Flow> subFlows = yFlow.getSubFlows().stream().map(YSubFlow::getFlow).collect(Collectors.toList());
Flow mainAffinitySubFlow = subFlows.stream().filter(flow -> flow.getFlowId().equals(flow.getAffinityGroupId())).findFirst().orElseThrow(() -> new FlowProcessingException(ErrorType.DATA_INVALID, format("Main affinity sub-flow of the y-flow %s not found", yFlowId)));
stateMachine.setMainAffinityFlowId(mainAffinitySubFlow.getFlowId());
boolean mainAffinitySubFlowIsAffected = isFlowAffected(mainAffinitySubFlow, affectedIsls);
Set<String> affectedFlowIds = subFlows.stream().filter(flow -> mainAffinitySubFlowIsAffected || isFlowAffected(flow, affectedIsls)).map(Flow::getFlowId).collect(Collectors.toSet());
stateMachine.setTargetSubFlowIds(affectedFlowIds);
stateMachine.saveNewEventToHistory("Y-flow was validated successfully", FlowEventData.Event.REROUTE);
return Optional.empty();
}
use of org.openkilda.model.YSubFlow in project open-kilda by telstra.
the class RerouteQueueService method isRetryRequired.
private boolean isRetryRequired(String flowId, RerouteError rerouteError, boolean isYFlow) {
if (rerouteError instanceof NoPathFoundError) {
log.info("Received no path found error for flow {}", flowId);
return true;
} else if (rerouteError instanceof RerouteInProgressError) {
log.info("Received reroute in progress error for flow {}", flowId);
return true;
} else if (rerouteError instanceof SpeakerRequestError) {
if (isYFlow) {
log.info("Received speaker request error for y-flow {}", flowId);
YFlow yFlow = yFlowRepository.findById(flowId).orElse(null);
if (yFlow == null) {
log.error("Y-flow {} not found", flowId);
return false;
}
Set<SwitchId> yFlowSwitchIds = yFlow.getSubFlows().stream().map(YSubFlow::getEndpointSwitchId).collect(Collectors.toSet());
yFlowSwitchIds.add(yFlow.getSharedEndpoint().getSwitchId());
boolean isRetryRequired = true;
SpeakerRequestError ruleFailedError = (SpeakerRequestError) rerouteError;
for (SwitchId switchId : yFlowSwitchIds) {
isRetryRequired &= !ruleFailedError.getSwitches().contains(switchId);
}
return isRetryRequired;
} else {
log.info("Received speaker request error for flow {}", flowId);
Flow flow = flowRepository.findById(flowId).orElse(null);
if (flow == null) {
log.error("Flow {} not found", flowId);
return false;
}
SpeakerRequestError ruleFailedError = (SpeakerRequestError) rerouteError;
return !ruleFailedError.getSwitches().contains(flow.getSrcSwitchId()) && !ruleFailedError.getSwitches().contains(flow.getDestSwitchId());
}
}
return false;
}
use of org.openkilda.model.YSubFlow in project open-kilda by telstra.
the class AbstractYFlowTest method verifyAffinity.
protected void verifyAffinity(String yFlowId) {
YFlow flow = getYFlow(yFlowId);
Set<String> affinityGroups = flow.getSubFlows().stream().map(YSubFlow::getFlow).map(Flow::getAffinityGroupId).collect(Collectors.toSet());
assertEquals(1, affinityGroups.size());
String affinityGroupId = affinityGroups.iterator().next();
Set<String> subFlowIds = flow.getSubFlows().stream().map(YSubFlow::getSubFlowId).collect(Collectors.toSet());
assertTrue(subFlowIds.contains(affinityGroupId));
}
use of org.openkilda.model.YSubFlow in project open-kilda by telstra.
the class TestYSubFlowBuilder method build.
/**
* Build {@link YSubFlow} instance.
*/
public YSubFlow build() {
checkArgument(endpoint != null, "YSubFlow endpoint must be defined");
YSubFlow subFlow = YSubFlow.builder().yFlow(yFlow).flow(flow).sharedEndpointVlan(sharedEndpointVlan).sharedEndpointInnerVlan(sharedEndpointInnerVlan).endpointSwitchId(endpoint.getSwitchId()).endpointPort(endpoint.getPortNumber()).endpointVlan(endpoint.getOuterVlanId()).endpointInnerVlan(endpoint.getInnerVlanId()).build();
subFlow.setTimeCreate(timeCreate);
subFlow.setTimeModify(timeModify);
return subFlow;
}
use of org.openkilda.model.YSubFlow in project open-kilda by telstra.
the class UpdateFlowAction method getOrCreateDiverseFlowGroupId.
private String getOrCreateDiverseFlowGroupId(String diverseFlowId) throws FlowProcessingException {
log.debug("Getting flow diverse group for flow with id {}", diverseFlowId);
String flowId = yFlowRepository.findById(diverseFlowId).map(Stream::of).orElseGet(Stream::empty).map(YFlow::getSubFlows).flatMap(Collection::stream).map(YSubFlow::getFlow).filter(flow -> flow.getFlowId().equals(flow.getAffinityGroupId())).map(Flow::getFlowId).findFirst().orElse(diverseFlowId);
return flowRepository.getOrCreateDiverseFlowGroupId(flowId).orElseThrow(() -> new FlowProcessingException(ErrorType.NOT_FOUND, format("Flow %s not found", flowId)));
}
Aggregations