Skip to content

Commit 306655d

Browse files
committed
minor fixups & ui polishing
1 parent a844a11 commit 306655d

File tree

33 files changed

+403
-98
lines changed

33 files changed

+403
-98
lines changed

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -167,12 +167,12 @@ public class HostResponse extends BaseResponseWithAnnotations {
167167
private Long memoryUsed;
168168

169169
@SerializedName("gputotal")
170-
@Param(description = "Total GPUs on the Host", responseObject = Double.class, since = "4.21")
171-
private Double gpuTotal;
170+
@Param(description = "Total GPUs on the Host", responseObject = Long.class, since = "4.21")
171+
private Long gpuTotal;
172172

173173
@SerializedName("gpuused")
174-
@Param(description = "Used GPUs on the Host", responseObject = Double.class, since = "4.21")
175-
private Double gpuUsed;
174+
@Param(description = "Used GPUs on the Host", responseObject = Long.class, since = "4.21")
175+
private Long gpuUsed;
176176

177177
@SerializedName(ApiConstants.GPUGROUP)
178178
@Param(description = "GPU cards present in the host", responseObject = GpuResponse.class, since = "4.4")
@@ -447,11 +447,11 @@ public void setMemoryUsed(Long memoryUsed) {
447447
this.memoryUsed = memoryUsed;
448448
}
449449

450-
public void setGpuTotal(Double gpuTotal) {
450+
public void setGpuTotal(Long gpuTotal) {
451451
this.gpuTotal = gpuTotal;
452452
}
453453

454-
public void setGpuUsed(Double gpuUsed) {
454+
public void setGpuUsed(Long gpuUsed) {
455455
this.gpuUsed = gpuUsed;
456456
}
457457

@@ -919,11 +919,11 @@ public Long getMemoryAllocatedBytes() {
919919
return memoryAllocatedBytes;
920920
}
921921

922-
public Double getGpuTotal() {
922+
public Long getGpuTotal() {
923923
return gpuTotal;
924924
}
925925

926-
public Double getGpuUsed() {
926+
public Long getGpuUsed() {
927927
return gpuUsed;
928928
}
929929

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

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,22 @@ public class ServiceOfferingResponse extends BaseResponseWithAnnotations {
250250
@Param(description = "the name of the vgpu profile to which service offering is linked", since = "4.21")
251251
private String vgpuProfileName;
252252

253+
@SerializedName(ApiConstants.VIDEORAM)
254+
@Param(description = "the video RAM size in MB")
255+
private Long videoRam;
256+
257+
@SerializedName(ApiConstants.MAXHEADS)
258+
@Param(description = "the maximum number of display heads")
259+
private Long maxHeads;
260+
261+
@SerializedName(ApiConstants.MAXRESOLUTIONX)
262+
@Param(description = "the maximum X resolution")
263+
private Long maxResolutionX;
264+
265+
@SerializedName(ApiConstants.MAXRESOLUTIONY)
266+
@Param(description = "the maximum Y resolution")
267+
private Long maxResolutionY;
268+
253269
@SerializedName(ApiConstants.GPU_COUNT)
254270
@Param(description = "the count of GPUs to attach ", since = "4.21")
255271
private Integer gpuCount;
@@ -616,6 +632,38 @@ public void setVgpuProfileName(String vgpuProfileName) {
616632
this.vgpuProfileName = vgpuProfileName;
617633
}
618634

635+
public Long getVideoRam() {
636+
return videoRam;
637+
}
638+
639+
public void setVideoRam(Long videoRam) {
640+
this.videoRam = videoRam;
641+
}
642+
643+
public Long getMaxHeads() {
644+
return maxHeads;
645+
}
646+
647+
public void setMaxHeads(Long maxHeads) {
648+
this.maxHeads = maxHeads;
649+
}
650+
651+
public Long getMaxResolutionX() {
652+
return maxResolutionX;
653+
}
654+
655+
public void setMaxResolutionX(Long maxResolutionX) {
656+
this.maxResolutionX = maxResolutionX;
657+
}
658+
659+
public Long getMaxResolutionY() {
660+
return maxResolutionY;
661+
}
662+
663+
public void setMaxResolutionY(Long maxResolutionY) {
664+
this.maxResolutionY = maxResolutionY;
665+
}
666+
619667
public String getVgpuProfileId() {
620668
return vgpuProfileId;
621669
}

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

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,22 @@ public class UserVmResponse extends BaseResponseWithTagInformation implements Co
198198
@Param(description = "the name of the vgpu profile to which service offering is linked", since = "4.21")
199199
private String vgpuProfileName;
200200

201+
@SerializedName(ApiConstants.VIDEORAM)
202+
@Param(description = "the video RAM size in MB")
203+
private Long videoRam;
204+
205+
@SerializedName(ApiConstants.MAXHEADS)
206+
@Param(description = "the maximum number of display heads")
207+
private Long maxHeads;
208+
209+
@SerializedName(ApiConstants.MAXRESOLUTIONX)
210+
@Param(description = "the maximum X resolution")
211+
private Long maxResolutionX;
212+
213+
@SerializedName(ApiConstants.MAXRESOLUTIONY)
214+
@Param(description = "the maximum Y resolution")
215+
private Long maxResolutionY;
216+
201217
@SerializedName(ApiConstants.GPU_COUNT)
202218
@Param(description = "the count of GPUs on the virtual machine", since = "4.21")
203219
private Integer gpuCount;
@@ -601,6 +617,22 @@ public String getVgpuProfileName() {
601617
return vgpuProfileName;
602618
}
603619

620+
public Long getVideoRam() {
621+
return videoRam;
622+
}
623+
624+
public Long getMaxHeads() {
625+
return maxHeads;
626+
}
627+
628+
public Long getMaxResolutionX() {
629+
return maxResolutionX;
630+
}
631+
632+
public Long getMaxResolutionY() {
633+
return maxResolutionY;
634+
}
635+
604636
public Integer getGpuCount() {
605637
return gpuCount;
606638
}
@@ -903,6 +935,22 @@ public void setVgpuProfileName(String vgpuProfileName) {
903935
this.vgpuProfileName = vgpuProfileName;
904936
}
905937

938+
public void setVideoRam(Long videoRam) {
939+
this.videoRam = videoRam;
940+
}
941+
942+
public void setMaxHeads(Long maxHeads) {
943+
this.maxHeads = maxHeads;
944+
}
945+
946+
public void setMaxResolutionX(Long maxResolutionX) {
947+
this.maxResolutionX = maxResolutionX;
948+
}
949+
950+
public void setMaxResolutionY(Long maxResolutionY) {
951+
this.maxResolutionY = maxResolutionY;
952+
}
953+
906954
public void setGpuCount(Integer gpuCount) {
907955
this.gpuCount = gpuCount;
908956
}

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,14 @@ public class ZoneResponse extends BaseResponseWithAnnotations implements SetReso
9797
@Param(description = "true if security groups support is enabled, false otherwise")
9898
private Boolean securityGroupsEnabled;
9999

100+
@SerializedName("gputotal")
101+
@Param(description = "Total GPUs in the Zone", responseObject = Long.class, since = "4.21")
102+
private Long gpuTotal;
103+
104+
@SerializedName("gpuused")
105+
@Param(description = "Used GPUs in the Zone", responseObject = Long.class, since = "4.21")
106+
private Long gpuUsed;
107+
100108
@SerializedName("allocationstate")
101109
@Param(description = "the allocation state of the cluster")
102110
private String allocationState;
@@ -226,6 +234,14 @@ public void setSecurityGroupsEnabled(boolean securityGroupsEnabled) {
226234
this.securityGroupsEnabled = securityGroupsEnabled;
227235
}
228236

237+
public void setGpuTotal(Long gpuTotal) {
238+
this.gpuTotal = gpuTotal;
239+
}
240+
241+
public void setGpuUsed(Long gpuUsed) {
242+
this.gpuUsed = gpuUsed;
243+
}
244+
229245
public void setAllocationState(String allocationState) {
230246
this.allocationState = allocationState;
231247
}
@@ -361,6 +377,14 @@ public boolean isSecurityGroupsEnabled() {
361377
return securityGroupsEnabled;
362378
}
363379

380+
public Long getGpuUsed() {
381+
return gpuUsed;
382+
}
383+
384+
public Long getGpuTotal() {
385+
return gpuTotal;
386+
}
387+
364388
public boolean isLocalStorageEnabled() {
365389
return localStorageEnabled;
366390
}

api/src/main/java/org/apache/cloudstack/gpu/GpuService.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,10 @@ public interface GpuService extends Manager {
139139
* VgpuTypesInfo.
140140
* The VgpuTypesInfo contains the information about the GPU device.
141141
*
142-
* @param host The host to get GPU group details for.
142+
* @param hostId The host ID to get GPU group details for.
143143
* @return The GPU group details.
144144
*/
145-
HashMap<String, HashMap<String, VgpuTypesInfo>> getGpuGroupDetailsFromGpuDevicesOnHost(Host host);
145+
HashMap<String, HashMap<String, VgpuTypesInfo>> getGpuGroupDetailsFromGpuDevicesOnHost(long hostId);
146146

147147
/**
148148
* This method is used to add the GPU devices to the host when the host is discovered or when the GPU devices are

engine/schema/src/main/java/com/cloud/gpu/dao/HostGpuGroupsDao.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.util.List;
2020

2121
import com.cloud.gpu.HostGpuGroupsVO;
22+
import com.cloud.utils.Pair;
2223
import com.cloud.utils.db.GenericDao;
2324

2425
public interface HostGpuGroupsDao extends GenericDao<HostGpuGroupsVO, Long> {
@@ -57,4 +58,15 @@ public interface HostGpuGroupsDao extends GenericDao<HostGpuGroupsVO, Long> {
5758
*/
5859
void persist(long hostId, List<String> gpuGroups);
5960

61+
62+
/**
63+
* Returns max and remaining GPU capacity
64+
*
65+
* @param dcId
66+
* @param podId
67+
* @param clusterId
68+
* @param hostId
69+
* @return Pair containing max GPU capacity and remaining GPU capacity
70+
*/
71+
Pair<Long, Long> getGpuStats(Long dcId, Long podId, Long clusterId, Long hostId);
6072
}

engine/schema/src/main/java/com/cloud/gpu/dao/HostGpuGroupsDaoImpl.java

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,16 @@
1616
// under the License.
1717
package com.cloud.gpu.dao;
1818

19+
import java.sql.PreparedStatement;
20+
import java.sql.ResultSet;
21+
import java.sql.SQLException;
22+
import java.util.ArrayList;
1923
import java.util.List;
2024

2125

26+
import com.cloud.utils.Pair;
27+
import com.cloud.utils.db.TransactionLegacy;
28+
import com.cloud.utils.exception.CloudRuntimeException;
2229
import org.springframework.stereotype.Component;
2330

2431
import com.cloud.gpu.HostGpuGroupsVO;
@@ -87,4 +94,75 @@ public void deleteGpuEntries(long hostId) {
8794
sc.setParameters("hostId", hostId);
8895
remove(sc);
8996
}
97+
98+
@Override
99+
public Pair<Long, Long> getGpuStats(Long dcId, Long podId, Long clusterId, Long hostId) {
100+
TransactionLegacy txn = TransactionLegacy.currentTxn();
101+
Pair<Long, Long> result = null;
102+
List<Long> resourceIdList = new ArrayList<>();
103+
String query = getStatsQuery(resourceIdList, dcId, podId, clusterId, hostId);
104+
105+
try {
106+
PreparedStatement pstmt = txn.prepareAutoCloseStatement(query);
107+
for (int i = 0; i < resourceIdList.size(); i++) {
108+
pstmt.setLong(1 + i, resourceIdList.get(i));
109+
}
110+
111+
ResultSet rs = pstmt.executeQuery();
112+
while (rs.next()) {
113+
result = new Pair<>(rs.getLong(1), rs.getLong(2));
114+
}
115+
return result;
116+
} catch (SQLException e) {
117+
throw new CloudRuntimeException("Error while fetching GPU stats: " + e.getMessage(), e);
118+
} catch (Throwable e) {
119+
throw new CloudRuntimeException("Caught: " + query, e);
120+
}
121+
}
122+
123+
private String getStatsQuery(List<Long> resourceIdList, Long dcId, Long podId, Long clusterId, Long hostId) {
124+
StringBuilder query = new StringBuilder("SELECT SUM(max_capacity), SUM(remaining_capacity)" +
125+
"FROM vgpu_types " +
126+
"WHERE" +
127+
" gpu_group_id IN (" +
128+
" SELECT" +
129+
" host_gpu_groups.id" +
130+
" FROM" +
131+
" host_gpu_groups" +
132+
" INNER JOIN host ON host.id = host_gpu_groups.host_id ");
133+
if (dcId != null) {
134+
query.append("WHERE host.data_center_id = ? ");
135+
resourceIdList.add(dcId);
136+
}
137+
138+
if (podId != null) {
139+
if (resourceIdList.isEmpty()) {
140+
query.append("WHERE ");
141+
} else {
142+
query.append("AND ");
143+
}
144+
query.append(" host.pod_id = ? ");
145+
resourceIdList.add(podId);
146+
}
147+
if (clusterId != null) {
148+
if (resourceIdList.isEmpty()) {
149+
query.append("WHERE ");
150+
} else {
151+
query.append("AND ");
152+
}
153+
query.append(" host.cluster_id = ? ");
154+
resourceIdList.add(clusterId);
155+
}
156+
if (hostId != null) {
157+
if (resourceIdList.isEmpty()) {
158+
query.append("WHERE ");
159+
} else {
160+
query.append("AND ");
161+
}
162+
query.append(" host.id = ? ");
163+
resourceIdList.add(hostId);
164+
}
165+
query.append(" )");
166+
return query.toString();
167+
}
90168
}

engine/schema/src/main/resources/META-INF/db/views/cloud.service_offering_view.sql

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ SELECT
7979
`vgpu_profile`.`id` AS `vgpu_profile_id`,
8080
`vgpu_profile`.`uuid` AS `vgpu_profile_uuid`,
8181
`vgpu_profile`.`name` AS `vgpu_profile_name`,
82+
`vgpu_profile`.`video_ram` AS `vgpu_profile_video_ram`,
83+
`vgpu_profile`.`max_heads` AS `vgpu_profile_max_heads`,
84+
`vgpu_profile`.`max_resolution_x` AS `vgpu_profile_max_resolution_x`,
85+
`vgpu_profile`.`max_resolution_y` AS `vgpu_profile_max_resolution_y`,
8286
`service_offering`.`gpu_count` AS `gpu_count`,
8387
`service_offering`.`gpu_display` AS `gpu_display`,
8488
GROUP_CONCAT(DISTINCT(domain.id)) AS domain_id,

engine/schema/src/main/resources/META-INF/db/views/cloud.user_vm_view.sql

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,10 @@ SELECT
106106
`service_offering`.`vgpu_profile_id` AS `vgpu_profile_id`,
107107
`vgpu_profile`.`uuid` AS `vgpu_profile_uuid`,
108108
`vgpu_profile`.`name` AS `vgpu_profile_name`,
109+
`vgpu_profile`.`video_ram` AS `vgpu_profile_video_ram`,
110+
`vgpu_profile`.`max_heads` AS `vgpu_profile_max_heads`,
111+
`vgpu_profile`.`max_resolution_x` AS `vgpu_profile_max_resolution_x`,
112+
`vgpu_profile`.`max_resolution_y` AS `vgpu_profile_max_resolution_y`,
109113
`gpu_card`.`id` AS `gpu_card_id`,
110114
`gpu_card`.`uuid` AS `gpu_card_uuid`,
111115
`gpu_card`.`name` AS `gpu_card_name`,

0 commit comments

Comments
 (0)