Search in sources :

Example 6 with AppInfo

use of com.alibaba.csp.sentinel.dashboard.discovery.AppInfo in project XHuiCloud by sindaZeng.

the class AppController method getMachinesByApp.

@GetMapping(value = "/{app}/machines.json")
public Result<List<MachineInfoVo>> getMachinesByApp(@PathVariable("app") String app) {
    AppInfo appInfo = appManagement.getDetailApp(app);
    if (appInfo == null) {
        return Result.ofSuccess(null);
    }
    List<MachineInfo> list = new ArrayList<>(appInfo.getMachines());
    Collections.sort(list, Comparator.comparing(MachineInfo::getApp).thenComparing(MachineInfo::getIp).thenComparingInt(MachineInfo::getPort));
    return Result.ofSuccess(MachineInfoVo.fromMachineInfoList(list));
}
Also used : MachineInfo(com.alibaba.csp.sentinel.dashboard.discovery.MachineInfo) ArrayList(java.util.ArrayList) AppInfo(com.alibaba.csp.sentinel.dashboard.discovery.AppInfo) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 7 with AppInfo

use of com.alibaba.csp.sentinel.dashboard.discovery.AppInfo in project XHuiCloud by sindaZeng.

the class ClusterConfigService method getClusterUniversalStateForAppMachine.

public CompletableFuture<ClusterGroupEntity> getClusterUniversalStateForAppMachine(String app, String machineId) {
    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 AsyncUtils.newFailedFuture(new IllegalArgumentException("app does not have machines"));
    }
    boolean machineOk = appInfo.getMachines().stream().filter(e -> e.isHealthy()).map(e -> e.getIp() + '@' + e.getPort()).anyMatch(e -> e.equals(machineId));
    if (!machineOk) {
        return AsyncUtils.newFailedFuture(new IllegalStateException("machine does not exist or disconnected"));
    }
    return getClusterUniversalState(app).thenApply(ClusterEntityUtils::wrapToClusterGroup).thenCompose(e -> e.stream().filter(e1 -> e1.getMachineId().equals(machineId)).findAny().map(CompletableFuture::completedFuture).orElse(AsyncUtils.newFailedFuture(new IllegalStateException("not a server: " + machineId))));
}
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) AppInfo(com.alibaba.csp.sentinel.dashboard.discovery.AppInfo)

Example 8 with AppInfo

use of com.alibaba.csp.sentinel.dashboard.discovery.AppInfo in project XHuiCloud by sindaZeng.

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 9 with AppInfo

use of com.alibaba.csp.sentinel.dashboard.discovery.AppInfo in project RuoYi-Cloud-Plus by JavaLionLi.

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 10 with AppInfo

use of com.alibaba.csp.sentinel.dashboard.discovery.AppInfo in project RuoYi-Cloud-Plus by JavaLionLi.

the class ClusterConfigService method getClusterUniversalStateForAppMachine.

public CompletableFuture<ClusterGroupEntity> getClusterUniversalStateForAppMachine(String app, String machineId) {
    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 AsyncUtils.newFailedFuture(new IllegalArgumentException("app does not have machines"));
    }
    boolean machineOk = appInfo.getMachines().stream().filter(e -> e.isHealthy()).map(e -> e.getIp() + '@' + e.getPort()).anyMatch(e -> e.equals(machineId));
    if (!machineOk) {
        return AsyncUtils.newFailedFuture(new IllegalStateException("machine does not exist or disconnected"));
    }
    return getClusterUniversalState(app).thenApply(ClusterEntityUtils::wrapToClusterGroup).thenCompose(e -> e.stream().filter(e1 -> e1.getMachineId().equals(machineId)).findAny().map(CompletableFuture::completedFuture).orElse(AsyncUtils.newFailedFuture(new IllegalStateException("not a server: " + machineId))));
}
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) AppInfo(com.alibaba.csp.sentinel.dashboard.discovery.AppInfo)

Aggregations

AppInfo (com.alibaba.csp.sentinel.dashboard.discovery.AppInfo)20 ArrayList (java.util.ArrayList)15 ClusterStateManager (com.alibaba.csp.sentinel.cluster.ClusterStateManager)10 SentinelApiClient (com.alibaba.csp.sentinel.dashboard.client.SentinelApiClient)10 AppManagement (com.alibaba.csp.sentinel.dashboard.discovery.AppManagement)10 MachineInfo (com.alibaba.csp.sentinel.dashboard.discovery.MachineInfo)10 ClusterGroupEntity (com.alibaba.csp.sentinel.dashboard.domain.cluster.ClusterGroupEntity)10 ClusterClientConfig (com.alibaba.csp.sentinel.dashboard.domain.cluster.config.ClusterClientConfig)10 ServerFlowConfig (com.alibaba.csp.sentinel.dashboard.domain.cluster.config.ServerFlowConfig)10 ServerTransportConfig (com.alibaba.csp.sentinel.dashboard.domain.cluster.config.ServerTransportConfig)10 ClusterClientModifyRequest (com.alibaba.csp.sentinel.dashboard.domain.cluster.request.ClusterClientModifyRequest)10 ClusterServerModifyRequest (com.alibaba.csp.sentinel.dashboard.domain.cluster.request.ClusterServerModifyRequest)10 ClusterClientStateVO (com.alibaba.csp.sentinel.dashboard.domain.cluster.state.ClusterClientStateVO)10 ClusterUniversalStatePairVO (com.alibaba.csp.sentinel.dashboard.domain.cluster.state.ClusterUniversalStatePairVO)10 ClusterUniversalStateVO (com.alibaba.csp.sentinel.dashboard.domain.cluster.state.ClusterUniversalStateVO)10 AsyncUtils (com.alibaba.csp.sentinel.dashboard.util.AsyncUtils)10 ClusterEntityUtils (com.alibaba.csp.sentinel.dashboard.util.ClusterEntityUtils)10 StringUtil (com.alibaba.csp.sentinel.util.StringUtil)10 List (java.util.List)10 Set (java.util.Set)10