Skip to content

Commit d60fffb

Browse files
abh1sardhslove
authored andcommitted
Fix listCapacity sort by usage (apache#11316)
1 parent c44506b commit d60fffb

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

api/src/main/java/org/apache/cloudstack/api/command/admin/resource/ListCapacityCmd.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,14 +132,16 @@ public void execute() {
132132
Collections.sort(capacityResponses, new Comparator<CapacityResponse>() {
133133
public int compare(CapacityResponse resp1, CapacityResponse resp2) {
134134
int res = resp1.getZoneName().compareTo(resp2.getZoneName());
135+
// Group by zone
135136
if (res != 0) {
136137
return res;
137-
} else {
138-
return resp1.getCapacityType().compareTo(resp2.getCapacityType());
139138
}
139+
// Sort by capacity type only if not already sorted by usage
140+
return (getSortBy() != null) ? 0 : resp1.getCapacityType().compareTo(resp2.getCapacityType());
140141
}
141142
});
142143

144+
143145
response.setResponses(capacityResponses);
144146
response.setResponseName(getCommandName());
145147
this.setResponseObject(response);

0 commit comments

Comments
 (0)