Search in sources :

Example 21 with CapacityVO

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

the class StorageManagerImpl method getStoragePoolUsedStats.

@Override
public CapacityVO getStoragePoolUsedStats(Long poolId, Long clusterId, Long podId, Long zoneId) {
    SearchCriteria<StoragePoolVO> sc = _storagePoolDao.createSearchCriteria();
    List<StoragePoolVO> pools = new ArrayList<StoragePoolVO>();
    if (zoneId != null) {
        sc.addAnd("dataCenterId", SearchCriteria.Op.EQ, zoneId);
    }
    if (podId != null) {
        sc.addAnd("podId", SearchCriteria.Op.EQ, podId);
    }
    if (clusterId != null) {
        sc.addAnd("clusterId", SearchCriteria.Op.EQ, clusterId);
    }
    if (poolId != null) {
        sc.addAnd("hostOrPoolId", SearchCriteria.Op.EQ, poolId);
    }
    sc.addAnd("parent", SearchCriteria.Op.EQ, 0L);
    if (poolId != null) {
        pools.add(_storagePoolDao.findById(poolId));
    } else {
        pools = _storagePoolDao.search(sc, null);
    }
    CapacityVO capacity = new CapacityVO(poolId, zoneId, podId, clusterId, 0, 0, Capacity.CAPACITY_TYPE_STORAGE);
    for (StoragePoolVO PrimaryDataStoreVO : pools) {
        StorageStats stats = ApiDBUtils.getStoragePoolStatistics(PrimaryDataStoreVO.getId());
        if (stats == null) {
            continue;
        }
        capacity.setUsedCapacity(stats.getByteUsed() + capacity.getUsedCapacity());
        capacity.setTotalCapacity(stats.getCapacityBytes() + capacity.getTotalCapacity());
    }
    return capacity;
}
Also used : CapacityVO(com.cloud.capacity.CapacityVO) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO) ArrayList(java.util.ArrayList)

Example 22 with CapacityVO

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

the class StorageManagerImpl method createCapacityEntry.

@Override
public void createCapacityEntry(StoragePoolVO storagePool, short capacityType, long allocated) {
    SearchCriteria<CapacityVO> capacitySC = _capacityDao.createSearchCriteria();
    capacitySC.addAnd("hostOrPoolId", SearchCriteria.Op.EQ, storagePool.getId());
    capacitySC.addAnd("dataCenterId", SearchCriteria.Op.EQ, storagePool.getDataCenterId());
    capacitySC.addAnd("capacityType", SearchCriteria.Op.EQ, capacityType);
    List<CapacityVO> capacities = _capacityDao.search(capacitySC, null);
    long totalOverProvCapacity;
    if (storagePool.getPoolType().supportsOverProvisioning()) {
        // All this is for the inaccuracy of floats for big number multiplication.
        BigDecimal overProvFactor = getStorageOverProvisioningFactor(storagePool.getId());
        totalOverProvCapacity = overProvFactor.multiply(new BigDecimal(storagePool.getCapacityBytes())).longValue();
        s_logger.debug("Found storage pool " + storagePool.getName() + " of type " + storagePool.getPoolType().toString() + " with overprovisioning factor " + overProvFactor.toString());
        s_logger.debug("Total over provisioned capacity calculated is " + overProvFactor + " * " + toHumanReadableSize(storagePool.getCapacityBytes()));
    } else {
        s_logger.debug("Found storage pool " + storagePool.getName() + " of type " + storagePool.getPoolType().toString());
        totalOverProvCapacity = storagePool.getCapacityBytes();
    }
    s_logger.debug("Total over provisioned capacity of the pool " + storagePool.getName() + " id: " + storagePool.getId() + " is " + toHumanReadableSize(totalOverProvCapacity));
    CapacityState capacityState = CapacityState.Enabled;
    if (storagePool.getScope() == ScopeType.ZONE) {
        DataCenterVO dc = ApiDBUtils.findZoneById(storagePool.getDataCenterId());
        AllocationState allocationState = dc.getAllocationState();
        capacityState = (allocationState == AllocationState.Disabled) ? CapacityState.Disabled : CapacityState.Enabled;
    } else {
        if (storagePool.getClusterId() != null) {
            ClusterVO cluster = ApiDBUtils.findClusterById(storagePool.getClusterId());
            if (cluster != null) {
                AllocationState allocationState = _configMgr.findClusterAllocationState(cluster);
                capacityState = (allocationState == AllocationState.Disabled) ? CapacityState.Disabled : CapacityState.Enabled;
            }
        }
    }
    if (storagePool.getScope() == ScopeType.HOST) {
        List<StoragePoolHostVO> stoargePoolHostVO = _storagePoolHostDao.listByPoolId(storagePool.getId());
        if (stoargePoolHostVO != null && !stoargePoolHostVO.isEmpty()) {
            HostVO host = _hostDao.findById(stoargePoolHostVO.get(0).getHostId());
            if (host != null) {
                capacityState = (host.getResourceState() == ResourceState.Disabled) ? CapacityState.Disabled : CapacityState.Enabled;
            }
        }
    }
    if (capacities.size() == 0) {
        CapacityVO capacity = new CapacityVO(storagePool.getId(), storagePool.getDataCenterId(), storagePool.getPodId(), storagePool.getClusterId(), allocated, totalOverProvCapacity, capacityType);
        capacity.setCapacityState(capacityState);
        _capacityDao.persist(capacity);
    } else {
        CapacityVO capacity = capacities.get(0);
        if (capacity.getTotalCapacity() != totalOverProvCapacity || allocated != capacity.getUsedCapacity() || capacity.getCapacityState() != capacityState) {
            capacity.setTotalCapacity(totalOverProvCapacity);
            capacity.setUsedCapacity(allocated);
            capacity.setCapacityState(capacityState);
            _capacityDao.update(capacity.getId(), capacity);
        }
    }
    s_logger.debug("Successfully set Capacity - " + toHumanReadableSize(totalOverProvCapacity) + " for capacity type - " + capacityType + " , DataCenterId - " + storagePool.getDataCenterId() + ", HostOrPoolId - " + storagePool.getId() + ", PodId " + storagePool.getPodId());
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) ClusterVO(com.cloud.dc.ClusterVO) CapacityState(com.cloud.capacity.CapacityState) AllocationState(com.cloud.org.Grouping.AllocationState) CapacityVO(com.cloud.capacity.CapacityVO) BigDecimal(java.math.BigDecimal) HostVO(com.cloud.host.HostVO)

Example 23 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)23 ArrayList (java.util.ArrayList)12 CapacityState (com.cloud.capacity.CapacityState)6 SummedCapacity (com.cloud.capacity.dao.CapacityDaoImpl.SummedCapacity)6 DataCenterVO (com.cloud.dc.DataCenterVO)6 HostVO (com.cloud.host.HostVO)4 ClusterVO (com.cloud.dc.ClusterVO)2 ExcludeList (com.cloud.deploy.DeploymentPlanner.ExcludeList)2 BigDecimal (java.math.BigDecimal)2 List (java.util.List)2 DomainJoinVO (com.cloud.api.query.vo.DomainJoinVO)1 CapacityResponse (com.cloud.api.response.CapacityResponse)1 DedicatedResourceVO (com.cloud.dc.DedicatedResourceVO)1 DataStore (com.cloud.engine.subsystem.api.storage.DataStore)1 ZoneScope (com.cloud.engine.subsystem.api.storage.ZoneScope)1 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)1 AllocationState (com.cloud.model.enumeration.AllocationState)1 AllocationState (com.cloud.org.Grouping.AllocationState)1 StoragePoolVO (com.cloud.storage.datastore.db.StoragePoolVO)1 Account (com.cloud.user.Account)1