use of com.huawei.esight.service.bean.ServerDeviceBean in project Server_Management_Plugin_vRealize by Huawei.
the class ESightAdapter method collectResourceDataFromESight.
/**
* 调用eSight REST API采集数据.
*
* @param host eSight服务器IP
* @return ResourceKey列表
*/
private List<ResourceKey> collectResourceDataFromESight(String host) {
List<ResourceKey> allResourceList = new ArrayList<>();
String[] serverTypes = new String[] { Constant.TREE_SERVER_TYPE_RACK, Constant.TREE_SERVER_TYPE_BLADE, Constant.TREE_SERVER_TYPE_HIGHDENSITY, Constant.TREE_SERVER_TYPE_KUNLUN };
// 服务器类型keyList
List<ResourceKey> serverTypeKeyList = new ArrayList<>();
for (String serverType : serverTypes) {
List<ServerDeviceBean> serverList = service.getServerDeviceList(serverType);
if (serverList.isEmpty()) {
continue;
}
// 收集 devices key
List<ResourceKey> serverDeviceKeyList = new ArrayList<>();
// 服务器分类
ResourceKey serverTypeKey = new ResourceKey(serverType, Constant.KIND_SERVER_TYPES, getAdapterKind());
ResourceIdentifierConfig ipIdentifier = new ResourceIdentifierConfig(Constant.ATTR_ID, host + serverType, true);
serverTypeKey.addIdentifier(ipIdentifier);
List<String> serverTypeChildHealthList = new ArrayList<>();
allResourceList.add(serverTypeKey);
serverTypeKeyList.add(serverTypeKey);
for (ServerDeviceBean deviceBean : serverList) {
setConfig(host, allResourceList, serverDeviceKeyList, serverTypeChildHealthList, deviceBean);
}
// 设置服务器类型(如rack, blade)和server device关联关系
relationshipsByResource.put(serverTypeKey, serverDeviceKeyList);
setHealStatus4GroupObject(serverTypeKey, Constant.ATTR_HEALTHSTATE, serverTypeChildHealthList);
logger.error(serverList.size() + " servers of type = " + serverType + " created.");
}
ResourceKey serverGroupKey = new ResourceKey(host, Constant.KIND_HOST_INSTANCE, getAdapterKind());
long timestamp = System.currentTimeMillis();
List<MetricData> metricDataList = new ArrayList<>();
// 设置healthState为正常状态
metricDataList.add(new MetricData(new MetricKey(false, Constant.ATTR_HEALTHSTATE), timestamp, ConvertUtils.convertHealthState(0)));
metricsByResource.put(serverGroupKey, metricDataList);
// eSight server IP和serverTypes的对应关系
relationshipsByResource.put(serverGroupKey, serverTypeKeyList);
allResourceList.add(serverGroupKey);
return allResourceList;
}
use of com.huawei.esight.service.bean.ServerDeviceBean 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;
}
use of com.huawei.esight.service.bean.ServerDeviceBean in project Server_Management_Plugin_vRealize by Huawei.
the class ESightServiceImplTest method testGetServerDetail.
/**
* 测试获取服务器信息方法
*/
@Test
public void testGetServerDetail() {
ESightService service = new ESightServiceImpl();
service.setLogger(Logger.getLogger(ESightServiceImpl.class));
InputStream inputStream = null;
try {
Properties configProperties = new Properties();
inputStream = this.getClass().getClassLoader().getResourceAsStream("unit-test.properties");
configProperties.load(inputStream);
String host = configProperties.getProperty("test.esight.ip");
int port = Integer.parseInt(configProperties.getProperty("test.esight.port"));
String account = configProperties.getProperty("test.esight.account");
String eSightCode = configProperties.getProperty("test.esight.code");
String openid = service.login(host, port, account, eSightCode);
Assert.assertNotNull(openid);
if (openid == null || openid.isEmpty()) {
logger.error("Login FAIL!");
fail("Login FAIL!");
}
String[] serverTypes = new String[] { "rack", "blade", "highdensity", "kunlun" };
for (String serverType : serverTypes) {
List<ServerDeviceBean> serverList = service.getServerDeviceList(serverType);
Assert.assertNotNull(serverList);
for (ServerDeviceBean bean : serverList) {
ServerDeviceDetailBean detailBean = service.getServerDetail(bean.getDn());
if (detailBean == null) {
logger.error("faile to fetch detail for device with dn ='" + bean.getDn() + "'");
}
Assert.assertNotNull(detailBean);
}
}
service.logout(openid);
logger.info("All Junit test PASSED!");
} catch (IOException e) {
logger.error("Call API ERROR", e);
fail("Excetion throw found!");
} finally {
if (inputStream != null) {
try {
inputStream.close();
} catch (IOException e) {
logger.error("close stream fail", e);
}
}
}
}
Aggregations