use of org.openkilda.messaging.model.FlowPathDto.FlowPathDtoBuilder in project open-kilda by telstra.
the class FlowOperationsService method getFlowPath.
/**
* Returns flow path. If flow has group, returns also path for each flow in group.
*
* @param flowId the flow to get a path.
*/
public List<FlowPathDto> getFlowPath(String flowId) throws FlowNotFoundException {
flowDashboardLogger.onFlowPathsRead(flowId);
Flow flow = flowRepository.findById(flowId).orElseThrow(() -> new FlowNotFoundException(flowId));
String groupId = flow.getDiverseGroupId();
if (groupId == null) {
return Collections.singletonList(toFlowPathDtoBuilder(flow).build());
} else {
Collection<Flow> flowsInGroup = flowRepository.findByDiverseGroupId(groupId);
Collection<FlowPath> flowPathsInGroup = flowPathRepository.findByFlowGroupId(groupId);
IntersectionComputer primaryIntersectionComputer = new IntersectionComputer(flow.getFlowId(), flow.getForwardPathId(), flow.getReversePathId(), flowPathsInGroup);
// target flow primary path
FlowPathDtoBuilder targetFlowDtoBuilder = this.toFlowPathDtoBuilder(flow).segmentsStats(primaryIntersectionComputer.getOverlappingStats());
// other flows in the the group
List<FlowPathDto> payloads = flowsInGroup.stream().filter(e -> !e.getFlowId().equals(flowId)).map(e -> this.mapGroupPathFlowDto(e, true, primaryIntersectionComputer)).collect(Collectors.toList());
if (flow.isAllocateProtectedPath()) {
IntersectionComputer protectedIntersectionComputer = new IntersectionComputer(flow.getFlowId(), flow.getProtectedForwardPathId(), flow.getProtectedReversePathId(), flowPathsInGroup);
// target flow protected path
targetFlowDtoBuilder.protectedPath(FlowProtectedPathDto.builder().forwardPath(buildPathFromFlow(flow, flow.getProtectedForwardPath())).reversePath(buildPathFromFlow(flow, flow.getProtectedReversePath())).segmentsStats(protectedIntersectionComputer.getOverlappingStats()).build());
// other flows in the the group
List<FlowPathDto> protectedPathPayloads = flowsInGroup.stream().filter(e -> !e.getFlowId().equals(flowId)).map(e -> this.mapGroupPathFlowDto(e, false, protectedIntersectionComputer)).collect(Collectors.toList());
payloads = union(payloads, protectedPathPayloads);
}
payloads.add(targetFlowDtoBuilder.build());
return payloads;
}
}
Aggregations