diff --git a/compute/src/main/java/org/zstack/compute/host/HostManagerImpl.java b/compute/src/main/java/org/zstack/compute/host/HostManagerImpl.java index d1c72ae88f..c913e7bb01 100755 --- a/compute/src/main/java/org/zstack/compute/host/HostManagerImpl.java +++ b/compute/src/main/java/org/zstack/compute/host/HostManagerImpl.java @@ -130,6 +130,8 @@ private void handleApiMessage(APIMessage msg) { } } private void handle(APIReleaseHostMsg msg) { + APIReleaseHostReply reply = new APIReleaseHostReply(); + String tag = HostSystemTags.SYSTEM_UUID.instantiateTag( Collections.singletonMap(HostSystemTags.SYSTEM_UUID_TOKEN, msg.getProductUuid()) ); @@ -141,7 +143,9 @@ private void handle(APIReleaseHostMsg msg) { .findValue(); if (hostUuid == null) { - throw new OperationFailureException(argerr("cannot find host with productUuid[%s]", msg.getProductUuid())); + reply.setError(argerr("cannot find host with productUuid[%s]", msg.getProductUuid())); + bus.reply(msg, reply); + return; } HostVO host = Q.New(HostVO.class) @@ -149,34 +153,28 @@ private void handle(APIReleaseHostMsg msg) { .find(); if (host == null) { - throw new OperationFailureException(err(SysErrors.RESOURCE_NOT_FOUND, "host[uuid:%s] not found, it may have been deleted", hostUuid)); + reply.setError(err(SysErrors.RESOURCE_NOT_FOUND, "host[uuid:%s] not found, it may have been deleted", hostUuid)); + bus.reply(msg, reply); + return; } - APIReleaseHostEvent evt = new APIReleaseHostEvent(msg.getId()); - if (host.getState() == HostState.Disabled) { ChangeHostStateMsg cmsg = new ChangeHostStateMsg(); cmsg.setUuid(hostUuid); cmsg.setStateEvent(HostStateEvent.enable.toString()); bus.makeTargetServiceIdByResourceUuid(cmsg, HostConstant.SERVICE_ID, hostUuid); - bus.send(cmsg, new CloudBusCallBack(msg) { - @Override - public void run(MessageReply reply) { - if (!reply.isSuccess()) { - evt.setError(reply.getError()); - } else { - evt.setInventory(((ChangeHostStateReply) reply).getInventory()); - evt.setSuccess(true); - } - bus.publish(evt); - } - }); + MessageReply r = bus.call(cmsg); + if (!r.isSuccess()) { + reply.setError(r.getError()); + } else { + reply.setInventory(((ChangeHostStateReply) r).getInventory()); + } } else { - evt.setInventory(HostInventory.valueOf(host)); - evt.setSuccess(true); - bus.publish(evt); + reply.setInventory(HostInventory.valueOf(host)); } + + bus.reply(msg, reply); } diff --git a/header/src/main/java/org/zstack/header/host/APIReleaseHostEvent.java b/header/src/main/java/org/zstack/header/host/APIReleaseHostEvent.java deleted file mode 100644 index 5228406dbd..0000000000 --- a/header/src/main/java/org/zstack/header/host/APIReleaseHostEvent.java +++ /dev/null @@ -1,37 +0,0 @@ -package org.zstack.header.host; - -import org.zstack.header.message.APIEvent; -import org.zstack.header.rest.RestResponse; - -@RestResponse(allTo = "inventory") -public class APIReleaseHostEvent extends APIEvent { - private HostInventory inventory; - - public APIReleaseHostEvent() { - super(null); - } - - public APIReleaseHostEvent(String apiId) { - super(apiId); - } - - public HostInventory getInventory() { - return inventory; - } - - public void setInventory(HostInventory inventory) { - this.inventory = inventory; - } - - public static APIReleaseHostEvent __example__() { - APIReleaseHostEvent event = new APIReleaseHostEvent(); - HostInventory inv = new HostInventory(); - inv.setName("host-1"); - inv.setUuid(uuid()); - inv.setState(HostState.Enabled.toString()); - inv.setStatus(HostStatus.Connected.toString()); - event.setInventory(inv); - event.setSuccess(true); - return event; - } -} \ No newline at end of file diff --git a/header/src/main/java/org/zstack/header/host/APIReleaseHostMsg.java b/header/src/main/java/org/zstack/header/host/APIReleaseHostMsg.java index aa869391a4..bedde46855 100644 --- a/header/src/main/java/org/zstack/header/host/APIReleaseHostMsg.java +++ b/header/src/main/java/org/zstack/header/host/APIReleaseHostMsg.java @@ -8,7 +8,7 @@ @RestRequest( path = "/hosts/release", method = HttpMethod.POST, - responseClass = APIReleaseHostEvent.class, + responseClass = APIReleaseHostReply.class, parameterName = "params" ) public class APIReleaseHostMsg extends APISyncCallMessage { diff --git a/header/src/main/java/org/zstack/header/host/APIReleaseHostMsgDoc_zh_cn.groovy b/header/src/main/java/org/zstack/header/host/APIReleaseHostMsgDoc_zh_cn.groovy index d234a5d1b0..6ae693ae0f 100644 --- a/header/src/main/java/org/zstack/header/host/APIReleaseHostMsgDoc_zh_cn.groovy +++ b/header/src/main/java/org/zstack/header/host/APIReleaseHostMsgDoc_zh_cn.groovy @@ -1,6 +1,6 @@ package org.zstack.header.host -import org.zstack.header.host.APIReleaseHostEvent +import org.zstack.header.host.APIReleaseHostReply doc { title "释放主机信息" @@ -52,7 +52,7 @@ doc { } response { - clz APIReleaseHostEvent.class + clz APIReleaseHostReply.class } } } \ No newline at end of file diff --git a/header/src/main/java/org/zstack/header/host/APIReleaseHostReply.java b/header/src/main/java/org/zstack/header/host/APIReleaseHostReply.java new file mode 100644 index 0000000000..50a5682b75 --- /dev/null +++ b/header/src/main/java/org/zstack/header/host/APIReleaseHostReply.java @@ -0,0 +1,52 @@ +package org.zstack.header.host; + +import org.zstack.header.errorcode.ErrorCode; +import org.zstack.header.message.APIReply; +import org.zstack.header.rest.RestResponse; + +@RestResponse(fieldsTo = {"success=actualSuccess", "inventory", "error=actualError"}) +public class APIReleaseHostReply extends APIReply { + private HostInventory inventory; + private Boolean actualSuccess; + private ErrorCode actualError; + + public HostInventory getInventory() { + return inventory; + } + + public void setInventory(HostInventory inventory) { + this.inventory = inventory; + } + + @Override + public boolean isSuccess() { + return true; + } + + public Boolean getActualSuccess() { + return super.isSuccess(); + } + + public void setActualSuccess(Boolean actualSuccess) { + this.actualSuccess = actualSuccess; + } + + public ErrorCode getActualError() { + return super.getError(); + } + + public void setActualError(ErrorCode actualError) { + this.actualError = actualError; + } + + public static APIReleaseHostReply __example__() { + APIReleaseHostReply reply = new APIReleaseHostReply(); + HostInventory inv = new HostInventory(); + inv.setName("host-1"); + inv.setUuid(uuid()); + inv.setState(HostState.Enabled.toString()); + inv.setStatus(HostStatus.Connected.toString()); + reply.setInventory(inv); + return reply; + } +} \ No newline at end of file diff --git a/header/src/main/java/org/zstack/header/host/APIReleaseHostEventDoc_zh_cn.groovy b/header/src/main/java/org/zstack/header/host/APIReleaseHostReplyDoc_zh_cn.groovy similarity index 82% rename from header/src/main/java/org/zstack/header/host/APIReleaseHostEventDoc_zh_cn.groovy rename to header/src/main/java/org/zstack/header/host/APIReleaseHostReplyDoc_zh_cn.groovy index a705587367..96fd57004e 100644 --- a/header/src/main/java/org/zstack/header/host/APIReleaseHostEventDoc_zh_cn.groovy +++ b/header/src/main/java/org/zstack/header/host/APIReleaseHostReplyDoc_zh_cn.groovy @@ -9,7 +9,7 @@ doc { ref { name "inventory" - path "org.zstack.header.host.APIReleaseHostEvent.inventory" + path "org.zstack.header.host.APIReleaseHostReply.inventory" desc "主机清单信息" type "HostInventory" since "5.4.6" @@ -23,7 +23,7 @@ doc { } ref { name "error" - path "org.zstack.header.host.APIReleaseHostEvent.error" + path "org.zstack.header.host.APIReleaseHostReply.error" desc "错误码,若不为null,则表示操作失败, 操作成功时该字段为null",false type "ErrorCode" since "5.4.6" diff --git a/sdk/src/main/java/org/zstack/sdk/ReleaseHostResult.java b/sdk/src/main/java/org/zstack/sdk/ReleaseHostResult.java index 475677210c..b6f993eb22 100644 --- a/sdk/src/main/java/org/zstack/sdk/ReleaseHostResult.java +++ b/sdk/src/main/java/org/zstack/sdk/ReleaseHostResult.java @@ -1,8 +1,17 @@ package org.zstack.sdk; import org.zstack.sdk.HostInventory; +import org.zstack.sdk.ErrorCode; public class ReleaseHostResult { + public java.lang.Boolean success; + public void setSuccess(java.lang.Boolean success) { + this.success = success; + } + public java.lang.Boolean getSuccess() { + return this.success; + } + public HostInventory inventory; public void setInventory(HostInventory inventory) { this.inventory = inventory; @@ -11,4 +20,12 @@ public HostInventory getInventory() { return this.inventory; } + public ErrorCode error; + public void setError(ErrorCode error) { + this.error = error; + } + public ErrorCode getError() { + return this.error; + } + }