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));
}
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))));
}
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);
}
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);
}
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))));
}
Aggregations