use of com.huawei.esight.api.rest.server.GetServerDeviceApi 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;
}
Aggregations