Search in sources :

Example 6 with CapacityVO

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

the class UserConcentratedAllocator method dataCenterAndPodHasEnoughCapacity.

private boolean dataCenterAndPodHasEnoughCapacity(long dataCenterId, long podId, long capacityNeeded, short capacityType, long[] hostCandidate) {
    List<CapacityVO> capacities = null;
    SearchCriteria<CapacityVO> sc = _capacityDao.createSearchCriteria();
    sc.addAnd("capacityType", SearchCriteria.Op.EQ, capacityType);
    sc.addAnd("dataCenterId", SearchCriteria.Op.EQ, dataCenterId);
    sc.addAnd("podId", SearchCriteria.Op.EQ, podId);
    s_logger.trace("Executing search");
    capacities = _capacityDao.search(sc, null);
    s_logger.trace("Done with a search");
    boolean enoughCapacity = false;
    if (capacities != null) {
        for (CapacityVO capacity : capacities) {
            if (capacityType == Capacity.CAPACITY_TYPE_CPU || capacityType == Capacity.CAPACITY_TYPE_MEMORY) {
                //
                if ((capacity.getTotalCapacity() - calcHostAllocatedCpuMemoryCapacity(capacity.getHostOrPoolId(), capacityType)) >= capacityNeeded) {
                    hostCandidate[0] = capacity.getHostOrPoolId();
                    enoughCapacity = true;
                    break;
                }
            } else {
                if ((capacity.getTotalCapacity() - capacity.getUsedCapacity()) >= capacityNeeded) {
                    hostCandidate[0] = capacity.getHostOrPoolId();
                    enoughCapacity = true;
                    break;
                }
            }
        }
    }
    return enoughCapacity;
}
Also used : CapacityVO(com.cloud.capacity.CapacityVO)

Example 7 with CapacityVO

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

the class AlertManagerImpl method createOrUpdateVlanCapacity.

private void createOrUpdateVlanCapacity(long dcId, 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);
    int totalVlans = _dcDao.countZoneVlans(dcId, false);
    int allocatedVlans = _dcDao.countZoneVlans(dcId, true);
    CapacityState vlanCapacityState = (capacityState == AllocationState.Disabled) ? CapacityState.Disabled : CapacityState.Enabled;
    if (capacities.size() == 0) {
        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)) {
        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 CapacityVO

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

the class AlertManagerImpl method createOrUpdateIpCapacity.

public void createOrUpdateIpCapacity(Long dcId, Long podId, short capacityType, AllocationState capacityState) {
    SearchCriteria<CapacityVO> capacitySC = _capacityDao.createSearchCriteria();
    List<CapacityVO> capacities = _capacityDao.search(capacitySC, null);
    capacitySC = _capacityDao.createSearchCriteria();
    capacitySC.addAnd("podId", SearchCriteria.Op.EQ, podId);
    capacitySC.addAnd("dataCenterId", SearchCriteria.Op.EQ, dcId);
    capacitySC.addAnd("capacityType", SearchCriteria.Op.EQ, capacityType);
    int totalIPs;
    int allocatedIPs;
    capacities = _capacityDao.search(capacitySC, null);
    if (capacityType == Capacity.CAPACITY_TYPE_PRIVATE_IP) {
        totalIPs = _privateIPAddressDao.countIPs(podId, dcId, false);
        allocatedIPs = _privateIPAddressDao.countIPs(podId, dcId, true);
    } else if (capacityType == Capacity.CAPACITY_TYPE_VIRTUAL_NETWORK_PUBLIC_IP) {
        totalIPs = _publicIPAddressDao.countIPsForNetwork(dcId, false, VlanType.VirtualNetwork);
        allocatedIPs = _publicIPAddressDao.countIPsForNetwork(dcId, true, VlanType.VirtualNetwork);
    } else {
        totalIPs = _publicIPAddressDao.countIPsForNetwork(dcId, false, VlanType.DirectAttached);
        allocatedIPs = _publicIPAddressDao.countIPsForNetwork(dcId, true, VlanType.DirectAttached);
    }
    CapacityState ipCapacityState = (capacityState == AllocationState.Disabled) ? CapacityState.Disabled : CapacityState.Enabled;
    if (capacities.size() == 0) {
        CapacityVO newPublicIPCapacity = new CapacityVO(null, dcId, podId, null, allocatedIPs, totalIPs, capacityType);
        newPublicIPCapacity.setCapacityState(ipCapacityState);
        _capacityDao.persist(newPublicIPCapacity);
    } else if (!(capacities.get(0).getUsedCapacity() == allocatedIPs && capacities.get(0).getTotalCapacity() == totalIPs && capacities.get(0).getCapacityState() == ipCapacityState)) {
        CapacityVO capacity = capacities.get(0);
        capacity.setUsedCapacity(allocatedIPs);
        capacity.setTotalCapacity(totalIPs);
        capacity.setCapacityState(ipCapacityState);
        _capacityDao.update(capacity.getId(), capacity);
    }
}
Also used : CapacityState(com.cloud.capacity.CapacityState) CapacityVO(com.cloud.capacity.CapacityVO)

Example 9 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);
    }
    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 10 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 + " * " + 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) {
        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 (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 != 0L || 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.org.Grouping.AllocationState) CapacityVO(com.cloud.capacity.CapacityVO) BigDecimal(java.math.BigDecimal)

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