Search in sources :

Example 1 with GetSwitchConnectedDevicesRequest

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);
}
Also used : OutputFieldsDeclarer(org.apache.storm.topology.OutputFieldsDeclarer) GetPortPropertiesRequest(org.openkilda.messaging.nbtopology.request.GetPortPropertiesRequest) KeyProvider(org.openkilda.wfm.share.utils.KeyProvider) FlowPath(org.openkilda.model.FlowPath) FlowOperationsService(org.openkilda.wfm.topology.nbworker.services.FlowOperationsService) DeactivateSwitchInfoData(org.openkilda.messaging.info.event.DeactivateSwitchInfoData) StreamType(org.openkilda.wfm.topology.nbworker.StreamType) SwitchLagPortResponse(org.openkilda.messaging.nbtopology.response.SwitchLagPortResponse) SwitchNotFoundException(org.openkilda.wfm.error.SwitchNotFoundException) LLDP(org.openkilda.model.ConnectedDeviceType.LLDP) MessageException(org.openkilda.messaging.error.MessageException) GetSwitchesRequest(org.openkilda.messaging.nbtopology.request.GetSwitchesRequest) ILinkOperationsServiceCarrier(org.openkilda.wfm.topology.nbworker.services.ILinkOperationsServiceCarrier) Map(java.util.Map) SwitchPatchRequest(org.openkilda.messaging.nbtopology.request.SwitchPatchRequest) DeleteSwitchResponse(org.openkilda.messaging.nbtopology.response.DeleteSwitchResponse) LagPortMapper(org.openkilda.wfm.share.mappers.LagPortMapper) PortMapper(org.openkilda.wfm.share.mappers.PortMapper) GetSwitchRequest(org.openkilda.messaging.nbtopology.request.GetSwitchRequest) SwitchPropertiesDto(org.openkilda.messaging.model.SwitchPropertiesDto) IslEndpoint(org.openkilda.model.IslEndpoint) IllegalSwitchStateException(org.openkilda.wfm.error.IllegalSwitchStateException) ActivateFlowMonitoringOnSwitchInfoData(org.openkilda.server42.control.messaging.flowrtt.ActivateFlowMonitoringOnSwitchInfoData) DeactivateIslMonitoringOnSwitchInfoData(org.openkilda.server42.control.messaging.islrtt.DeactivateIslMonitoringOnSwitchInfoData) IllegalSwitchPropertiesException(org.openkilda.wfm.error.IllegalSwitchPropertiesException) GetSwitchResponse(org.openkilda.messaging.nbtopology.response.GetSwitchResponse) Collection(java.util.Collection) Set(java.util.Set) InfoData(org.openkilda.messaging.info.InfoData) CommandContext(org.openkilda.wfm.CommandContext) PersistenceException(org.openkilda.persistence.exceptions.PersistenceException) Fields(org.apache.storm.tuple.Fields) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) SwitchOperationsService(org.openkilda.wfm.topology.nbworker.services.SwitchOperationsService) FlowRerouteRequest(org.openkilda.messaging.command.flow.FlowRerouteRequest) List(java.util.List) PortProperties(org.openkilda.model.PortProperties) TimedExecution(org.openkilda.wfm.share.metrics.TimedExecution) PortPropertiesPayload(org.openkilda.messaging.payload.switches.PortPropertiesPayload) Entry(java.util.Map.Entry) UpdateSwitchPropertiesRequest(org.openkilda.messaging.nbtopology.request.UpdateSwitchPropertiesRequest) BaseRequest(org.openkilda.messaging.nbtopology.request.BaseRequest) GetSwitchConnectedDevicesRequest(org.openkilda.messaging.nbtopology.request.GetSwitchConnectedDevicesRequest) ActivateIslMonitoringOnSwitchInfoData(org.openkilda.server42.control.messaging.islrtt.ActivateIslMonitoringOnSwitchInfoData) GetSwitchPropertiesRequest(org.openkilda.messaging.nbtopology.request.GetSwitchPropertiesRequest) SwitchPortConnectedDevicesDto(org.openkilda.messaging.nbtopology.response.SwitchPortConnectedDevicesDto) GetSwitchLagPortsRequest(org.openkilda.messaging.nbtopology.request.GetSwitchLagPortsRequest) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) SwitchValidateRequest(org.openkilda.messaging.command.switches.SwitchValidateRequest) Values(org.apache.storm.tuple.Values) Tuple(org.apache.storm.tuple.Tuple) SwitchConnectionsResponse(org.openkilda.messaging.nbtopology.response.SwitchConnectionsResponse) SwitchConnectedDeviceDto(org.openkilda.messaging.nbtopology.response.SwitchConnectedDeviceDto) PersistenceManager(org.openkilda.persistence.PersistenceManager) DeactivateFlowMonitoringOnSwitchInfoData(org.openkilda.server42.control.messaging.flowrtt.DeactivateFlowMonitoringOnSwitchInfoData) UpdateSwitchUnderMaintenanceRequest(org.openkilda.messaging.nbtopology.request.UpdateSwitchUnderMaintenanceRequest) Switch(org.openkilda.model.Switch) ConnectedDeviceMapper(org.openkilda.wfm.share.mappers.ConnectedDeviceMapper) ErrorType(org.openkilda.messaging.error.ErrorType) DeleteSwitchRequest(org.openkilda.messaging.nbtopology.request.DeleteSwitchRequest) Endpoint(org.openkilda.wfm.share.model.Endpoint) SwitchOperationsServiceCarrier(org.openkilda.wfm.topology.nbworker.services.SwitchOperationsServiceCarrier) ARP(org.openkilda.model.ConnectedDeviceType.ARP) SwitchPropertiesResponse(org.openkilda.messaging.nbtopology.response.SwitchPropertiesResponse) SwitchConnectionsRequest(org.openkilda.messaging.nbtopology.request.SwitchConnectionsRequest) GetAllSwitchPropertiesRequest(org.openkilda.messaging.nbtopology.request.GetAllSwitchPropertiesRequest) SwitchConnectedDevicesResponse(org.openkilda.messaging.nbtopology.response.SwitchConnectedDevicesResponse) SwitchId(org.openkilda.model.SwitchId) SwitchPropertiesNotFoundException(org.openkilda.wfm.error.SwitchPropertiesNotFoundException) Comparator(java.util.Comparator) Collections(java.util.Collections) SwitchConnectedDevice(org.openkilda.model.SwitchConnectedDevice) ArrayList(java.util.ArrayList) SwitchPortConnectedDevicesDto(org.openkilda.messaging.nbtopology.response.SwitchPortConnectedDevicesDto) SwitchConnectedDeviceDto(org.openkilda.messaging.nbtopology.response.SwitchConnectedDeviceDto) SwitchNotFoundException(org.openkilda.wfm.error.SwitchNotFoundException) MessageException(org.openkilda.messaging.error.MessageException) List(java.util.List) ArrayList(java.util.ArrayList) SwitchConnectedDevice(org.openkilda.model.SwitchConnectedDevice) SwitchConnectedDevicesResponse(org.openkilda.messaging.nbtopology.response.SwitchConnectedDevicesResponse)

Example 2 with GetSwitchConnectedDevicesRequest

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);
}
Also used : GetSwitchConnectedDevicesRequest(org.openkilda.messaging.nbtopology.request.GetSwitchConnectedDevicesRequest) CommandMessage(org.openkilda.messaging.command.CommandMessage)

Aggregations

GetSwitchConnectedDevicesRequest (org.openkilda.messaging.nbtopology.request.GetSwitchConnectedDevicesRequest)2 String.format (java.lang.String.format)1 Instant (java.time.Instant)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 Comparator (java.util.Comparator)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 OutputFieldsDeclarer (org.apache.storm.topology.OutputFieldsDeclarer)1 Fields (org.apache.storm.tuple.Fields)1 Tuple (org.apache.storm.tuple.Tuple)1 Values (org.apache.storm.tuple.Values)1 CommandMessage (org.openkilda.messaging.command.CommandMessage)1 FlowRerouteRequest (org.openkilda.messaging.command.flow.FlowRerouteRequest)1 SwitchValidateRequest (org.openkilda.messaging.command.switches.SwitchValidateRequest)1