Search in sources :

Example 1 with PortDetail

use of org.openkilda.integration.model.PortDetail 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 2 with PortDetail

use of org.openkilda.integration.model.PortDetail 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

PortDetail (org.openkilda.integration.model.PortDetail)2 PortInfo (org.openkilda.model.PortInfo)2 ArrayList (java.util.ArrayList)1 JSONObject (org.json.simple.JSONObject)1 PortsDetail (org.openkilda.integration.model.PortsDetail)1