use of org.openkilda.wfm.error.FlowNotFoundException 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;
}
}
use of org.openkilda.wfm.error.FlowNotFoundException in project open-kilda by telstra.
the class FlowOperationsBolt method processFlowReadRequest.
@TimedExecution("flow_read")
private List<FlowResponse> processFlowReadRequest(FlowReadRequest readRequest) {
try {
String flowId = readRequest.getFlowId();
Flow flow = flowOperationsService.getFlow(flowId);
FlowStats flowStats = flowOperationsService.getFlowStats(flowId);
FlowResponse response = flowOperationsService.buildFlowResponse(flow, flowStats);
return Collections.singletonList(response);
} catch (FlowNotFoundException e) {
throw new MessageException(ErrorType.NOT_FOUND, "Can not get flow: " + e.getMessage(), "Flow not found");
} catch (Exception e) {
log.error("Can not get flow", e);
throw new MessageException(ErrorType.INTERNAL_ERROR, "Can not get flow", "Internal Error");
}
}
use of org.openkilda.wfm.error.FlowNotFoundException in project open-kilda by telstra.
the class FlowOperationsBolt method processFlowConnectedDeviceRequest.
private List<FlowConnectedDevicesResponse> processFlowConnectedDeviceRequest(FlowConnectedDeviceRequest request) {
Collection<SwitchConnectedDevice> devices;
try {
devices = flowOperationsService.getFlowConnectedDevice(request.getFlowId()).stream().filter(device -> request.getSince().isBefore(device.getTimeLastSeen()) || request.getSince().equals(device.getTimeLastSeen())).collect(Collectors.toList());
} catch (FlowNotFoundException e) {
throw new MessageException(ErrorType.NOT_FOUND, e.getMessage(), "Could not get connected devices for non existent flow");
}
FlowConnectedDevicesResponse response = new FlowConnectedDevicesResponse(new TypedConnectedDevicesDto(new ArrayList<>(), new ArrayList<>()), new TypedConnectedDevicesDto(new ArrayList<>(), new ArrayList<>()));
for (SwitchConnectedDevice device : devices) {
ConnectedDeviceDto deviceDto = ConnectedDeviceMapper.INSTANCE.mapSwitchDeviceToFlowDeviceDto(device);
if (device.getSource() == null) {
log.warn("Switch Connected Device {} has Flow ID {} but has no 'source' property.", device, device.getFlowId());
} else if (device.getSource()) {
if (device.getType() == LLDP) {
response.getSource().getLldp().add(deviceDto);
} else if (device.getType() == ARP) {
response.getSource().getArp().add(deviceDto);
}
} else {
if (device.getType() == LLDP) {
response.getDestination().getLldp().add(deviceDto);
} else if (device.getType() == ARP) {
response.getDestination().getArp().add(deviceDto);
}
}
}
return Collections.singletonList(response);
}
Aggregations