Search in sources :

Example 11 with CapacityVO

use of com.cloud.capacity.CapacityVO in project cloudstack by apache.

the class ManagementServerImpl method getStorageUsed.

List<SummedCapacity> getStorageUsed(Long clusterId, Long podId, Long zoneId, Integer capacityType) {
    if (capacityType == null || capacityType == Capacity.CAPACITY_TYPE_SECONDARY_STORAGE) {
        final List<SummedCapacity> list = new ArrayList<SummedCapacity>();
        if (zoneId != null) {
            final DataCenterVO zone = ApiDBUtils.findZoneById(zoneId);
            if (zone == null || zone.getAllocationState() == AllocationState.Disabled) {
                return null;
            }
            List<CapacityVO> capacities = new ArrayList<CapacityVO>();
            capacities.add(_storageMgr.getSecondaryStorageUsedStats(null, zoneId));
            capacities.add(_storageMgr.getStoragePoolUsedStats(null, clusterId, podId, zoneId));
            for (CapacityVO capacity : capacities) {
                if (capacity.getTotalCapacity() != 0) {
                    capacity.setUsedPercentage((float) capacity.getUsedCapacity() / capacity.getTotalCapacity());
                } else {
                    capacity.setUsedPercentage(0);
                }
                final SummedCapacity summedCapacity = new SummedCapacity(capacity.getUsedCapacity(), capacity.getTotalCapacity(), capacity.getUsedPercentage(), capacity.getCapacityType(), capacity.getDataCenterId(), capacity.getPodId(), capacity.getClusterId());
                list.add(summedCapacity);
            }
        } else {
            List<DataCenterVO> dcList = _dcDao.listEnabledZones();
            for (DataCenterVO dc : dcList) {
                List<CapacityVO> capacities = new ArrayList<CapacityVO>();
                capacities.add(_storageMgr.getSecondaryStorageUsedStats(null, dc.getId()));
                capacities.add(_storageMgr.getStoragePoolUsedStats(null, null, null, dc.getId()));
                for (CapacityVO capacity : capacities) {
                    if (capacity.getTotalCapacity() != 0) {
                        capacity.setUsedPercentage((float) capacity.getUsedCapacity() / capacity.getTotalCapacity());
                    } else {
                        capacity.setUsedPercentage(0);
                    }
                    SummedCapacity summedCapacity = new SummedCapacity(capacity.getUsedCapacity(), capacity.getTotalCapacity(), capacity.getUsedPercentage(), capacity.getCapacityType(), capacity.getDataCenterId(), capacity.getPodId(), capacity.getClusterId());
                    list.add(summedCapacity);
                }
            }
        // End of for
        }
        return list;
    }
    return null;
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) CapacityVO(com.cloud.capacity.CapacityVO) ArrayList(java.util.ArrayList) SummedCapacity(com.cloud.capacity.dao.CapacityDaoImpl.SummedCapacity)

Aggregations

CapacityVO (com.cloud.capacity.CapacityVO)11 ArrayList (java.util.ArrayList)6 CapacityState (com.cloud.capacity.CapacityState)3 SummedCapacity (com.cloud.capacity.dao.CapacityDaoImpl.SummedCapacity)3 DataCenterVO (com.cloud.dc.DataCenterVO)3 ClusterVO (com.cloud.dc.ClusterVO)1 ExcludeList (com.cloud.deploy.DeploymentPlanner.ExcludeList)1 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)1 HostVO (com.cloud.host.HostVO)1 AllocationState (com.cloud.org.Grouping.AllocationState)1 BigDecimal (java.math.BigDecimal)1 List (java.util.List)1 CapacityResponse (org.apache.cloudstack.api.response.CapacityResponse)1 DataStore (org.apache.cloudstack.engine.subsystem.api.storage.DataStore)1 ZoneScope (org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope)1 StoragePoolVO (org.apache.cloudstack.storage.datastore.db.StoragePoolVO)1