use of org.openkilda.messaging.nbtopology.response.SwitchPortConnectedDevicesDto in project open-kilda by telstra.
the class SwitchOperationsBolt method getSwitchConnectedDevices.
private SwitchConnectedDevicesResponse getSwitchConnectedDevices(GetSwitchConnectedDevicesRequest request) {
Collection<SwitchConnectedDevice> devices;
try {
devices = switchOperationsService.getSwitchConnectedDevices(request.getSwitchId());
} catch (SwitchNotFoundException e) {
throw new MessageException(ErrorType.NOT_FOUND, e.getMessage(), "Could not get connected devices for non existent switch");
}
Map<Integer, List<SwitchConnectedDevice>> deviceByPort = devices.stream().filter(device -> request.getSince().isBefore(device.getTimeLastSeen()) || request.getSince().equals(device.getTimeLastSeen())).collect(Collectors.groupingBy(SwitchConnectedDevice::getPortNumber, Collectors.toList()));
List<SwitchPortConnectedDevicesDto> ports = new ArrayList<>();
for (Entry<Integer, List<SwitchConnectedDevice>> entry : deviceByPort.entrySet()) {
List<SwitchConnectedDeviceDto> lldpDevices = new ArrayList<>();
List<SwitchConnectedDeviceDto> arpDevices = new ArrayList<>();
for (SwitchConnectedDevice device : entry.getValue()) {
if (device.getType() == LLDP) {
lldpDevices.add(ConnectedDeviceMapper.INSTANCE.map(device));
} else if (device.getType() == ARP) {
arpDevices.add(ConnectedDeviceMapper.INSTANCE.map(device));
}
}
lldpDevices.sort(Comparator.comparing(o -> Instant.parse(o.getTimeLastSeen())));
arpDevices.sort(Comparator.comparing(o -> Instant.parse(o.getTimeLastSeen())));
ports.add(new SwitchPortConnectedDevicesDto(entry.getKey(), lldpDevices, arpDevices));
}
return new SwitchConnectedDevicesResponse(ports);
}
Aggregations