Search in sources :

Example 1 with NodeVo

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

the class FetchJsonTreeCommandHandler method visit.

/**
 * Preorder traversal.
 */
private void visit(DefaultNode node, List<NodeVo> results, String parentId) {
    NodeVo vo = NodeVo.fromDefaultNode(node, parentId);
    results.add(vo);
    String id = vo.getId();
    for (Node n : node.getChildList()) {
        visit((DefaultNode) n, results, id);
    }
}
Also used : DefaultNode(com.alibaba.csp.sentinel.node.DefaultNode) Node(com.alibaba.csp.sentinel.node.Node) NodeVo(com.alibaba.csp.sentinel.command.vo.NodeVo)

Example 2 with NodeVo

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

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 3 with NodeVo

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

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 4 with NodeVo

use of com.alibaba.csp.sentinel.command.vo.NodeVo in project pig by pig-mesh.

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 5 with NodeVo

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

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)

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