Search in sources :

Example 1 with ConnectedDeviceDto

use of org.openkilda.messaging.nbtopology.response.ConnectedDeviceDto 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);
}
Also used : FlowNotFoundException(org.openkilda.wfm.error.FlowNotFoundException) ConnectedDeviceDto(org.openkilda.messaging.nbtopology.response.ConnectedDeviceDto) MessageException(org.openkilda.messaging.error.MessageException) ArrayList(java.util.ArrayList) TypedConnectedDevicesDto(org.openkilda.messaging.nbtopology.response.TypedConnectedDevicesDto) FlowConnectedDevicesResponse(org.openkilda.messaging.nbtopology.response.FlowConnectedDevicesResponse) SwitchConnectedDevice(org.openkilda.model.SwitchConnectedDevice)

Aggregations

ArrayList (java.util.ArrayList)1 MessageException (org.openkilda.messaging.error.MessageException)1 ConnectedDeviceDto (org.openkilda.messaging.nbtopology.response.ConnectedDeviceDto)1 FlowConnectedDevicesResponse (org.openkilda.messaging.nbtopology.response.FlowConnectedDevicesResponse)1 TypedConnectedDevicesDto (org.openkilda.messaging.nbtopology.response.TypedConnectedDevicesDto)1 SwitchConnectedDevice (org.openkilda.model.SwitchConnectedDevice)1 FlowNotFoundException (org.openkilda.wfm.error.FlowNotFoundException)1