use of com.dtstack.taier.scheduler.impl.pojo.ComponentMultiTestResult in project Taier by DTStack.
the class ConsoleComponentService method testConnects.
/**
* 测试所有组件连通性
*
* @param clusterName
* @return
*/
public List<ComponentMultiTestResult> testConnects(String clusterName) {
Cluster cluster = clusterMapper.getByClusterName(clusterName);
List<Component> components = getComponents(cluster);
if (CollectionUtils.isEmpty(components)) {
return new ArrayList<>();
}
Map sftpMap = componentService.getComponentByClusterId(cluster.getId(), EComponentType.SFTP.getTypeCode(), false, Map.class, null);
Map<Component, CompletableFuture<ComponentTestResult>> completableFutureMap = components.stream().collect(Collectors.toMap(component -> component, c -> CompletableFuture.supplyAsync(() -> testComponentWithResult(clusterName, cluster, sftpMap, c), connectPool)));
CompletableFuture<List<ComponentTestResult>> completableFuture = CompletableFuture.allOf(completableFutureMap.values().toArray(new CompletableFuture[0])).thenApply((f) -> completableFutureMap.keySet().stream().map(component -> {
try {
return completableFutureMap.get(component).get(env.getTestConnectTimeout(), TimeUnit.SECONDS);
} catch (Exception e) {
ComponentTestResult testResult = new ComponentTestResult();
testResult.setResult(false);
testResult.setErrorMsg(ExceptionUtil.getErrorMessage(e));
testResult.setComponentVersion(component.getVersionValue());
testResult.setComponentTypeCode(component.getComponentTypeCode());
return testResult;
}
}).collect(Collectors.toList()));
try {
List<ComponentTestResult> componentTestResults = completableFuture.get();
Map<Integer, List<ComponentTestResult>> componentCodeResultMap = componentTestResults.stream().collect(Collectors.groupingBy(ComponentTestResult::getComponentTypeCode, Collectors.collectingAndThen(Collectors.toList(), c -> c)));
return componentCodeResultMap.keySet().stream().map(componentCode -> {
ComponentMultiTestResult multiTestResult = new ComponentMultiTestResult(componentCode);
multiTestResult.setMultiVersion(componentCodeResultMap.get(componentCode));
List<ComponentTestResult> testResults = componentCodeResultMap.get(componentCode);
multiTestResult.setResult(testResults.stream().allMatch(ComponentTestResult::getResult));
testResults.stream().filter(componentTestResult -> StringUtils.isNotBlank(componentTestResult.getErrorMsg())).findFirst().ifPresent(errorResult -> multiTestResult.setErrorMsg(errorResult.getErrorMsg()));
return multiTestResult;
}).collect(Collectors.toList());
} catch (Exception e) {
throw new RdosDefineException(e);
}
}
use of com.dtstack.taier.scheduler.impl.pojo.ComponentMultiTestResult in project Taier by DTStack.
the class TenantService method checkClusterCanUse.
public void checkClusterCanUse(String clusterName) throws Exception {
List<ComponentMultiTestResult> testConnectionVO = consoleComponentService.testConnects(clusterName);
boolean canUse = true;
StringBuilder msg = new StringBuilder();
msg.append("此集群不可用,测试连通性为通过:\n");
for (ComponentMultiTestResult testResult : testConnectionVO) {
EComponentType componentType = EComponentType.getByCode(testResult.getComponentTypeCode());
if (!EComponentType.notCheckComponent.contains(componentType) && !testResult.getResult()) {
canUse = false;
msg.append("组件:").append(componentType.getName()).append(" ").append(JSON.toJSONString(testResult.getErrorMsg())).append("\n");
}
}
if (!canUse) {
throw new RdosDefineException(msg.toString());
}
}
Aggregations