use of org.openkilda.messaging.command.yflow.YFlowRerouteResponse in project open-kilda by telstra.
the class OnSubFlowAllocatedAction method buildRerouteResponseMessage.
private Message buildRerouteResponseMessage(YFlowRerouteFsm stateMachine) {
String yFlowId = stateMachine.getYFlowId();
List<Long> oldFlowPathCookies = stateMachine.getOldYFlowPathCookies();
List<FlowPath> flowPaths = transactionManager.doInTransaction(() -> {
YFlow yflow = yFlowRepository.findById(yFlowId).orElseThrow(() -> new FlowProcessingException(ErrorType.NOT_FOUND, format("Y-flow %s not found", yFlowId)));
SwitchId sharedSwitchId = yflow.getSharedEndpoint().getSwitchId();
List<FlowPath> paths = new ArrayList<>();
for (YSubFlow subFlow : yflow.getSubFlows()) {
Flow flow = subFlow.getFlow();
FlowPath flowPath = flow.getPaths().stream().filter(path -> sharedSwitchId.equals(path.getSrcSwitchId()) && !path.isProtected() && !oldFlowPathCookies.contains(path.getCookie().getValue())).findFirst().orElse(sharedSwitchId.equals(flow.getForwardPath().getSrcSwitchId()) ? flow.getForwardPath() : flow.getReversePath());
paths.add(flowPath);
}
return paths;
});
List<PathSegment> sharedPathSegments = IntersectionComputer.calculatePathIntersectionFromSource(flowPaths);
PathInfoData sharedPath = FlowPathMapper.INSTANCE.map(sharedPathSegments);
List<SubFlowPathDto> subFlowPathDtos = flowPaths.stream().map(flowPath -> new SubFlowPathDto(flowPath.getFlowId(), FlowPathMapper.INSTANCE.map(flowPath))).sorted(Comparator.comparing(SubFlowPathDto::getFlowId)).collect(Collectors.toList());
PathInfoData oldSharedPath = stateMachine.getOldSharedPath();
List<SubFlowPathDto> oldSubFlowPathDtos = stateMachine.getOldSubFlowPathDtos();
YFlowRerouteResponse response = new YFlowRerouteResponse(sharedPath, subFlowPathDtos, !(sharedPath.equals(oldSharedPath) && subFlowPathDtos.equals(oldSubFlowPathDtos)));
CommandContext commandContext = stateMachine.getCommandContext();
return new InfoMessage(response, commandContext.getCreateTime(), commandContext.getCorrelationId());
}
Aggregations