Search in sources :

Example 1 with EsInfo

use of cn.exrick.manager.dto.EsInfo in project xmall by Exrick.

the class SearchItemServiceImpl method getEsInfo.

@Override
public EsInfo getEsInfo() {
    String healthUrl = "http://" + ES_CONNECT_IP + ":" + ES_NODE_CLIENT_PORT + "/_cluster/health";
    String countUrl = "http://" + ES_CONNECT_IP + ":" + ES_NODE_CLIENT_PORT + "/_count";
    String healthResult = HttpUtil.sendGet(healthUrl);
    String countResult = HttpUtil.sendGet(countUrl);
    if (StringUtils.isBlank(healthResult) || StringUtils.isBlank(countResult)) {
        throw new XmallException("连接集群失败,请检查ES运行状态");
    }
    EsInfo esInfo = new EsInfo();
    EsCount esCount = new EsCount();
    try {
        esInfo = new Gson().fromJson(healthResult, EsInfo.class);
        esCount = new Gson().fromJson(countResult, EsCount.class);
        esInfo.setCount(esCount.getCount());
    } catch (Exception e) {
        e.printStackTrace();
        throw new XmallException("获取ES信息出错");
    }
    return esInfo;
}
Also used : EsInfo(cn.exrick.manager.dto.EsInfo) Gson(com.google.gson.Gson) XmallException(cn.exrick.common.exception.XmallException) EsCount(cn.exrick.manager.dto.EsCount) XmallException(cn.exrick.common.exception.XmallException)

Aggregations

XmallException (cn.exrick.common.exception.XmallException)1 EsCount (cn.exrick.manager.dto.EsCount)1 EsInfo (cn.exrick.manager.dto.EsInfo)1 Gson (com.google.gson.Gson)1