Search in sources :

Example 1 with PortInfo

use of org.openkilda.model.PortInfo 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;
}
Also used : PortInfo(org.openkilda.model.PortInfo) Port(org.openkilda.integration.source.store.dto.Port) ArrayList(java.util.ArrayList) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) IntegrationException(org.openkilda.integration.exception.IntegrationException) SwitchPortStats(org.openkilda.model.SwitchPortStats)

Example 2 with PortInfo

use of org.openkilda.model.PortInfo in project open-kilda by telstra.

the class StatsService method getPortInfo.

private List<PortInfo> getPortInfo(final Map<String, Map<String, Double>> portStatsByPortNo) {
    List<PortInfo> portInfos = new ArrayList<PortInfo>();
    for (Map.Entry<String, Map<String, Double>> portStats : portStatsByPortNo.entrySet()) {
        PortInfo portInfo = new PortInfo();
        portInfo.setPortNumber(portStats.getKey());
        portInfo.setAssignmenttype("PORT");
        portInfo.setStatus(Status.DOWN);
        if (portStats.getValue().containsKey("state")) {
            portInfo.setStatus(portStats.getValue().get("state") == 0 ? Status.DOWN : Status.UP);
            portStats.getValue().remove("state");
        }
        portInfo.setStats(portStats.getValue());
        portInfos.add(portInfo);
    }
    return portInfos;
}
Also used : PortInfo(org.openkilda.model.PortInfo) ArrayList(java.util.ArrayList) HashMap(java.util.HashMap) Map(java.util.Map)

Example 3 with PortInfo

use of org.openkilda.model.PortInfo 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);
    }
}
Also used : PortInfo(org.openkilda.model.PortInfo) PortDiscrepancy(org.openkilda.model.PortDiscrepancy) Port(org.openkilda.integration.source.store.dto.Port) ArrayList(java.util.ArrayList)

Example 4 with PortInfo

use of org.openkilda.model.PortInfo in project open-kilda by telstra.

the class PortConverter method toPortsInfo.

/**
 * To ports info.
 *
 * @param jsonObject the json object
 * @param switchId the switch id
 * @return the list
 * @throws JsonParseException the json parse exception
 * @throws JsonMappingException the json mapping exception
 * @throws IOException Signals that an I/O exception has occurred.
 */
public static List<PortInfo> toPortsInfo(final JSONObject jsonObject, final String switchId) throws JsonParseException, JsonMappingException, IOException {
    List<PortInfo> ports = new ArrayList<PortInfo>();
    if (jsonObject != null) {
        Object object = jsonObject.get(switchId);
        if (object != null) {
            String val = JSONValue.toJSONString(object);
            PortsDetail portsDetail = JsonUtil.toObject(val, PortsDetail.class);
            List<PortDetail> portDetailList = portsDetail.getPortDetail();
            if (portDetailList != null && !portDetailList.isEmpty()) {
                ports = getPortsInfo(portDetailList, switchId, ports);
            }
        }
    }
    return ports;
}
Also used : PortInfo(org.openkilda.model.PortInfo) PortDetail(org.openkilda.integration.model.PortDetail) ArrayList(java.util.ArrayList) JSONObject(org.json.simple.JSONObject) PortsDetail(org.openkilda.integration.model.PortsDetail)

Example 5 with PortInfo

use of org.openkilda.model.PortInfo in project open-kilda by telstra.

the class PortConverter method getPortsInfo.

/**
 * Gets the ports info.
 *
 * @param portsDetail the ports detail
 * @param key the key
 * @param switchPortsInfoList the switch ports info list
 * @return the ports info
 */
private static List<PortInfo> getPortsInfo(final List<PortDetail> portsDetail, final String key, final List<PortInfo> switchPortsInfoList) {
    for (PortDetail portDetail : portsDetail) {
        if (!portDetail.getPortNumber().equalsIgnoreCase("local")) {
            PortInfo info = setPortInfo(key, portDetail);
            switchPortsInfoList.add(info);
        }
    }
    Collections.sort(switchPortsInfoList);
    return switchPortsInfoList;
}
Also used : PortInfo(org.openkilda.model.PortInfo) PortDetail(org.openkilda.integration.model.PortDetail)

Aggregations

PortInfo (org.openkilda.model.PortInfo)7 ArrayList (java.util.ArrayList)4 PortDetail (org.openkilda.integration.model.PortDetail)2 Port (org.openkilda.integration.source.store.dto.Port)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 JSONObject (org.json.simple.JSONObject)1 IntegrationException (org.openkilda.integration.exception.IntegrationException)1 PortsDetail (org.openkilda.integration.model.PortsDetail)1 IslLink (org.openkilda.integration.model.response.IslLink)1 IslPath (org.openkilda.integration.model.response.IslPath)1 PortDiscrepancy (org.openkilda.model.PortDiscrepancy)1 SwitchPortStats (org.openkilda.model.SwitchPortStats)1