From fc4d497dea7c7d8dc418490f831833201a819fdf Mon Sep 17 00:00:00 2001 From: Rohit Yadav Date: Fri, 7 Feb 2020 12:19:39 +0530 Subject: [PATCH 1/2] systemvm: list systemvm response to return agent state and version This makes the listSystemVms API to return the host status (agent state), version and last pinged information. This makes it possible for UIs to call a single API to get this information. Signed-off-by: Rohit Yadav --- .../api/response/SystemVmResponse.java | 44 ++++++++++++++++++- .../java/com/cloud/api/ApiResponseHelper.java | 7 ++- 2 files changed, 47 insertions(+), 4 deletions(-) diff --git a/api/src/main/java/org/apache/cloudstack/api/response/SystemVmResponse.java b/api/src/main/java/org/apache/cloudstack/api/response/SystemVmResponse.java index 49ab473a37a1..234550470baf 100644 --- a/api/src/main/java/org/apache/cloudstack/api/response/SystemVmResponse.java +++ b/api/src/main/java/org/apache/cloudstack/api/response/SystemVmResponse.java @@ -19,14 +19,14 @@ import java.util.Date; import java.util.List; -import com.google.gson.annotations.SerializedName; - import org.apache.cloudstack.api.ApiConstants; import org.apache.cloudstack.api.BaseResponse; import org.apache.cloudstack.api.EntityReference; +import com.cloud.host.Status; import com.cloud.serializer.Param; import com.cloud.vm.VirtualMachine; +import com.google.gson.annotations.SerializedName; @EntityReference(value = VirtualMachine.class) public class SystemVmResponse extends BaseResponse { @@ -138,6 +138,10 @@ public class SystemVmResponse extends BaseResponse { @Param(description = "the state of the system VM") private String state; + @SerializedName("agentstate") + @Param(description = "the agent state of the system VM") + private String agentState; + @SerializedName("activeviewersessions") @Param(description = "the number of active console sessions for the console proxy system vm") private Integer activeViewerSessions; @@ -150,6 +154,14 @@ public class SystemVmResponse extends BaseResponse { @Param(description = "public vlan range") private List publicVlan; + @SerializedName("lastpinged") + @Param(description = "the date and time the host was last pinged") + private Date lastPinged; + + @SerializedName("version") + @Param(description = "the systemvm agent version") + private String version; + @Override public String getObjectId() { return this.getId(); @@ -331,6 +343,18 @@ public void setState(String state) { this.state = state; } + public String getAgentState() { + return agentState; + } + + public void setAgentState(Status agentState) { + if (agentState != null) { + this.agentState = agentState.toString(); + } else { + this.agentState = Status.Unknown.toString(); + } + } + public Integer getActiveViewerSessions() { return activeViewerSessions; } @@ -378,4 +402,20 @@ public List getPublicVlan() { public void setPublicVlan(List publicVlan) { this.publicVlan = publicVlan; } + + public Date getLastPinged() { + return lastPinged; + } + + public void setLastPinged(Date lastPinged) { + this.lastPinged = lastPinged; + } + + public String getVersion() { + return version; + } + + public void setVersion(String version) { + this.version = version; + } } diff --git a/server/src/main/java/com/cloud/api/ApiResponseHelper.java b/server/src/main/java/com/cloud/api/ApiResponseHelper.java index b8e60325ea22..d8c966d86e76 100644 --- a/server/src/main/java/com/cloud/api/ApiResponseHelper.java +++ b/server/src/main/java/com/cloud/api/ApiResponseHelper.java @@ -31,8 +31,6 @@ import javax.inject.Inject; -import com.cloud.vm.snapshot.VMSnapshotVO; -import com.cloud.vm.snapshot.dao.VMSnapshotDao; import org.apache.cloudstack.acl.ControlledEntity; import org.apache.cloudstack.acl.ControlledEntity.ACLType; import org.apache.cloudstack.affinity.AffinityGroup; @@ -336,6 +334,8 @@ import com.cloud.vm.dao.NicExtraDhcpOptionDao; import com.cloud.vm.dao.NicSecondaryIpVO; import com.cloud.vm.snapshot.VMSnapshot; +import com.cloud.vm.snapshot.VMSnapshotVO; +import com.cloud.vm.snapshot.dao.VMSnapshotDao; public class ApiResponseHelper implements ResponseGenerator { @@ -1375,6 +1375,9 @@ public SystemVmResponse createSystemVmResponse(VirtualMachine vm) { vmResponse.setHostId(host.getUuid()); vmResponse.setHostName(host.getName()); vmResponse.setHypervisor(host.getHypervisorType().toString()); + vmResponse.setAgentState(host.getStatus()); + vmResponse.setLastPinged(new Date(host.getLastPinged())); + vmResponse.setVersion(host.getVersion()); } } From 8722ed889df26f5ac1b74c79c757a78cfafdf1b0 Mon Sep 17 00:00:00 2001 From: Rohit Yadav Date: Fri, 7 Feb 2020 15:27:56 +0530 Subject: [PATCH 2/2] ui changes and code review Signed-off-by: Rohit Yadav --- .../api/response/SystemVmResponse.java | 6 ++-- ui/scripts/system.js | 31 +++---------------- 2 files changed, 7 insertions(+), 30 deletions(-) diff --git a/api/src/main/java/org/apache/cloudstack/api/response/SystemVmResponse.java b/api/src/main/java/org/apache/cloudstack/api/response/SystemVmResponse.java index 234550470baf..0e80954566f0 100644 --- a/api/src/main/java/org/apache/cloudstack/api/response/SystemVmResponse.java +++ b/api/src/main/java/org/apache/cloudstack/api/response/SystemVmResponse.java @@ -139,7 +139,7 @@ public class SystemVmResponse extends BaseResponse { private String state; @SerializedName("agentstate") - @Param(description = "the agent state of the system VM") + @Param(description = "the agent state of the system VM", since = "4.13.1") private String agentState; @SerializedName("activeviewersessions") @@ -155,11 +155,11 @@ public class SystemVmResponse extends BaseResponse { private List publicVlan; @SerializedName("lastpinged") - @Param(description = "the date and time the host was last pinged") + @Param(description = "the date and time the host was last pinged", since = "4.13.1") private Date lastPinged; @SerializedName("version") - @Param(description = "the systemvm agent version") + @Param(description = "the systemvm agent version", since = "4.13.1") private String version; @Override diff --git a/ui/scripts/system.js b/ui/scripts/system.js index 5ef561ff5c0b..fe9b35912cee 100755 --- a/ui/scripts/system.js +++ b/ui/scripts/system.js @@ -9368,7 +9368,7 @@ url: createURL('listSystemVms'), data: data, success: function (json) { - var systemvmObjs = json.listsystemvmsresponse.systemvm; + var systemvmObjs = json.listsystemvmsresponse.systemvm || []; $(systemvmObjs).each(function(idx, item) { var controlIp = item.linklocalip; if (item.hypervisor == "VMware") { @@ -9377,32 +9377,9 @@ item.controlip = controlIp; }); - if (systemvmObjs != undefined) { - $.ajax({ - url: createURL('listHosts'), - data: { - details: 'min' - }, - success: function (json) { - var hostObjs = json.listhostsresponse.host; - for (var i = 0; i < systemvmObjs.length; i++) { - for (var k = 0; k < hostObjs.length; k++) { - if (hostObjs[k].name == systemvmObjs[i].name) { - systemvmObjs[i].agentstate = hostObjs[k].state; - break; - } - } - } - args.response.success({ - data: systemvmObjs - }); - } - }); - } else { - args.response.success({ - data:[] - }); - } + args.response.success({ + data: systemvmObjs + }); } }); },