Search in sources :

Example 1 with ComponentMultiTestResult

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);
    }
}
Also used : IComponentVO(com.dtstack.taier.scheduler.vo.IComponentVO) ClusterTenantMapper(com.dtstack.taier.dao.mapper.ClusterTenantMapper) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) StringUtils(org.apache.commons.lang3.StringUtils) MathUtil(com.dtstack.taier.common.util.MathUtil) ComponentService(com.dtstack.taier.scheduler.service.ComponentService) Keytab(org.apache.kerby.kerberos.kerb.keytab.Keytab) MD5Util(com.dtstack.taier.pluginapi.util.MD5Util) QueueService(com.dtstack.taier.scheduler.service.QueueService) DictType(com.dtstack.taier.common.enums.DictType) Xml2JsonUtil(com.dtstack.taier.common.util.Xml2JsonUtil) ComponentVersionUtil(com.dtstack.taier.common.util.ComponentVersionUtil) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) Collectors(java.util.stream.Collectors) ComponentTestResult(com.dtstack.taier.pluginapi.pojo.ComponentTestResult) PublicUtil(com.dtstack.taier.pluginapi.util.PublicUtil) ComponentVO(com.dtstack.taier.scheduler.vo.ComponentVO) DownloadType(com.dtstack.taier.common.enums.DownloadType) WorkerOperator(com.dtstack.taier.scheduler.WorkerOperator) Krb5FileUtil(com.dtstack.taier.scheduler.utils.Krb5FileUtil) Resource(com.dtstack.taier.dao.dto.Resource) ConfigConstant(com.dtstack.taier.pluginapi.constrant.ConfigConstant) JSONObject(com.alibaba.fastjson.JSONObject) PartCluster(com.dtstack.taier.develop.model.PartCluster) ComponentMultiTestResult(com.dtstack.taier.scheduler.impl.pojo.ComponentMultiTestResult) BeanUtils(org.springframework.beans.BeanUtils) java.util(java.util) ZipUtil(com.dtstack.taier.common.util.ZipUtil) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) Part(com.dtstack.taier.develop.model.Part) SftpFileManage(com.dtstack.taier.pluginapi.sftp.SftpFileManage) ClusterFactory(com.dtstack.taier.develop.model.ClusterFactory) EnvironmentContext(com.dtstack.taier.common.env.EnvironmentContext) RdosDefineException(com.dtstack.taier.common.exception.RdosDefineException) BooleanUtils(org.apache.commons.lang3.BooleanUtils) CompletableFuture(java.util.concurrent.CompletableFuture) ClusterMapper(com.dtstack.taier.dao.mapper.ClusterMapper) CustomThreadFactory(com.dtstack.taier.pluginapi.CustomThreadFactory) JSONArray(com.alibaba.fastjson.JSONArray) Lists(com.google.common.collect.Lists) CollectionUtils(org.apache.commons.collections.CollectionUtils) ClientTemplate(com.dtstack.taier.scheduler.impl.pojo.ClientTemplate) ErrorCode(com.dtstack.taier.common.exception.ErrorCode) ComponentConfigUtils(com.dtstack.taier.scheduler.utils.ComponentConfigUtils) ConsoleKerberosMapper(com.dtstack.taier.dao.mapper.ConsoleKerberosMapper) com.dtstack.taier.dao.domain(com.dtstack.taier.dao.domain) Logger(org.slf4j.Logger) MapUtils(org.apache.commons.collections.MapUtils) ExceptionUtil(com.dtstack.taier.pluginapi.exception.ExceptionUtil) XmlFileUtil(com.dtstack.taier.scheduler.utils.XmlFileUtil) FileUtils(org.apache.commons.io.FileUtils) IOException(java.io.IOException) ScheduleDictService(com.dtstack.taier.scheduler.service.ScheduleDictService) File(java.io.File) ComponentMapper(com.dtstack.taier.dao.mapper.ComponentMapper) SftpConfig(com.dtstack.taier.pluginapi.sftp.SftpConfig) EComponentType(com.dtstack.taier.common.enums.EComponentType) TimeUnit(java.util.concurrent.TimeUnit) ZIP_SUFFIX(com.dtstack.taier.common.constant.CommonConstant.ZIP_SUFFIX) ComponentConfigService(com.dtstack.taier.scheduler.service.ComponentConfigService) PrincipalName(org.apache.kerby.kerberos.kerb.type.base.PrincipalName) Transactional(org.springframework.transaction.annotation.Transactional) RdosDefineException(com.dtstack.taier.common.exception.RdosDefineException) PartCluster(com.dtstack.taier.develop.model.PartCluster) ComponentMultiTestResult(com.dtstack.taier.scheduler.impl.pojo.ComponentMultiTestResult) RdosDefineException(com.dtstack.taier.common.exception.RdosDefineException) IOException(java.io.IOException) CompletableFuture(java.util.concurrent.CompletableFuture) ComponentTestResult(com.dtstack.taier.pluginapi.pojo.ComponentTestResult)

Example 2 with ComponentMultiTestResult

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());
    }
}
Also used : RdosDefineException(com.dtstack.taier.common.exception.RdosDefineException) ComponentMultiTestResult(com.dtstack.taier.scheduler.impl.pojo.ComponentMultiTestResult) EComponentType(com.dtstack.taier.common.enums.EComponentType)

Aggregations

EComponentType (com.dtstack.taier.common.enums.EComponentType)2 RdosDefineException (com.dtstack.taier.common.exception.RdosDefineException)2 ComponentMultiTestResult (com.dtstack.taier.scheduler.impl.pojo.ComponentMultiTestResult)2 JSONArray (com.alibaba.fastjson.JSONArray)1 JSONObject (com.alibaba.fastjson.JSONObject)1 ZIP_SUFFIX (com.dtstack.taier.common.constant.CommonConstant.ZIP_SUFFIX)1 DictType (com.dtstack.taier.common.enums.DictType)1 DownloadType (com.dtstack.taier.common.enums.DownloadType)1 EnvironmentContext (com.dtstack.taier.common.env.EnvironmentContext)1 ErrorCode (com.dtstack.taier.common.exception.ErrorCode)1 ComponentVersionUtil (com.dtstack.taier.common.util.ComponentVersionUtil)1 MathUtil (com.dtstack.taier.common.util.MathUtil)1 Xml2JsonUtil (com.dtstack.taier.common.util.Xml2JsonUtil)1 ZipUtil (com.dtstack.taier.common.util.ZipUtil)1 com.dtstack.taier.dao.domain (com.dtstack.taier.dao.domain)1 Resource (com.dtstack.taier.dao.dto.Resource)1 ClusterMapper (com.dtstack.taier.dao.mapper.ClusterMapper)1 ClusterTenantMapper (com.dtstack.taier.dao.mapper.ClusterTenantMapper)1 ComponentMapper (com.dtstack.taier.dao.mapper.ComponentMapper)1 ConsoleKerberosMapper (com.dtstack.taier.dao.mapper.ConsoleKerberosMapper)1