Repository: dtstack/taier
Issue: 资源组件HiveServer连接测试失败

 报错信息：
{"componentTypeCode":0,"errorMsg":"com.dtstack.taier.pluginapi.exception.PluginDefineException: get conn exception:com.dtstack.taier.pluginapi.exception.PluginDefineException: get conn exception:com.dtstack.taier.pluginapi.exception.PluginDefineException: java.lang.NullPointerException\\r\\ncom.dtstack.taier.pluginapi.exception.PluginDefineException: get conn exception:com.dtstack.taier.pluginapi.exception.PluginDefineException: get conn exception:com.dtstack.taier.pluginapi.exception.PluginDefineException: java.lang.NullPointerException\\r\\n\\tat com.dtstack.taier.rdbs.common.executor.AbstractConnFactory.init(AbstractConnFactory.java:91)\\r\\n\\tat com.dtstack.taier.rdbs.hive.HiveConnFactory.init(HiveConnFactory.java:66)\\r\\n\\tat com.dtstack.taier.rdbs.common.AbstractRdbsClient.testConnect(AbstractRdbsClient.java:160)\\r\\n\\tat com.dtstack.taier.common.client.ClientProxy.lambda$null$9(ClientProxy.java:273)\\r\\n\\tat com.dtstack.taier.pluginapi.callback.ClassLoaderCallBackMethod.callbackAndReset(ClassLoaderCallBackMethod.java:31)\\r\\n\\tat com.dtstack.taier.common.client.ClientProxy.lambda$testConnect$10(ClientProxy.java:273)\\r\\n\\tat java.util.concurrent.CompletableFuture$AsyncSupply.run$$$capture(CompletableFuture.java:1590)\\r\\n\\tat java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java)\\r\\n\\tat java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)\\r\\n\\tat java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)\\r\\n\\tat java.lang.Thread.run(Thread.java:748)\\r\\n","result":false}

报错原因：
com.dtstack.taier.rdbs.common.executor.AbstractConnFactory 85行处 properties.get("yarnConf")为null

解决办法：
重载com.dtstack.taier.scheduler.service.ComponentService中wrapperConfig方法：（对hiveserver组间补充yarnConf配置）
public JSONObject wrapperConfig(int componentType, String componentConfig, Map<String, String> sftpConfig, KerberosConfig kerberosConfig) {
        JSONObject dataInfo = JSONObject.parseObject(componentConfig);
        if (EComponentType.YARN.getTypeCode() == componentType) {
            JSONObject confInfo = new JSONObject();
            confInfo.put(EComponentType.YARN.getConfName(), dataInfo);
            dataInfo = confInfo;
        } else if (EComponentType.HDFS.getTypeCode() == componentType) {
            JSONObject confInfo = new JSONObject();
            confInfo.put(EComponentType.HDFS.getConfName(), dataInfo);
            dataInfo = confInfo;
        }
        //开启了kerberos
        if (null != kerberosConfig) {
            dataInfo.put(KERBEROS_FILE_TIMESTAMP, kerberosConfig.getGmtModified());
            dataInfo.put(OPEN_KERBEROS, kerberosConfig.getOpenKerberos());
            dataInfo.put(REMOTE_DIR, kerberosConfig.getRemotePath());
            dataInfo.put(PRINCIPAL_FILE, kerberosConfig.getName());
            dataInfo.put(KRB_NAME, kerberosConfig.getKrbName());
            dataInfo.put(PRINCIPAL, kerberosConfig.getPrincipal());
            dataInfo.put(MERGE_KRB5_CONTENT_KEY, kerberosConfig.getMergeKrbContent());
        }
        //common参数
        dataInfo.put(EComponentType.SFTP.getConfName(), sftpConfig);
        return dataInfo;
    }

    private void putYarnConfig(Long clusterId, JSONObject dataInfo) {
        Map yarnMap = getComponentByClusterId(clusterId, EComponentType.YARN.getTypeCode(), false, Map.class, null);
        if (null != yarnMap) {
            dataInfo.put(EComponentType.YARN.getConfName(), yarnMap);
        }
    }

Changed files:
taier-data-develop/src/main/java/com/dtstack/taier/develop/service/console/ConsoleComponentService.java
taier-data-develop/src/main/java/com/dtstack/taier/develop/service/console/ConsoleService.java
taier-scheduler/src/main/java/com/dtstack/taier/scheduler/service/ComponentService.java

diff --git a/taier-data-develop/src/main/java/com/dtstack/taier/develop/service/console/ConsoleComponentService.java b/taier-data-develop/src/main/java/com/dtstack/taier/develop/service/console/ConsoleComponentService.java
index 2847d19f..c1e9fbc8 100644
--- a/taier-data-develop/src/main/java/com/dtstack/taier/develop/service/console/ConsoleComponentService.java
+++ b/taier-data-develop/src/main/java/com/dtstack/taier/develop/service/console/ConsoleComponentService.java
@@ -1098,7 +1098,7 @@ public class ConsoleComponentService {
             if (EComponentType.HDFS.getTypeCode().equals(componentType)) {
                 typeName = componentService.buildHdfsTypeName(null, clusterId);
             }
-            JSONObject pluginInfo = componentService.wrapperConfig(componentType, componentConfig, sftpConfig, kerberosConfig);
+            JSONObject pluginInfo = componentService.wrapperConfig(componentType, componentConfig, sftpConfig, kerberosConfig, clusterId);
             pluginInfo.put(TYPE_NAME_KEY, typeName);
             componentTestResult = workerOperator.testConnect(pluginInfo.toJSONString());
             if (null == componentTestResult) {
diff --git a/taier-data-develop/src/main/java/com/dtstack/taier/develop/service/console/ConsoleService.java b/taier-data-develop/src/main/java/com/dtstack/taier/develop/service/console/ConsoleService.java
index aab6dcb3..e257f6c8 100644
--- a/taier-data-develop/src/main/java/com/dtstack/taier/develop/service/console/ConsoleService.java
+++ b/taier-data-develop/src/main/java/com/dtstack/taier/develop/service/console/ConsoleService.java
@@ -457,7 +457,7 @@ public class ConsoleService {
                 //开启kerberos 添加信息
                 KerberosConfig kerberosConfig = consoleKerberosMapper.getByComponentType(cluster.getId(), yarnComponent.getComponentTypeCode(), ComponentVersionUtil.formatMultiVersion(yarnComponent.getComponentTypeCode(),yarnComponent.getVersionValue()));
                 Map sftpMap = componentService.getComponentByClusterId(cluster.getId(), EComponentType.SFTP.getTypeCode(), false, Map.class,null);
-                pluginInfo = componentService.wrapperConfig(yarnComponent.getComponentTypeCode(),componentConfig.toJSONString(),sftpMap,kerberosConfig);
+                pluginInfo = componentService.wrapperConfig(yarnComponent.getComponentTypeCode(),componentConfig.toJSONString(),sftpMap,kerberosConfig,cluster.getId());
             }
             String typeName = componentConfig.getString(ConfigConstant.TYPE_NAME_KEY);
             if (StringUtils.isBlank(typeName)) {
diff --git a/taier-scheduler/src/main/java/com/dtstack/taier/scheduler/service/ComponentService.java b/taier-scheduler/src/main/java/com/dtstack/taier/scheduler/service/ComponentService.java
index df3127c0..abf42fb3 100644
--- a/taier-scheduler/src/main/java/com/dtstack/taier/scheduler/service/ComponentService.java
+++ b/taier-scheduler/src/main/java/com/dtstack/taier/scheduler/service/ComponentService.java
@@ -93,7 +93,7 @@ public class ComponentService {
                     ComponentVersionUtil.formatMultiVersion(componentCode, componentVersion));
         }
         Map sftpMap = getComponentByClusterId(clusterId, EComponentType.SFTP.getTypeCode(), false, Map.class, null);
-        pluginInfo = wrapperConfig(componentCode, componentConfig.toJSONString(), sftpMap, kerberosConfig);
+        pluginInfo = wrapperConfig(componentCode, componentConfig.toJSONString(), sftpMap, kerberosConfig,clusterId);
         return pluginInfo;
     }
 
@@ -105,11 +105,13 @@ public class ComponentService {
      * @param componentConfig
      * @return
      */
-    public JSONObject wrapperConfig(int componentType, String componentConfig, Map<String, String> sftpConfig, KerberosConfig kerberosConfig) {
+    public JSONObject wrapperConfig(int componentType, String componentConfig, Map<String, String> sftpConfig, KerberosConfig kerberosConfig,Long clusterId) {
         EComponentType eComponentType = EComponentType.getByCode(componentType);
         JSONObject dataInfo = new JSONObject();
         if (EComponentType.YARN.equals(eComponentType) || EComponentType.HDFS.equals(eComponentType)) {
             dataInfo.put(eComponentType.getConfName(), JSONObject.parseObject(componentConfig));
+        } if (EComponentType.HIVE_SERVER.equals(eComponentType)) {
+            putYarnConfig(clusterId, dataInfo);
         } else {
             dataInfo = JSONObject.parseObject(componentConfig);
         }
@@ -130,6 +132,13 @@ public class ComponentService {
         return dataInfo;
     }
 
+    private void putYarnConfig(Long clusterId, JSONObject dataInfo) {
+        Map yarnMap = getComponentByClusterId(clusterId, EComponentType.YARN.getTypeCode(), false, Map.class, null);
+        if (null != yarnMap) {
+            dataInfo.put(EComponentType.YARN.getConfName(), yarnMap);
+        }
+    }
+
     public Component getComponentByClusterId(Long clusterId, Integer componentType, String componentVersion) {
         return componentMapper.getByClusterIdAndComponentType(clusterId, componentType, componentVersion, null);
     }