Bug 13059: Make zoneId in ListCapacity call optional. When no parameter is passed list capacity for all zones.

Reviewed-By: Kishan
This commit is contained in:
Nitin Mehta 2012-01-23 20:32:50 +05:30
parent 7fb6a695c1
commit 23cfbb6cab
3 changed files with 39 additions and 12 deletions

View File

@ -33,7 +33,7 @@ import com.cloud.api.response.CapacityResponse;
import com.cloud.api.response.ListResponse;
import com.cloud.capacity.Capacity;
@Implementation(description="Lists capacity.", responseObject=CapacityResponse.class)
@Implementation(description="Lists all the system wide capacities.", responseObject=CapacityResponse.class)
public class ListCapacityCmd extends BaseListCmd {
public static final Logger s_logger = Logger.getLogger(ListCapacityCmd.class.getName());
@ -46,7 +46,7 @@ public class ListCapacityCmd extends BaseListCmd {
/////////////////////////////////////////////////////
@IdentityMapper(entityTableName="data_center")
@Parameter(name=ApiConstants.ZONE_ID, type=CommandType.LONG, required=true, description="lists capacity by the Zone ID")
@Parameter(name=ApiConstants.ZONE_ID, type=CommandType.LONG, description="lists capacity by the Zone ID")
private Long zoneId;
@IdentityMapper(entityTableName="host_pod_ref")
@ -57,7 +57,7 @@ public class ListCapacityCmd extends BaseListCmd {
@Parameter(name=ApiConstants.CLUSTER_ID, type=CommandType.LONG, description="lists capacity by the Cluster ID")
private Long clusterId;
@Parameter(name=ApiConstants.FETCH_LATEST, type=CommandType.BOOLEAN, description="recalculate capacities")
@Parameter(name=ApiConstants.FETCH_LATEST, type=CommandType.BOOLEAN, description="recalculate capacities and fetch the latest")
private Boolean fetchLatest;
@Parameter(name=ApiConstants.TYPE, type=CommandType.INTEGER, description="lists capacity by type" +

View File

@ -108,12 +108,17 @@ public class CapacityDaoImpl extends GenericDaoBase<CapacityVO, Long> implements
public List<SummedCapacity> findCapacityBy(Integer capacityType, Long zoneId, Long podId, Long clusterId){
SummedCapacitySearch = createSearchBuilder(SummedCapacity.class);
SummedCapacitySearch.select("dcId", Func.NATIVE, SummedCapacitySearch.entity().getDataCenterId());
SummedCapacitySearch.select("sumUsed", Func.SUM, SummedCapacitySearch.entity().getUsedCapacity());
SummedCapacitySearch.select("sumReserved", Func.SUM, SummedCapacitySearch.entity().getReservedCapacity());
SummedCapacitySearch.select("sumTotal", Func.SUM, SummedCapacitySearch.entity().getTotalCapacity());
SummedCapacitySearch.select("capacityType", Func.NATIVE, SummedCapacitySearch.entity().getCapacityType());
SummedCapacitySearch.groupBy(SummedCapacitySearch.entity().getCapacityType());
if (zoneId==null && podId==null && clusterId==null){ // List all the capacities grouped by zone, capacity Type
SummedCapacitySearch.groupBy(SummedCapacitySearch.entity().getDataCenterId(), SummedCapacitySearch.entity().getCapacityType());
}else {
SummedCapacitySearch.groupBy(SummedCapacitySearch.entity().getCapacityType());
}
if (zoneId != null){
SummedCapacitySearch.and("dcId", SummedCapacitySearch.entity().getDataCenterId(), Op.EQ);
@ -262,6 +267,7 @@ public class CapacityDaoImpl extends GenericDaoBase<CapacityVO, Long> implements
public short capacityType;
public Long clusterId;
public Long podId;
public Long dcId;
public SummedCapacity() {
}
public SummedCapacity(long sumUsed, long sumReserved, long sumTotal,
@ -274,6 +280,11 @@ public class CapacityDaoImpl extends GenericDaoBase<CapacityVO, Long> implements
this.clusterId = clusterId;
this.podId = podId;
}
public SummedCapacity(long sumUsed, long sumReserved, long sumTotal,
short capacityType, Long clusterId, Long podId, Long zoneId) {
this(sumUsed, sumReserved, sumTotal, capacityType, clusterId, podId);
this.dcId = zoneId;
}
public Short getCapacityType() {
return capacityType;
}
@ -286,6 +297,9 @@ public class CapacityDaoImpl extends GenericDaoBase<CapacityVO, Long> implements
public Long getTotalCapacity() {
return sumTotal;
}
public Long getDataCenterId() {
return dcId;
}
}
public List<SummedCapacity> findByClusterPodZone(Long zoneId, Long podId, Long clusterId){

View File

@ -1939,7 +1939,7 @@ public class ManagementServerImpl implements ManagementServer {
List<CapacityVO> capacities = new ArrayList<CapacityVO>();
for (SummedCapacity summedCapacity : summedCapacities){
CapacityVO capacity = new CapacityVO(null, zoneId, podId, clusterId,
CapacityVO capacity = new CapacityVO(null, summedCapacity.getDataCenterId(), podId, clusterId,
summedCapacity.getUsedCapacity() + summedCapacity.getReservedCapacity(),
summedCapacity.getTotalCapacity(), summedCapacity.getCapacityType());
@ -1950,14 +1950,27 @@ public class ManagementServerImpl implements ManagementServer {
}
// op_host_Capacity contains only allocated stats and the real time stats are stored "in memory".
//Show Sec. Storage only when the api is invoked for the zone layer.
if ((capacityType == null || capacityType == Capacity.CAPACITY_TYPE_SECONDARY_STORAGE) && podId == null && clusterId == null) {
capacities.add(_storageMgr.getSecondaryStorageUsedStats(null, zoneId));
// Show Sec. Storage only when the api is invoked for the zone layer.
List<DataCenterVO> dcList = new ArrayList<DataCenterVO>();
if (zoneId==null && podId==null && clusterId==null){
dcList = ApiDBUtils.listZones();
}else if (zoneId != null){
dcList.add(ApiDBUtils.findZoneById(zoneId));
}else{
if (capacityType == null || capacityType == Capacity.CAPACITY_TYPE_STORAGE) {
capacities.add(_storageMgr.getStoragePoolUsedStats(null, clusterId, podId, zoneId));
}
}
if (capacityType == null || capacityType == Capacity.CAPACITY_TYPE_STORAGE) {
capacities.add(_storageMgr.getStoragePoolUsedStats(null, clusterId, podId, zoneId));
for(DataCenterVO zone : dcList){
zoneId = zone.getId();
if ((capacityType == null || capacityType == Capacity.CAPACITY_TYPE_SECONDARY_STORAGE) && podId == null && clusterId == null) {
capacities.add(_storageMgr.getSecondaryStorageUsedStats(null, zoneId));
}
if (capacityType == null || capacityType == Capacity.CAPACITY_TYPE_STORAGE) {
capacities.add(_storageMgr.getStoragePoolUsedStats(null, clusterId, podId, zoneId));
}
}
return capacities;
}