use of org.openkilda.messaging.nbtopology.request.GetSwitchConnectedDevicesRequest 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);
}
use of org.openkilda.messaging.nbtopology.request.GetSwitchConnectedDevicesRequest in project open-kilda by telstra.
the class SwitchServiceImpl method getSwitchConnectedDevices.
@Override
public CompletableFuture<SwitchConnectedDevicesResponse> getSwitchConnectedDevices(SwitchId switchId, Instant since) {
logger.info("Get connected devices for switch {} since {}", switchId, since);
GetSwitchConnectedDevicesRequest request = new GetSwitchConnectedDevicesRequest(switchId, since);
CommandMessage message = new CommandMessage(request, System.currentTimeMillis(), RequestCorrelationId.getId(), Destination.WFM);
return messagingChannel.sendAndGet(nbworkerTopic, message).thenApply(org.openkilda.messaging.nbtopology.response.SwitchConnectedDevicesResponse.class::cast).thenApply(connectedDeviceMapper::map);
}
Aggregations