Skip to content

Commit

Permalink
[ISSUE-3380][linkis-engineplugin-elasticsearch]errorcode code optimiz…
Browse files Browse the repository at this point in the history
…ation (#3531)
binbinCheng authored Oct 18, 2022
1 parent 4455d58 commit aaee556
Showing 6 changed files with 87 additions and 7 deletions.
8 changes: 8 additions & 0 deletions docs/errorcode/elasticsearch-errorcode.md
Original file line number Diff line number Diff line change
@@ -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|


Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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)
Original file line number Diff line number Diff line change
@@ -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)
Original file line number Diff line number Diff line change
@@ -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)
Original file line number Diff line number Diff line change
@@ -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 {

0 comments on commit aaee556

Please sign in to comment.