Skip to content

Commit 1531102

Browse files
author
gitlab
committed
Merge branch 'ZS-24281@@2' into 'master'
[BugFix: ZSTACK-24281] See merge request zstackio/zstack!5980
2 parents eb1a6f7 + 113465b commit 1531102

10 files changed

Lines changed: 329 additions & 8 deletions

File tree

conf/serviceConfig/longjob.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,7 @@
1919
<message>
2020
<name>org.zstack.header.longjob.APIRerunLongJobMsg</name>
2121
</message>
22+
<message>
23+
<name>org.zstack.header.longjob.APIUpdateLongJobMsg</name>
24+
</message>
2225
</service>
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package org.zstack.header.longjob;
2+
3+
import org.zstack.header.longjob.LongJobInventory;
4+
import org.zstack.header.message.APIEvent;
5+
import org.zstack.header.rest.RestResponse;
6+
7+
/**
8+
* * Created on 2/27/2020
9+
* */
10+
11+
@RestResponse(allTo = "inventory")
12+
public class APIUpdateLongJobEvent extends APIEvent {
13+
private LongJobInventory inventory;
14+
15+
public APIUpdateLongJobEvent() {
16+
17+
}
18+
19+
public APIUpdateLongJobEvent(String apiId) {
20+
super(apiId);
21+
}
22+
23+
public LongJobInventory getInventory() {
24+
return inventory;
25+
}
26+
27+
public void setInventory(LongJobInventory inventory) {
28+
this.inventory = inventory;
29+
}
30+
31+
public static APIUpdateLongJobEvent __example__() {
32+
APIUpdateLongJobEvent event = new APIUpdateLongJobEvent();
33+
LongJobInventory lj = new LongJobInventory();
34+
lj.setUuid(uuid());
35+
lj.setName("new-name");
36+
lj.setDescription("new-description");
37+
event.setInventory(lj);
38+
return event;
39+
}
40+
41+
}
42+
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package org.zstack.header.longjob;
2+
3+
import org.hamcrest.StringDescription;
4+
import org.springframework.http.HttpMethod;
5+
import org.zstack.header.identity.Action;
6+
import org.zstack.header.longjob.LongJobConstants;
7+
import org.zstack.header.longjob.LongJobVO;
8+
import org.zstack.header.message.APIMessage;
9+
import org.zstack.header.message.APIParam;
10+
import org.zstack.header.rest.RestRequest;
11+
12+
/**
13+
* * Created on 2/3/2020
14+
* */
15+
@Action(category = LongJobConstants.ACTION_CATEGORY)
16+
@RestRequest(
17+
path = "/longjobs/{uuid}/actions",
18+
isAction = true,
19+
method = HttpMethod.PUT,
20+
responseClass = APIUpdateLongJobEvent.class
21+
)
22+
public class APIUpdateLongJobMsg extends APIMessage {
23+
@APIParam(resourceType = LongJobVO.class, checkAccount = true, operationTarget = true)
24+
private String uuid;
25+
26+
@APIParam(maxLength = 255, required = false)
27+
private String name;
28+
29+
@APIParam(maxLength = 2048, required = false)
30+
private String description;
31+
32+
public String getDescription() {
33+
return description;
34+
}
35+
36+
public void setDescription(String description) {
37+
this.description = description;
38+
}
39+
40+
public String getName() {
41+
return name;
42+
}
43+
44+
public void setName(String name) {
45+
this.name = name;
46+
}
47+
48+
public String getUuid() {
49+
return uuid;
50+
}
51+
52+
public void setUuid(String uuid) {
53+
this.uuid = uuid;
54+
}
55+
56+
public static APIUpdateLongJobMsg __example__() {
57+
APIUpdateLongJobMsg msg = new APIUpdateLongJobMsg();
58+
msg.setUuid(uuid());
59+
msg.setName("new-name");
60+
msg.setDescription("new-description");
61+
return msg;
62+
}
63+
}
64+

longjob/src/main/java/org/zstack/longjob/LongJobManagerImpl.java

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ private void handleApiMessage(APIMessage msg) {
116116
handle((APICancelLongJobMsg) msg);
117117
} else if (msg instanceof APIDeleteLongJobMsg) {
118118
handle((APIDeleteLongJobMsg) msg);
119+
} else if (msg instanceof APIUpdateLongJobMsg) {
120+
handle((APIUpdateLongJobMsg) msg);
119121
} else if (msg instanceof APIRerunLongJobMsg) {
120122
handle((APIRerunLongJobMsg) msg);
121123
} else {
@@ -158,6 +160,44 @@ public void run(MessageReply rly) {
158160
});
159161
}
160162

163+
private void handle(APIUpdateLongJobMsg msg) {
164+
thdf.chainSubmit(new ChainTask(msg) {
165+
@Override
166+
public String getSyncSignature() {
167+
return String.format("update-longjob-%s", msg.getUuid());
168+
}
169+
170+
@Override
171+
public void run(SyncTaskChain chain) {
172+
APIUpdateLongJobEvent evt = new APIUpdateLongJobEvent(msg.getId());
173+
LongJobVO vo = dbf.findByUuid(msg.getUuid(), LongJobVO.class);
174+
175+
boolean update = false;
176+
if (msg.getName() != null) {
177+
vo.setName(msg.getName());
178+
update = true;
179+
}
180+
if (msg.getDescription() != null) {
181+
vo.setDescription(msg.getDescription());
182+
update = true;
183+
}
184+
if (update) {
185+
vo = dbf.updateAndRefresh(vo);
186+
}
187+
188+
evt.setInventory(LongJobInventory.valueOf(vo));
189+
bus.publish(evt);
190+
chain.next();
191+
}
192+
193+
@Override
194+
public String getName() {
195+
return String.format("update-longjob-%s", msg.getName());
196+
}
197+
});
198+
}
199+
200+
161201
private void handle(APIDeleteLongJobMsg msg) {
162202
thdf.chainSubmit(new ChainTask(msg) {
163203
@Override
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 UpdateLongJobAction 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.UpdateLongJobResult 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 uuid;
30+
31+
@Param(required = false, maxLength = 255, nonempty = false, nullElements = false, emptyString = true, noTrim = false)
32+
public java.lang.String name;
33+
34+
@Param(required = false, maxLength = 2048, nonempty = false, nullElements = false, emptyString = true, noTrim = false)
35+
public java.lang.String description;
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.UpdateLongJobResult value = res.getResult(org.zstack.sdk.UpdateLongJobResult.class);
70+
ret.value = value == null ? new org.zstack.sdk.UpdateLongJobResult() : 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 = "PUT";
100+
info.path = "/longjobs/{uuid}/actions";
101+
info.needSession = true;
102+
info.needPoll = true;
103+
info.parameterName = "updateLongJob";
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 UpdateLongJobResult {
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+
}

sdk/src/main/java/org/zstack/sdk/zwatch/datatype/AlarmDataV2.java

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@ public java.lang.String getTAG_ACCOUNT_UUID() {
2020
return this.TAG_ACCOUNT_UUID;
2121
}
2222

23+
public java.lang.String TAG_EMERGENCY_LEVEL;
24+
public void setTAG_EMERGENCY_LEVEL(java.lang.String TAG_EMERGENCY_LEVEL) {
25+
this.TAG_EMERGENCY_LEVEL = TAG_EMERGENCY_LEVEL;
26+
}
27+
public java.lang.String getTAG_EMERGENCY_LEVEL() {
28+
return this.TAG_EMERGENCY_LEVEL;
29+
}
30+
2331
public java.lang.String FIELD_CONTEXT;
2432
public void setFIELD_CONTEXT(java.lang.String FIELD_CONTEXT) {
2533
this.FIELD_CONTEXT = FIELD_CONTEXT;
@@ -76,14 +84,6 @@ public java.lang.String getFIELD_RESOURCE_UUID() {
7684
return this.FIELD_RESOURCE_UUID;
7785
}
7886

79-
public java.lang.String TAG_EMERGENCY_LEVEL;
80-
public void setTAG_EMERGENCY_LEVEL(java.lang.String TAG_EMERGENCY_LEVEL) {
81-
this.TAG_EMERGENCY_LEVEL = TAG_EMERGENCY_LEVEL;
82-
}
83-
public java.lang.String getTAG_EMERGENCY_LEVEL() {
84-
return this.TAG_EMERGENCY_LEVEL;
85-
}
86-
8787
public java.lang.String FIELD_READ_STATUS;
8888
public void setFIELD_READ_STATUS(java.lang.String FIELD_READ_STATUS) {
8989
this.FIELD_READ_STATUS = FIELD_READ_STATUS;
@@ -100,4 +100,12 @@ public java.util.Set getQueryableLabels() {
100100
return this.queryableLabels;
101101
}
102102

103+
public java.util.Set tagsFromV1;
104+
public void setTagsFromV1(java.util.Set tagsFromV1) {
105+
this.tagsFromV1 = tagsFromV1;
106+
}
107+
public java.util.Set getTagsFromV1() {
108+
return this.tagsFromV1;
109+
}
110+
103111
}

sdk/src/main/java/org/zstack/sdk/zwatch/datatype/AuditDataV2.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,4 +92,12 @@ public java.lang.String getSuccess() {
9292
return this.success;
9393
}
9494

95+
public java.util.Set tagsFromV1;
96+
public void setTagsFromV1(java.util.Set tagsFromV1) {
97+
this.tagsFromV1 = tagsFromV1;
98+
}
99+
public java.util.Set getTagsFromV1() {
100+
return this.tagsFromV1;
101+
}
102+
95103
}

sdk/src/main/java/org/zstack/sdk/zwatch/datatype/Label.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,12 @@ public Operator getOp() {
2828
return this.op;
2929
}
3030

31+
public boolean compatible;
32+
public void setCompatible(boolean compatible) {
33+
this.compatible = compatible;
34+
}
35+
public boolean getCompatible() {
36+
return this.compatible;
37+
}
38+
3139
}

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28673,6 +28673,33 @@ trait ApiHelper {
2867328673
}
2867428674

2867528675

28676+
def updateLongJob(@DelegatesTo(strategy = Closure.OWNER_FIRST, value = org.zstack.sdk.UpdateLongJobAction.class) Closure c) {
28677+
def a = new org.zstack.sdk.UpdateLongJobAction()
28678+
a.sessionId = Test.currentEnvSpec?.session?.uuid
28679+
c.resolveStrategy = Closure.OWNER_FIRST
28680+
c.delegate = a
28681+
c()
28682+
28683+
28684+
if (System.getProperty("apipath") != null) {
28685+
if (a.apiId == null) {
28686+
a.apiId = Platform.uuid
28687+
}
28688+
28689+
def tracker = new ApiPathTracker(a.apiId)
28690+
def out = errorOut(a.call())
28691+
def path = tracker.getApiPath()
28692+
if (!path.isEmpty()) {
28693+
Test.apiPaths[a.class.name] = path.join(" --->\n")
28694+
}
28695+
28696+
return out
28697+
} else {
28698+
return errorOut(a.call())
28699+
}
28700+
}
28701+
28702+
2867628703
def updateMdevDevice(@DelegatesTo(strategy = Closure.OWNER_FIRST, value = org.zstack.sdk.UpdateMdevDeviceAction.class) Closure c) {
2867728704
def a = new org.zstack.sdk.UpdateMdevDeviceAction()
2867828705
a.sessionId = Test.currentEnvSpec?.session?.uuid

0 commit comments

Comments
 (0)