Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: 对接蓝鲸消息通知中心 #2659 #2672

Merged
merged 18 commits into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Tencent is pleased to support the open source community by making BK-JOB蓝鲸智云作业平台 available.
*
* Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved.
*
* BK-JOB蓝鲸智云作业平台 is licensed under the MIT License.
*
* License for BK-JOB蓝鲸智云作业平台:
* --------------------------------------------------------------------
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
* to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of
* the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
* THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/

package com.tencent.bk.job.common.i18n.locale;

/**
* 蓝鲸公共协议涉及的常量
*/
public class BkConsts {

// 国际化语言Header取值
public static final String HEADER_VALUE_LANG_ZH = "zh";
public static final String HEADER_VALUE_LANG_ZH_CN = "zh-cn";
public static final String HEADER_VALUE_LANG_EN = "en";
public static final String HEADER_VALUE_LANG_EN_US = "en-us";

}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public class LocaleUtils {
public static final String LANG_ZH = "zh";
public static final String LANG_EN = "en";
public static final String LANG_EN_US = "en_US";

/**
* 蓝鲸通用的LANG HEADER
*/
Expand All @@ -50,19 +51,28 @@ public class LocaleUtils {
private static final Map<String, String> localeMap = new HashMap<>();

static {
localeMap.put("zh", LANG_ZH);
localeMap.put("zh-cn", LANG_ZH_CN);
localeMap.put(BkConsts.HEADER_VALUE_LANG_ZH, LANG_ZH);
localeMap.put(BkConsts.HEADER_VALUE_LANG_ZH_CN, LANG_ZH_CN);
localeMap.put("zh_cn", LANG_ZH_CN);
localeMap.put("en", LANG_EN);
localeMap.put("en-us", LANG_EN_US);
localeMap.put(BkConsts.HEADER_VALUE_LANG_EN, LANG_EN);
localeMap.put(BkConsts.HEADER_VALUE_LANG_EN_US, LANG_EN_US);
localeMap.put("en_us", LANG_EN_US);
}

private static final Map<String, String> bkLangMap = new HashMap<>();

static {
bkLangMap.put(LANG_ZH, BkConsts.HEADER_VALUE_LANG_ZH);
bkLangMap.put(LANG_ZH_CN, BkConsts.HEADER_VALUE_LANG_ZH_CN);
bkLangMap.put(LANG_EN, BkConsts.HEADER_VALUE_LANG_EN);
bkLangMap.put(LANG_EN_US, BkConsts.HEADER_VALUE_LANG_EN_US);
}

/**
* 对不同形式的language Header值进行统一
*
* @param lang
* @return
* @param lang 语言Header取值
* @return 标准化后的语言Header取值
*/
public static String getNormalLang(String lang) {
lang = lang.toLowerCase();
Expand All @@ -72,6 +82,19 @@ public static String getNormalLang(String lang) {
return lang;
}

/**
* 根据标准语言取值获取蓝鲸协议语言参数取值
*
* @param normalLang 标准语言取值
* @return 蓝鲸协议语言参数取值
*/
public static String getBkLang(String normalLang) {
if (bkLangMap.containsKey(normalLang)) {
return bkLangMap.get(normalLang);
}
return null;
}

public static Locale getLocale(String lang) {
if (StringUtils.isBlank(lang)) {
return Locale.SIMPLIFIED_CHINESE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@
#第三方API请求错误
1216001=第三方 API 请求错误

#消息通知中心异常
1217001=消息通知中心API不存在:{0}
1217002=消息通知中心接口数据异常

##业务错误-通用

1241001=请求参数缺失
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@
#第三方API请求错误
1216001=Third API data unexpected

#消息通知中心异常
1217001=BK-Notice API not found:{0}
1217002=BK-Notice API data unexpected

## Business error - common
1241001=Missing request parameters
1241002=Invalid request parameters
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@
#第三方API请求错误
1216001=Third API data unexpected

#消息通知中心异常
1217001=BK-Notice API not found:{0}
1217002=BK-Notice API data unexpected

## Business error - common
1241001=Missing request parameters
1241002=Invalid request parameters
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@
#第三方API请求错误
1216001=第三方 API 请求错误

#消息通知中心异常
1217001=消息通知中心API不存在:{0}
1217002=消息通知中心接口数据异常

##业务错误-通用

1241001=请求参数缺失
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@
#第三方API请求错误
1216001=第三方 API 请求错误

#消息通知中心异常
1217001=消息通知中心API不存在:{0}
1217002=消息通知中心接口数据异常

##业务错误-通用

1241001=请求参数缺失
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,5 @@ validation.constraints.AccountDescription_tooLong.message=账号描述不能超
validation.constraints.InvalidJobInstanceId.message=任务实例ID必须为正整数
validation.constraints.InvalidStepInstanceId.message=步骤实例ID必须为正整数
validation.constraints.queryAgentInfoHostIds_tooMany.message=单次查询主机数量不可超过5000
validation.constraints.InvalidAnnouncementsOffset.message=公告偏移量必须大于等于0
validation.constraints.InvalidAnnouncementsLimit.message=公告获取数量必须大于等于1
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,5 @@ validation.constraints.AccountDescription_tooLong.message=Account description le
validation.constraints.InvalidJobInstanceId.message=Job instance id must be a positive number
validation.constraints.InvalidStepInstanceId.message=Step instance id must be a positive number
validation.constraints.queryAgentInfoHostIds_tooMany.message=HostIds size can not be over 5000
validation.constraints.InvalidAnnouncementsOffset.message=Announcements offset must be equal or greater than 0
validation.constraints.InvalidAnnouncementsLimit.message=Announcements limit must be equal or greater than 1
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,5 @@ validation.constraints.AccountDescription_tooLong.message=Account description le
validation.constraints.InvalidJobInstanceId.message=Job instance id must be a positive number
validation.constraints.InvalidStepInstanceId.message=Step instance id must be a positive number
validation.constraints.queryAgentInfoHostIds_tooMany.message=HostIds size can not be over 5000
validation.constraints.InvalidAnnouncementsOffset.message=Announcements offset must be equal or greater than 0
validation.constraints.InvalidAnnouncementsLimit.message=Announcements limit must be equal or greater than 1
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,5 @@ validation.constraints.AccountDescription_tooLong.message=账号描述不能超
validation.constraints.InvalidJobInstanceId.message=任务实例ID必须为正整数
validation.constraints.InvalidStepInstanceId.message=步骤实例ID必须为正整数
validation.constraints.queryAgentInfoHostIds_tooMany.message=单次查询主机数量不可超过5000
validation.constraints.InvalidAnnouncementsOffset.message=公告偏移量必须大于等于0
validation.constraints.InvalidAnnouncementsLimit.message=公告获取数量必须大于等于1
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,5 @@ validation.constraints.AccountDescription_tooLong.message=账号描述不能超
validation.constraints.InvalidJobInstanceId.message=任务实例ID必须为正整数
validation.constraints.InvalidStepInstanceId.message=步骤实例ID必须为正整数
validation.constraints.queryAgentInfoHostIds_tooMany.message=单次查询主机数量不可超过5000
validation.constraints.InvalidAnnouncementsOffset.message=公告偏移量必须大于等于0
validation.constraints.InvalidAnnouncementsLimit.message=公告获取数量必须大于等于1
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ Default job logback configuration provided for import
</encoder>
</appender>


<!-- 审计事件日志 -->
<appender name="audit-event-appender" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${AUDIT_EVENT_LOG_FILE}</file>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,90 @@ public class ErrorCode {
*/
public static final int RESULT_OK = 0;

// ==================================== 系统级错误 ================================================//

// ======= 系统错误-平台服务错误 =======//
// LICENSE 不可用
public static final int LICENSE_ERROR = 1210101;
// GSE 不可用
public static final int GSE_ERROR = 1210001;
// GSE数据异常:{0}
public static final int GSE_API_DATA_ERROR = 1210002;

// CMDB错误
// CMDB服务状态不可达 - 地址配置错误或者地址无法正确解析
public static final int CMDB_UNREACHABLE_SERVER = 1211001;
// CMDB接口返回数据结构异常- 一般是被网关防火墙重定向返回统一登录页面
public static final int CMDB_API_DATA_ERROR = 1211002;
// 根据动态分组ID查找主机失败,动态分组ID:{0},原因:{1},请确认指定的动态分组在业务下是否存在
public static final int FAIL_TO_FIND_HOST_BY_DYNAMIC_GROUP = 1211003;
// 根据业务ID查找动态分组失败,业务ID:{0},原因:{1},请确认指定的业务是否存在动态分组
public static final int FAIL_TO_FIND_DYNAMIC_GROUP_BY_BIZ = 1211004;

// PaaS异常
// CMSI接口访问异常
public static final int CMSI_API_ACCESS_ERROR = 1213001;
// 用户管理接口访问异常
public static final int USER_MANAGE_API_ACCESS_ERROR = 1213002;
// 调用CMSI接口获取通知渠道数据异常
public static final int CMSI_MSG_CHANNEL_DATA_ERROR = 1213003;
// 调用CMSI接口发送通知失败,错误码:{0},错误信息:{1}
public static final int CMSI_FAIL_TO_SEND_MSG = 1213004;

// 制品库异常
// Artifactory接口返回数据结构异常
public static final int ARTIFACTORY_API_DATA_ERROR = 1214001;
// 制品库中找不到节点:{0},请到制品库核实
public static final int CAN_NOT_FIND_NODE_IN_ARTIFACTORY = 1214002;

// IAM接口数据异常- 一般是被网关防火墙重定向返回统一登录页面
public static final int IAM_API_DATA_ERROR = 1215001;
// 用户({0})账号已被冻结,请处理后再重试
public static final int IAM_USER_ACCOUNT_FROZEN = 1215002;

// 第三方API请求错误
public static final int API_ERROR = 1216001;

// 消息通知中心异常
// 消息通知中心API不存在:{0}
public static final int BK_NOTICE_API_NOT_FOUND = 1217001;
// 消息通知中心接口数据异常
public static final int BK_NOTICE_API_DATA_ERROR = 1217002;

// ======== 系统错误-权限错误 ==================//
// 用户({0})权限不足,请前往权限中心确认并申请补充后重试
public static final int PERMISSION_DENIED = 1238001;
// 蓝鲸统一权限错误码,用户({0})权限不足,请前往权限中心确认并申请补充后重试
public static final int BK_PERMISSION_DENIED = 9900403;

// ========= 系统错误-请求 ====================//
// 内部服务异常
public static final int INTERNAL_ERROR = 1240002;
// 错误的请求
public static final int BAD_REQUEST = 1240003;
// Cookie过期或者不存在
public static final int COOKIE_ILLEGAL = 1240004;
// 服务不可用
public static final int SERVICE_UNAVAILABLE = 1240001;
// 服务认证失败
public static final int SERVICE_AUTH_FAIL = 1240005;
// 配置异常:{0}
public static final int INVALID_CONFIG = 1240006;
// 命令行参数异常:{0}
public static final int INVALID_CMD_ARGS = 1240007;

// ======= 系统错误-公共组件错误 =======//
// Redis服务不可用,连接不上 - IP不存在或者配置错误
public static final int REDIS_CONNECT_FAIL = 1250001;
// Redis服务内存满或者其他问题 - 内存不足够
public static final int REDIS_DATA_EXCEPTION = 1250002;
// DB 不可用
public static final int DB_ERROR = 1252001;
// MQ 不可用
public static final int MQ_ERROR = 1255001;
// NFS存储 不可用
public static final int NFS_ERROR = 1259001;

// ==================================== 业务级错误 ================================================//
/*
* 业务通用-1241xxx
Expand Down Expand Up @@ -291,6 +375,10 @@ public class ErrorCode {
public static final int FAIL_TO_DOWNLOAD_NODE_FROM_ARTIFACTORY = 1249002;
// 备份服务 end

// ======= 系统错误-公共组件错误 =======//
// 1250xxx-1259xxx被【系统错误-公共组件错误】占用
// ======= 系统错误-公共组件错误 =======//

// 文件网关 start
// 文件源不存在:{0}
public static final int FILE_SOURCE_NOT_EXIST = 1260001;
Expand Down Expand Up @@ -354,81 +442,4 @@ public class ErrorCode {
// 迁移失败,任务: {0}, 详情: {1}
public static final int MIGRATION_FAIL = 1263001;

// ==================================== 系统级错误 ================================================//
// ======== 系统错误-权限错误 ==================//
// 用户({0})权限不足,请前往权限中心确认并申请补充后重试
public static final int PERMISSION_DENIED = 1238001;
// 蓝鲸统一权限错误码,用户({0})权限不足,请前往权限中心确认并申请补充后重试
public static final int BK_PERMISSION_DENIED = 9900403;

// ========= 系统错误-请求 ====================//
// 内部服务异常
public static final int INTERNAL_ERROR = 1240002;
// 错误的请求
public static final int BAD_REQUEST = 1240003;
// Cookie过期或者不存在
public static final int COOKIE_ILLEGAL = 1240004;
// 服务不可用
public static final int SERVICE_UNAVAILABLE = 1240001;
// 服务认证失败
public static final int SERVICE_AUTH_FAIL = 1240005;
// 配置异常:{0}
public static final int INVALID_CONFIG = 1240006;
// 命令行参数异常:{0}
public static final int INVALID_CMD_ARGS = 1240007;

// ======= 系统错误-公共组件错误 =======//
// Redis服务不可用,连接不上 - IP不存在或者配置错误
public static final int REDIS_CONNECT_FAIL = 1250001;
// Redis服务内存满或者其他问题 - 内存不足够
public static final int REDIS_DATA_EXCEPTION = 1250002;
// NFS存储 不可用
public static final int NFS_ERROR = 1259001;
// DB 不可用
public static final int DB_ERROR = 1252001;
// MQ 不可用
public static final int MQ_ERROR = 1255001;

// ======= 系统错误-平台服务错误 =======//
// LICENSE 不可用
public static final int LICENSE_ERROR = 1210101;
// GSE 不可用
public static final int GSE_ERROR = 1210001;
// GSE数据异常:{0}
public static final int GSE_API_DATA_ERROR = 1210002;

// CMDB错误
// CMDB服务状态不可达 - 地址配置错误或者地址无法正确解析
public static final int CMDB_UNREACHABLE_SERVER = 1211001;
// CMDB接口返回数据结构异常- 一般是被网关防火墙重定向返回统一登录页面
public static final int CMDB_API_DATA_ERROR = 1211002;
// 根据动态分组ID查找主机失败,动态分组ID:{0},原因:{1},请确认指定的动态分组在业务下是否存在
public static final int FAIL_TO_FIND_HOST_BY_DYNAMIC_GROUP = 1211003;
// 根据业务ID查找动态分组失败,业务ID:{0},原因:{1},请确认指定的业务是否存在动态分组
public static final int FAIL_TO_FIND_DYNAMIC_GROUP_BY_BIZ = 1211004;

// PaaS异常
// CMSI接口访问异常
public static final int CMSI_API_ACCESS_ERROR = 1213001;
// 用户管理接口访问异常
public static final int USER_MANAGE_API_ACCESS_ERROR = 1213002;
// 调用CMSI接口获取通知渠道数据异常
public static final int CMSI_MSG_CHANNEL_DATA_ERROR = 1213003;
// 调用CMSI接口发送通知失败,错误码:{0},错误信息:{1}
public static final int CMSI_FAIL_TO_SEND_MSG = 1213004;

// 制品库异常
// Artifactory接口返回数据结构异常
public static final int ARTIFACTORY_API_DATA_ERROR = 1214001;
// 制品库中找不到节点:{0},请到制品库核实
public static final int CAN_NOT_FIND_NODE_IN_ARTIFACTORY = 1214002;

// IAM接口数据异常- 一般是被网关防火墙重定向返回统一登录页面
public static final int IAM_API_DATA_ERROR = 1215001;
// 用户({0})账号已被冻结,请处理后再重试
public static final int IAM_USER_ACCOUNT_FROZEN = 1215002;

// 第三方API请求错误
public static final int API_ERROR = 1216001;

}
Loading
Loading