Skip to content

Commit 03e622c

Browse files
committed
fix SDK
1 parent 3e02b68 commit 03e622c

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

rest/src/main/java/org/zstack/rest/RestServer.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -627,7 +627,7 @@ private void handleApi(Api api, Map body, String parameterName, HttpEntity<Strin
627627
}
628628

629629
Object parameter;
630-
if (req.getMethod().equals(HttpMethod.GET.toString())) {
630+
if (req.getMethod().equals(HttpMethod.GET.toString()) || req.getMethod().equals(HttpMethod.DELETE.toString())) {
631631
// GET uses query string to pass parameters
632632
Map<String, Object> m = new HashMap<>();
633633

@@ -659,7 +659,7 @@ private void handleApi(Api api, Map body, String parameterName, HttpEntity<Strin
659659

660660
if (requestInfo.get().headers.containsKey(RestConstants.HEADER_JOB_UUID)) {
661661
String jobUuid = requestInfo.get().headers.get(RestConstants.HEADER_JOB_UUID).get(0);
662-
if (!StringDSL.isZstackUuid(jobUuid)) {
662+
if (jobUuid.length() != 32) {
663663
throw new RestException(HttpStatus.BAD_REQUEST.value(), String.format("Invalid header[%s], it" +
664664
" must be a UUID with '-' stripped", RestConstants.HEADER_JOB_UUID));
665665
}
@@ -673,7 +673,7 @@ private void handleApi(Api api, Map body, String parameterName, HttpEntity<Strin
673673
msg.setSession(session);
674674
}
675675

676-
if (!req.getMethod().equals(HttpMethod.GET.toString())) {
676+
if (!req.getMethod().equals(HttpMethod.GET.toString()) && !req.getMethod().equals(HttpMethod.DELETE.toString())) {
677677
Object systemTags = body.get("systemTags");
678678
if (systemTags != null) {
679679
msg.setSystemTags((List<String>) systemTags);

sdk/src/main/java/org/zstack/sdk/ZSClient.java

+10-3
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ private void fillNonQueryApiRequestBuilder(Request.Builder reqBuilder) {
337337
}
338338
}
339339

340-
if (info.httpMethod.equals("GET")) {
340+
if (info.httpMethod.equals("GET") || info.httpMethod.equals("DELETE")) {
341341
for (Map.Entry<String, Object> e : params.entrySet()) {
342342
String k = e.getKey();
343343
Object v = e.getValue();
@@ -347,13 +347,20 @@ private void fillNonQueryApiRequestBuilder(Request.Builder reqBuilder) {
347347
builder.addQueryParameter(k, o.toString());
348348
}
349349
} else if (v instanceof Map) {
350-
throw new ApiException(String.format("GET won't support map as a parameter type. %s.%s", action.getClass(), k));
350+
throw new ApiException(String.format("%s won't support map as a parameter type. %s.%s",
351+
info.httpMethod, action.getClass(), k));
351352
} else {
352353
builder.addQueryParameter(k, v.toString());
353354
}
354355
}
355356

356-
reqBuilder.url(builder.build().url().toString()).get();
357+
if (info.httpMethod.equals("GET")) {
358+
reqBuilder.url(builder.build().url().toString()).get();
359+
} else if (info.httpMethod.equals("DELETE")) {
360+
reqBuilder.url(builder.build().url().toString()).delete();
361+
} else {
362+
throw new RuntimeException("should not be here");
363+
}
357364
} else {
358365
Map m = new HashMap();
359366
m.put(info.parameterName, params);

test/src/test/java/org/zstack/test/compute/zone/TestCreateZoneRest1.java

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import org.zstack.core.componentloader.ComponentLoader;
77
import org.zstack.core.db.DatabaseFacade;
88
import org.zstack.header.exception.CloudRuntimeException;
9+
import org.zstack.header.message.APIDeleteMessage;
910
import org.zstack.header.rest.RESTFacade;
1011
import org.zstack.header.zone.ZoneState;
1112
import org.zstack.rest.RestConstants;
@@ -87,6 +88,7 @@ public void test() throws ApiSenderException, InterruptedException {
8788
DeleteZoneAction da = new DeleteZoneAction();
8889
da.uuid = zone.uuid;
8990
da.sessionId = api.getAdminSession().getUuid();
91+
da.deleteMode = APIDeleteMessage.DeletionMode.Enforcing.toString();
9092
da.call();
9193

9294
qaction = new QueryZoneAction();

0 commit comments

Comments
 (0)