use of org.openkilda.messaging.nbtopology.response.FlowConnectedDevicesResponse 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