Search in sources :

Example 6 with NodeVo

use of com.alibaba.csp.sentinel.command.vo.NodeVo in project spring-boot-student by wyh-spring-ecosystem-student.

the class ResourceVo method fromNodeVoList.

public static List<ResourceVo> fromNodeVoList(List<NodeVo> nodeVos) {
    if (nodeVos == null) {
        return null;
    }
    List<ResourceVo> list = new ArrayList<>();
    for (NodeVo nodeVo : nodeVos) {
        ResourceVo vo = new ResourceVo();
        vo.parentTtId = nodeVo.getParentId();
        vo.ttId = nodeVo.getId();
        vo.resource = nodeVo.getResource();
        vo.threadNum = nodeVo.getThreadNum();
        vo.passQps = nodeVo.getPassQps();
        vo.blockQps = nodeVo.getBlockQps();
        vo.totalQps = nodeVo.getTotalQps();
        vo.averageRt = nodeVo.getAverageRt();
        vo.exceptionQps = nodeVo.getExceptionQps();
        vo.oneMinutePass = nodeVo.getOneMinutePass();
        vo.oneMinuteBlock = nodeVo.getOneMinuteBlock();
        vo.oneMinuteException = nodeVo.getOneMinuteException();
        vo.oneMinuteTotal = nodeVo.getOneMinuteTotal();
        list.add(vo);
    }
    return list;
}
Also used : ArrayList(java.util.ArrayList) NodeVo(com.alibaba.csp.sentinel.command.vo.NodeVo)

Example 7 with NodeVo

use of com.alibaba.csp.sentinel.command.vo.NodeVo in project XHuiCloud by sindaZeng.

the class ResourceController method fetchResourceChainListOfMachine.

/**
 * Fetch real time statistics info of the machine.
 *
 * @param ip        ip to fetch
 * @param port      port of the ip
 * @param type      one of [root, default, cluster], 'root' means fetching from tree root node, 'default' means
 *                  fetching from tree default node, 'cluster' means fetching from cluster node.
 * @param searchKey key to search
 * @return node statistics info.
 */
@GetMapping("/machineResource.json")
public Result<List<ResourceVo>> fetchResourceChainListOfMachine(String ip, Integer port, String type, String searchKey) {
    if (StringUtil.isEmpty(ip) || port == null) {
        return Result.ofFail(-1, "invalid param, give ip, port");
    }
    final String ROOT = "root";
    final String DEFAULT = "default";
    if (StringUtil.isEmpty(type)) {
        type = ROOT;
    }
    if (ROOT.equalsIgnoreCase(type) || DEFAULT.equalsIgnoreCase(type)) {
        List<NodeVo> nodeVos = httpFetcher.fetchResourceOfMachine(ip, port, type);
        if (nodeVos == null) {
            return Result.ofSuccess(null);
        }
        ResourceTreeNode treeNode = ResourceTreeNode.fromNodeVoList(nodeVos);
        treeNode.searchIgnoreCase(searchKey);
        return Result.ofSuccess(ResourceVo.fromResourceTreeNode(treeNode));
    } else {
        // Normal (cluster node).
        List<NodeVo> nodeVos = httpFetcher.fetchClusterNodeOfMachine(ip, port, true);
        if (nodeVos == null) {
            return Result.ofSuccess(null);
        }
        if (StringUtil.isNotEmpty(searchKey)) {
            nodeVos = nodeVos.stream().filter(node -> node.getResource().toLowerCase().contains(searchKey.toLowerCase())).collect(Collectors.toList());
        }
        return Result.ofSuccess(ResourceVo.fromNodeVoList(nodeVos));
    }
}
Also used : NodeVo(com.alibaba.csp.sentinel.command.vo.NodeVo) ResourceTreeNode(com.alibaba.csp.sentinel.dashboard.domain.ResourceTreeNode) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 8 with NodeVo

use of com.alibaba.csp.sentinel.command.vo.NodeVo in project XHuiCloud by sindaZeng.

the class ResourceTreeNode method fromNodeVoList.

public static ResourceTreeNode fromNodeVoList(List<NodeVo> nodeVos) {
    if (nodeVos == null || nodeVos.isEmpty()) {
        return null;
    }
    ResourceTreeNode root = null;
    Map<String, ResourceTreeNode> map = new HashMap<>();
    for (NodeVo vo : nodeVos) {
        ResourceTreeNode node = fromNodeVo(vo);
        map.put(node.id, node);
        // real root
        if (node.parentId == null || node.parentId.isEmpty()) {
            root = node;
        } else if (map.containsKey(node.parentId)) {
            map.get(node.parentId).children.add(node);
        } else {
        // impossible
        }
    }
    return root;
}
Also used : HashMap(java.util.HashMap) NodeVo(com.alibaba.csp.sentinel.command.vo.NodeVo)

Example 9 with NodeVo

use of com.alibaba.csp.sentinel.command.vo.NodeVo in project RuoYi-Cloud-Plus by JavaLionLi.

the class ResourceController method fetchResourceChainListOfMachine.

/**
 * Fetch real time statistics info of the machine.
 *
 * @param ip        ip to fetch
 * @param port      port of the ip
 * @param type      one of [root, default, cluster], 'root' means fetching from tree root node, 'default' means
 *                  fetching from tree default node, 'cluster' means fetching from cluster node.
 * @param searchKey key to search
 * @return node statistics info.
 */
@GetMapping("/machineResource.json")
public Result<List<ResourceVo>> fetchResourceChainListOfMachine(String ip, Integer port, String type, String searchKey) {
    if (StringUtil.isEmpty(ip) || port == null) {
        return Result.ofFail(-1, "invalid param, give ip, port");
    }
    final String ROOT = "root";
    final String DEFAULT = "default";
    if (StringUtil.isEmpty(type)) {
        type = ROOT;
    }
    if (ROOT.equalsIgnoreCase(type) || DEFAULT.equalsIgnoreCase(type)) {
        List<NodeVo> nodeVos = httpFetcher.fetchResourceOfMachine(ip, port, type);
        if (nodeVos == null) {
            return Result.ofSuccess(null);
        }
        ResourceTreeNode treeNode = ResourceTreeNode.fromNodeVoList(nodeVos);
        treeNode.searchIgnoreCase(searchKey);
        return Result.ofSuccess(ResourceVo.fromResourceTreeNode(treeNode));
    } else {
        // Normal (cluster node).
        List<NodeVo> nodeVos = httpFetcher.fetchClusterNodeOfMachine(ip, port, true);
        if (nodeVos == null) {
            return Result.ofSuccess(null);
        }
        if (StringUtil.isNotEmpty(searchKey)) {
            nodeVos = nodeVos.stream().filter(node -> node.getResource().toLowerCase().contains(searchKey.toLowerCase())).collect(Collectors.toList());
        }
        return Result.ofSuccess(ResourceVo.fromNodeVoList(nodeVos));
    }
}
Also used : NodeVo(com.alibaba.csp.sentinel.command.vo.NodeVo) ResourceTreeNode(com.alibaba.csp.sentinel.dashboard.domain.ResourceTreeNode) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 10 with NodeVo

use of com.alibaba.csp.sentinel.command.vo.NodeVo in project Sentinel by alibaba.

the class ResourceTreeNode method fromNodeVoList.

public static ResourceTreeNode fromNodeVoList(List<NodeVo> nodeVos) {
    if (nodeVos == null || nodeVos.isEmpty()) {
        return null;
    }
    ResourceTreeNode root = null;
    Map<String, ResourceTreeNode> map = new HashMap<>();
    for (NodeVo vo : nodeVos) {
        ResourceTreeNode node = fromNodeVo(vo);
        map.put(node.id, node);
        // real root
        if (node.parentId == null || node.parentId.isEmpty()) {
            root = node;
        } else if (map.containsKey(node.parentId)) {
            map.get(node.parentId).children.add(node);
        } else {
        // impossible
        }
    }
    return root;
}
Also used : HashMap(java.util.HashMap) NodeVo(com.alibaba.csp.sentinel.command.vo.NodeVo)

Aggregations

NodeVo (com.alibaba.csp.sentinel.command.vo.NodeVo)16 ResourceTreeNode (com.alibaba.csp.sentinel.dashboard.domain.ResourceTreeNode)5 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)5 GetMapping (org.springframework.web.bind.annotation.GetMapping)5 DefaultNode (com.alibaba.csp.sentinel.node.DefaultNode)1 Node (com.alibaba.csp.sentinel.node.Node)1