You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@linkis.apache.org by ca...@apache.org on 2022/10/18 02:37:15 UTC

[incubator-linkis] branch dev-1.3.1-errorcode updated: [ISSUE-3380][linkis-engineplugin-elasticsearch]errorcode code optimization (#3531)

This is an automated email from the ASF dual-hosted git repository.

casion pushed a commit to branch dev-1.3.1-errorcode
in repository https://gitbox.apache.org/repos/asf/incubator-linkis.git


The following commit(s) were added to refs/heads/dev-1.3.1-errorcode by this push:
     new aaee55647 [ISSUE-3380][linkis-engineplugin-elasticsearch]errorcode code optimization (#3531)
aaee55647 is described below

commit aaee55647f587cb7d8e7e374dfcf8a79600e9182
Author: 成彬彬 <10...@users.noreply.github.com>
AuthorDate: Tue Oct 18 10:37:09 2022 +0800

    [ISSUE-3380][linkis-engineplugin-elasticsearch]errorcode code optimization (#3531)
---
 docs/errorcode/elasticsearch-errorcode.md          |  8 +++
 .../errorcode/EasticsearchErrorCodeSummary.java    | 68 ++++++++++++++++++++++
 .../exception/EsConvertResponseException.scala     |  4 +-
 .../exception/EsParamsIllegalException.scala       |  4 +-
 .../executor/client/EsClientFactory.scala          |  5 +-
 .../executor/client/impl/ResponseHandlerImpl.scala |  5 +-
 6 files changed, 87 insertions(+), 7 deletions(-)

diff --git a/docs/errorcode/elasticsearch-errorcode.md b/docs/errorcode/elasticsearch-errorcode.md
new file mode 100644
index 000000000..5cff34db1
--- /dev/null
+++ b/docs/errorcode/elasticsearch-errorcode.md
@@ -0,0 +1,8 @@
+## elasticsearch  errorcode
+
+| module name(模块名) | error code(错误码)  | describe(描述) |enumeration name(枚举)| Exception Class(类名)|
+| -------- | -------- | ----- |-----|-----|
+|elasticsearch |70112|cluster is blank!(集群是空白的!)|CLUSTER_IS_BLANK|EasticsearchErrorCodeSummary|
+|elasticsearch |70113|EsEngineExecutor convert response fail, response content is empty.(EsEngineExecutor 转换响应失败,响应内容为空.)|RESPONSE_FAIL_IS_EMPTY|EasticsearchErrorCodeSummary|
+
+
diff --git a/linkis-engineconn-plugins/elasticsearch/src/main/java/org/apache/linkis/engineplugin/elasticsearch/errorcode/EasticsearchErrorCodeSummary.java b/linkis-engineconn-plugins/elasticsearch/src/main/java/org/apache/linkis/engineplugin/elasticsearch/errorcode/EasticsearchErrorCodeSummary.java
new file mode 100644
index 000000000..553b66a97
--- /dev/null
+++ b/linkis-engineconn-plugins/elasticsearch/src/main/java/org/apache/linkis/engineplugin/elasticsearch/errorcode/EasticsearchErrorCodeSummary.java
@@ -0,0 +1,68 @@
+/*
+ * 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.elasticsearch.errorcode;
+
+public enum EasticsearchErrorCodeSummary {
+  CLUSTER_IS_BLANK(70112, "cluster is blank!(集群是空白的!)", "cluster is blank!(集群是空白的!)"),
+  RESPONSE_FAIL_IS_EMPTY(
+      70113,
+      "EsEngineExecutor convert response fail, response content is empty.(EsEngineExecutor 转换响应失败,响应内容为空.)",
+      "EsEngineExecutor convert response fail, response content is empty.(EsEngineExecutor 转换响应失败,响应内容为空.)");
+
+  /** (errorCode)错误码 */
+  private int errorCode;
+  /** (errorDesc)错误描述 */
+  private String errorDesc;
+  /** Possible reasons for the error(错误可能出现的原因) */
+  private String comment;
+
+  EasticsearchErrorCodeSummary(int errorCode, String errorDesc, String comment) {
+    this.errorCode = errorCode;
+    this.errorDesc = errorDesc;
+    this.comment = comment;
+  }
+
+  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;
+  }
+
+  @Override
+  public String toString() {
+    return "errorCode: " + this.errorCode + ", errorDesc:" + this.errorDesc;
+  }
+}
diff --git a/linkis-engineconn-plugins/elasticsearch/src/main/scala/org/apache/linkis/engineplugin/elasticsearch/exception/EsConvertResponseException.scala b/linkis-engineconn-plugins/elasticsearch/src/main/scala/org/apache/linkis/engineplugin/elasticsearch/exception/EsConvertResponseException.scala
index a5699feba..998a2d81d 100644
--- a/linkis-engineconn-plugins/elasticsearch/src/main/scala/org/apache/linkis/engineplugin/elasticsearch/exception/EsConvertResponseException.scala
+++ b/linkis-engineconn-plugins/elasticsearch/src/main/scala/org/apache/linkis/engineplugin/elasticsearch/exception/EsConvertResponseException.scala
@@ -18,5 +18,7 @@
 package org.apache.linkis.engineplugin.elasticsearch.exception
 
 import org.apache.linkis.common.exception.ErrorException
+import org.apache.linkis.engineplugin.elasticsearch.errorcode.EasticsearchErrorCodeSummary.RESPONSE_FAIL_IS_EMPTY
 
-case class EsConvertResponseException(errorMsg: String) extends ErrorException(70113, errorMsg)
+case class EsConvertResponseException(errorMsg: String)
+    extends ErrorException(RESPONSE_FAIL_IS_EMPTY.getErrorCode, errorMsg)
diff --git a/linkis-engineconn-plugins/elasticsearch/src/main/scala/org/apache/linkis/engineplugin/elasticsearch/exception/EsParamsIllegalException.scala b/linkis-engineconn-plugins/elasticsearch/src/main/scala/org/apache/linkis/engineplugin/elasticsearch/exception/EsParamsIllegalException.scala
index 7fe705756..f6c7d4131 100644
--- a/linkis-engineconn-plugins/elasticsearch/src/main/scala/org/apache/linkis/engineplugin/elasticsearch/exception/EsParamsIllegalException.scala
+++ b/linkis-engineconn-plugins/elasticsearch/src/main/scala/org/apache/linkis/engineplugin/elasticsearch/exception/EsParamsIllegalException.scala
@@ -18,5 +18,7 @@
 package org.apache.linkis.engineplugin.elasticsearch.exception
 
 import org.apache.linkis.common.exception.ErrorException
+import org.apache.linkis.engineplugin.elasticsearch.errorcode.EasticsearchErrorCodeSummary.CLUSTER_IS_BLANK
 
-case class EsParamsIllegalException(errorMsg: String) extends ErrorException(70112, errorMsg)
+case class EsParamsIllegalException(errorMsg: String)
+    extends ErrorException(CLUSTER_IS_BLANK.getErrorCode, errorMsg)
diff --git a/linkis-engineconn-plugins/elasticsearch/src/main/scala/org/apache/linkis/engineplugin/elasticsearch/executor/client/EsClientFactory.scala b/linkis-engineconn-plugins/elasticsearch/src/main/scala/org/apache/linkis/engineplugin/elasticsearch/executor/client/EsClientFactory.scala
index c4e3ef17f..30cb6690b 100644
--- a/linkis-engineconn-plugins/elasticsearch/src/main/scala/org/apache/linkis/engineplugin/elasticsearch/executor/client/EsClientFactory.scala
+++ b/linkis-engineconn-plugins/elasticsearch/src/main/scala/org/apache/linkis/engineplugin/elasticsearch/executor/client/EsClientFactory.scala
@@ -19,6 +19,7 @@ package org.apache.linkis.engineplugin.elasticsearch.executor.client
 
 import org.apache.linkis.common.conf.CommonVars
 import org.apache.linkis.engineplugin.elasticsearch.conf.ElasticSearchConfiguration._
+import org.apache.linkis.engineplugin.elasticsearch.errorcode.EasticsearchErrorCodeSummary.CLUSTER_IS_BLANK
 import org.apache.linkis.engineplugin.elasticsearch.exception.EsParamsIllegalException
 
 import org.apache.commons.lang3.StringUtils
@@ -81,11 +82,11 @@ object EsClientFactory {
   private def createRestClient(options: util.Map[String, String]): EsClient = {
     val clusterStr = options.get(ES_CLUSTER.key)
     if (StringUtils.isBlank(clusterStr)) {
-      throw EsParamsIllegalException("cluster is blank!")
+      throw EsParamsIllegalException(CLUSTER_IS_BLANK.getErrorDesc)
     }
     val cluster = getCluster(clusterStr)
     if (cluster.isEmpty) {
-      throw EsParamsIllegalException("cluster is empty!")
+      throw EsParamsIllegalException(CLUSTER_IS_BLANK.getErrorDesc)
     }
     val username = options.get(ES_USERNAME.key)
     val password = options.get(ES_PASSWORD.key)
diff --git a/linkis-engineconn-plugins/elasticsearch/src/main/scala/org/apache/linkis/engineplugin/elasticsearch/executor/client/impl/ResponseHandlerImpl.scala b/linkis-engineconn-plugins/elasticsearch/src/main/scala/org/apache/linkis/engineplugin/elasticsearch/executor/client/impl/ResponseHandlerImpl.scala
index 23e6a4cba..19233a07d 100644
--- a/linkis-engineconn-plugins/elasticsearch/src/main/scala/org/apache/linkis/engineplugin/elasticsearch/executor/client/impl/ResponseHandlerImpl.scala
+++ b/linkis-engineconn-plugins/elasticsearch/src/main/scala/org/apache/linkis/engineplugin/elasticsearch/executor/client/impl/ResponseHandlerImpl.scala
@@ -18,6 +18,7 @@
 package org.apache.linkis.engineplugin.elasticsearch.executor.client.impl
 
 import org.apache.linkis.common.utils.Utils
+import org.apache.linkis.engineplugin.elasticsearch.errorcode.EasticsearchErrorCodeSummary._
 import org.apache.linkis.engineplugin.elasticsearch.exception.EsConvertResponseException
 import org.apache.linkis.engineplugin.elasticsearch.executor.client.{
   ElasticSearchJsonResponse,
@@ -53,9 +54,7 @@ class ResponseHandlerImpl extends ResponseHandler {
     val contentBytes = EntityUtils.toByteArray(response.getEntity)
 
     if (contentBytes == null || contentBytes.isEmpty) {
-      throw EsConvertResponseException(
-        "EsEngineExecutor convert response fail, response content is empty."
-      )
+      throw EsConvertResponseException(RESPONSE_FAIL_IS_EMPTY.getErrorDesc)
     }
 
     val jsonNode = Utils.tryCatch {


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@linkis.apache.org
For additional commands, e-mail: commits-help@linkis.apache.org