Search in sources :

Example 6 with CapacityState

use of com.cloud.capacity.CapacityState 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 7 with CapacityState

use of com.cloud.capacity.CapacityState in project cosmic by MissionCriticalCloud.

the class AlertManagerImpl method createOrUpdateVlanCapacity.

private void createOrUpdateVlanCapacity(final long dcId, final AllocationState capacityState) {
    SearchCriteria<CapacityVO> capacitySC = _capacityDao.createSearchCriteria();
    List<CapacityVO> capacities = _capacityDao.search(capacitySC, null);
    capacitySC = _capacityDao.createSearchCriteria();
    capacitySC.addAnd("dataCenterId", SearchCriteria.Op.EQ, dcId);
    capacitySC.addAnd("capacityType", SearchCriteria.Op.EQ, Capacity.CAPACITY_TYPE_VLAN);
    capacities = _capacityDao.search(capacitySC, null);
    final int totalVlans = _dcDao.countZoneVlans(dcId, false);
    final int allocatedVlans = _dcDao.countZoneVlans(dcId, true);
    final CapacityState vlanCapacityState = (capacityState == AllocationState.Disabled) ? CapacityState.Disabled : CapacityState.Enabled;
    if (capacities.size() == 0) {
        final CapacityVO newVlanCapacity = new CapacityVO(null, dcId, null, null, allocatedVlans, totalVlans, Capacity.CAPACITY_TYPE_VLAN);
        newVlanCapacity.setCapacityState(vlanCapacityState);
        _capacityDao.persist(newVlanCapacity);
    } else if (!(capacities.get(0).getUsedCapacity() == allocatedVlans && capacities.get(0).getTotalCapacity() == totalVlans && capacities.get(0).getCapacityState() == vlanCapacityState)) {
        final CapacityVO capacity = capacities.get(0);
        capacity.setUsedCapacity(allocatedVlans);
        capacity.setTotalCapacity(totalVlans);
        capacity.setCapacityState(vlanCapacityState);
        _capacityDao.update(capacity.getId(), capacity);
    }
}
Also used : CapacityState(com.cloud.capacity.CapacityState) CapacityVO(com.cloud.capacity.CapacityVO)

Example 8 with CapacityState

use of com.cloud.capacity.CapacityState in project cosmic by MissionCriticalCloud.

the class StorageManagerImpl method createCapacityEntry.

@Override
public void createCapacityEntry(final StoragePoolVO storagePool, final short capacityType, final long allocated) {
    final 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);
    final List<CapacityVO> capacities = _capacityDao.search(capacitySC, null);
    final long totalOverProvCapacity;
    if (storagePool.getPoolType() == StoragePoolType.NetworkFilesystem) {
        // All this is for the inaccuracy of floats for big number multiplication.
        final 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 + " * " + 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 " + totalOverProvCapacity);
    CapacityState capacityState = CapacityState.Enabled;
    if (storagePool.getScope() == ScopeType.ZONE) {
        final DataCenterVO dc = ApiDBUtils.findZoneById(storagePool.getDataCenterId());
        final AllocationState allocationState = dc.getAllocationState();
        capacityState = allocationState == AllocationState.Disabled ? CapacityState.Disabled : CapacityState.Enabled;
    } else {
        if (storagePool.getClusterId() != null) {
            final ClusterVO cluster = ApiDBUtils.findClusterById(storagePool.getClusterId());
            if (cluster != null) {
                final AllocationState allocationState = _configMgr.findClusterAllocationState(cluster);
                capacityState = allocationState == AllocationState.Disabled ? CapacityState.Disabled : CapacityState.Enabled;
            }
        }
    }
    if (capacities.size() == 0) {
        final CapacityVO capacity = new CapacityVO(storagePool.getId(), storagePool.getDataCenterId(), storagePool.getPodId(), storagePool.getClusterId(), allocated, totalOverProvCapacity, capacityType);
        capacity.setCapacityState(capacityState);
        _capacityDao.persist(capacity);
    } else {
        final 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 - " + 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.model.enumeration.AllocationState) CapacityVO(com.cloud.capacity.CapacityVO) BigDecimal(java.math.BigDecimal)

Aggregations

CapacityState (com.cloud.capacity.CapacityState)8 CapacityVO (com.cloud.capacity.CapacityVO)6 ClusterVO (com.cloud.dc.ClusterVO)2 DataCenterVO (com.cloud.dc.DataCenterVO)2 NoTransitionException (com.cloud.utils.fsm.NoTransitionException)2 BigDecimal (java.math.BigDecimal)2 HostVO (com.cloud.host.HostVO)1 AllocationState (com.cloud.model.enumeration.AllocationState)1 AllocationState (com.cloud.org.Grouping.AllocationState)1 StoragePoolVO (org.apache.cloudstack.storage.datastore.db.StoragePoolVO)1