diff --git a/docs/errorcode/linkis-engineplugin-hive.md b/docs/errorcode/linkis-engineplugin-hive.md new file mode 100644 index 0000000000..105e91cef5 --- /dev/null +++ b/docs/errorcode/linkis-engineplugin-hive.md @@ -0,0 +1,10 @@ +## linkis-engineplugin-hive errorcode + + +| 模块名(服务名) | 错误码 | 描述 | module | +|--------------------------|-------| ---- |--------------| +| linkis-engineplugin-hive | 26040 |failed to create hive executor(创建hive执行器失败)| hiveEngine | +| linkis-engineplugin-hive | 26041 |cannot find hive-exec.jar, start session failed(找不到 hive-exec.jar,启动会话失败)| hiveEngine | +| linkis-engineplugin-hive | 26042 |cannot get the field schemas(无法获取字段模式)| hiveEngine | +| linkis-engineplugin-hive | 26043 |invalid value(无效值)| hiveEngine | + diff --git a/linkis-engineconn-plugins/hive/src/main/java/org/apache/linkis/engineplugin/hive/errorcode/HiveErrorCodeSummary.java b/linkis-engineconn-plugins/hive/src/main/java/org/apache/linkis/engineplugin/hive/errorcode/HiveErrorCodeSummary.java new file mode 100644 index 0000000000..6c12583f09 --- /dev/null +++ b/linkis-engineconn-plugins/hive/src/main/java/org/apache/linkis/engineplugin/hive/errorcode/HiveErrorCodeSummary.java @@ -0,0 +1,97 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.linkis.engineplugin.hive.errorcode; + +import org.apache.linkis.common.errorcode.ErrorCodeUtils; + +public enum HiveErrorCodeSummary { + /** + * 10000-10999 linkis-frame 11000-12999 linkis-commons 13000-14999 linkis-spring-cloud-services + * 15000-19999 linkis-public-enhancements 20000-24999 linkis-computation-governance 25000-25999 + * linkis-extensions 26000-29999 linkis-engineconn-plugins + */ + CREATE_HIVE_EXECUTOR_ERROR( + 26040, + "failed to create hive executor(创建hive执行器失败)", + "failed to create hive executor(创建hive执行器失败)", + "hiveEngine"), + HIVE_EXEC_JAR_ERROR( + 26041, + "cannot find hive-exec.jar, start session failed(找不到 hive-exec.jar,启动会话失败)", + "cannot find hive-exec.jar, start session failed(找不到 hive-exec.jar,启动会话失败)", + "hiveEngine"), + GET_FIELD_SCHEMAS_ERROR( + 26042, + "cannot get the field schemas(无法获取字段模式)", + "cannot get the field schemas(无法获取字段模式)", + "hiveEngine"), + INVALID_VALUE(26043, "invalid value(无效值)", "invalid value(无效值)", "hiveEngine"); + + private int errorCode; + + private String errorDesc; + + private String comment; + + private String module; + + HiveErrorCodeSummary(int errorCode, String errorDesc, String comment, String module) { + ErrorCodeUtils.validateErrorCode(errorCode, 26000, 29999); + this.errorCode = errorCode; + this.errorDesc = errorDesc; + this.comment = comment; + this.module = module; + } + + public int getErrorCode() { + return errorCode; + } + + public void setErrorCode(int errorCode) { + this.errorCode = errorCode; + } + + public String getErrorDesc() { + return errorDesc; + } + + public void setErrorDesc(String errorDesc) { + this.errorDesc = errorDesc; + } + + public String getComment() { + return comment; + } + + public void setComment(String comment) { + this.comment = comment; + } + + public String getModule() { + return module; + } + + public void setModule(String module) { + this.module = module; + } + + @Override + public String toString() { + return "errorCode: " + this.errorCode + ", errorDesc:" + this.errorDesc; + } +} diff --git a/linkis-engineconn-plugins/hive/src/main/scala/org/apache/linkis/engineplugin/hive/creation/HiveEngineConnFactory.scala b/linkis-engineconn-plugins/hive/src/main/scala/org/apache/linkis/engineplugin/hive/creation/HiveEngineConnFactory.scala index d4a78c5ba6..9a46975979 100644 --- a/linkis-engineconn-plugins/hive/src/main/scala/org/apache/linkis/engineplugin/hive/creation/HiveEngineConnFactory.scala +++ b/linkis-engineconn-plugins/hive/src/main/scala/org/apache/linkis/engineplugin/hive/creation/HiveEngineConnFactory.scala @@ -25,6 +25,8 @@ import org.apache.linkis.engineconn.executor.entity.LabelExecutor import org.apache.linkis.engineplugin.hive.common.HiveUtils import org.apache.linkis.engineplugin.hive.conf.HiveEngineConfiguration import org.apache.linkis.engineplugin.hive.entity.HiveSession +import org.apache.linkis.engineplugin.hive.errorcode.HiveErrorCodeSummary.CREATE_HIVE_EXECUTOR_ERROR +import org.apache.linkis.engineplugin.hive.errorcode.HiveErrorCodeSummary.HIVE_EXEC_JAR_ERROR import org.apache.linkis.engineplugin.hive.exception.HiveSessionStartFailedException import org.apache.linkis.engineplugin.hive.executor.HiveEngineConnExecutor import org.apache.linkis.hadoop.common.utils.HDFSUtils @@ -62,7 +64,10 @@ class HiveEngineConnFactory extends ComputationSingleExecutorEngineConnFactory w hiveSession.baos ) case _ => - throw HiveSessionStartFailedException(40012, "Failed to create hive executor") + throw HiveSessionStartFailedException( + CREATE_HIVE_EXECUTOR_ERROR.getErrorCode, + CREATE_HIVE_EXECUTOR_ERROR.getErrorDesc + ) } } @@ -77,8 +82,8 @@ class HiveEngineConnFactory extends ComputationSingleExecutorEngineConnFactory w .jarOfClass(classOf[Driver]) .getOrElse( throw HiveSessionStartFailedException( - 40012, - "cannot find hive-exec.jar, start session failed!" + HIVE_EXEC_JAR_ERROR.getErrorCode, + HIVE_EXEC_JAR_ERROR.getErrorDesc ) ) ) diff --git a/linkis-engineconn-plugins/hive/src/main/scala/org/apache/linkis/engineplugin/hive/exception/NotSupportedHiveTypeException.scala b/linkis-engineconn-plugins/hive/src/main/scala/org/apache/linkis/engineplugin/hive/exception/NotSupportedHiveTypeException.scala index 84e617e10e..8416ae5e9d 100644 --- a/linkis-engineconn-plugins/hive/src/main/scala/org/apache/linkis/engineplugin/hive/exception/NotSupportedHiveTypeException.scala +++ b/linkis-engineconn-plugins/hive/src/main/scala/org/apache/linkis/engineplugin/hive/exception/NotSupportedHiveTypeException.scala @@ -19,20 +19,8 @@ package org.apache.linkis.engineplugin.hive.exception import org.apache.linkis.common.exception.ErrorException -case class NotSupportedHiveTypeException(errCode: Int, desc: String) - extends ErrorException(errCode, desc) {} - -case class HadoopConfSetFailedException(errCode: Int, desc: String) - extends ErrorException(errCode, desc) {} - case class HiveSessionStartFailedException(erroCode: Int, desc: String) - extends ErrorException(erroCode, desc) {} + extends ErrorException(erroCode, desc) -/** - * @param erroCode - * 41004 - * @param desc - * hive query fail - */ case class HiveQueryFailedException(erroCode: Int, desc: String) - extends ErrorException(erroCode, desc) {} + extends ErrorException(erroCode, desc) diff --git a/linkis-engineconn-plugins/hive/src/main/scala/org/apache/linkis/engineplugin/hive/executor/HiveEngineConnExecutor.scala b/linkis-engineconn-plugins/hive/src/main/scala/org/apache/linkis/engineplugin/hive/executor/HiveEngineConnExecutor.scala index f1bc209144..7a1d119b0e 100644 --- a/linkis-engineconn-plugins/hive/src/main/scala/org/apache/linkis/engineplugin/hive/executor/HiveEngineConnExecutor.scala +++ b/linkis-engineconn-plugins/hive/src/main/scala/org/apache/linkis/engineplugin/hive/executor/HiveEngineConnExecutor.scala @@ -28,6 +28,7 @@ import org.apache.linkis.engineconn.core.EngineConnObject import org.apache.linkis.engineconn.executor.entity.ResourceFetchExecutor import org.apache.linkis.engineplugin.hive.conf.{Counters, HiveEngineConfiguration} import org.apache.linkis.engineplugin.hive.cs.CSHiveHelper +import org.apache.linkis.engineplugin.hive.errorcode.HiveErrorCodeSummary.GET_FIELD_SCHEMAS_ERROR import org.apache.linkis.engineplugin.hive.exception.HiveQueryFailedException import org.apache.linkis.engineplugin.hive.progress.HiveProgressHelper import org.apache.linkis.governance.common.paser.SQLCodeParser @@ -234,7 +235,11 @@ class HiveEngineConnExecutor( val fieldSchemas = if (hiveResponse.getSchema != null) hiveResponse.getSchema.getFieldSchemas else if (driver.getSchema != null) driver.getSchema.getFieldSchemas - else throw HiveQueryFailedException(41005, "cannot get the field schemas.") + else + throw HiveQueryFailedException( + GET_FIELD_SCHEMAS_ERROR.getErrorCode, + GET_FIELD_SCHEMAS_ERROR.getErrorDesc + ) LOG.debug("fieldSchemas are " + fieldSchemas) if (fieldSchemas == null || isNoResultSql(realCode)) { diff --git a/linkis-engineconn-plugins/hive/src/main/scala/org/apache/linkis/engineplugin/hive/hook/HiveAddMetaTableNameHook.scala b/linkis-engineconn-plugins/hive/src/main/scala/org/apache/linkis/engineplugin/hive/hook/HiveAddMetaTableNameHook.scala index 85c538c8d3..8720e527f2 100644 --- a/linkis-engineconn-plugins/hive/src/main/scala/org/apache/linkis/engineplugin/hive/hook/HiveAddMetaTableNameHook.scala +++ b/linkis-engineconn-plugins/hive/src/main/scala/org/apache/linkis/engineplugin/hive/hook/HiveAddMetaTableNameHook.scala @@ -21,6 +21,7 @@ import org.apache.linkis.common.utils.{Logging, Utils} import org.apache.linkis.engineconn.common.creation.EngineCreationContext import org.apache.linkis.engineconn.computation.executor.execute.EngineExecutionContext import org.apache.linkis.engineconn.computation.executor.hook.ComputationExecutorHook +import org.apache.linkis.engineplugin.hive.errorcode.HiveErrorCodeSummary.INVALID_VALUE import org.apache.linkis.engineplugin.hive.exception.HiveQueryFailedException import org.apache.commons.lang3.StringUtils @@ -78,8 +79,8 @@ class HiveAddMetaTableNameHook extends ComputationExecutorHook with Logging { engineExecutionContext.setEnableResultsetMetaWithTableName(boolValue) } { case e: IllegalArgumentException => throw HiveQueryFailedException( - 41006, - s"Invalid value : ${value} in param [${mather.group()}]" + INVALID_VALUE.getErrorCode, + INVALID_VALUE.getErrorDesc.concat(s" : ${value} in param [${mather.group()}]") ) } } diff --git a/linkis-engineconn-plugins/hive/src/test/java/org/apache/linkis/common/errorcode/HiveErrorCodeSummaryTest.java b/linkis-engineconn-plugins/hive/src/test/java/org/apache/linkis/common/errorcode/HiveErrorCodeSummaryTest.java new file mode 100644 index 0000000000..9ebb36d6af --- /dev/null +++ b/linkis-engineconn-plugins/hive/src/test/java/org/apache/linkis/common/errorcode/HiveErrorCodeSummaryTest.java @@ -0,0 +1,166 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.linkis.common.errorcode; + +import org.junit.jupiter.api.Test; + +import static org.apache.linkis.engineplugin.hive.errorcode.HiveErrorCodeSummary.CREATE_HIVE_EXECUTOR_ERROR; +import static org.apache.linkis.engineplugin.hive.errorcode.HiveErrorCodeSummary.GET_FIELD_SCHEMAS_ERROR; +import static org.apache.linkis.engineplugin.hive.errorcode.HiveErrorCodeSummary.HIVE_EXEC_JAR_ERROR; +import static org.apache.linkis.engineplugin.hive.errorcode.HiveErrorCodeSummary.INVALID_VALUE; +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class HiveErrorCodeSummaryTest { + @Test + void testGetErrorCode() { + assertEquals(26040, CREATE_HIVE_EXECUTOR_ERROR.getErrorCode()); + assertEquals(26041, HIVE_EXEC_JAR_ERROR.getErrorCode()); + assertEquals(26042, GET_FIELD_SCHEMAS_ERROR.getErrorCode()); + assertEquals(26043, INVALID_VALUE.getErrorCode()); + } + + @Test + void testSetErrorCode() { + CREATE_HIVE_EXECUTOR_ERROR.setErrorCode(1); + assertEquals(1, CREATE_HIVE_EXECUTOR_ERROR.getErrorCode()); + CREATE_HIVE_EXECUTOR_ERROR.setErrorCode(26040); + assertEquals(26040, CREATE_HIVE_EXECUTOR_ERROR.getErrorCode()); + + HIVE_EXEC_JAR_ERROR.setErrorCode(1); + assertEquals(1, HIVE_EXEC_JAR_ERROR.getErrorCode()); + HIVE_EXEC_JAR_ERROR.setErrorCode(26041); + assertEquals(26041, HIVE_EXEC_JAR_ERROR.getErrorCode()); + + GET_FIELD_SCHEMAS_ERROR.setErrorCode(1); + assertEquals(1, GET_FIELD_SCHEMAS_ERROR.getErrorCode()); + GET_FIELD_SCHEMAS_ERROR.setErrorCode(26042); + assertEquals(26042, GET_FIELD_SCHEMAS_ERROR.getErrorCode()); + + INVALID_VALUE.setErrorCode(1); + assertEquals(1, INVALID_VALUE.getErrorCode()); + INVALID_VALUE.setErrorCode(26043); + assertEquals(26043, INVALID_VALUE.getErrorCode()); + } + + @Test + void testGetErrorDesc() { + assertEquals( + "failed to create hive executor(创建hive执行器失败)", CREATE_HIVE_EXECUTOR_ERROR.getErrorDesc()); + assertEquals( + "cannot find hive-exec.jar, start session failed(找不到 hive-exec.jar,启动会话失败)", + HIVE_EXEC_JAR_ERROR.getErrorDesc()); + assertEquals("cannot get the field schemas(无法获取字段模式)", GET_FIELD_SCHEMAS_ERROR.getErrorDesc()); + assertEquals("invalid value(无效值)", INVALID_VALUE.getErrorDesc()); + } + + @Test + void testSetErrorDesc() { + CREATE_HIVE_EXECUTOR_ERROR.setErrorDesc("test"); + assertEquals("test", CREATE_HIVE_EXECUTOR_ERROR.getErrorDesc()); + CREATE_HIVE_EXECUTOR_ERROR.setErrorDesc("failed to create hive executor(创建hive执行器失败)"); + assertEquals( + "failed to create hive executor(创建hive执行器失败)", CREATE_HIVE_EXECUTOR_ERROR.getErrorDesc()); + + HIVE_EXEC_JAR_ERROR.setErrorDesc("test"); + assertEquals("test", HIVE_EXEC_JAR_ERROR.getErrorDesc()); + HIVE_EXEC_JAR_ERROR.setErrorDesc( + "cannot find hive-exec.jar, start session failed(找不到 hive-exec.jar,启动会话失败)"); + assertEquals( + "cannot find hive-exec.jar, start session failed(找不到 hive-exec.jar,启动会话失败)", + HIVE_EXEC_JAR_ERROR.getErrorDesc()); + + GET_FIELD_SCHEMAS_ERROR.setErrorDesc("test"); + assertEquals("test", GET_FIELD_SCHEMAS_ERROR.getErrorDesc()); + GET_FIELD_SCHEMAS_ERROR.setErrorDesc("cannot get the field schemas(无法获取字段模式)"); + assertEquals("cannot get the field schemas(无法获取字段模式)", GET_FIELD_SCHEMAS_ERROR.getErrorDesc()); + + INVALID_VALUE.setErrorDesc("test"); + assertEquals("test", INVALID_VALUE.getErrorDesc()); + INVALID_VALUE.setErrorDesc("invalid value(无效值)"); + assertEquals("invalid value(无效值)", INVALID_VALUE.getErrorDesc()); + } + + @Test + void testGetComment() { + assertEquals( + "failed to create hive executor(创建hive执行器失败)", CREATE_HIVE_EXECUTOR_ERROR.getComment()); + assertEquals( + "cannot find hive-exec.jar, start session failed(找不到 hive-exec.jar,启动会话失败)", + HIVE_EXEC_JAR_ERROR.getComment()); + assertEquals("cannot get the field schemas(无法获取字段模式)", GET_FIELD_SCHEMAS_ERROR.getComment()); + assertEquals("invalid value(无效值)", INVALID_VALUE.getComment()); + } + + @Test + void testSetComment() { + CREATE_HIVE_EXECUTOR_ERROR.setComment("test"); + assertEquals("test", CREATE_HIVE_EXECUTOR_ERROR.getComment()); + CREATE_HIVE_EXECUTOR_ERROR.setComment("failed to create hive executor(创建hive执行器失败)"); + assertEquals( + "failed to create hive executor(创建hive执行器失败)", CREATE_HIVE_EXECUTOR_ERROR.getComment()); + + HIVE_EXEC_JAR_ERROR.setComment("test"); + assertEquals("test", HIVE_EXEC_JAR_ERROR.getComment()); + HIVE_EXEC_JAR_ERROR.setComment( + "cannot find hive-exec.jar, start session failed(找不到 hive-exec.jar,启动会话失败)"); + assertEquals( + "cannot find hive-exec.jar, start session failed(找不到 hive-exec.jar,启动会话失败)", + HIVE_EXEC_JAR_ERROR.getComment()); + + GET_FIELD_SCHEMAS_ERROR.setComment("test"); + assertEquals("test", GET_FIELD_SCHEMAS_ERROR.getComment()); + GET_FIELD_SCHEMAS_ERROR.setComment("cannot get the field schemas(无法获取字段模式)"); + assertEquals("cannot get the field schemas(无法获取字段模式)", GET_FIELD_SCHEMAS_ERROR.getComment()); + + INVALID_VALUE.setComment("test"); + assertEquals("test", INVALID_VALUE.getComment()); + INVALID_VALUE.setComment("invalid value(无效值)"); + assertEquals("invalid value(无效值)", INVALID_VALUE.getComment()); + } + + @Test + void testGetModule() { + assertEquals("hiveEngine", CREATE_HIVE_EXECUTOR_ERROR.getModule()); + assertEquals("hiveEngine", HIVE_EXEC_JAR_ERROR.getModule()); + assertEquals("hiveEngine", GET_FIELD_SCHEMAS_ERROR.getModule()); + assertEquals("hiveEngine", INVALID_VALUE.getModule()); + } + + @Test + void testSetModule() { + CREATE_HIVE_EXECUTOR_ERROR.setModule("test"); + assertEquals("test", CREATE_HIVE_EXECUTOR_ERROR.getModule()); + CREATE_HIVE_EXECUTOR_ERROR.setModule("hiveEngine"); + assertEquals("hiveEngine", CREATE_HIVE_EXECUTOR_ERROR.getModule()); + + HIVE_EXEC_JAR_ERROR.setModule("test"); + assertEquals("test", HIVE_EXEC_JAR_ERROR.getModule()); + HIVE_EXEC_JAR_ERROR.setModule("hiveEngine"); + assertEquals("hiveEngine", HIVE_EXEC_JAR_ERROR.getModule()); + + GET_FIELD_SCHEMAS_ERROR.setModule("test"); + assertEquals("test", GET_FIELD_SCHEMAS_ERROR.getModule()); + GET_FIELD_SCHEMAS_ERROR.setModule("hiveEngine"); + assertEquals("hiveEngine", GET_FIELD_SCHEMAS_ERROR.getModule()); + + INVALID_VALUE.setModule("test"); + assertEquals("test", INVALID_VALUE.getModule()); + INVALID_VALUE.setModule("hiveEngine"); + assertEquals("hiveEngine", INVALID_VALUE.getModule()); + } +}