Search in sources :

Example 1 with ClusterServerStateVO

use of com.alibaba.csp.sentinel.dashboard.domain.cluster.state.ClusterServerStateVO in project Sentinel by alibaba.

the class ClusterEntityUtils method wrapToAppClusterServerState.

public static List<AppClusterServerStateWrapVO> wrapToAppClusterServerState(List<ClusterUniversalStatePairVO> list) {
    if (list == null || list.isEmpty()) {
        return new ArrayList<>();
    }
    Map<String, AppClusterServerStateWrapVO> map = new HashMap<>();
    Set<String> tokenServerSet = new HashSet<>();
    // Handle token servers that belong to current app.
    for (ClusterUniversalStatePairVO stateVO : list) {
        int mode = stateVO.getState().getStateInfo().getMode();
        if (mode == ClusterStateManager.CLUSTER_SERVER) {
            String ip = stateVO.getIp();
            String serverId = ip + '@' + stateVO.getCommandPort();
            ClusterServerStateVO serverStateVO = stateVO.getState().getServer();
            map.computeIfAbsent(serverId, v -> new AppClusterServerStateWrapVO().setId(serverId).setIp(ip).setPort(serverStateVO.getPort()).setState(serverStateVO).setBelongToApp(true).setConnectedCount(serverStateVO.getConnection().stream().mapToInt(ConnectionGroupVO::getConnectedCount).sum()));
            tokenServerSet.add(ip + ":" + serverStateVO.getPort());
        }
    }
    // Handle token servers from other app.
    for (ClusterUniversalStatePairVO stateVO : list) {
        int mode = stateVO.getState().getStateInfo().getMode();
        if (mode == ClusterStateManager.CLUSTER_CLIENT) {
            ClusterClientStateVO clientState = stateVO.getState().getClient();
            if (clientState == null) {
                continue;
            }
            String serverIp = clientState.getClientConfig().getServerHost();
            int serverPort = clientState.getClientConfig().getServerPort();
            if (tokenServerSet.contains(serverIp + ":" + serverPort)) {
                continue;
            }
            // We are not able to get the commandPort of foreign token server directly.
            String serverId = String.format("%s:%d", serverIp, serverPort);
            map.computeIfAbsent(serverId, v -> new AppClusterServerStateWrapVO().setId(serverId).setIp(serverIp).setPort(serverPort).setBelongToApp(false));
        }
    }
    return new ArrayList<>(map.values());
}
Also used : AppClusterServerStateWrapVO(com.alibaba.csp.sentinel.dashboard.domain.cluster.state.AppClusterServerStateWrapVO) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ClusterUniversalStatePairVO(com.alibaba.csp.sentinel.dashboard.domain.cluster.state.ClusterUniversalStatePairVO) ClusterClientStateVO(com.alibaba.csp.sentinel.dashboard.domain.cluster.state.ClusterClientStateVO) HashSet(java.util.HashSet) ClusterServerStateVO(com.alibaba.csp.sentinel.dashboard.domain.cluster.state.ClusterServerStateVO)

Example 2 with ClusterServerStateVO

use of com.alibaba.csp.sentinel.dashboard.domain.cluster.state.ClusterServerStateVO in project spring-boot-student by wyh-spring-ecosystem-student.

the class ClusterEntityUtils method wrapToAppClusterServerState.

public static List<AppClusterServerStateWrapVO> wrapToAppClusterServerState(List<ClusterUniversalStatePairVO> list) {
    if (list == null || list.isEmpty()) {
        return new ArrayList<>();
    }
    Map<String, AppClusterServerStateWrapVO> map = new HashMap<>();
    Set<String> tokenServerSet = new HashSet<>();
    // Handle token servers that belong to current app.
    for (ClusterUniversalStatePairVO stateVO : list) {
        int mode = stateVO.getState().getStateInfo().getMode();
        if (mode == ClusterStateManager.CLUSTER_SERVER) {
            String ip = stateVO.getIp();
            String serverId = ip + '@' + stateVO.getCommandPort();
            ClusterServerStateVO serverStateVO = stateVO.getState().getServer();
            map.computeIfAbsent(serverId, v -> new AppClusterServerStateWrapVO().setId(serverId).setIp(ip).setPort(serverStateVO.getPort()).setState(serverStateVO).setBelongToApp(true).setConnectedCount(serverStateVO.getConnection().stream().mapToInt(ConnectionGroupVO::getConnectedCount).sum()));
            tokenServerSet.add(ip + ":" + serverStateVO.getPort());
        }
    }
    // Handle token servers from other app.
    for (ClusterUniversalStatePairVO stateVO : list) {
        int mode = stateVO.getState().getStateInfo().getMode();
        if (mode == ClusterStateManager.CLUSTER_CLIENT) {
            ClusterClientStateVO clientState = stateVO.getState().getClient();
            if (clientState == null) {
                continue;
            }
            String serverIp = clientState.getClientConfig().getServerHost();
            int serverPort = clientState.getClientConfig().getServerPort();
            if (tokenServerSet.contains(serverIp + ":" + serverPort)) {
                continue;
            }
            // We are not able to get the commandPort of foreign token server directly.
            String serverId = String.format("%s:%d", serverIp, serverPort);
            map.computeIfAbsent(serverId, v -> new AppClusterServerStateWrapVO().setId(serverId).setIp(serverIp).setPort(serverPort).setBelongToApp(false));
        }
    }
    return new ArrayList<>(map.values());
}
Also used : AppClusterServerStateWrapVO(com.alibaba.csp.sentinel.dashboard.domain.cluster.state.AppClusterServerStateWrapVO) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ClusterUniversalStatePairVO(com.alibaba.csp.sentinel.dashboard.domain.cluster.state.ClusterUniversalStatePairVO) ClusterClientStateVO(com.alibaba.csp.sentinel.dashboard.domain.cluster.state.ClusterClientStateVO) HashSet(java.util.HashSet) ClusterServerStateVO(com.alibaba.csp.sentinel.dashboard.domain.cluster.state.ClusterServerStateVO)

Example 3 with ClusterServerStateVO

use of com.alibaba.csp.sentinel.dashboard.domain.cluster.state.ClusterServerStateVO in project XHuiCloud by sindaZeng.

the class ClusterEntityUtils method wrapToAppClusterServerState.

public static List<AppClusterServerStateWrapVO> wrapToAppClusterServerState(List<ClusterUniversalStatePairVO> list) {
    if (list == null || list.isEmpty()) {
        return new ArrayList<>();
    }
    Map<String, AppClusterServerStateWrapVO> map = new HashMap<>();
    Set<String> tokenServerSet = new HashSet<>();
    // Handle token servers that belong to current app.
    for (ClusterUniversalStatePairVO stateVO : list) {
        int mode = stateVO.getState().getStateInfo().getMode();
        if (mode == ClusterStateManager.CLUSTER_SERVER) {
            String ip = stateVO.getIp();
            String serverId = ip + '@' + stateVO.getCommandPort();
            ClusterServerStateVO serverStateVO = stateVO.getState().getServer();
            map.computeIfAbsent(serverId, v -> new AppClusterServerStateWrapVO().setId(serverId).setIp(ip).setPort(serverStateVO.getPort()).setState(serverStateVO).setBelongToApp(true).setConnectedCount(serverStateVO.getConnection().stream().mapToInt(ConnectionGroupVO::getConnectedCount).sum()));
            tokenServerSet.add(ip + ":" + serverStateVO.getPort());
        }
    }
    // Handle token servers from other app.
    for (ClusterUniversalStatePairVO stateVO : list) {
        int mode = stateVO.getState().getStateInfo().getMode();
        if (mode == ClusterStateManager.CLUSTER_CLIENT) {
            ClusterClientStateVO clientState = stateVO.getState().getClient();
            if (clientState == null) {
                continue;
            }
            String serverIp = clientState.getClientConfig().getServerHost();
            int serverPort = clientState.getClientConfig().getServerPort();
            if (tokenServerSet.contains(serverIp + ":" + serverPort)) {
                continue;
            }
            // We are not able to get the commandPort of foreign token server directly.
            String serverId = String.format("%s:%d", serverIp, serverPort);
            map.computeIfAbsent(serverId, v -> new AppClusterServerStateWrapVO().setId(serverId).setIp(serverIp).setPort(serverPort).setBelongToApp(false));
        }
    }
    return new ArrayList<>(map.values());
}
Also used : AppClusterServerStateWrapVO(com.alibaba.csp.sentinel.dashboard.domain.cluster.state.AppClusterServerStateWrapVO) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ClusterUniversalStatePairVO(com.alibaba.csp.sentinel.dashboard.domain.cluster.state.ClusterUniversalStatePairVO) ClusterClientStateVO(com.alibaba.csp.sentinel.dashboard.domain.cluster.state.ClusterClientStateVO) HashSet(java.util.HashSet) ClusterServerStateVO(com.alibaba.csp.sentinel.dashboard.domain.cluster.state.ClusterServerStateVO)

Example 4 with ClusterServerStateVO

use of com.alibaba.csp.sentinel.dashboard.domain.cluster.state.ClusterServerStateVO in project pig by pig-mesh.

the class ClusterEntityUtils method wrapToAppClusterServerState.

public static List<AppClusterServerStateWrapVO> wrapToAppClusterServerState(List<ClusterUniversalStatePairVO> list) {
    if (list == null || list.isEmpty()) {
        return new ArrayList<>();
    }
    Map<String, AppClusterServerStateWrapVO> map = new HashMap<>();
    Set<String> tokenServerSet = new HashSet<>();
    // Handle token servers that belong to current app.
    for (ClusterUniversalStatePairVO stateVO : list) {
        int mode = stateVO.getState().getStateInfo().getMode();
        if (mode == ClusterStateManager.CLUSTER_SERVER) {
            String ip = stateVO.getIp();
            String serverId = ip + '@' + stateVO.getCommandPort();
            ClusterServerStateVO serverStateVO = stateVO.getState().getServer();
            map.computeIfAbsent(serverId, v -> new AppClusterServerStateWrapVO().setId(serverId).setIp(ip).setPort(serverStateVO.getPort()).setState(serverStateVO).setBelongToApp(true).setConnectedCount(serverStateVO.getConnection().stream().mapToInt(ConnectionGroupVO::getConnectedCount).sum()));
            tokenServerSet.add(ip + ":" + serverStateVO.getPort());
        }
    }
    // Handle token servers from other app.
    for (ClusterUniversalStatePairVO stateVO : list) {
        int mode = stateVO.getState().getStateInfo().getMode();
        if (mode == ClusterStateManager.CLUSTER_CLIENT) {
            ClusterClientStateVO clientState = stateVO.getState().getClient();
            if (clientState == null) {
                continue;
            }
            String serverIp = clientState.getClientConfig().getServerHost();
            int serverPort = clientState.getClientConfig().getServerPort();
            if (tokenServerSet.contains(serverIp + ":" + serverPort)) {
                continue;
            }
            // We are not able to get the commandPort of foreign token server
            // directly.
            String serverId = String.format("%s:%d", serverIp, serverPort);
            map.computeIfAbsent(serverId, v -> new AppClusterServerStateWrapVO().setId(serverId).setIp(serverIp).setPort(serverPort).setBelongToApp(false));
        }
    }
    return new ArrayList<>(map.values());
}
Also used : AppClusterServerStateWrapVO(com.alibaba.csp.sentinel.dashboard.domain.cluster.state.AppClusterServerStateWrapVO) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ClusterUniversalStatePairVO(com.alibaba.csp.sentinel.dashboard.domain.cluster.state.ClusterUniversalStatePairVO) ClusterClientStateVO(com.alibaba.csp.sentinel.dashboard.domain.cluster.state.ClusterClientStateVO) HashSet(java.util.HashSet) ClusterServerStateVO(com.alibaba.csp.sentinel.dashboard.domain.cluster.state.ClusterServerStateVO)

Aggregations

AppClusterServerStateWrapVO (com.alibaba.csp.sentinel.dashboard.domain.cluster.state.AppClusterServerStateWrapVO)4 ClusterClientStateVO (com.alibaba.csp.sentinel.dashboard.domain.cluster.state.ClusterClientStateVO)4 ClusterServerStateVO (com.alibaba.csp.sentinel.dashboard.domain.cluster.state.ClusterServerStateVO)4 ClusterUniversalStatePairVO (com.alibaba.csp.sentinel.dashboard.domain.cluster.state.ClusterUniversalStatePairVO)4 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 HashSet (java.util.HashSet)4