diff --git a/conf/db/zsv/V5.1.0__schema.sql b/conf/db/zsv/V5.1.0__schema.sql index 243651492d9..8b62359af27 100644 --- a/conf/db/zsv/V5.1.0__schema.sql +++ b/conf/db/zsv/V5.1.0__schema.sql @@ -1,5 +1,18 @@ DELETE FROM `EncryptedResourceKeyRefVO` WHERE `resourceUuid` NOT IN (SELECT `uuid` FROM `ResourceVO`); -ALTER TABLE `EncryptedResourceKeyRefVO` - ADD CONSTRAINT `fkEncryptedResourceKeyRefResourceVO` FOREIGN KEY (`resourceUuid`) REFERENCES `ResourceVO`(`uuid`) - ON DELETE CASCADE; +ALTER TABLE `EncryptedResourceKeyRefVO` + ADD CONSTRAINT `fkEncryptedResourceKeyRefResourceVO` FOREIGN KEY (`resourceUuid`) REFERENCES `ResourceVO`(`uuid`) + ON DELETE CASCADE; + +CREATE TABLE IF NOT EXISTS `zstack`.`LiveRecoveryAlertReceiptVO` ( + `uuid` varchar(64) NOT NULL, + `sourceUuid` varchar(64) NOT NULL, + `alertUuid` varchar(64) NOT NULL, + `eventSequence` bigint(20) NOT NULL, + `alertEventType` varchar(64) NOT NULL, + `createDate` datetime DEFAULT NULL, + `lastOpDate` datetime DEFAULT NULL, + PRIMARY KEY (`uuid`), + KEY `idxLiveRecoveryAlertReceiptSourceAlertSequence` (`sourceUuid`, `alertUuid`, `eventSequence`), + KEY `idxLiveRecoveryAlertReceiptCreateDate` (`createDate`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; diff --git a/sdk/src/main/java/org/zstack/sdk/zwatch/liverecovery/api/PushLiveRecoveryAlertEventAction.java b/sdk/src/main/java/org/zstack/sdk/zwatch/liverecovery/api/PushLiveRecoveryAlertEventAction.java new file mode 100644 index 00000000000..9d70b101ab2 --- /dev/null +++ b/sdk/src/main/java/org/zstack/sdk/zwatch/liverecovery/api/PushLiveRecoveryAlertEventAction.java @@ -0,0 +1,101 @@ +package org.zstack.sdk.zwatch.liverecovery.api; + +import java.util.HashMap; +import java.util.Map; +import org.zstack.sdk.*; + +public class PushLiveRecoveryAlertEventAction 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.liverecovery.api.PushLiveRecoveryAlertResult value; + + public Result throwExceptionIfError() { + if (error != null) { + throw new ApiException( + String.format("error[code: %s, description: %s, details: %s]", error.code, error.description, error.details) + ); + } + + return this; + } + } + + @Param(required = true, maxLength = 65535, nonempty = false, nullElements = false, emptyString = true, noTrim = false) + public java.lang.String payloadJson; + + @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.liverecovery.api.PushLiveRecoveryAlertResult value = res.getResult(org.zstack.sdk.zwatch.liverecovery.api.PushLiveRecoveryAlertResult.class); + ret.value = value == null ? new org.zstack.sdk.zwatch.liverecovery.api.PushLiveRecoveryAlertResult() : 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 = "/zwatch/live-recovery/alert-events"; + info.needSession = true; + info.needPoll = true; + info.parameterName = "params"; + return info; + } + +} diff --git a/sdk/src/main/java/org/zstack/sdk/zwatch/liverecovery/api/PushLiveRecoveryAlertResult.java b/sdk/src/main/java/org/zstack/sdk/zwatch/liverecovery/api/PushLiveRecoveryAlertResult.java new file mode 100644 index 00000000000..7a370b4e5e1 --- /dev/null +++ b/sdk/src/main/java/org/zstack/sdk/zwatch/liverecovery/api/PushLiveRecoveryAlertResult.java @@ -0,0 +1,38 @@ +package org.zstack.sdk.zwatch.liverecovery.api; + + + +public class PushLiveRecoveryAlertResult { + public java.lang.String remoteEventId; + public void setRemoteEventId(java.lang.String remoteEventId) { + this.remoteEventId = remoteEventId; + } + public java.lang.String getRemoteEventId() { + return this.remoteEventId; + } + + public java.lang.String remoteAlertId; + public void setRemoteAlertId(java.lang.String remoteAlertId) { + this.remoteAlertId = remoteAlertId; + } + public java.lang.String getRemoteAlertId() { + return this.remoteAlertId; + } + + public boolean duplicate; + public void setDuplicate(boolean duplicate) { + this.duplicate = duplicate; + } + public boolean getDuplicate() { + return this.duplicate; + } + + public boolean stale; + public void setStale(boolean stale) { + this.stale = stale; + } + public boolean getStale() { + return this.stale; + } + +} diff --git a/testlib/src/main/java/org/zstack/testlib/ApiHelper.groovy b/testlib/src/main/java/org/zstack/testlib/ApiHelper.groovy index 7160cd1d93d..e87caa02b4b 100644 --- a/testlib/src/main/java/org/zstack/testlib/ApiHelper.groovy +++ b/testlib/src/main/java/org/zstack/testlib/ApiHelper.groovy @@ -42640,6 +42640,33 @@ abstract class ApiHelper { } + def pushLiveRecoveryAlertEvent(@DelegatesTo(strategy = Closure.OWNER_FIRST, value = org.zstack.sdk.zwatch.liverecovery.api.PushLiveRecoveryAlertEventAction.class) Closure c) { + def a = new org.zstack.sdk.zwatch.liverecovery.api.PushLiveRecoveryAlertEventAction() + 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 addThirdpartyPlatform(@DelegatesTo(strategy = Closure.OWNER_FIRST, value = org.zstack.sdk.zwatch.thirdparty.api.AddThirdpartyPlatformAction.class) Closure c) { def a = new org.zstack.sdk.zwatch.thirdparty.api.AddThirdpartyPlatformAction() a.sessionId = Test.currentEnvSpec?.session?.uuid