Skip to content

Commit 294aef5

Browse files
authored
Fix listCapacity sort by usage (apache#11316)
1 parent 7506a54 commit 294aef5

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
@@ -127,14 +127,16 @@ public void execute() {
127127
Collections.sort(capacityResponses, new Comparator<CapacityResponse>() {
128128
public int compare(CapacityResponse resp1, CapacityResponse resp2) {
129129
int res = resp1.getZoneName().compareTo(resp2.getZoneName());
130+
// Group by zone
130131
if (res != 0) {
131132
return res;
132-
} else {
133-
return resp1.getCapacityType().compareTo(resp2.getCapacityType());
134133
}
134+
// Sort by capacity type only if not already sorted by usage
135+
return (getSortBy() != null) ? 0 : resp1.getCapacityType().compareTo(resp2.getCapacityType());
135136
}
136137
});
137138

139+
138140
response.setResponses(capacityResponses);
139141
response.setResponseName(getCommandName());
140142
this.setResponseObject(response);

0 commit comments

Comments
 (0)