Search in sources :

Example 1 with ClusterUniversalStatePairVO

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

the class ClusterConfigService method getClusterUniversalState.

/**
 * Get cluster state list of all available machines of provided application.
 *
 * @param app application name
 * @return cluster state list of all available machines of the application
 * @since 1.4.1
 */
public CompletableFuture<List<ClusterUniversalStatePairVO>> getClusterUniversalState(String app) {
    if (StringUtil.isBlank(app)) {
        return AsyncUtils.newFailedFuture(new IllegalArgumentException("app cannot be empty"));
    }
    AppInfo appInfo = appManagement.getDetailApp(app);
    if (appInfo == null || appInfo.getMachines() == null) {
        return CompletableFuture.completedFuture(new ArrayList<>());
    }
    List<CompletableFuture<ClusterUniversalStatePairVO>> futures = appInfo.getMachines().stream().filter(e -> e.isHealthy()).map(machine -> getClusterUniversalState(app, machine.getIp(), machine.getPort()).thenApply(e -> new ClusterUniversalStatePairVO(machine.getIp(), machine.getPort(), e))).collect(Collectors.toList());
    return AsyncUtils.sequenceSuccessFuture(futures);
}
Also used : AppManagement(com.alibaba.csp.sentinel.dashboard.discovery.AppManagement) ClusterServerModifyRequest(com.alibaba.csp.sentinel.dashboard.domain.cluster.request.ClusterServerModifyRequest) ClusterUniversalStateVO(com.alibaba.csp.sentinel.dashboard.domain.cluster.state.ClusterUniversalStateVO) ClusterGroupEntity(com.alibaba.csp.sentinel.dashboard.domain.cluster.ClusterGroupEntity) ClusterClientStateVO(com.alibaba.csp.sentinel.dashboard.domain.cluster.state.ClusterClientStateVO) Set(java.util.Set) Autowired(org.springframework.beans.factory.annotation.Autowired) CompletableFuture(java.util.concurrent.CompletableFuture) Collectors(java.util.stream.Collectors) AppInfo(com.alibaba.csp.sentinel.dashboard.discovery.AppInfo) ArrayList(java.util.ArrayList) ClusterClientModifyRequest(com.alibaba.csp.sentinel.dashboard.domain.cluster.request.ClusterClientModifyRequest) AsyncUtils(com.alibaba.csp.sentinel.dashboard.util.AsyncUtils) StringUtil(com.alibaba.csp.sentinel.util.StringUtil) ServerFlowConfig(com.alibaba.csp.sentinel.dashboard.domain.cluster.config.ServerFlowConfig) List(java.util.List) ServerTransportConfig(com.alibaba.csp.sentinel.dashboard.domain.cluster.config.ServerTransportConfig) SentinelApiClient(com.alibaba.csp.sentinel.dashboard.client.SentinelApiClient) Service(org.springframework.stereotype.Service) ClusterUniversalStatePairVO(com.alibaba.csp.sentinel.dashboard.domain.cluster.state.ClusterUniversalStatePairVO) ClusterEntityUtils(com.alibaba.csp.sentinel.dashboard.util.ClusterEntityUtils) ClusterClientConfig(com.alibaba.csp.sentinel.dashboard.domain.cluster.config.ClusterClientConfig) ClusterStateManager(com.alibaba.csp.sentinel.cluster.ClusterStateManager) CompletableFuture(java.util.concurrent.CompletableFuture) ClusterUniversalStatePairVO(com.alibaba.csp.sentinel.dashboard.domain.cluster.state.ClusterUniversalStatePairVO) AppInfo(com.alibaba.csp.sentinel.dashboard.discovery.AppInfo)

Example 2 with ClusterUniversalStatePairVO

use of com.alibaba.csp.sentinel.dashboard.domain.cluster.state.ClusterUniversalStatePairVO 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 3 with ClusterUniversalStatePairVO

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

the class ClusterEntityUtils method wrapToClusterGroup.

public static List<ClusterGroupEntity> wrapToClusterGroup(List<ClusterUniversalStatePairVO> list) {
    if (list == null || list.isEmpty()) {
        return new ArrayList<>();
    }
    Map<String, ClusterGroupEntity> map = new HashMap<>();
    for (ClusterUniversalStatePairVO stateVO : list) {
        int mode = stateVO.getState().getStateInfo().getMode();
        String ip = stateVO.getIp();
        if (mode == ClusterStateManager.CLUSTER_SERVER) {
            String serverAddress = getIp(ip);
            int port = stateVO.getState().getServer().getPort();
            map.computeIfAbsent(serverAddress, v -> new ClusterGroupEntity().setBelongToApp(true).setMachineId(ip + '@' + stateVO.getCommandPort()).setIp(ip).setPort(port));
        }
    }
    for (ClusterUniversalStatePairVO stateVO : list) {
        int mode = stateVO.getState().getStateInfo().getMode();
        String ip = stateVO.getIp();
        if (mode == ClusterStateManager.CLUSTER_CLIENT) {
            String targetServer = stateVO.getState().getClient().getClientConfig().getServerHost();
            Integer targetPort = stateVO.getState().getClient().getClientConfig().getServerPort();
            if (StringUtil.isBlank(targetServer) || targetPort == null || targetPort <= 0) {
                continue;
            }
            ClusterGroupEntity group = map.computeIfAbsent(targetServer, v -> new ClusterGroupEntity().setBelongToApp(true).setMachineId(targetServer).setIp(targetServer).setPort(targetPort));
            group.getClientSet().add(ip + '@' + stateVO.getCommandPort());
        }
    }
    return new ArrayList<>(map.values());
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ClusterUniversalStatePairVO(com.alibaba.csp.sentinel.dashboard.domain.cluster.state.ClusterUniversalStatePairVO) ClusterGroupEntity(com.alibaba.csp.sentinel.dashboard.domain.cluster.ClusterGroupEntity)

Example 4 with ClusterUniversalStatePairVO

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

the class ClusterEntityUtils method wrapToAppClusterClientState.

public static List<AppClusterClientStateWrapVO> wrapToAppClusterClientState(List<ClusterUniversalStatePairVO> list) {
    if (list == null || list.isEmpty()) {
        return new ArrayList<>();
    }
    Map<String, AppClusterClientStateWrapVO> map = new HashMap<>();
    for (ClusterUniversalStatePairVO stateVO : list) {
        int mode = stateVO.getState().getStateInfo().getMode();
        if (mode == ClusterStateManager.CLUSTER_CLIENT) {
            String ip = stateVO.getIp();
            String clientId = ip + '@' + stateVO.getCommandPort();
            ClusterClientStateVO clientStateVO = stateVO.getState().getClient();
            map.computeIfAbsent(clientId, v -> new AppClusterClientStateWrapVO().setId(clientId).setIp(ip).setState(clientStateVO).setCommandPort(stateVO.getCommandPort()));
        }
    }
    return new ArrayList<>(map.values());
}
Also used : AppClusterClientStateWrapVO(com.alibaba.csp.sentinel.dashboard.domain.cluster.state.AppClusterClientStateWrapVO) 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)

Example 5 with ClusterUniversalStatePairVO

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

the class ClusterEntityUtils method wrapToClusterGroup.

public static List<ClusterGroupEntity> wrapToClusterGroup(List<ClusterUniversalStatePairVO> list) {
    if (list == null || list.isEmpty()) {
        return new ArrayList<>();
    }
    Map<String, ClusterGroupEntity> map = new HashMap<>();
    for (ClusterUniversalStatePairVO stateVO : list) {
        int mode = stateVO.getState().getStateInfo().getMode();
        String ip = stateVO.getIp();
        if (mode == ClusterStateManager.CLUSTER_SERVER) {
            String serverAddress = getIp(ip);
            int port = stateVO.getState().getServer().getPort();
            String targetAddress = serverAddress + ":" + port;
            map.computeIfAbsent(targetAddress, v -> new ClusterGroupEntity().setBelongToApp(true).setMachineId(ip + '@' + stateVO.getCommandPort()).setIp(ip).setPort(port));
        }
    }
    for (ClusterUniversalStatePairVO stateVO : list) {
        int mode = stateVO.getState().getStateInfo().getMode();
        String ip = stateVO.getIp();
        if (mode == ClusterStateManager.CLUSTER_CLIENT) {
            String targetServer = stateVO.getState().getClient().getClientConfig().getServerHost();
            Integer targetPort = stateVO.getState().getClient().getClientConfig().getServerPort();
            if (StringUtil.isBlank(targetServer) || targetPort == null || targetPort <= 0) {
                continue;
            }
            String targetAddress = targetServer + ":" + targetPort;
            ClusterGroupEntity group = map.computeIfAbsent(targetAddress, v -> new ClusterGroupEntity().setBelongToApp(true).setMachineId(targetServer).setIp(targetServer).setPort(targetPort));
            group.getClientSet().add(ip + '@' + stateVO.getCommandPort());
        }
    }
    return new ArrayList<>(map.values());
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ClusterUniversalStatePairVO(com.alibaba.csp.sentinel.dashboard.domain.cluster.state.ClusterUniversalStatePairVO) ClusterGroupEntity(com.alibaba.csp.sentinel.dashboard.domain.cluster.ClusterGroupEntity)

Aggregations

ClusterUniversalStatePairVO (com.alibaba.csp.sentinel.dashboard.domain.cluster.state.ClusterUniversalStatePairVO)17 ArrayList (java.util.ArrayList)17 ClusterClientStateVO (com.alibaba.csp.sentinel.dashboard.domain.cluster.state.ClusterClientStateVO)13 HashMap (java.util.HashMap)12 ClusterGroupEntity (com.alibaba.csp.sentinel.dashboard.domain.cluster.ClusterGroupEntity)9 ClusterStateManager (com.alibaba.csp.sentinel.cluster.ClusterStateManager)5 SentinelApiClient (com.alibaba.csp.sentinel.dashboard.client.SentinelApiClient)5 AppInfo (com.alibaba.csp.sentinel.dashboard.discovery.AppInfo)5 AppManagement (com.alibaba.csp.sentinel.dashboard.discovery.AppManagement)5 ClusterClientConfig (com.alibaba.csp.sentinel.dashboard.domain.cluster.config.ClusterClientConfig)5 ServerFlowConfig (com.alibaba.csp.sentinel.dashboard.domain.cluster.config.ServerFlowConfig)5 ServerTransportConfig (com.alibaba.csp.sentinel.dashboard.domain.cluster.config.ServerTransportConfig)5 ClusterClientModifyRequest (com.alibaba.csp.sentinel.dashboard.domain.cluster.request.ClusterClientModifyRequest)5 ClusterServerModifyRequest (com.alibaba.csp.sentinel.dashboard.domain.cluster.request.ClusterServerModifyRequest)5 ClusterUniversalStateVO (com.alibaba.csp.sentinel.dashboard.domain.cluster.state.ClusterUniversalStateVO)5 AsyncUtils (com.alibaba.csp.sentinel.dashboard.util.AsyncUtils)5 ClusterEntityUtils (com.alibaba.csp.sentinel.dashboard.util.ClusterEntityUtils)5 StringUtil (com.alibaba.csp.sentinel.util.StringUtil)5 List (java.util.List)5 Set (java.util.Set)5