Search in sources :

Example 1 with ServerDeviceBean

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;
}
Also used : ResourceIdentifierConfig(com.integrien.alive.common.adapter3.config.ResourceIdentifierConfig) ServerDeviceBean(com.huawei.esight.service.bean.ServerDeviceBean) ArrayList(java.util.ArrayList) ResourceKey(com.integrien.alive.common.adapter3.ResourceKey) MetricKey(com.integrien.alive.common.adapter3.MetricKey) MetricData(com.integrien.alive.common.adapter3.MetricData)

Example 2 with ServerDeviceBean

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;
}
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)

Example 3 with ServerDeviceBean

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);
            }
        }
    }
}
Also used : ServerDeviceBean(com.huawei.esight.service.bean.ServerDeviceBean) InputStream(java.io.InputStream) ServerDeviceDetailBean(com.huawei.esight.service.bean.ServerDeviceDetailBean) IOException(java.io.IOException) Properties(java.util.Properties) Test(org.junit.Test)

Aggregations

ServerDeviceBean (com.huawei.esight.service.bean.ServerDeviceBean)3 ArrayList (java.util.ArrayList)2 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 ServerDeviceDetailBean (com.huawei.esight.service.bean.ServerDeviceDetailBean)1 MetricData (com.integrien.alive.common.adapter3.MetricData)1 MetricKey (com.integrien.alive.common.adapter3.MetricKey)1 ResourceKey (com.integrien.alive.common.adapter3.ResourceKey)1 ResourceIdentifierConfig (com.integrien.alive.common.adapter3.config.ResourceIdentifierConfig)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 Properties (java.util.Properties)1 Test (org.junit.Test)1