Search in sources :

Example 1 with ResoponseAtom

use of com.chinaunicom.etcd.v2.model.ResoponseAtom in project mesosFramework by zhizuqiu.

the class EtcdService method getNodes.

/**
 * 从请求队列中获取请求
 *
 * @param logTime   任务标识
 * @param queuePath 队列路径
 * @return 返回请求节点,如果不存在第一个请求,返回null
 */
public List<Node> getNodes(Long logTime, String queuePath) {
    try {
        ResoponseAtom result = etcd.getInOdrderKeys(queuePath);
        logger.debug("[" + logTime + "]" + "getNodes");
        List<Node> nodes = result.getNode().getNodes();
        if (nodes != null && nodes.size() > 0) {
            logger.info("[" + logTime + "]" + "getNodes size:" + nodes.size());
            return nodes;
        }
    } catch (ClientException e) {
        logger.error("[" + logTime + "]" + "getNodes->ClientException->" + e.getDetail().getMessage());
        return null;
    } catch (ServerException e) {
        logger.error("[" + logTime + "]" + "getNodes->ServerException->" + e.getDetail().getMessage());
        return null;
    } catch (Exception e) {
        logger.error("[" + logTime + "]" + "getNodes->Exception->" + e.getMessage());
        return null;
    }
    return new ArrayList<>();
}
Also used : ServerException(com.chinaunicom.etcd.v2.exception.ServerException) ResponseNode(com.chinaunicom.etcd.v2.model.ResponseNode) Node(com.chinaunicom.etcd.v2.model.Node) ArrayList(java.util.ArrayList) ClientException(com.chinaunicom.etcd.v2.exception.ClientException) ResoponseAtom(com.chinaunicom.etcd.v2.model.ResoponseAtom) JsonSyntaxException(com.google.gson.JsonSyntaxException) ClientException(com.chinaunicom.etcd.v2.exception.ClientException) ServerException(com.chinaunicom.etcd.v2.exception.ServerException)

Example 2 with ResoponseAtom

use of com.chinaunicom.etcd.v2.model.ResoponseAtom in project mesosFramework by zhizuqiu.

the class EtcdService method getFirstNode.

/**
 * 从请求队列中获取第一个请求
 *
 * @param logTime   任务标识
 * @param queuePath 队列路径
 * @return 返回请求节点,如果不存在第一个请求,返回null
 */
public Node getFirstNode(Long logTime, String queuePath) {
    Node requestNode = null;
    try {
        ResoponseAtom result = etcd.getInOdrderKeys(queuePath);
        logger.debug("[" + logTime + "]" + "从请求队列中获取请求成功");
        List<Node> nodes = result.getNode().getNodes();
        if (nodes != null && nodes.size() > 0) {
            requestNode = nodes.get(0);
            logger.info("[" + logTime + "]" + "当前队列中请求数:" + nodes.size());
        }
    } catch (ClientException e) {
        logger.error("[" + logTime + "]" + "从请求队列中获取请求失败->请求无效->" + e.getDetail().getMessage());
    } catch (ServerException e) {
        logger.error("[" + logTime + "]" + "从请求队列中获取请求失败->服务器异常->" + e.getMessage());
    } catch (Exception e) {
        logger.error("[" + logTime + "]" + "从请求队列中获取请求失败->其他异常->" + e.getMessage());
    }
    return requestNode;
}
Also used : ServerException(com.chinaunicom.etcd.v2.exception.ServerException) ResponseNode(com.chinaunicom.etcd.v2.model.ResponseNode) Node(com.chinaunicom.etcd.v2.model.Node) ClientException(com.chinaunicom.etcd.v2.exception.ClientException) ResoponseAtom(com.chinaunicom.etcd.v2.model.ResoponseAtom) JsonSyntaxException(com.google.gson.JsonSyntaxException) ClientException(com.chinaunicom.etcd.v2.exception.ClientException) ServerException(com.chinaunicom.etcd.v2.exception.ServerException)

Aggregations

ClientException (com.chinaunicom.etcd.v2.exception.ClientException)2 ServerException (com.chinaunicom.etcd.v2.exception.ServerException)2 Node (com.chinaunicom.etcd.v2.model.Node)2 ResoponseAtom (com.chinaunicom.etcd.v2.model.ResoponseAtom)2 ResponseNode (com.chinaunicom.etcd.v2.model.ResponseNode)2 JsonSyntaxException (com.google.gson.JsonSyntaxException)2 ArrayList (java.util.ArrayList)1