Skip to content

Commit

Permalink
[Fix-16517][Alert Instance] Alert plugin instance i18n wrong result i…
Browse files Browse the repository at this point in the history
…n rendering frontend ui (#16751)
  • Loading branch information
sdhzwc authored Nov 5, 2024
1 parent 0719949 commit 7876d45
Show file tree
Hide file tree
Showing 14 changed files with 95 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.apache.dolphinscheduler.alert.api.AlertChannel;
import org.apache.dolphinscheduler.alert.api.AlertChannelFactory;
import org.apache.dolphinscheduler.alert.api.AlertInputTips;
import org.apache.dolphinscheduler.common.utils.JSONUtils;
import org.apache.dolphinscheduler.spi.params.base.PluginParams;
import org.apache.dolphinscheduler.spi.params.base.Validate;
import org.apache.dolphinscheduler.spi.params.input.InputParam;
Expand All @@ -42,44 +43,46 @@ public List<PluginParams> params() {

InputParam calledNumber =
InputParam.newBuilder(VoiceAlertConstants.NAME_CALLED_NUMBER, VoiceAlertConstants.CALLED_NUMBER)
.setPlaceholder(AlertInputTips.CALLED_NUMBER.getMsg())
.setPlaceholder(JSONUtils.toJsonString(AlertInputTips.getAllMsg(AlertInputTips.CALLED_NUMBER)))
.addValidate(Validate.newBuilder()
.setRequired(true)
.build())
.build();

InputParam calledShowNumber = InputParam
.newBuilder(VoiceAlertConstants.NAME_CALLED_SHOW_NUMBER, VoiceAlertConstants.CALLED_SHOW_NUMBER)
.setPlaceholder(AlertInputTips.CALLED_SHOW_NUMBER.getMsg())
.setPlaceholder(JSONUtils.toJsonString(AlertInputTips.getAllMsg(AlertInputTips.CALLED_SHOW_NUMBER)))
.addValidate(Validate.newBuilder()
.setRequired(false)
.build())
.build();

InputParam ttsCode = InputParam.newBuilder(VoiceAlertConstants.NAME_TTS_CODE, VoiceAlertConstants.TTS_CODE)
.setPlaceholder(AlertInputTips.TTS_CODE.getMsg())
.setPlaceholder(JSONUtils.toJsonString(AlertInputTips.getAllMsg(AlertInputTips.TTS_CODE)))
.addValidate(Validate.newBuilder()
.setRequired(false)
.build())
.build();

InputParam address = InputParam.newBuilder(VoiceAlertConstants.NAME_ADDRESS, VoiceAlertConstants.ADDRESS)
.setPlaceholder(AlertInputTips.ALIYUN_VIICE_ADDRESS.getMsg())
.setPlaceholder(JSONUtils.toJsonString(AlertInputTips.getAllMsg(AlertInputTips.ALIYUN_VIICE_ADDRESS)))
.addValidate(Validate.newBuilder()
.setRequired(false)
.build())
.build();

InputParam accessKeyId =
InputParam.newBuilder(VoiceAlertConstants.NAME_ACCESS_KEY_ID, VoiceAlertConstants.ACCESS_KEY_ID)
.setPlaceholder(AlertInputTips.ALIYUN_VIICE_ACCESSKEYID.getMsg())
.setPlaceholder(JSONUtils
.toJsonString(AlertInputTips.getAllMsg(AlertInputTips.ALIYUN_VIICE_ACCESSKEYID)))
.addValidate(Validate.newBuilder()
.setRequired(false)
.build())
.build();
InputParam accessKeySecret =
InputParam.newBuilder(VoiceAlertConstants.NAME_ACCESS_KEY_SECRET, VoiceAlertConstants.ACCESS_KEY_SECRET)
.setPlaceholder(AlertInputTips.ALIYUN_VIICE_ACCESSKEY_SECRET.getMsg())
.setPlaceholder(JSONUtils
.toJsonString(AlertInputTips.getAllMsg(AlertInputTips.ALIYUN_VIICE_ACCESSKEY_SECRET)))
.addValidate(Validate.newBuilder()
.setRequired(false)
.build())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@

package org.apache.dolphinscheduler.alert.api;

import java.util.HashMap;
import java.util.Locale;
import java.util.Map;

import org.springframework.context.i18n.LocaleContextHolder;

Expand Down Expand Up @@ -73,4 +75,11 @@ public String getMsg() {
return this.enMsg;
}
}

public static Map<String, String> getAllMsg(AlertInputTips alertInputTips) {
Map<String, String> allMsgMap = new HashMap<>();
allMsgMap.put("zhMsg", alertInputTips.zhMsg);
allMsgMap.put("enMsg", alertInputTips.enMsg);
return allMsgMap;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.apache.dolphinscheduler.alert.api.AlertChannel;
import org.apache.dolphinscheduler.alert.api.AlertChannelFactory;
import org.apache.dolphinscheduler.alert.api.AlertInputTips;
import org.apache.dolphinscheduler.common.utils.JSONUtils;
import org.apache.dolphinscheduler.spi.params.base.DataType;
import org.apache.dolphinscheduler.spi.params.base.ParamsOptions;
import org.apache.dolphinscheduler.spi.params.base.PluginParams;
Expand Down Expand Up @@ -137,7 +138,7 @@ public List<PluginParams> params() {
.build();
InputParam passwordParam = InputParam
.newBuilder(DingTalkParamsConstants.NAME_DING_TALK_PASSWORD, DingTalkParamsConstants.DING_TALK_PASSWORD)
.setPlaceholder(AlertInputTips.PASSWORD.getMsg())
.setPlaceholder(JSONUtils.toJsonString(AlertInputTips.getAllMsg(AlertInputTips.PASSWORD)))
.setType("password")
.build();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.apache.dolphinscheduler.alert.api.AlertConstants;
import org.apache.dolphinscheduler.alert.api.AlertInputTips;
import org.apache.dolphinscheduler.alert.api.ShowType;
import org.apache.dolphinscheduler.common.utils.JSONUtils;
import org.apache.dolphinscheduler.spi.params.base.DataType;
import org.apache.dolphinscheduler.spi.params.base.ParamsOptions;
import org.apache.dolphinscheduler.spi.params.base.PluginParams;
Expand Down Expand Up @@ -54,7 +55,7 @@ public List<PluginParams> params() {
InputParam receivesParam = InputParam
.newBuilder(MailParamsConstants.NAME_PLUGIN_DEFAULT_EMAIL_RECEIVERS,
MailParamsConstants.PLUGIN_DEFAULT_EMAIL_RECEIVERS)
.setPlaceholder(AlertInputTips.RECEIVERS.getMsg())
.setPlaceholder(JSONUtils.toJsonString(AlertInputTips.getAllMsg(AlertInputTips.RECEIVERS)))
.addValidate(Validate.newBuilder()
.setRequired(true)
.build())
Expand Down Expand Up @@ -93,12 +94,12 @@ public List<PluginParams> params() {
.build();

InputParam mailUser = InputParam.newBuilder(MailParamsConstants.NAME_MAIL_USER, MailParamsConstants.MAIL_USER)
.setPlaceholder(AlertInputTips.USERNAME.getMsg())
.setPlaceholder(JSONUtils.toJsonString(AlertInputTips.getAllMsg(AlertInputTips.USERNAME)))
.build();

InputParam mailPassword =
InputParam.newBuilder(MailParamsConstants.NAME_MAIL_PASSWD, MailParamsConstants.MAIL_PASSWD)
.setPlaceholder(AlertInputTips.PASSWORD.getMsg())
.setPlaceholder(JSONUtils.toJsonString(AlertInputTips.getAllMsg(AlertInputTips.PASSWORD)))
.setType("password")
.build();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.apache.dolphinscheduler.alert.api.AlertChannel;
import org.apache.dolphinscheduler.alert.api.AlertChannelFactory;
import org.apache.dolphinscheduler.alert.api.AlertInputTips;
import org.apache.dolphinscheduler.common.utils.JSONUtils;
import org.apache.dolphinscheduler.spi.params.base.DataType;
import org.apache.dolphinscheduler.spi.params.base.ParamsOptions;
import org.apache.dolphinscheduler.spi.params.base.PluginParams;
Expand Down Expand Up @@ -86,7 +87,7 @@ public List<PluginParams> params() {
.build();
InputParam passwordParam = InputParam
.newBuilder(FeiShuParamsConstants.NAME_FEI_SHU_PASSWORD, FeiShuParamsConstants.FEI_SHU_PASSWORD)
.setPlaceholder(AlertInputTips.PASSWORD.getMsg())
.setPlaceholder(JSONUtils.toJsonString(AlertInputTips.getAllMsg(AlertInputTips.PASSWORD)))
.setType("password")
.build();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.apache.dolphinscheduler.alert.api.AlertChannelFactory;
import org.apache.dolphinscheduler.alert.api.AlertInputTips;
import org.apache.dolphinscheduler.common.model.OkHttpRequestHeaderContentType;
import org.apache.dolphinscheduler.common.utils.JSONUtils;
import org.apache.dolphinscheduler.spi.params.base.DataType;
import org.apache.dolphinscheduler.spi.params.base.ParamsOptions;
import org.apache.dolphinscheduler.spi.params.base.PluginParams;
Expand All @@ -46,15 +47,15 @@ public String name() {
public List<PluginParams> params() {

InputParam url = InputParam.newBuilder(HttpAlertConstants.NAME_URL, HttpAlertConstants.URL)
.setPlaceholder(AlertInputTips.URL.getMsg())
.setPlaceholder(JSONUtils.toJsonString(AlertInputTips.getAllMsg(AlertInputTips.URL)))
.addValidate(Validate.newBuilder()
.setRequired(true)
.build())
.build();

InputParam headerParams =
InputParam.newBuilder(HttpAlertConstants.NAME_HEADER_PARAMS, HttpAlertConstants.HEADER_PARAMS)
.setPlaceholder(AlertInputTips.HEADER.getMsg())
.setPlaceholder(JSONUtils.toJsonString(AlertInputTips.getAllMsg(AlertInputTips.HEADER)))
.addValidate(Validate.newBuilder()
.setRequired(false)
.build())
Expand All @@ -75,7 +76,7 @@ public List<PluginParams> params() {

InputParam bodyParams =
InputParam.newBuilder(HttpAlertConstants.NAME_BODY_PARAMS, HttpAlertConstants.BODY_PARAMS)
.setPlaceholder(AlertInputTips.JSON_BODY.getMsg())
.setPlaceholder(JSONUtils.toJsonString(AlertInputTips.getAllMsg(AlertInputTips.JSON_BODY)))
.addValidate(Validate.newBuilder()
.setRequired(false)
.build())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.apache.dolphinscheduler.alert.api.AlertChannel;
import org.apache.dolphinscheduler.alert.api.AlertChannelFactory;
import org.apache.dolphinscheduler.alert.api.AlertInputTips;
import org.apache.dolphinscheduler.common.utils.JSONUtils;
import org.apache.dolphinscheduler.spi.params.base.PluginParams;
import org.apache.dolphinscheduler.spi.params.base.Validate;
import org.apache.dolphinscheduler.spi.params.input.InputParam;
Expand All @@ -43,7 +44,7 @@ public List<PluginParams> params() {
InputParam
.newBuilder(PrometheusAlertConstants.NAME_ALERT_MANAGER_URL,
PrometheusAlertConstants.ALERT_MANAGER_URL)
.setPlaceholder(AlertInputTips.URL.getMsg())
.setPlaceholder(JSONUtils.toJsonString(AlertInputTips.getAllMsg(AlertInputTips.URL)))
.addValidate(Validate.newBuilder()
.setRequired(true)
.build())
Expand All @@ -52,14 +53,14 @@ public List<PluginParams> params() {
InputParam
.newBuilder(PrometheusAlertConstants.NAME_ALERT_MANAGER_ANNOTATIONS,
PrometheusAlertConstants.ALERT_MANAGER_ANNOTATIONS)
.setPlaceholder(AlertInputTips.ANNOTATION.getMsg())
.setPlaceholder(JSONUtils.toJsonString(AlertInputTips.getAllMsg(AlertInputTips.ANNOTATION)))
.addValidate(Validate.newBuilder()
.setRequired(false).build())
.build();
InputParam generatorUrlParam =
InputParam
.newBuilder(PrometheusAlertConstants.NAME_GENERATOR_URL, PrometheusAlertConstants.GENERATOR_URL)
.setPlaceholder(AlertInputTips.GENERATOR_URL.getMsg())
.setPlaceholder(JSONUtils.toJsonString(AlertInputTips.getAllMsg(AlertInputTips.GENERATOR_URL)))
.addValidate(Validate.newBuilder()
.setRequired(false).build())
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.apache.dolphinscheduler.alert.api.AlertChannel;
import org.apache.dolphinscheduler.alert.api.AlertChannelFactory;
import org.apache.dolphinscheduler.alert.api.AlertInputTips;
import org.apache.dolphinscheduler.common.utils.JSONUtils;
import org.apache.dolphinscheduler.spi.params.base.ParamsOptions;
import org.apache.dolphinscheduler.spi.params.base.PluginParams;
import org.apache.dolphinscheduler.spi.params.base.Validate;
Expand Down Expand Up @@ -47,15 +48,15 @@ public List<PluginParams> params() {
.addValidate(Validate.newBuilder()
.setRequired(false)
.build())
.setPlaceholder(AlertInputTips.CUSTOMIZED_PARAMS.getMsg())
.setPlaceholder(JSONUtils.toJsonString(AlertInputTips.getAllMsg(AlertInputTips.CUSTOMIZED_PARAMS)))
.build();
// need check file type and file exist
InputParam scriptPathParam =
InputParam.newBuilder(ScriptParamsConstants.NAME_SCRIPT_PATH, ScriptParamsConstants.SCRIPT_PATH)
.addValidate(Validate.newBuilder()
.setRequired(true)
.build())
.setPlaceholder(AlertInputTips.SCRIPT_PATH.getMsg())
.setPlaceholder(JSONUtils.toJsonString(AlertInputTips.getAllMsg(AlertInputTips.SCRIPT_PATH)))
.build();

RadioParam scriptTypeParams = RadioParam
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.apache.dolphinscheduler.alert.api.AlertChannel;
import org.apache.dolphinscheduler.alert.api.AlertChannelFactory;
import org.apache.dolphinscheduler.alert.api.AlertInputTips;
import org.apache.dolphinscheduler.common.utils.JSONUtils;
import org.apache.dolphinscheduler.spi.params.base.PluginParams;
import org.apache.dolphinscheduler.spi.params.base.Validate;
import org.apache.dolphinscheduler.spi.params.input.InputParam;
Expand All @@ -46,14 +47,14 @@ public List<PluginParams> params() {
.addValidate(Validate.newBuilder()
.setRequired(true)
.build())
.setPlaceholder(AlertInputTips.WEBHOOK.getMsg())
.setPlaceholder(JSONUtils.toJsonString(AlertInputTips.getAllMsg(AlertInputTips.WEBHOOK)))
.build();

InputParam botName = InputParam.newBuilder(SlackParamsConstants.SLACK_BOT_NAME, SlackParamsConstants.SLACK_BOT)
.addValidate(Validate.newBuilder()
.setRequired(true)
.build())
.setPlaceholder(AlertInputTips.BOT_NAME.getMsg())
.setPlaceholder(JSONUtils.toJsonString(AlertInputTips.getAllMsg(AlertInputTips.BOT_NAME)))
.build();

paramsList.add(webHookParam);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.apache.dolphinscheduler.alert.api.AlertChannel;
import org.apache.dolphinscheduler.alert.api.AlertChannelFactory;
import org.apache.dolphinscheduler.alert.api.AlertInputTips;
import org.apache.dolphinscheduler.common.utils.JSONUtils;
import org.apache.dolphinscheduler.spi.params.base.DataType;
import org.apache.dolphinscheduler.spi.params.base.ParamsOptions;
import org.apache.dolphinscheduler.spi.params.base.PluginParams;
Expand Down Expand Up @@ -60,23 +61,23 @@ public List<PluginParams> params() {
.addValidate(Validate.newBuilder()
.setRequired(true)
.build())
.setPlaceholder(AlertInputTips.WEBHOOK.getMsg())
.setPlaceholder(JSONUtils.toJsonString(AlertInputTips.getAllMsg(AlertInputTips.WEBHOOK)))
.build();

InputParam botTokenParam = InputParam
.newBuilder(TelegramParamsConstants.NAME_TELEGRAM_BOT_TOKEN, TelegramParamsConstants.TELEGRAM_BOT_TOKEN)
.addValidate(Validate.newBuilder()
.setRequired(true)
.build())
.setPlaceholder(AlertInputTips.BOT_TOKEN.getMsg())
.setPlaceholder(JSONUtils.toJsonString(AlertInputTips.getAllMsg(AlertInputTips.BOT_TOKEN)))
.build();

InputParam chatIdParam = InputParam
.newBuilder(TelegramParamsConstants.NAME_TELEGRAM_CHAT_ID, TelegramParamsConstants.TELEGRAM_CHAT_ID)
.addValidate(Validate.newBuilder()
.setRequired(true)
.build())
.setPlaceholder(AlertInputTips.CHANNEL_ID.getMsg())
.setPlaceholder(JSONUtils.toJsonString(AlertInputTips.getAllMsg(AlertInputTips.CHANNEL_ID)))
.build();

SelectParam parseMode = SelectParam
Expand Down Expand Up @@ -135,7 +136,7 @@ public List<PluginParams> params() {
.addValidate(Validate.newBuilder()
.setRequired(false)
.build())
.setPlaceholder("if enable use authentication, you need input password")
.setPlaceholder(JSONUtils.toJsonString(AlertInputTips.getAllMsg(AlertInputTips.PASSWORD)))
.setType("password")
.build();

Expand Down
Loading

0 comments on commit 7876d45

Please sign in to comment.