Search in sources :

Example 1 with ResponseServerDeviceListBean

use of com.huawei.esight.service.bean.ResponseServerDeviceListBean in project Server_Management_Plugin_vRealize by Huawei.

the class ESightServiceImpl method getServerDeviceList.

@Override
public List<ServerDeviceBean> getServerDeviceList(String servertype) {
    GetServerDeviceApi<String> api = new GetServerDeviceApi<>(esightServer, openIdProvider);
    int pageNo = 1;
    List<ServerDeviceBean> result = new ArrayList<>();
    // 分页读取所有数据
    while (true) {
        String response = api.doCall(servertype, pageNo + "", Constant.PAGE_SIZE, String.class);
        if (logger.isInfoEnabled()) {
            logger.info("Json string for server type = '" + servertype + "', pageNo='" + pageNo + "' is :  " + response);
        }
        ResponseServerDeviceListBean bean = ConvertUtils.json2Object(response, ResponseServerDeviceListBean.class);
        if (bean == null) {
            break;
        }
        // 分页数据保存到result
        result.addAll(bean.getData());
        if (bean.getTotalPage() <= pageNo) {
            break;
        }
        pageNo++;
    }
    // 将子服务器数据保存到result
    List<ServerDeviceBean> childList = new ArrayList<>();
    for (ServerDeviceBean bean : result) {
        for (ChildBladeBean child : bean.getChildBlades()) {
            ServerDeviceBean deviceBean = new ServerDeviceBean();
            deviceBean.setDn(child.getDn());
            deviceBean.setIpAddress(child.getIpAddress());
            deviceBean.setVersion(child.getVersion());
            deviceBean.setLocation(child.getLocation());
            deviceBean.setChildBlade(true);
            childList.add(deviceBean);
        }
    }
    result.addAll(0, childList);
    // 结果排序
    Collections.sort(result, new ServerDeviceBean());
    return result;
}
Also used : ResponseServerDeviceListBean(com.huawei.esight.service.bean.ResponseServerDeviceListBean) ServerDeviceBean(com.huawei.esight.service.bean.ServerDeviceBean) GetServerDeviceApi(com.huawei.esight.api.rest.server.GetServerDeviceApi) ArrayList(java.util.ArrayList) ChildBladeBean(com.huawei.esight.service.bean.ChildBladeBean)

Aggregations

GetServerDeviceApi (com.huawei.esight.api.rest.server.GetServerDeviceApi)1 ChildBladeBean (com.huawei.esight.service.bean.ChildBladeBean)1 ResponseServerDeviceListBean (com.huawei.esight.service.bean.ResponseServerDeviceListBean)1 ServerDeviceBean (com.huawei.esight.service.bean.ServerDeviceBean)1 ArrayList (java.util.ArrayList)1