Search in sources :

Example 1 with CapacityVO

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

the class ApiResponseHelper method getStatsCapacityresponse.

private static List<CapacityResponse> getStatsCapacityresponse(final Long poolId, final Long clusterId, final Long podId, final Long zoneId) {
    final List<CapacityVO> capacities = new ArrayList<>();
    capacities.add(ApiDBUtils.getStoragePoolUsedStats(poolId, clusterId, podId, zoneId));
    if (clusterId == null && podId == null) {
        capacities.add(ApiDBUtils.getSecondaryStorageUsedStats(poolId, zoneId));
    }
    final List<CapacityResponse> capacityResponses = new ArrayList<>();
    for (final CapacityVO capacity : capacities) {
        final CapacityResponse capacityResponse = new CapacityResponse();
        capacityResponse.setCapacityType(capacity.getCapacityType());
        capacityResponse.setCapacityUsed(capacity.getUsedCapacity());
        capacityResponse.setCapacityTotal(capacity.getTotalCapacity());
        if (capacityResponse.getCapacityTotal() != 0) {
            capacityResponse.setPercentageAllocated(s_percentFormat.format((float) capacityResponse.getCapacityUsed() / (float) capacityResponse.getCapacityTotal() * 100f));
        } else {
            capacityResponse.setPercentageAllocated(s_percentFormat.format(0L));
        }
        capacityResponses.add(capacityResponse);
    }
    return capacityResponses;
}
Also used : CapacityResponse(com.cloud.api.response.CapacityResponse) CapacityVO(com.cloud.capacity.CapacityVO) ArrayList(java.util.ArrayList)

Example 2 with CapacityVO

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

the class UserConcentratedAllocator method dataCenterAndPodHasEnoughCapacity.

private boolean dataCenterAndPodHasEnoughCapacity(final long dataCenterId, final long podId, final long capacityNeeded, final short capacityType, final long[] hostCandidate) {
    final List<CapacityVO> capacities;
    final 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 (final 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 3 with CapacityVO

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

the class AlertManagerImpl method createOrUpdateIpCapacity.

public void createOrUpdateIpCapacity(final Long dcId, final Long podId, final short capacityType, final 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);
    final int totalIPs;
    final 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);
    }
    final CapacityState ipCapacityState = (capacityState == AllocationState.Disabled) ? CapacityState.Disabled : CapacityState.Enabled;
    if (capacities.size() == 0) {
        final 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)) {
        final 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 4 with CapacityVO

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

the class StorageManagerImpl method getStoragePoolUsedStats.

@Override
public CapacityVO getStoragePoolUsedStats(final Long poolId, final Long clusterId, final Long podId, final Long zoneId) {
    final SearchCriteria<StoragePoolVO> sc = _storagePoolDao.createSearchCriteria();
    List<StoragePoolVO> pools = new ArrayList<>();
    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);
    }
    final CapacityVO capacity = new CapacityVO(poolId, zoneId, podId, clusterId, 0, 0, Capacity.CAPACITY_TYPE_STORAGE);
    for (final StoragePoolVO PrimaryDataStoreVO : pools) {
        final 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(com.cloud.storage.datastore.db.StoragePoolVO) ArrayList(java.util.ArrayList)

Example 5 with CapacityVO

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

the class ApiResponseHelper method getStatsCapacityresponse.

private static List<CapacityResponse> getStatsCapacityresponse(Long poolId, Long clusterId, Long podId, Long zoneId) {
    List<CapacityVO> capacities = new ArrayList<CapacityVO>();
    capacities.add(ApiDBUtils.getStoragePoolUsedStats(poolId, clusterId, podId, zoneId));
    if (clusterId == null && podId == null) {
        capacities.add(ApiDBUtils.getSecondaryStorageUsedStats(poolId, zoneId));
    }
    List<CapacityResponse> capacityResponses = new ArrayList<CapacityResponse>();
    for (CapacityVO capacity : capacities) {
        CapacityResponse capacityResponse = new CapacityResponse();
        capacityResponse.setCapacityType(capacity.getCapacityType());
        capacityResponse.setCapacityName(CapacityVO.getCapacityName(capacity.getCapacityType()));
        capacityResponse.setCapacityUsed(capacity.getUsedCapacity());
        capacityResponse.setCapacityTotal(capacity.getTotalCapacity());
        if (capacityResponse.getCapacityTotal() != 0) {
            capacityResponse.setPercentUsed(s_percentFormat.format((float) capacityResponse.getCapacityUsed() / (float) capacityResponse.getCapacityTotal() * 100f));
        } else {
            capacityResponse.setPercentUsed(s_percentFormat.format(0L));
        }
        capacityResponses.add(capacityResponse);
    }
    return capacityResponses;
}
Also used : CapacityResponse(org.apache.cloudstack.api.response.CapacityResponse) CapacityVO(com.cloud.capacity.CapacityVO) ArrayList(java.util.ArrayList)

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