Skip to content

Commit 78cc0a4

Browse files
server: use host record related to a ssvm/cpvm (apache#3876)
This implements the systemvm list API response creator to find and use the host record for a ssvm/cpvm to get the agent status and other details like last disconnected date and agent version. Fixes 3875 Signed-off-by: Rohit Yadav <[email protected]>
1 parent afcbbc4 commit 78cc0a4

File tree

3 files changed

+21
-10
lines changed

3 files changed

+21
-10
lines changed

api/src/main/java/org/apache/cloudstack/api/response/SystemVmResponse.java

+7-7
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,9 @@ public class SystemVmResponse extends BaseResponse {
154154
@Param(description = "public vlan range")
155155
private List<String> publicVlan;
156156

157-
@SerializedName("lastpinged")
158-
@Param(description = "the date and time the host was last pinged", since = "4.13.1")
159-
private Date lastPinged;
157+
@SerializedName("disconnected")
158+
@Param(description = "the last disconnected date of host", since = "4.13.1")
159+
private Date disconnectedOn;
160160

161161
@SerializedName("version")
162162
@Param(description = "the systemvm agent version", since = "4.13.1")
@@ -403,12 +403,12 @@ public void setPublicVlan(List<String> publicVlan) {
403403
this.publicVlan = publicVlan;
404404
}
405405

406-
public Date getLastPinged() {
407-
return lastPinged;
406+
public Date getDisconnectedOn() {
407+
return disconnectedOn;
408408
}
409409

410-
public void setLastPinged(Date lastPinged) {
411-
this.lastPinged = lastPinged;
410+
public void setDisconnectedOn(Date disconnectedOn) {
411+
this.disconnectedOn = disconnectedOn;
412412
}
413413

414414
public String getVersion() {

server/src/main/java/com/cloud/api/ApiDBUtils.java

+4
Original file line numberDiff line numberDiff line change
@@ -1039,6 +1039,10 @@ public static HostVO findHostById(Long hostId) {
10391039
return s_hostDao.findByIdIncludingRemoved(hostId);
10401040
}
10411041

1042+
public static HostVO findHostByTypeNameAndZoneId(Long zoneId, String name, Host.Type type) {
1043+
return s_hostDao.findByTypeNameAndZoneId(zoneId, name, type);
1044+
}
1045+
10421046
public static IPAddressVO findIpAddressById(long addressId) {
10431047
return s_ipAddressDao.findById(addressId);
10441048
}

server/src/main/java/com/cloud/api/ApiResponseHelper.java

+10-3
Original file line numberDiff line numberDiff line change
@@ -1375,9 +1375,16 @@ public SystemVmResponse createSystemVmResponse(VirtualMachine vm) {
13751375
vmResponse.setHostId(host.getUuid());
13761376
vmResponse.setHostName(host.getName());
13771377
vmResponse.setHypervisor(host.getHypervisorType().toString());
1378-
vmResponse.setAgentState(host.getStatus());
1379-
vmResponse.setLastPinged(new Date(host.getLastPinged()));
1380-
vmResponse.setVersion(host.getVersion());
1378+
}
1379+
}
1380+
1381+
if (vm.getType() == Type.SecondaryStorageVm || vm.getType() == Type.ConsoleProxy) {
1382+
Host systemVmHost = ApiDBUtils.findHostByTypeNameAndZoneId(vm.getDataCenterId(), vm.getHostName(),
1383+
Type.SecondaryStorageVm.equals(vm.getType()) ? Host.Type.SecondaryStorageVM : Host.Type.ConsoleProxy);
1384+
if (systemVmHost != null) {
1385+
vmResponse.setAgentState(systemVmHost.getStatus());
1386+
vmResponse.setDisconnectedOn(systemVmHost.getDisconnectedOn());
1387+
vmResponse.setVersion(systemVmHost.getVersion());
13811388
}
13821389
}
13831390

0 commit comments

Comments
 (0)