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;
}
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;
}
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);
}
}
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;
}
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;
}
Aggregations