Search in sources :

Example 11 with ComponentTestResult

use of com.dtstack.taier.pluginapi.pojo.ComponentTestResult in project Taier by DTStack.

the class AbstractRdbsClientTest method testTestConnect.

@Test
public void testTestConnect() throws Exception {
    ComponentTestResult result = testRdbsClient.testConnect(null);
    Assert.assertFalse(result.getResult());
    TestConnFactory connFactory = PowerMockito.mock(TestConnFactory.class);
    PowerMockito.doAnswer(new Answer() {

        @Override
        public String answer(InvocationOnMock invocationOnMock) throws Throwable {
            return "test";
        }
    }).when(connFactory).init(any(Properties.class));
    MemberModifier.field(TestRdbsClient.class, "connFactory").set(testRdbsClient, connFactory);
    String pluginInfo = "{\"test\": \"test\"}";
    ComponentTestResult okResult = testRdbsClient.testConnect(pluginInfo);
    Assert.assertTrue(okResult.getResult());
}
Also used : Answer(org.mockito.stubbing.Answer) ComponentTestResult(com.dtstack.taier.pluginapi.pojo.ComponentTestResult) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Properties(java.util.Properties) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 12 with ComponentTestResult

use of com.dtstack.taier.pluginapi.pojo.ComponentTestResult in project Taier by DTStack.

the class ConsoleComponentService method testConnect.

/**
 * 测试单个组件联通性
 */
public ComponentTestResult testConnect(Integer componentType, String componentConfig, String clusterName, String versionName, Long clusterId, KerberosConfig kerberosConfig, Map<String, String> sftpConfig, Integer storeType, Integer deployType) {
    ComponentTestResult componentTestResult = new ComponentTestResult();
    try {
        if (EComponentType.notCheckComponent.contains(EComponentType.getByCode(componentType))) {
            componentTestResult.setResult(true);
            return componentTestResult;
        }
        String typeName = null;
        if (EComponentType.HDFS.getTypeCode().equals(componentType)) {
            typeName = componentService.buildHdfsTypeName(null, clusterId);
        } else {
            typeName = convertComponentTypeToClient(clusterName, componentType, versionName, storeType, deployType);
        }
        JSONObject pluginInfo = componentService.wrapperConfig(componentType, componentConfig, sftpConfig, kerberosConfig, clusterName);
        pluginInfo.put(TYPE_NAME_KEY, typeName);
        componentTestResult = workerOperator.testConnect(pluginInfo.toJSONString());
        if (null == componentTestResult) {
            componentTestResult = new ComponentTestResult();
            componentTestResult.setResult(false);
            componentTestResult.setErrorMsg("测试联通性失败");
            return componentTestResult;
        }
        // 单组件连通性测试回写yarn的队列信息
        if (EComponentType.YARN.getTypeCode().equals(componentType) && componentTestResult.getResult() && Objects.nonNull(componentTestResult.getClusterResourceDescription())) {
            queueService.updateQueue(clusterId, componentTestResult.getClusterResourceDescription());
        }
    } catch (Throwable e) {
        if (Objects.isNull(componentTestResult)) {
            componentTestResult = new ComponentTestResult();
        }
        componentTestResult.setResult(false);
        componentTestResult.setErrorMsg(ExceptionUtil.getErrorMessage(e));
    } finally {
        if (null != componentTestResult) {
            componentTestResult.setComponentTypeCode(componentType);
            componentTestResult.setComponentVersion(versionName);
        }
    }
    return componentTestResult;
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) ComponentTestResult(com.dtstack.taier.pluginapi.pojo.ComponentTestResult)

Example 13 with ComponentTestResult

use of com.dtstack.taier.pluginapi.pojo.ComponentTestResult in project Taier by DTStack.

the class ConsoleComponentService method testComponentWithResult.

private ComponentTestResult testComponentWithResult(String clusterName, Cluster cluster, Map sftpMap, Component component) {
    ComponentTestResult testResult = new ComponentTestResult();
    try {
        KerberosConfig kerberosConfig = consoleKerberosMapper.getByComponentType(cluster.getId(), component.getComponentTypeCode(), ComponentVersionUtil.isMultiVersionComponent(component.getComponentTypeCode()) ? StringUtils.isNotBlank(component.getVersionValue()) ? component.getVersionValue() : componentMapper.getDefaultComponentVersionByClusterAndComponentType(cluster.getId(), component.getComponentTypeCode()) : null);
        String componentConfig = componentService.getComponentByClusterId(cluster.getId(), component.getComponentTypeCode(), false, String.class, null);
        testResult = this.testConnect(component.getComponentTypeCode(), componentConfig, clusterName, component.getVersionName(), component.getClusterId(), kerberosConfig, sftpMap, component.getStoreType(), component.getDeployType());
        // 测试联通性
        if (EComponentType.YARN.getTypeCode().equals(component.getComponentTypeCode()) && testResult.getResult()) {
            if (null != testResult.getClusterResourceDescription()) {
                queueService.updateQueue(cluster.getId(), testResult.getClusterResourceDescription());
            } else {
                testResult.setResult(false);
                testResult.setErrorMsg(clusterName + "获取yarn信息为空");
            }
        }
    } catch (Exception e) {
        testResult.setResult(false);
        testResult.setErrorMsg(ExceptionUtil.getErrorMessage(e));
        LOGGER.error("test connect {}  error ", component.getId(), e);
    } finally {
        testResult.setComponentVersion(component.getVersionValue());
        testResult.setComponentTypeCode(component.getComponentTypeCode());
    }
    return testResult;
}
Also used : ComponentTestResult(com.dtstack.taier.pluginapi.pojo.ComponentTestResult) RdosDefineException(com.dtstack.taier.common.exception.RdosDefineException) IOException(java.io.IOException)

Example 14 with ComponentTestResult

use of com.dtstack.taier.pluginapi.pojo.ComponentTestResult in project Taier by DTStack.

the class ConsoleComponentService method testConnect.

public ComponentTestResult testConnect(String clusterName, Integer componentType, String versionName) {
    if (StringUtils.isBlank(clusterName)) {
        throw new RdosDefineException(ErrorCode.NAME_FORMAT_ERROR);
    }
    Cluster cluster = clusterMapper.getByClusterName(clusterName);
    if (null == cluster) {
        throw new RdosDefineException(ErrorCode.CANT_NOT_FIND_CLUSTER);
    }
    Component testComponent = componentMapper.getByVersionName(cluster.getId(), componentType, versionName, null);
    if (null == testComponent) {
        throw new RdosDefineException(ErrorCode.COMPONENT_INVALID);
    }
    if (EComponentType.notCheckComponent.contains(EComponentType.getByCode(componentType))) {
        ComponentTestResult componentTestResult = new ComponentTestResult();
        componentTestResult.setComponentTypeCode(componentType);
        componentTestResult.setResult(true);
        componentTestResult.setComponentVersion(testComponent.getVersionValue());
        return componentTestResult;
    }
    Map sftpMap = componentService.getComponentByClusterId(cluster.getId(), EComponentType.SFTP.getTypeCode(), false, Map.class, null);
    return testComponentWithResult(clusterName, cluster, sftpMap, testComponent);
}
Also used : RdosDefineException(com.dtstack.taier.common.exception.RdosDefineException) ComponentTestResult(com.dtstack.taier.pluginapi.pojo.ComponentTestResult) PartCluster(com.dtstack.taier.develop.model.PartCluster)

Example 15 with ComponentTestResult

use of com.dtstack.taier.pluginapi.pojo.ComponentTestResult in project Taier by DTStack.

the class DtHdfsClient method testConnect.

/**
 * 测试联通性 yarn需要返回集群队列信息
 * @param pluginInfo
 * @return
 */
@Override
public ComponentTestResult testConnect(String pluginInfo) {
    ComponentTestResult testResult = new ComponentTestResult();
    testResult.setResult(false);
    try {
        Config allConfig = PublicUtil.jsonStrToObject(pluginInfo, Config.class);
        return this.checkHdfsConnect(allConfig);
    } catch (Exception e) {
        LOG.error("test yarn connect error", e);
        testResult.setErrorMsg(ExceptionUtil.getErrorMessage(e));
    }
    return testResult;
}
Also used : ComponentTestResult(com.dtstack.taier.pluginapi.pojo.ComponentTestResult) IOException(java.io.IOException) PluginDefineException(com.dtstack.taier.pluginapi.exception.PluginDefineException)

Aggregations

ComponentTestResult (com.dtstack.taier.pluginapi.pojo.ComponentTestResult)15 PluginDefineException (com.dtstack.taier.pluginapi.exception.PluginDefineException)8 IOException (java.io.IOException)8 RdosDefineException (com.dtstack.taier.common.exception.RdosDefineException)3 JSONObject (com.alibaba.fastjson.JSONObject)2 PartCluster (com.dtstack.taier.develop.model.PartCluster)2 HadoopConf (com.dtstack.taier.hadoop.util.HadoopConf)2 SftpConfig (com.dtstack.taier.pluginapi.sftp.SftpConfig)2 SftpFileManage (com.dtstack.taier.pluginapi.sftp.SftpFileManage)2 Configuration (org.apache.hadoop.conf.Configuration)2 YarnClient (org.apache.hadoop.yarn.client.api.YarnClient)2 YarnConfiguration (org.apache.hadoop.yarn.conf.YarnConfiguration)2 YarnException (org.apache.hadoop.yarn.exceptions.YarnException)2 JSONArray (com.alibaba.fastjson.JSONArray)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 EComponentType (com.dtstack.taier.common.enums.EComponentType)1 EnvironmentContext (com.dtstack.taier.common.env.EnvironmentContext)1 ErrorCode (com.dtstack.taier.common.exception.ErrorCode)1