Skip to content

Commit

Permalink
[linkis-module]module errorcode optimization and documentation (#3550)
Browse files Browse the repository at this point in the history
  • Loading branch information
binbinCheng authored Oct 18, 2022
1 parent 9f6d28f commit 46259eb
Show file tree
Hide file tree
Showing 12 changed files with 153 additions and 26 deletions.
15 changes: 15 additions & 0 deletions docs/errorcode/linkis-module-errorcode.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
## linkis-module errorcode

| module name(模块名) | error code(错误码) | describe(描述) |enumeration name(枚举)| Exception Class(类名)|
| -------- | -------- | ----- |-----|-----|
|linkis-module |10010|DataWorkCloud service must set the version, please add property [[wds.linkis.server.version]] to properties file.(DataWorkCloud 服务必须设置版本,请将属性 [[wds.linkis.server.version]] 添加到属性文件.)|DATAWORKCLOUD_MUST_VERSION|LinkisModuleErrorCodeSummary|
|linkis-module |10021|Failed to get user parameters! Reason: RPC request Service failed!(获取用户参数失败!原因:RPC请求服务失败!)|FETCH_MAPCACHE_ERROR|LinkisModuleErrorCodeSummary|
|linkis-module |10050|Application {} is not exists any instances(应用程序 {} 不存在任何实例)|NOT_EXISTS_APPLICATION|LinkisModuleErrorCodeSummary|
|linkis-module |11000|The wds.linkis.server.home或BDP_SERVER_HOME haven't set!(wds.linkis.server.home 或 BDP_SERVER_HOME 没有设置!)|HAVE_NOT_SET|LinkisModuleErrorCodeSummary|
|linkis-module |11001|Verification failed,{} cannot be empty!(验证失败,{} 不能为空!)|VERIFICATION_CANNOT_EMPTY|LinkisModuleErrorCodeSummary|
|linkis-module |11002|Login has expired, please log in again!(登录已过期,请重新登录!)|NOT_LOGGED|LinkisModuleErrorCodeSummary|
|linkis-module |11003|Illegal user token information(非法的用户token信息).|ILLEGAL_USER_TOKEN|LinkisModuleErrorCodeSummary|
|linkis-module |11004|ServerSocket{} does not exist!(ServerSocket{}不存在!)|SERVERSSOCKET_NOT_EXIST|LinkisModuleErrorCodeSummary|
|linkis-module |11005|The receive queue for WebSocket is full, please try again later!(WebSocket的接收队列已满,请稍后重试!)|WEBSOCKET_IS_FULL|LinkisModuleErrorCodeSummary|
|linkis-module |11035|WebSocket consumer has stopped, please contact the administrator to handle!(WebSocket的消费器已停止,请联系管理员处理!)|WEBSOCKET_STOPPED|LinkisModuleErrorCodeSummary|

Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
/*
* 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.errorcode;

public enum LinkisModuleErrorCodeSummary {
DATAWORKCLOUD_MUST_VERSION(
10010,
"DataWorkCloud service must set the version, please add property [[wds.linkis.server.version]] to properties file.(DataWorkCloud 服务必须设置版本,请将属性 [[wds.linkis.server.version]] 添加到属性文件.)",
"DataWorkCloud service must set the version, please add property [[wds.linkis.server.version]] to properties file.(DataWorkCloud 服务必须设置版本,请将属性 [[wds.linkis.server.version]] 添加到属性文件.)"),
FETCH_MAPCACHE_ERROR(
10021,
"Failed to get user parameters! Reason: RPC request Service failed!(获取用户参数失败!原因:RPC请求服务失败!)",
"Failed to get user parameters! Reason: RPC request Service failed!(获取用户参数失败!原因:RPC请求服务失败!)"),
NOT_EXISTS_APPLICATION(
10050,
"Application {} is not exists any instances(应用程序 {} 不存在任何实例)",
"Application {} is not exists any instances(应用程序 {} 不存在任何实例)"),
HAVE_NOT_SET(
11000,
"The wds.linkis.server.home或BDP_SERVER_HOME haven't set!(wds.linkis.server.home 或 BDP_SERVER_HOME 没有设置!)",
"The wds.linkis.server.home或BDP_SERVER_HOME haven't set!(wds.linkis.server.home 或 BDP_SERVER_HOME 没有设置!)"),
VERIFICATION_CANNOT_EMPTY(
11001,
"Verification failed,{} cannot be empty!(验证失败,{} 不能为空!)",
"Verification failed,{} cannot be empty!(验证失败,{}不能为空!)"),
LOGGED_ID(11002, "", ""),
NOT_LOGGED(
11002,
"Login has expired, please log in again!(登录已过期,请重新登录!)",
"Login has expired, please log in again!(登录已过期,请重新登录!)"),
ILLEGAL_ID(11003, "", ""),
ILLEGAL_USER_TOKEN(
11003,
"Illegal user token information(非法的用户token信息).",
"Illegal user token information(非法的用户token信息)."),
SERVERSSOCKET_NOT_EXIST(
11004,
"ServerSocket{} does not exist!(ServerSocket{}不存在!)",
"ServerSocket{} does not exist!(ServerSocket{}不存在!)"),
WEBSOCKET_IS_FULL(
11005,
"The receive queue for WebSocket is full, please try again later!(WebSocket的接收队列已满,请稍后重试!)",
"The receive queue for WebSocket is full, please try again later!(WebSocket的接收队列已满,请稍后重试!)"),
WEBSOCKET_STOPPED(
11035,
"WebSocket consumer has stopped, please contact the administrator to handle!(WebSocket的消费器已停止,请联系管理员处理!)",
"WebSocket consumer has stopped, please contact the administrator to handle!(WebSocket的消费器已停止,请联系管理员处理!)");

/** (errorCode)错误码 */
private int errorCode;
/** (errorDesc)错误描述 */
private String errorDesc;
/** Possible reasons for the error(错误可能出现的原因) */
private String comment;

LinkisModuleErrorCodeSummary(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
Expand Up @@ -19,6 +19,7 @@ package org.apache.linkis.server.conf

import org.apache.linkis.common.conf.{CommonVars, Configuration, TimeType}
import org.apache.linkis.common.utils.{DESUtil, Logging, Utils}
import org.apache.linkis.errorcode.LinkisModuleErrorCodeSummary._
import org.apache.linkis.server.exception.BDPInitServerException

import org.apache.commons.lang3.StringUtils
Expand All @@ -41,8 +42,8 @@ object ServerConfiguration extends Logging {

if (StringUtils.isBlank(BDP_SERVER_VERSION)) {
throw new BDPInitServerException(
10010,
"DataWorkCloud service must set the version, please add property [[wds.linkis.server.version]] to properties file."
DATAWORKCLOUD_MUST_VERSION.getErrorCode,
DATAWORKCLOUD_MUST_VERSION.getErrorDesc
)
}

Expand Down Expand Up @@ -84,7 +85,7 @@ object ServerConfiguration extends Logging {
CommonVars("wds.linkis.server.distinct.mode", lang.Boolean.TRUE)

if (!BDP_SERVER_DISTINCT_MODE.getValue && StringUtils.isEmpty(BDP_SERVER_HOME.getValue)) {
throw new BDPInitServerException(11000, "wds.linkis.server.home或BDP_SERVER_HOME haven't set!")
throw new BDPInitServerException(HAVE_NOT_SET.getErrorCode, HAVE_NOT_SET.getErrorDesc)
}

val BDP_SERVER_SOCKET_MODE: CommonVars[lang.Boolean] =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,7 @@
package org.apache.linkis.server.exception

import org.apache.linkis.common.exception.ErrorException
import org.apache.linkis.errorcode.LinkisModuleErrorCodeSummary.ILLEGAL_ID

class IllegalUserTicketException(message: String) extends ErrorException(11003, message)
class IllegalUserTicketException(message: String)
extends ErrorException(ILLEGAL_ID.getErrorCode, message)
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,7 @@
*/

package org.apache.linkis.server.exception
import org.apache.linkis.errorcode.LinkisModuleErrorCodeSummary._

class NonLoginException(message: String) extends BDPServerErrorException(11002, message)
class NonLoginException(message: String)
extends BDPServerErrorException(LOGGED_ID.getErrorCode, message)
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import org.apache.linkis.common.exception.{
WarnException
}
import org.apache.linkis.common.utils.Utils
import org.apache.linkis.errorcode.LinkisModuleErrorCodeSummary._
import org.apache.linkis.server.exception.{BDPServerErrorException, NonLoginException}
import org.apache.linkis.server.security.SecurityFilter

Expand Down Expand Up @@ -52,7 +53,7 @@ package object server {
keys.foreach(k =>
if (!json.contains(k) || json.get(k) == null || StringUtils.isEmpty(json.get(k).toString)) {
throw new BDPServerErrorException(
11001,
VERIFICATION_CANNOT_EMPTY.getErrorCode,
s"Verification failed, $k cannot be empty!(验证失败,$k 不能为空!)"
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package org.apache.linkis.server.security

import org.apache.linkis.common.conf.Configuration
import org.apache.linkis.common.utils.{Logging, RSAUtils, Utils}
import org.apache.linkis.errorcode.LinkisModuleErrorCodeSummary._
import org.apache.linkis.server.conf.{ServerConfiguration, SessionHAConfiguration}
import org.apache.linkis.server.exception.{
IllegalUserTicketException,
Expand Down Expand Up @@ -92,7 +93,7 @@ object SSOUtils extends Logging {
ServerConfiguration.getUsernameByTicket(userTicketId).map { userAndLoginTime =>
{
if (userAndLoginTime.indexOf(",") < 0) {
throw new IllegalUserTicketException(s"Illegal user token information(非法的用户token信息).")
throw new IllegalUserTicketException(ILLEGAL_USER_TOKEN.getErrorDesc)
}
val index = userAndLoginTime.lastIndexOf(",")
(userAndLoginTime.substring(0, index), userAndLoginTime.substring(index + 1).toLong)
Expand Down Expand Up @@ -157,9 +158,8 @@ object SSOUtils extends Logging {
}
}

def getLoginUsername(getCookies: => Array[Cookie]): String = getLoginUser(getCookies).getOrElse(
throw new NonLoginException(s"You are not logged in, please login first(您尚未登录,请先登录!)")
)
def getLoginUsername(getCookies: => Array[Cookie]): String =
getLoginUser(getCookies).getOrElse(throw new NonLoginException(NOT_LOGGED.getErrorDesc))

def getLoginUser(getCookies: => Array[Cookie]): Option[String] = getLoginUser(_ =>
Option(getCookies).flatMap(_.find(_.getName == USER_TICKET_ID_STRING).map(_.getValue))
Expand All @@ -169,16 +169,12 @@ object SSOUtils extends Logging {
getUserTicketId(USER_TICKET_ID_STRING).map { t =>
isTimeoutOrNot(t)
getUserAndLoginTime(t)
.getOrElse(
throw new IllegalUserTicketException(s"Illegal user token information(非法的用户token信息).")
)
.getOrElse(throw new IllegalUserTicketException(ILLEGAL_USER_TOKEN.getErrorDesc))
._1
}

def getLoginUsername(getUserTicketId: String => Option[String]): String =
getLoginUser(getUserTicketId).getOrElse(
throw new NonLoginException(s"You are not logged in, please login first(您尚未登录,请先登录!)")
)
getLoginUser(getUserTicketId).getOrElse(throw new NonLoginException(NOT_LOGGED.getErrorDesc))

private[security] def getLoginUserIgnoreTimeout(
getUserTicketId: String => Option[String]
Expand All @@ -195,7 +191,7 @@ object SSOUtils extends Logging {
@throws(classOf[LoginExpireException])
private def isTimeoutOrNot(userTicketId: String): Unit =
if (!userTicketIdToLastAccessTime.containsKey(userTicketId)) {
throw new LoginExpireException("You are not logged in, please login first!(您尚未登录,请先登录!)")
throw new LoginExpireException(NOT_LOGGED.getErrorDesc)
} else {
val lastAccessTime = userTicketIdToLastAccessTime.get(userTicketId)
if (
Expand All @@ -209,7 +205,7 @@ object SSOUtils extends Logging {
) > sessionTimeout
) {
userTicketIdToLastAccessTime.remove(userTicketId)
throw new LoginExpireException("Login has expired, please log in again!(登录已过期,请重新登录!)")
throw new LoginExpireException(NOT_LOGGED.getErrorDesc)
}
} else if (System.currentTimeMillis - lastAccessTime >= sessionTimeout * 0.5) {
userTicketIdToLastAccessTime.put(userTicketId, System.currentTimeMillis)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package org.apache.linkis.server.security

import org.apache.linkis.common.conf.Configuration
import org.apache.linkis.common.utils.{Logging, RSAUtils, Utils}
import org.apache.linkis.errorcode.LinkisModuleErrorCodeSummary.ILLEGAL_USER_TOKEN
import org.apache.linkis.server.{Message, _}
import org.apache.linkis.server.conf.ServerConfiguration
import org.apache.linkis.server.exception.{
Expand Down Expand Up @@ -201,7 +202,7 @@ object SecurityFilter {
ServerConfiguration.BDP_TEST_USER.getValue;
} else {
getLoginUser(req).getOrElse(
throw new IllegalUserTicketException(s"Illegal user token information(非法的用户token信息).")
throw new IllegalUserTicketException(ILLEGAL_USER_TOKEN.getErrorDesc)
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package org.apache.linkis.server.socket
import org.apache.linkis.common.conf.Configuration.DEFAULT_DATE_PATTERN
import org.apache.linkis.common.listener.Event
import org.apache.linkis.common.utils.{Logging, Utils}
import org.apache.linkis.errorcode.LinkisModuleErrorCodeSummary._
import org.apache.linkis.server.Message
import org.apache.linkis.server.conf.ServerConfiguration._
import org.apache.linkis.server.exception.BDPServerErrorException
Expand Down Expand Up @@ -61,7 +62,7 @@ private[server] class ControllerServer(serverListenerEventBus: ServerListenerEve
val socket = socketList.get(id)
if (socket == null) {
throw new BDPServerErrorException(
11004,
SERVERSSOCKET_NOT_EXIST.getErrorCode,
s"ServerSocket($id) does not exist!(ServerSocket($id)不存在!)"
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package org.apache.linkis.server.socket.controller

import org.apache.linkis.common.listener.ListenerEventBus
import org.apache.linkis.errorcode.LinkisModuleErrorCodeSummary._
import org.apache.linkis.server.exception.BDPServerErrorException

import org.apache.commons.lang3.StringUtils
Expand Down Expand Up @@ -55,13 +56,13 @@ class ServerListenerEventBus(
override protected val dropEvent: DropEvent = new DropEvent {

override def onDropEvent(event: SocketServerEvent): Unit = throw new BDPServerErrorException(
11035,
"WebSocket consumer has stopped, please contact the administrator to handle!(WebSocket的消费器已停止,请联系管理员处理!)"
WEBSOCKET_STOPPED.getErrorCode,
WEBSOCKET_STOPPED.getErrorDesc
)

override def onBusStopped(event: SocketServerEvent): Unit = throw new BDPServerErrorException(
11005,
"The receive queue for WebSocket is full, please try again later!(WebSocket的接收队列已满,请稍后重试!)"
WEBSOCKET_IS_FULL.getErrorCode,
WEBSOCKET_IS_FULL.getErrorDesc
)

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package org.apache.linkis.rpc

import org.apache.linkis.common.exception.ErrorException
import org.apache.linkis.common.utils.Utils
import org.apache.linkis.errorcode.LinkisModuleErrorCodeSummary.FETCH_MAPCACHE_ERROR
import org.apache.linkis.protocol.CacheableProtocol
import org.apache.linkis.rpc.errorcode.RPCErrorConstants
import org.apache.linkis.server.exception.FetchMapCacheFailedException
Expand All @@ -37,7 +38,7 @@ abstract class RPCMapCache[M, K, V](applicationName: String) {
case error: ErrorException => error
case t: Throwable =>
new FetchMapCacheFailedException(
RPCErrorConstants.FETCH_MAPCACHE_ERROR,
FETCH_MAPCACHE_ERROR.getErrorCode,
"Failed to get " +
"user " +
"parameters! Reason: RPC request(获取用户参数失败!原因:RPC请求)" + applicationName + "Service failed!(服务失败!)",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package org.apache.linkis.gateway.route

import org.apache.linkis.common.ServiceInstance
import org.apache.linkis.common.utils.{Logging, Utils}
import org.apache.linkis.errorcode.LinkisModuleErrorCodeSummary.NOT_EXISTS_APPLICATION
import org.apache.linkis.gateway.config.GatewayConfiguration
import org.apache.linkis.gateway.exception.TooManyServiceException
import org.apache.linkis.gateway.http.GatewayContext
Expand Down Expand Up @@ -52,7 +53,7 @@ abstract class AbstractGatewayRouter extends GatewayRouter with Logging {
var service = findService
if (service.isEmpty) {
val applicationNotExists = new NoApplicationExistsException(
10050,
NOT_EXISTS_APPLICATION.getErrorCode,
"Application " +
serviceId + " is not exists any instances."
)
Expand Down

0 comments on commit 46259eb

Please sign in to comment.