Skip to content

Commit df4e983

Browse files
author
gitlab
committed
Merge branch 'feature-iam2-script@@2' into 'master'
[Feature: ZSTACK-24643] IAM2 script See merge request zstackio/zstack!6089
2 parents bf2e50b + a1c6021 commit df4e983

4 files changed

Lines changed: 153 additions & 0 deletions

File tree

build/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,11 @@
447447
<artifactId>sdnController</artifactId>
448448
<version>${project.version}</version>
449449
</dependency>
450+
<dependency>
451+
<groupId>org.zstack</groupId>
452+
<artifactId>iam2-script-plugin</artifactId>
453+
<version>${project.version}</version>
454+
</dependency>
450455
</dependencies>
451456
</profile>
452457
</profiles>
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
package org.zstack.sdk;
2+
3+
import java.util.HashMap;
4+
import java.util.Map;
5+
import org.zstack.sdk.*;
6+
7+
public class RunIAM2ScriptAction extends AbstractAction {
8+
9+
private static final HashMap<String, Parameter> parameterMap = new HashMap<>();
10+
11+
private static final HashMap<String, Parameter> nonAPIParameterMap = new HashMap<>();
12+
13+
public static class Result {
14+
public ErrorCode error;
15+
public org.zstack.sdk.RunIAM2ScriptResult value;
16+
17+
public Result throwExceptionIfError() {
18+
if (error != null) {
19+
throw new ApiException(
20+
String.format("error[code: %s, description: %s, details: %s]", error.code, error.description, error.details)
21+
);
22+
}
23+
24+
return this;
25+
}
26+
}
27+
28+
@Param(required = true, nonempty = false, nullElements = false, emptyString = true, noTrim = false)
29+
public java.lang.String scriptContent;
30+
31+
@Param(required = false, nonempty = false, nullElements = false, emptyString = true, noTrim = false)
32+
public java.lang.String scriptExecutor;
33+
34+
@Param(required = false, nonempty = false, nullElements = false, emptyString = true, noTrim = false)
35+
public java.util.List scriptParams;
36+
37+
@Param(required = false)
38+
public java.util.List systemTags;
39+
40+
@Param(required = false)
41+
public java.util.List userTags;
42+
43+
@Param(required = false)
44+
public String sessionId;
45+
46+
@Param(required = false)
47+
public String accessKeyId;
48+
49+
@Param(required = false)
50+
public String accessKeySecret;
51+
52+
@Param(required = false)
53+
public String requestIp;
54+
55+
@NonAPIParam
56+
public long timeout = -1;
57+
58+
@NonAPIParam
59+
public long pollingInterval = -1;
60+
61+
62+
private Result makeResult(ApiResult res) {
63+
Result ret = new Result();
64+
if (res.error != null) {
65+
ret.error = res.error;
66+
return ret;
67+
}
68+
69+
org.zstack.sdk.RunIAM2ScriptResult value = res.getResult(org.zstack.sdk.RunIAM2ScriptResult.class);
70+
ret.value = value == null ? new org.zstack.sdk.RunIAM2ScriptResult() : value;
71+
72+
return ret;
73+
}
74+
75+
public Result call() {
76+
ApiResult res = ZSClient.call(this);
77+
return makeResult(res);
78+
}
79+
80+
public void call(final Completion<Result> completion) {
81+
ZSClient.call(this, new InternalCompletion() {
82+
@Override
83+
public void complete(ApiResult res) {
84+
completion.complete(makeResult(res));
85+
}
86+
});
87+
}
88+
89+
protected Map<String, Parameter> getParameterMap() {
90+
return parameterMap;
91+
}
92+
93+
protected Map<String, Parameter> getNonAPIParameterMap() {
94+
return nonAPIParameterMap;
95+
}
96+
97+
protected RestInfo getRestInfo() {
98+
RestInfo info = new RestInfo();
99+
info.httpMethod = "POST";
100+
info.path = "/iam2/iam2-script/run";
101+
info.needSession = true;
102+
info.needPoll = true;
103+
info.parameterName = "params";
104+
return info;
105+
}
106+
107+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package org.zstack.sdk;
2+
3+
import org.zstack.sdk.LongJobInventory;
4+
5+
public class RunIAM2ScriptResult {
6+
public LongJobInventory inventory;
7+
public void setInventory(LongJobInventory inventory) {
8+
this.inventory = inventory;
9+
}
10+
public LongJobInventory getInventory() {
11+
return this.inventory;
12+
}
13+
14+
}

testlib/src/main/java/org/zstack/testlib/ApiHelper.groovy

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25031,6 +25031,33 @@ trait ApiHelper {
2503125031
}
2503225032

2503325033

25034+
def runIAM2Script(@DelegatesTo(strategy = Closure.OWNER_FIRST, value = org.zstack.sdk.RunIAM2ScriptAction.class) Closure c) {
25035+
def a = new org.zstack.sdk.RunIAM2ScriptAction()
25036+
a.sessionId = Test.currentEnvSpec?.session?.uuid
25037+
c.resolveStrategy = Closure.OWNER_FIRST
25038+
c.delegate = a
25039+
c()
25040+
25041+
25042+
if (System.getProperty("apipath") != null) {
25043+
if (a.apiId == null) {
25044+
a.apiId = Platform.uuid
25045+
}
25046+
25047+
def tracker = new ApiPathTracker(a.apiId)
25048+
def out = errorOut(a.call())
25049+
def path = tracker.getApiPath()
25050+
if (!path.isEmpty()) {
25051+
Test.apiPaths[a.class.name] = path.join(" --->\n")
25052+
}
25053+
25054+
return out
25055+
} else {
25056+
return errorOut(a.call())
25057+
}
25058+
}
25059+
25060+
2503425061
def runSchedulerTrigger(@DelegatesTo(strategy = Closure.OWNER_FIRST, value = org.zstack.sdk.RunSchedulerTriggerAction.class) Closure c) {
2503525062
def a = new org.zstack.sdk.RunSchedulerTriggerAction()
2503625063
a.sessionId = Test.currentEnvSpec?.session?.uuid

0 commit comments

Comments
 (0)