use of org.openkilda.messaging.info.stats.PortStatusData in project open-kilda by telstra.
the class RecordHandler method doPortsCommandDataRequest.
private void doPortsCommandDataRequest(Set<SwitchId> scope, PortsCommandData payload, String correlationId) {
ISwitchManager switchManager = context.getModuleContext().getServiceImpl(ISwitchManager.class);
try {
logger.info("Getting ports data. Requester: {}", payload.getRequester());
Map<DatapathId, IOFSwitch> allSwitchMap = context.getSwitchManager().getAllSwitchMap(true);
for (Map.Entry<DatapathId, IOFSwitch> entry : allSwitchMap.entrySet()) {
SwitchId switchId = new SwitchId(entry.getKey().toString());
if (!scope.contains(switchId)) {
continue;
}
try {
IOFSwitch sw = entry.getValue();
Set<PortStatusData> statuses = new HashSet<>();
for (OFPortDesc portDesc : switchManager.getPhysicalPorts(sw.getId())) {
statuses.add(new PortStatusData(portDesc.getPortNo().getPortNumber(), portDesc.isEnabled() ? PortStatus.UP : PortStatus.DOWN));
}
SwitchPortStatusData response = SwitchPortStatusData.builder().switchId(switchId).ports(statuses).requester(payload.getRequester()).build();
InfoMessage infoMessage = new InfoMessage(response, System.currentTimeMillis(), correlationId);
getKafkaProducer().sendMessageAndTrack(context.getKafkaStatsTopic(), infoMessage);
} catch (Exception e) {
logger.error("Could not get port stats data for switch '{}' with error '{}'", switchId, e.getMessage(), e);
}
}
} catch (Exception e) {
logger.error("Could not get port data for stats '{}'", e.getMessage(), e);
}
}
Aggregations