use of org.openkilda.integration.source.store.dto.Port in project open-kilda by telstra.
the class StatsService method getSwitchPortsStats.
/**
* Gets the switch ports stats.
*
* @param startDate
* the start date
* @param endDate
* the end date
* @param downSample
* the down sample
* @param switchId
* the switch id
* @return the switch ports stats
*/
public List<PortInfo> getSwitchPortsStats(String startDate, String endDate, String downSample, String switchId) {
List<String> switchIds = Arrays.asList(switchId);
List<SwitchPortStats> switchPortStats = new ArrayList<SwitchPortStats>();
try {
String result = statsIntegrationService.getStats(startDate, endDate, downSample, switchIds, null, null, null, null, null, null, StatsType.SWITCH_PORT, null, null);
ObjectMapper mapper = new ObjectMapper();
switchPortStats = mapper.readValue(result, TypeFactory.defaultInstance().constructCollectionLikeType(List.class, SwitchPortStats.class));
} catch (Exception e) {
LOGGER.error("Error occurred while retriving switch port stats", e);
}
List<PortInfo> portStats = getSwitchPortStatsReport(switchPortStats, switchId);
if (storeService.getSwitchStoreConfig().getUrls().size() > 0) {
if (!CollectionUtil.isEmpty(switchIds)) {
try {
List<Port> inventoryPorts = switchStoreService.getSwitchPort(IoUtil.switchCodeToSwitchId(switchIds.get(0)));
processInventoryPorts(portStats, inventoryPorts);
} catch (Exception ex) {
LOGGER.error("Error occurred while retriving switch ports stats for inventory", ex);
}
}
}
return portStats;
}
use of org.openkilda.integration.source.store.dto.Port in project open-kilda by telstra.
the class StatsService method processInventoryPorts.
private void processInventoryPorts(final List<PortInfo> portStats, final List<Port> inventoryPorts) {
if (!CollectionUtil.isEmpty(inventoryPorts)) {
List<PortInfo> discrepancyPorts = new ArrayList<PortInfo>();
for (Port port : inventoryPorts) {
int index = -1;
for (PortInfo portInfo : portStats) {
if (port.getPortNumber() == Integer.parseInt(portInfo.getPortNumber())) {
index = portStats.indexOf(portInfo);
break;
}
}
if (index >= 0) {
PortInfo portInfo = portStats.get(index);
portConverter.appendInventoryInfo(portInfo, port);
PortDiscrepancy portDiscrepancy = new PortDiscrepancy();
portDiscrepancy.setControllerDiscrepancy(false);
if (!portInfo.getAssignmenttype().equalsIgnoreCase(port.getAssignmentType())) {
portDiscrepancy.setAssignmentType(true);
portDiscrepancy.setControllerAssignmentType(portInfo.getAssignmenttype());
portDiscrepancy.setInventoryAssignmentType(port.getAssignmentType());
}
portInfo.setDiscrepancy(portDiscrepancy);
} else {
PortInfo portInfoObj = new PortInfo();
portConverter.toPortInfo(portInfoObj, port);
discrepancyPorts.add(portInfoObj);
}
}
for (PortInfo portInfo : portStats) {
boolean flag = false;
for (Port port : inventoryPorts) {
if (port.getPortNumber() == Integer.parseInt(portInfo.getPortNumber())) {
flag = true;
break;
}
}
if (!flag) {
PortDiscrepancy discrepancy = new PortDiscrepancy();
discrepancy.setInventoryDiscrepancy(true);
discrepancy.setControllerDiscrepancy(false);
discrepancy.setAssignmentType(true);
discrepancy.setControllerAssignmentType(portInfo.getAssignmenttype());
discrepancy.setInventoryAssignmentType(null);
portInfo.setDiscrepancy(discrepancy);
}
}
portStats.addAll(discrepancyPorts);
}
}
Aggregations