From 1c09305a88aa01acb7cb919ea8bd8ee7c26aeff6 Mon Sep 17 00:00:00 2001 From: "lin.ma" Date: Wed, 15 Apr 2026 20:00:55 +0800 Subject: [PATCH] [zwatch]: add GlobalErrorCode and i18n translations for external alert integration Add error code ORG_ZSTACK_ZWATCH_ALARM_10030 (invalid URL) with 10-language i18n translations for the external alert integration API interceptor URL validation. Resolves: ZSTAC-84319 Change-Id: I61657078726f6168766d79626c64727865736d63 --- .../global-error-de-DE.json | 1 + .../global-error-en_US.json | 1 + .../global-error-fr-FR.json | 1 + .../global-error-id-ID.json | 1 + .../global-error-ja-JP.json | 1 + .../global-error-ko-KR.json | 1 + .../global-error-ru-RU.json | 1 + .../global-error-th-TH.json | 1 + .../global-error-zh_CN.json | 1 + .../global-error-zh_TW.json | 1 + .../CheckExternalAlertIntegrationAction.java | 104 +++++++++++++++++ .../CheckExternalAlertIntegrationResult.java | 46 ++++++++ .../RemoveExternalAlertIntegrationAction.java | 101 +++++++++++++++++ .../RemoveExternalAlertIntegrationResult.java | 7 ++ .../SetupExternalAlertIntegrationAction.java | 107 ++++++++++++++++++ .../SetupExternalAlertIntegrationResult.java | 30 +++++ .../java/org/zstack/testlib/ApiHelper.groovy | 95 +++++++++++++++- .../CloudOperationsErrorCode.java | 2 + 18 files changed, 496 insertions(+), 6 deletions(-) create mode 100644 sdk/src/main/java/org/zstack/sdk/zwatch/alarm/integration/CheckExternalAlertIntegrationAction.java create mode 100644 sdk/src/main/java/org/zstack/sdk/zwatch/alarm/integration/CheckExternalAlertIntegrationResult.java create mode 100644 sdk/src/main/java/org/zstack/sdk/zwatch/alarm/integration/RemoveExternalAlertIntegrationAction.java create mode 100644 sdk/src/main/java/org/zstack/sdk/zwatch/alarm/integration/RemoveExternalAlertIntegrationResult.java create mode 100644 sdk/src/main/java/org/zstack/sdk/zwatch/alarm/integration/SetupExternalAlertIntegrationAction.java create mode 100644 sdk/src/main/java/org/zstack/sdk/zwatch/alarm/integration/SetupExternalAlertIntegrationResult.java diff --git a/conf/i18n/globalErrorCodeMapping/global-error-de-DE.json b/conf/i18n/globalErrorCodeMapping/global-error-de-DE.json index 1e24c52ea11..dab7f5d29ab 100644 --- a/conf/i18n/globalErrorCodeMapping/global-error-de-DE.json +++ b/conf/i18n/globalErrorCodeMapping/global-error-de-DE.json @@ -847,6 +847,7 @@ "ORG_ZSTACK_ZWATCH_ALARM_10025": "Die Metrik hat nicht das angegebene Label[%s]", "ORG_ZSTACK_ZWATCH_ALARM_10023": "Doppeltes Label definiert für den Alarm mit UUID [uuid:%s]", "ORG_ZSTACK_ZWATCH_ALARM_10029": "Die Metrik[%s] ist auf Administratoren beschränkt und ist für Ihre aktuelle Benutzerrolle nicht verfügbar.", + "ORG_ZSTACK_ZWATCH_ALARM_10030": "Ungültige URL[%s]", "ORG_ZSTACK_NETWORK_SERVICE_LB_10171": "Backend-Server konnte nicht geändert werden, da vmincs und Server-IPs null sind", "ORG_ZSTACK_ZWATCH_ALARM_10028": "Namespace[%s] enthält nicht die Metrik[%s]", "ORG_ZSTACK_ZWATCH_ALARM_10027": "Namespace[%s] wird nicht unterstützt", diff --git a/conf/i18n/globalErrorCodeMapping/global-error-en_US.json b/conf/i18n/globalErrorCodeMapping/global-error-en_US.json index af8d1b29ac6..0149aa15017 100644 --- a/conf/i18n/globalErrorCodeMapping/global-error-en_US.json +++ b/conf/i18n/globalErrorCodeMapping/global-error-en_US.json @@ -847,6 +847,7 @@ "ORG_ZSTACK_ZWATCH_ALARM_10025": "the metric does not have the specified label[%s]", "ORG_ZSTACK_ZWATCH_ALARM_10023": "duplicate label defined for the alarm with UUID [uuid:%s]", "ORG_ZSTACK_ZWATCH_ALARM_10029": "the metric[%s] is restricted to administrators and is not available for your current user role.", + "ORG_ZSTACK_ZWATCH_ALARM_10030": "invalid url[%s]", "ORG_ZSTACK_NETWORK_SERVICE_LB_10171": "could not modify backend server because vmincs and server IPs are null", "ORG_ZSTACK_ZWATCH_ALARM_10028": "namespace[%s] does not contain the metric[%s]", "ORG_ZSTACK_ZWATCH_ALARM_10027": "namespace[%s] is not supported", diff --git a/conf/i18n/globalErrorCodeMapping/global-error-fr-FR.json b/conf/i18n/globalErrorCodeMapping/global-error-fr-FR.json index 8fb00fa5776..fc1164723d7 100644 --- a/conf/i18n/globalErrorCodeMapping/global-error-fr-FR.json +++ b/conf/i18n/globalErrorCodeMapping/global-error-fr-FR.json @@ -847,6 +847,7 @@ "ORG_ZSTACK_ZWATCH_ALARM_10025": "la métrique ne possède pas l'étiquette spécifiée[%s]", "ORG_ZSTACK_ZWATCH_ALARM_10023": "étiquette en double définie pour l'alarme avec UUID [uuid:%s]", "ORG_ZSTACK_ZWATCH_ALARM_10029": "la métrique[%s] est restreinte aux administrateurs et n'est pas disponible pour votre rôle utilisateur actuel.", + "ORG_ZSTACK_ZWATCH_ALARM_10030": "URL invalide[%s]", "ORG_ZSTACK_NETWORK_SERVICE_LB_10171": "impossible de modifier le serveur backend car vmincs et les IPs du serveur sont null", "ORG_ZSTACK_ZWATCH_ALARM_10028": "l'espace de noms[%s] ne contient pas la métrique[%s]", "ORG_ZSTACK_ZWATCH_ALARM_10027": "l'espace de noms[%s] n'est pas pris en charge", diff --git a/conf/i18n/globalErrorCodeMapping/global-error-id-ID.json b/conf/i18n/globalErrorCodeMapping/global-error-id-ID.json index 7e41658f314..69dd3d9c6f0 100644 --- a/conf/i18n/globalErrorCodeMapping/global-error-id-ID.json +++ b/conf/i18n/globalErrorCodeMapping/global-error-id-ID.json @@ -847,6 +847,7 @@ "ORG_ZSTACK_ZWATCH_ALARM_10025": "metrik tidak memiliki label yang ditentukan[%s]", "ORG_ZSTACK_ZWATCH_ALARM_10023": "label duplikat didefinisikan untuk alarm dengan UUID [uuid:%s]", "ORG_ZSTACK_ZWATCH_ALARM_10029": "metrik[%s] dibatasi untuk administrator dan tidak tersedia untuk peran pengguna Anda saat ini.", + "ORG_ZSTACK_ZWATCH_ALARM_10030": "URL tidak valid[%s]", "ORG_ZSTACK_NETWORK_SERVICE_LB_10171": "tidak dapat memodifikasi server backend karena vmincs dan IP server kosong", "ORG_ZSTACK_ZWATCH_ALARM_10028": "namespace[%s] tidak berisi metrik[%s]", "ORG_ZSTACK_ZWATCH_ALARM_10027": "namespace[%s] tidak didukung", diff --git a/conf/i18n/globalErrorCodeMapping/global-error-ja-JP.json b/conf/i18n/globalErrorCodeMapping/global-error-ja-JP.json index bf73aa503ff..f7de70a52da 100644 --- a/conf/i18n/globalErrorCodeMapping/global-error-ja-JP.json +++ b/conf/i18n/globalErrorCodeMapping/global-error-ja-JP.json @@ -847,6 +847,7 @@ "ORG_ZSTACK_ZWATCH_ALARM_10025": "メトリクスに、指定されたラベル[%s]がありません", "ORG_ZSTACK_ZWATCH_ALARM_10023": "UUID [uuid:%s]のアラームに重複するラベルが定義されています", "ORG_ZSTACK_ZWATCH_ALARM_10029": "メトリクス[%s]は管理者向けに制限されており、現在のユーザーロールでは利用できません", + "ORG_ZSTACK_ZWATCH_ALARM_10030": "無効なURL[%s]", "ORG_ZSTACK_NETWORK_SERVICE_LB_10171": "vmincsとサーバーIPがnullのため、バックエンドサーバーを変更できませんでした", "ORG_ZSTACK_ZWATCH_ALARM_10028": "名前空間[%s]にはメトリクス[%s]が含まれていません", "ORG_ZSTACK_ZWATCH_ALARM_10027": "名前空間[%s]はサポートされていません", diff --git a/conf/i18n/globalErrorCodeMapping/global-error-ko-KR.json b/conf/i18n/globalErrorCodeMapping/global-error-ko-KR.json index d9323871208..2b2874d0761 100644 --- a/conf/i18n/globalErrorCodeMapping/global-error-ko-KR.json +++ b/conf/i18n/globalErrorCodeMapping/global-error-ko-KR.json @@ -847,6 +847,7 @@ "ORG_ZSTACK_ZWATCH_ALARM_10025": "메트릭에 지정된 라벨[%s]이 없습니다", "ORG_ZSTACK_ZWATCH_ALARM_10023": "UUID [uuid:%s]가 있는 알람에 중복된 라벨이 정의되어 있습니다", "ORG_ZSTACK_ZWATCH_ALARM_10029": "메트릭[%s]은 관리자에게만 제한되어 있으며, 현재 사용자 역할에서는 사용할 수 없습니다", + "ORG_ZSTACK_ZWATCH_ALARM_10030": "잘못된 URL[%s]", "ORG_ZSTACK_NETWORK_SERVICE_LB_10171": "vmincs와 서버 IP가 null이므로 백엔드 서버를 수정할 수 없습니다", "ORG_ZSTACK_ZWATCH_ALARM_10028": "네임스페이스[%s]에 메트릭[%s]이 포함되어 있지 않습니다", "ORG_ZSTACK_ZWATCH_ALARM_10027": "네임스페이스[%s]가 지원되지 않습니다", diff --git a/conf/i18n/globalErrorCodeMapping/global-error-ru-RU.json b/conf/i18n/globalErrorCodeMapping/global-error-ru-RU.json index 55bde5ee0c5..ea4465e3829 100644 --- a/conf/i18n/globalErrorCodeMapping/global-error-ru-RU.json +++ b/conf/i18n/globalErrorCodeMapping/global-error-ru-RU.json @@ -847,6 +847,7 @@ "ORG_ZSTACK_ZWATCH_ALARM_10025": "метрика не содержит указанную метку[%s]", "ORG_ZSTACK_ZWATCH_ALARM_10023": "дублирующаяся метка определена для сигнала тревоги с UUID [uuid:%s]", "ORG_ZSTACK_ZWATCH_ALARM_10029": "метрика[%s] ограничена для администраторов и недоступна для вашей текущей роли пользователя.", + "ORG_ZSTACK_ZWATCH_ALARM_10030": "недопустимый URL[%s]", "ORG_ZSTACK_NETWORK_SERVICE_LB_10171": "не удалось изменить backend-сервер, так как vmincs и IP-адреса серверов равны null", "ORG_ZSTACK_ZWATCH_ALARM_10028": "namespace[%s] не содержит метрику[%s]", "ORG_ZSTACK_ZWATCH_ALARM_10027": "namespace[%s] не поддерживается", diff --git a/conf/i18n/globalErrorCodeMapping/global-error-th-TH.json b/conf/i18n/globalErrorCodeMapping/global-error-th-TH.json index 3118556b6d7..aedafc11219 100644 --- a/conf/i18n/globalErrorCodeMapping/global-error-th-TH.json +++ b/conf/i18n/globalErrorCodeMapping/global-error-th-TH.json @@ -847,6 +847,7 @@ "ORG_ZSTACK_ZWATCH_ALARM_10025": "เมทริกไม่มีป้ายกำกับที่ระบุ[%s]", "ORG_ZSTACK_ZWATCH_ALARM_10023": "มีการกำหนดป้ายกำกับซ้ำสำหรับ alarm ที่มี UUID [uuid:%s]", "ORG_ZSTACK_ZWATCH_ALARM_10029": "เมทริก[%s] จำกัดสำหรับผู้ดูแลระบบและไม่พร้อมใช้งานสำหรับบทบาทผู้ใช้ปัจจุบันของคุณ", + "ORG_ZSTACK_ZWATCH_ALARM_10030": "URL ไม่ถูกต้อง[%s]", "ORG_ZSTACK_NETWORK_SERVICE_LB_10171": "ไม่สามารถแก้ไขเซิร์ฟเวอร์แบ็กเอนด์ได้เนื่องจาก vmincs และ IP เซิร์ฟเวอร์เป็นค่าว่าง", "ORG_ZSTACK_ZWATCH_ALARM_10028": "namespace[%s] ไม่มีเมทริก[%s]", "ORG_ZSTACK_ZWATCH_ALARM_10027": "namespace[%s] ไม่ได้รับการสนับสนุน", diff --git a/conf/i18n/globalErrorCodeMapping/global-error-zh_CN.json b/conf/i18n/globalErrorCodeMapping/global-error-zh_CN.json index be35880ac65..629826498d3 100644 --- a/conf/i18n/globalErrorCodeMapping/global-error-zh_CN.json +++ b/conf/i18n/globalErrorCodeMapping/global-error-zh_CN.json @@ -847,6 +847,7 @@ "ORG_ZSTACK_ZWATCH_ALARM_10025": "指标[%s]不存在标签[%s]", "ORG_ZSTACK_ZWATCH_ALARM_10023": "重复标签[key:%s, 操作符:%s, 值:%s]告警[uuid:%s]", "ORG_ZSTACK_ZWATCH_ALARM_10029": "指标[%s]仅管理员可见,当前用户不可用", + "ORG_ZSTACK_ZWATCH_ALARM_10030": "无效的URL[%s]", "ORG_ZSTACK_NETWORK_SERVICE_LB_10171": "无法更改后端服务器,因为 vmincs 和 serverips 为空", "ORG_ZSTACK_ZWATCH_ALARM_10028": "命名空间[%s]不存在度量[%s]", "ORG_ZSTACK_ZWATCH_ALARM_10027": "命名空间[%s]不支持", diff --git a/conf/i18n/globalErrorCodeMapping/global-error-zh_TW.json b/conf/i18n/globalErrorCodeMapping/global-error-zh_TW.json index b696d46d059..ca81bc92b20 100644 --- a/conf/i18n/globalErrorCodeMapping/global-error-zh_TW.json +++ b/conf/i18n/globalErrorCodeMapping/global-error-zh_TW.json @@ -847,6 +847,7 @@ "ORG_ZSTACK_ZWATCH_ALARM_10025": "指標[%s]不儲在標签[%s]", "ORG_ZSTACK_ZWATCH_ALARM_10023": "重复標签[key:%s, 操作符:%s, 值:%s]告警[uuid:%s]", "ORG_ZSTACK_ZWATCH_ALARM_10029": "指標[%s]仅管理員可见,當前用戶不可用", + "ORG_ZSTACK_ZWATCH_ALARM_10030": "無效的URL[%s]", "ORG_ZSTACK_NETWORK_SERVICE_LB_10171": "無法更改後端服務器,因为 vmincs 和 serverips 为空", "ORG_ZSTACK_ZWATCH_ALARM_10028": "命名空間[%s]不儲在度量[%s]", "ORG_ZSTACK_ZWATCH_ALARM_10027": "命名空間[%s]不支持", diff --git a/sdk/src/main/java/org/zstack/sdk/zwatch/alarm/integration/CheckExternalAlertIntegrationAction.java b/sdk/src/main/java/org/zstack/sdk/zwatch/alarm/integration/CheckExternalAlertIntegrationAction.java new file mode 100644 index 00000000000..3cd5f74e9ec --- /dev/null +++ b/sdk/src/main/java/org/zstack/sdk/zwatch/alarm/integration/CheckExternalAlertIntegrationAction.java @@ -0,0 +1,104 @@ +package org.zstack.sdk.zwatch.alarm.integration; + +import java.util.HashMap; +import java.util.Map; +import org.zstack.sdk.*; + +public class CheckExternalAlertIntegrationAction extends AbstractAction { + + private static final HashMap parameterMap = new HashMap<>(); + + private static final HashMap nonAPIParameterMap = new HashMap<>(); + + public static class Result { + public ErrorCode error; + public org.zstack.sdk.zwatch.alarm.integration.CheckExternalAlertIntegrationResult value; + + public Result throwExceptionIfError() { + if (error != null) { + throw new ApiException( + String.format("error[code: %s, description: %s, details: %s, globalErrorCode: %s]", error.code, error.description, error.details, error.globalErrorCode) + ); + } + + return this; + } + } + + @Param(required = true, maxLength = 36, nonempty = false, nullElements = false, emptyString = true, noTrim = false) + public java.lang.String endpointUuid; + + @Param(required = true, maxLength = 2048, nonempty = false, nullElements = false, emptyString = true, noTrim = false) + public java.lang.String expectedUrl; + + @Param(required = false) + public java.util.List systemTags; + + @Param(required = false) + public java.util.List userTags; + + @Param(required = false) + public String sessionId; + + @Param(required = false) + public String accessKeyId; + + @Param(required = false) + public String accessKeySecret; + + @Param(required = false) + public String requestIp; + + @NonAPIParam + public long timeout = -1; + + @NonAPIParam + public long pollingInterval = -1; + + + private Result makeResult(ApiResult res) { + Result ret = new Result(); + if (res.error != null) { + ret.error = res.error; + return ret; + } + + org.zstack.sdk.zwatch.alarm.integration.CheckExternalAlertIntegrationResult value = res.getResult(org.zstack.sdk.zwatch.alarm.integration.CheckExternalAlertIntegrationResult.class); + ret.value = value == null ? new org.zstack.sdk.zwatch.alarm.integration.CheckExternalAlertIntegrationResult() : value; + + return ret; + } + + public Result call() { + ApiResult res = ZSClient.call(this); + return makeResult(res); + } + + public void call(final Completion completion) { + ZSClient.call(this, new InternalCompletion() { + @Override + public void complete(ApiResult res) { + completion.complete(makeResult(res)); + } + }); + } + + protected Map getParameterMap() { + return parameterMap; + } + + protected Map getNonAPIParameterMap() { + return nonAPIParameterMap; + } + + protected RestInfo getRestInfo() { + RestInfo info = new RestInfo(); + info.httpMethod = "POST"; + info.path = "/sns/external-alert-integrations/check"; + info.needSession = true; + info.needPoll = true; + info.parameterName = "params"; + return info; + } + +} diff --git a/sdk/src/main/java/org/zstack/sdk/zwatch/alarm/integration/CheckExternalAlertIntegrationResult.java b/sdk/src/main/java/org/zstack/sdk/zwatch/alarm/integration/CheckExternalAlertIntegrationResult.java new file mode 100644 index 00000000000..523c5083753 --- /dev/null +++ b/sdk/src/main/java/org/zstack/sdk/zwatch/alarm/integration/CheckExternalAlertIntegrationResult.java @@ -0,0 +1,46 @@ +package org.zstack.sdk.zwatch.alarm.integration; + + + +public class CheckExternalAlertIntegrationResult { + public boolean healthy; + public void setHealthy(boolean healthy) { + this.healthy = healthy; + } + public boolean getHealthy() { + return this.healthy; + } + + public boolean endpointExists; + public void setEndpointExists(boolean endpointExists) { + this.endpointExists = endpointExists; + } + public boolean getEndpointExists() { + return this.endpointExists; + } + + public boolean urlMatched; + public void setUrlMatched(boolean urlMatched) { + this.urlMatched = urlMatched; + } + public boolean getUrlMatched() { + return this.urlMatched; + } + + public boolean subscribed; + public void setSubscribed(boolean subscribed) { + this.subscribed = subscribed; + } + public boolean getSubscribed() { + return this.subscribed; + } + + public boolean templateExists; + public void setTemplateExists(boolean templateExists) { + this.templateExists = templateExists; + } + public boolean getTemplateExists() { + return this.templateExists; + } + +} diff --git a/sdk/src/main/java/org/zstack/sdk/zwatch/alarm/integration/RemoveExternalAlertIntegrationAction.java b/sdk/src/main/java/org/zstack/sdk/zwatch/alarm/integration/RemoveExternalAlertIntegrationAction.java new file mode 100644 index 00000000000..fcdfaf08d02 --- /dev/null +++ b/sdk/src/main/java/org/zstack/sdk/zwatch/alarm/integration/RemoveExternalAlertIntegrationAction.java @@ -0,0 +1,101 @@ +package org.zstack.sdk.zwatch.alarm.integration; + +import java.util.HashMap; +import java.util.Map; +import org.zstack.sdk.*; + +public class RemoveExternalAlertIntegrationAction extends AbstractAction { + + private static final HashMap parameterMap = new HashMap<>(); + + private static final HashMap nonAPIParameterMap = new HashMap<>(); + + public static class Result { + public ErrorCode error; + public org.zstack.sdk.zwatch.alarm.integration.RemoveExternalAlertIntegrationResult value; + + public Result throwExceptionIfError() { + if (error != null) { + throw new ApiException( + String.format("error[code: %s, description: %s, details: %s, globalErrorCode: %s]", error.code, error.description, error.details, error.globalErrorCode) + ); + } + + return this; + } + } + + @Param(required = true, maxLength = 36, nonempty = false, nullElements = false, emptyString = true, noTrim = false) + public java.lang.String endpointUuid; + + @Param(required = false) + public java.util.List systemTags; + + @Param(required = false) + public java.util.List userTags; + + @Param(required = false) + public String sessionId; + + @Param(required = false) + public String accessKeyId; + + @Param(required = false) + public String accessKeySecret; + + @Param(required = false) + public String requestIp; + + @NonAPIParam + public long timeout = -1; + + @NonAPIParam + public long pollingInterval = -1; + + + private Result makeResult(ApiResult res) { + Result ret = new Result(); + if (res.error != null) { + ret.error = res.error; + return ret; + } + + org.zstack.sdk.zwatch.alarm.integration.RemoveExternalAlertIntegrationResult value = res.getResult(org.zstack.sdk.zwatch.alarm.integration.RemoveExternalAlertIntegrationResult.class); + ret.value = value == null ? new org.zstack.sdk.zwatch.alarm.integration.RemoveExternalAlertIntegrationResult() : value; + + return ret; + } + + public Result call() { + ApiResult res = ZSClient.call(this); + return makeResult(res); + } + + public void call(final Completion completion) { + ZSClient.call(this, new InternalCompletion() { + @Override + public void complete(ApiResult res) { + completion.complete(makeResult(res)); + } + }); + } + + protected Map getParameterMap() { + return parameterMap; + } + + protected Map getNonAPIParameterMap() { + return nonAPIParameterMap; + } + + protected RestInfo getRestInfo() { + RestInfo info = new RestInfo(); + info.httpMethod = "DELETE"; + info.path = "/sns/external-alert-integrations/{endpointUuid}"; + info.needSession = true; + info.needPoll = true; + info.parameterName = ""; + return info; + } + +} diff --git a/sdk/src/main/java/org/zstack/sdk/zwatch/alarm/integration/RemoveExternalAlertIntegrationResult.java b/sdk/src/main/java/org/zstack/sdk/zwatch/alarm/integration/RemoveExternalAlertIntegrationResult.java new file mode 100644 index 00000000000..f6d4e089e4b --- /dev/null +++ b/sdk/src/main/java/org/zstack/sdk/zwatch/alarm/integration/RemoveExternalAlertIntegrationResult.java @@ -0,0 +1,7 @@ +package org.zstack.sdk.zwatch.alarm.integration; + + + +public class RemoveExternalAlertIntegrationResult { + +} diff --git a/sdk/src/main/java/org/zstack/sdk/zwatch/alarm/integration/SetupExternalAlertIntegrationAction.java b/sdk/src/main/java/org/zstack/sdk/zwatch/alarm/integration/SetupExternalAlertIntegrationAction.java new file mode 100644 index 00000000000..65c44ca52c4 --- /dev/null +++ b/sdk/src/main/java/org/zstack/sdk/zwatch/alarm/integration/SetupExternalAlertIntegrationAction.java @@ -0,0 +1,107 @@ +package org.zstack.sdk.zwatch.alarm.integration; + +import java.util.HashMap; +import java.util.Map; +import org.zstack.sdk.*; + +public class SetupExternalAlertIntegrationAction extends AbstractAction { + + private static final HashMap parameterMap = new HashMap<>(); + + private static final HashMap nonAPIParameterMap = new HashMap<>(); + + public static class Result { + public ErrorCode error; + public org.zstack.sdk.zwatch.alarm.integration.SetupExternalAlertIntegrationResult value; + + public Result throwExceptionIfError() { + if (error != null) { + throw new ApiException( + String.format("error[code: %s, description: %s, details: %s, globalErrorCode: %s]", error.code, error.description, error.details, error.globalErrorCode) + ); + } + + return this; + } + } + + @Param(required = true, maxLength = 255, nonempty = false, nullElements = false, emptyString = true, noTrim = false) + public java.lang.String name; + + @Param(required = true, maxLength = 2048, nonempty = false, nullElements = false, emptyString = true, noTrim = false) + public java.lang.String url; + + @Param(required = false, maxLength = 2048, nonempty = false, nullElements = false, emptyString = true, noTrim = false) + public java.lang.String description; + + @Param(required = false) + public java.util.List systemTags; + + @Param(required = false) + public java.util.List userTags; + + @Param(required = false) + public String sessionId; + + @Param(required = false) + public String accessKeyId; + + @Param(required = false) + public String accessKeySecret; + + @Param(required = false) + public String requestIp; + + @NonAPIParam + public long timeout = -1; + + @NonAPIParam + public long pollingInterval = -1; + + + private Result makeResult(ApiResult res) { + Result ret = new Result(); + if (res.error != null) { + ret.error = res.error; + return ret; + } + + org.zstack.sdk.zwatch.alarm.integration.SetupExternalAlertIntegrationResult value = res.getResult(org.zstack.sdk.zwatch.alarm.integration.SetupExternalAlertIntegrationResult.class); + ret.value = value == null ? new org.zstack.sdk.zwatch.alarm.integration.SetupExternalAlertIntegrationResult() : value; + + return ret; + } + + public Result call() { + ApiResult res = ZSClient.call(this); + return makeResult(res); + } + + public void call(final Completion completion) { + ZSClient.call(this, new InternalCompletion() { + @Override + public void complete(ApiResult res) { + completion.complete(makeResult(res)); + } + }); + } + + protected Map getParameterMap() { + return parameterMap; + } + + protected Map getNonAPIParameterMap() { + return nonAPIParameterMap; + } + + protected RestInfo getRestInfo() { + RestInfo info = new RestInfo(); + info.httpMethod = "POST"; + info.path = "/sns/external-alert-integrations"; + info.needSession = true; + info.needPoll = true; + info.parameterName = "params"; + return info; + } + +} diff --git a/sdk/src/main/java/org/zstack/sdk/zwatch/alarm/integration/SetupExternalAlertIntegrationResult.java b/sdk/src/main/java/org/zstack/sdk/zwatch/alarm/integration/SetupExternalAlertIntegrationResult.java new file mode 100644 index 00000000000..327d73337bb --- /dev/null +++ b/sdk/src/main/java/org/zstack/sdk/zwatch/alarm/integration/SetupExternalAlertIntegrationResult.java @@ -0,0 +1,30 @@ +package org.zstack.sdk.zwatch.alarm.integration; + + + +public class SetupExternalAlertIntegrationResult { + public java.lang.String endpointUuid; + public void setEndpointUuid(java.lang.String endpointUuid) { + this.endpointUuid = endpointUuid; + } + public java.lang.String getEndpointUuid() { + return this.endpointUuid; + } + + public java.lang.String topicUuid; + public void setTopicUuid(java.lang.String topicUuid) { + this.topicUuid = topicUuid; + } + public java.lang.String getTopicUuid() { + return this.topicUuid; + } + + public boolean created; + public void setCreated(boolean created) { + this.created = created; + } + public boolean getCreated() { + return this.created; + } + +} diff --git a/testlib/src/main/java/org/zstack/testlib/ApiHelper.groovy b/testlib/src/main/java/org/zstack/testlib/ApiHelper.groovy index 5a9b5138a3d..ea3583249d5 100644 --- a/testlib/src/main/java/org/zstack/testlib/ApiHelper.groovy +++ b/testlib/src/main/java/org/zstack/testlib/ApiHelper.groovy @@ -26962,26 +26962,27 @@ abstract class ApiHelper { } } + def getVpcVRouterSnatLogState(@DelegatesTo(strategy = Closure.OWNER_FIRST, value = org.zstack.sdk.GetVpcVRouterSnatLogStateAction.class) Closure c) { def a = new org.zstack.sdk.GetVpcVRouterSnatLogStateAction() a.sessionId = Test.currentEnvSpec?.session?.uuid c.resolveStrategy = Closure.OWNER_FIRST c.delegate = a c() - + if (System.getProperty("apipath") != null) { if (a.apiId == null) { a.apiId = Platform.uuid } - + def tracker = new ApiPathTracker(a.apiId) def out = errorOut(a.call()) def path = tracker.getApiPath() if (!path.isEmpty()) { Test.apiPaths[a.class.name] = path.join(" --->\n") } - + return out } else { return errorOut(a.call()) @@ -40918,26 +40919,27 @@ abstract class ApiHelper { } } + def setVpcVRouterSnatLogState(@DelegatesTo(strategy = Closure.OWNER_FIRST, value = org.zstack.sdk.SetVpcVRouterSnatLogStateAction.class) Closure c) { def a = new org.zstack.sdk.SetVpcVRouterSnatLogStateAction() a.sessionId = Test.currentEnvSpec?.session?.uuid c.resolveStrategy = Closure.OWNER_FIRST c.delegate = a c() - + if (System.getProperty("apipath") != null) { if (a.apiId == null) { a.apiId = Platform.uuid } - + def tracker = new ApiPathTracker(a.apiId) def out = errorOut(a.call()) def path = tracker.getApiPath() if (!path.isEmpty()) { Test.apiPaths[a.class.name] = path.join(" --->\n") } - + return out } else { return errorOut(a.call()) @@ -55625,6 +55627,87 @@ abstract class ApiHelper { } + def checkExternalAlertIntegration(@DelegatesTo(strategy = Closure.OWNER_FIRST, value = org.zstack.sdk.zwatch.alarm.integration.CheckExternalAlertIntegrationAction.class) Closure c) { + def a = new org.zstack.sdk.zwatch.alarm.integration.CheckExternalAlertIntegrationAction() + a.sessionId = Test.currentEnvSpec?.session?.uuid + c.resolveStrategy = Closure.OWNER_FIRST + c.delegate = a + c() + + + if (System.getProperty("apipath") != null) { + if (a.apiId == null) { + a.apiId = Platform.uuid + } + + def tracker = new ApiPathTracker(a.apiId) + def out = errorOut(a.call()) + def path = tracker.getApiPath() + if (!path.isEmpty()) { + Test.apiPaths[a.class.name] = path.join(" --->\n") + } + + return out + } else { + return errorOut(a.call()) + } + } + + + def removeExternalAlertIntegration(@DelegatesTo(strategy = Closure.OWNER_FIRST, value = org.zstack.sdk.zwatch.alarm.integration.RemoveExternalAlertIntegrationAction.class) Closure c) { + def a = new org.zstack.sdk.zwatch.alarm.integration.RemoveExternalAlertIntegrationAction() + a.sessionId = Test.currentEnvSpec?.session?.uuid + c.resolveStrategy = Closure.OWNER_FIRST + c.delegate = a + c() + + + if (System.getProperty("apipath") != null) { + if (a.apiId == null) { + a.apiId = Platform.uuid + } + + def tracker = new ApiPathTracker(a.apiId) + def out = errorOut(a.call()) + def path = tracker.getApiPath() + if (!path.isEmpty()) { + Test.apiPaths[a.class.name] = path.join(" --->\n") + } + + return out + } else { + return errorOut(a.call()) + } + } + + + def setupExternalAlertIntegration(@DelegatesTo(strategy = Closure.OWNER_FIRST, value = org.zstack.sdk.zwatch.alarm.integration.SetupExternalAlertIntegrationAction.class) Closure c) { + def a = new org.zstack.sdk.zwatch.alarm.integration.SetupExternalAlertIntegrationAction() + a.sessionId = Test.currentEnvSpec?.session?.uuid + c.resolveStrategy = Closure.OWNER_FIRST + c.delegate = a + c() + + + if (System.getProperty("apipath") != null) { + if (a.apiId == null) { + a.apiId = Platform.uuid + } + + def tracker = new ApiPathTracker(a.apiId) + def out = errorOut(a.call()) + def path = tracker.getApiPath() + if (!path.isEmpty()) { + Test.apiPaths[a.class.name] = path.join(" --->\n") + } + + return out + } else { + return errorOut(a.call()) + } + } + + def createSNSTextTemplate(@DelegatesTo(strategy = Closure.OWNER_FIRST, value = org.zstack.sdk.zwatch.alarm.sns.CreateSNSTextTemplateAction.class) Closure c) { def a = new org.zstack.sdk.zwatch.alarm.sns.CreateSNSTextTemplateAction() a.sessionId = Test.currentEnvSpec?.session?.uuid diff --git a/utils/src/main/java/org/zstack/utils/clouderrorcode/CloudOperationsErrorCode.java b/utils/src/main/java/org/zstack/utils/clouderrorcode/CloudOperationsErrorCode.java index 47e32c7cf90..0427cbe45ea 100644 --- a/utils/src/main/java/org/zstack/utils/clouderrorcode/CloudOperationsErrorCode.java +++ b/utils/src/main/java/org/zstack/utils/clouderrorcode/CloudOperationsErrorCode.java @@ -5200,6 +5200,8 @@ public class CloudOperationsErrorCode { public static final String ORG_ZSTACK_ZWATCH_ALARM_10029 = "ORG_ZSTACK_ZWATCH_ALARM_10029"; + public static final String ORG_ZSTACK_ZWATCH_ALARM_10030 = "ORG_ZSTACK_ZWATCH_ALARM_10030"; + public static final String ORG_ZSTACK_SNS_PLATFORM_FEISHU_10000 = "ORG_ZSTACK_SNS_PLATFORM_FEISHU_10000"; public static final String ORG_ZSTACK_ZWATCH_ALARM_SNS_10000 = "ORG_ZSTACK_ZWATCH_ALARM_SNS_10000";