Skip to content

Commit 23cfbb6

Browse files
committed
Bug 13059: Make zoneId in ListCapacity call optional. When no parameter is passed list capacity for all zones.
Reviewed-By: Kishan
1 parent 7fb6a69 commit 23cfbb6

3 files changed

Lines changed: 39 additions & 12 deletions

File tree

‎api/src/com/cloud/api/commands/ListCapacityCmd.java‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
import com.cloud.api.response.ListResponse;
3434
import com.cloud.capacity.Capacity;
3535

36-
@Implementation(description="Lists capacity.", responseObject=CapacityResponse.class)
36+
@Implementation(description="Lists all the system wide capacities.", responseObject=CapacityResponse.class)
3737
public class ListCapacityCmd extends BaseListCmd {
3838

3939
public static final Logger s_logger = Logger.getLogger(ListCapacityCmd.class.getName());
@@ -46,7 +46,7 @@ public class ListCapacityCmd extends BaseListCmd {
4646
/////////////////////////////////////////////////////
4747

4848
@IdentityMapper(entityTableName="data_center")
49-
@Parameter(name=ApiConstants.ZONE_ID, type=CommandType.LONG, required=true, description="lists capacity by the Zone ID")
49+
@Parameter(name=ApiConstants.ZONE_ID, type=CommandType.LONG, description="lists capacity by the Zone ID")
5050
private Long zoneId;
5151

5252
@IdentityMapper(entityTableName="host_pod_ref")
@@ -57,7 +57,7 @@ public class ListCapacityCmd extends BaseListCmd {
5757
@Parameter(name=ApiConstants.CLUSTER_ID, type=CommandType.LONG, description="lists capacity by the Cluster ID")
5858
private Long clusterId;
5959

60-
@Parameter(name=ApiConstants.FETCH_LATEST, type=CommandType.BOOLEAN, description="recalculate capacities")
60+
@Parameter(name=ApiConstants.FETCH_LATEST, type=CommandType.BOOLEAN, description="recalculate capacities and fetch the latest")
6161
private Boolean fetchLatest;
6262

6363
@Parameter(name=ApiConstants.TYPE, type=CommandType.INTEGER, description="lists capacity by type" +

‎server/src/com/cloud/capacity/dao/CapacityDaoImpl.java‎

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,17 @@ public CapacityDaoImpl() {
108108
public List<SummedCapacity> findCapacityBy(Integer capacityType, Long zoneId, Long podId, Long clusterId){
109109

110110
SummedCapacitySearch = createSearchBuilder(SummedCapacity.class);
111+
SummedCapacitySearch.select("dcId", Func.NATIVE, SummedCapacitySearch.entity().getDataCenterId());
111112
SummedCapacitySearch.select("sumUsed", Func.SUM, SummedCapacitySearch.entity().getUsedCapacity());
112113
SummedCapacitySearch.select("sumReserved", Func.SUM, SummedCapacitySearch.entity().getReservedCapacity());
113114
SummedCapacitySearch.select("sumTotal", Func.SUM, SummedCapacitySearch.entity().getTotalCapacity());
114115
SummedCapacitySearch.select("capacityType", Func.NATIVE, SummedCapacitySearch.entity().getCapacityType());
115-
116-
SummedCapacitySearch.groupBy(SummedCapacitySearch.entity().getCapacityType());
116+
117+
if (zoneId==null && podId==null && clusterId==null){ // List all the capacities grouped by zone, capacity Type
118+
SummedCapacitySearch.groupBy(SummedCapacitySearch.entity().getDataCenterId(), SummedCapacitySearch.entity().getCapacityType());
119+
}else {
120+
SummedCapacitySearch.groupBy(SummedCapacitySearch.entity().getCapacityType());
121+
}
117122

118123
if (zoneId != null){
119124
SummedCapacitySearch.and("dcId", SummedCapacitySearch.entity().getDataCenterId(), Op.EQ);
@@ -262,6 +267,7 @@ public static class SummedCapacity {
262267
public short capacityType;
263268
public Long clusterId;
264269
public Long podId;
270+
public Long dcId;
265271
public SummedCapacity() {
266272
}
267273
public SummedCapacity(long sumUsed, long sumReserved, long sumTotal,
@@ -274,6 +280,11 @@ public SummedCapacity(long sumUsed, long sumReserved, long sumTotal,
274280
this.clusterId = clusterId;
275281
this.podId = podId;
276282
}
283+
public SummedCapacity(long sumUsed, long sumReserved, long sumTotal,
284+
short capacityType, Long clusterId, Long podId, Long zoneId) {
285+
this(sumUsed, sumReserved, sumTotal, capacityType, clusterId, podId);
286+
this.dcId = zoneId;
287+
}
277288
public Short getCapacityType() {
278289
return capacityType;
279290
}
@@ -286,6 +297,9 @@ public long getReservedCapacity() {
286297
public Long getTotalCapacity() {
287298
return sumTotal;
288299
}
300+
public Long getDataCenterId() {
301+
return dcId;
302+
}
289303
}
290304
public List<SummedCapacity> findByClusterPodZone(Long zoneId, Long podId, Long clusterId){
291305

‎server/src/com/cloud/server/ManagementServerImpl.java‎

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1939,7 +1939,7 @@ public List<CapacityVO> listCapacities(ListCapacityCmd cmd) {
19391939
List<CapacityVO> capacities = new ArrayList<CapacityVO>();
19401940

19411941
for (SummedCapacity summedCapacity : summedCapacities){
1942-
CapacityVO capacity = new CapacityVO(null, zoneId, podId, clusterId,
1942+
CapacityVO capacity = new CapacityVO(null, summedCapacity.getDataCenterId(), podId, clusterId,
19431943
summedCapacity.getUsedCapacity() + summedCapacity.getReservedCapacity(),
19441944
summedCapacity.getTotalCapacity(), summedCapacity.getCapacityType());
19451945

@@ -1950,14 +1950,27 @@ public List<CapacityVO> listCapacities(ListCapacityCmd cmd) {
19501950
}
19511951

19521952
// op_host_Capacity contains only allocated stats and the real time stats are stored "in memory".
1953-
//Show Sec. Storage only when the api is invoked for the zone layer.
1954-
if ((capacityType == null || capacityType == Capacity.CAPACITY_TYPE_SECONDARY_STORAGE) && podId == null && clusterId == null) {
1955-
capacities.add(_storageMgr.getSecondaryStorageUsedStats(null, zoneId));
1953+
// Show Sec. Storage only when the api is invoked for the zone layer.
1954+
List<DataCenterVO> dcList = new ArrayList<DataCenterVO>();
1955+
if (zoneId==null && podId==null && clusterId==null){
1956+
dcList = ApiDBUtils.listZones();
1957+
}else if (zoneId != null){
1958+
dcList.add(ApiDBUtils.findZoneById(zoneId));
1959+
}else{
1960+
if (capacityType == null || capacityType == Capacity.CAPACITY_TYPE_STORAGE) {
1961+
capacities.add(_storageMgr.getStoragePoolUsedStats(null, clusterId, podId, zoneId));
1962+
}
19561963
}
1957-
if (capacityType == null || capacityType == Capacity.CAPACITY_TYPE_STORAGE) {
1958-
capacities.add(_storageMgr.getStoragePoolUsedStats(null, clusterId, podId, zoneId));
1964+
1965+
for(DataCenterVO zone : dcList){
1966+
zoneId = zone.getId();
1967+
if ((capacityType == null || capacityType == Capacity.CAPACITY_TYPE_SECONDARY_STORAGE) && podId == null && clusterId == null) {
1968+
capacities.add(_storageMgr.getSecondaryStorageUsedStats(null, zoneId));
1969+
}
1970+
if (capacityType == null || capacityType == Capacity.CAPACITY_TYPE_STORAGE) {
1971+
capacities.add(_storageMgr.getStoragePoolUsedStats(null, clusterId, podId, zoneId));
1972+
}
19591973
}
1960-
19611974
return capacities;
19621975
}
19631976

0 commit comments

Comments
 (0)