use of com.cloud.legacymodel.storage.StorageStats in project cosmic by MissionCriticalCloud.
the class StoragePoolJoinDaoImpl method newStoragePoolResponse.
@Override
public StoragePoolResponse newStoragePoolResponse(final StoragePoolJoinVO pool) {
final StoragePoolResponse poolResponse = new StoragePoolResponse();
poolResponse.setId(pool.getUuid());
poolResponse.setName(pool.getName());
poolResponse.setState(pool.getStatus());
String path = pool.getPath();
// cifs store may contain password entry, remove the password
path = StringUtils.cleanString(path);
poolResponse.setPath(path);
poolResponse.setIpAddress(pool.getHostAddress());
poolResponse.setZoneId(pool.getZoneUuid());
poolResponse.setZoneName(pool.getZoneName());
poolResponse.setType(pool.getPoolType().toString());
poolResponse.setPodId(pool.getPodUuid());
poolResponse.setPodName(pool.getPodName());
poolResponse.setCreated(pool.getCreated());
if (pool.getScope() != null) {
poolResponse.setScope(pool.getScope().toString());
}
if (pool.getHypervisor() != null) {
poolResponse.setHypervisor(pool.getHypervisor().toString());
}
final long allocatedSize = pool.getUsedCapacity() + pool.getReservedCapacity();
poolResponse.setDiskSizeTotal(pool.getCapacityBytes());
poolResponse.setDiskSizeAllocated(allocatedSize);
poolResponse.setCapacityIops(pool.getCapacityIops());
// TODO: StatsCollector does not persist data
final StorageStats stats = ApiDBUtils.getStoragePoolStatistics(pool.getId());
if (stats != null) {
final Long used = stats.getByteUsed();
poolResponse.setDiskSizeUsed(used);
}
poolResponse.setClusterId(pool.getClusterUuid());
poolResponse.setClusterName(pool.getClusterName());
poolResponse.setTags(pool.getTag());
poolResponse.setOverProvisionFactor(Double.toString(CapacityManager.StorageOverprovisioningFactor.valueIn(pool.getId())));
// set async job
if (pool.getJobId() != null) {
poolResponse.setJobId(pool.getJobUuid());
poolResponse.setJobStatus(pool.getJobStatus());
}
poolResponse.setObjectName("storagepool");
return poolResponse;
}
use of com.cloud.legacymodel.storage.StorageStats in project cosmic by MissionCriticalCloud.
the class StoragePoolJoinDaoImpl method newStoragePoolForMigrationResponse.
@Override
public StoragePoolResponse newStoragePoolForMigrationResponse(final StoragePoolJoinVO pool) {
final StoragePoolResponse poolResponse = new StoragePoolResponse();
poolResponse.setId(pool.getUuid());
poolResponse.setName(pool.getName());
poolResponse.setState(pool.getStatus());
String path = pool.getPath();
// cifs store may contain password entry, remove the password
path = StringUtils.cleanString(path);
poolResponse.setPath(path);
poolResponse.setIpAddress(pool.getHostAddress());
poolResponse.setZoneId(pool.getZoneUuid());
poolResponse.setZoneName(pool.getZoneName());
if (pool.getPoolType() != null) {
poolResponse.setType(pool.getPoolType().toString());
}
poolResponse.setPodId(pool.getPodUuid());
poolResponse.setPodName(pool.getPodName());
poolResponse.setCreated(pool.getCreated());
poolResponse.setScope(pool.getScope().toString());
if (pool.getHypervisor() != null) {
poolResponse.setHypervisor(pool.getHypervisor().toString());
}
final long allocatedSize = pool.getUsedCapacity();
poolResponse.setDiskSizeTotal(pool.getCapacityBytes());
poolResponse.setDiskSizeAllocated(allocatedSize);
poolResponse.setCapacityIops(pool.getCapacityIops());
poolResponse.setOverProvisionFactor(Double.toString(CapacityManager.StorageOverprovisioningFactor.valueIn(pool.getId())));
// TODO: StatsCollector does not persist data
final StorageStats stats = ApiDBUtils.getStoragePoolStatistics(pool.getId());
if (stats != null) {
final Long used = stats.getByteUsed();
poolResponse.setDiskSizeUsed(used);
}
poolResponse.setClusterId(pool.getClusterUuid());
poolResponse.setClusterName(pool.getClusterName());
poolResponse.setTags(pool.getTag());
// set async job
poolResponse.setJobId(pool.getJobUuid());
poolResponse.setJobStatus(pool.getJobStatus());
poolResponse.setObjectName("storagepool");
return poolResponse;
}
use of com.cloud.legacymodel.storage.StorageStats 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 = this._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(this._storagePoolDao.findById(poolId));
} else {
pools = this._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.legacymodel.storage.StorageStats in project cosmic by MissionCriticalCloud.
the class StorageManagerImpl method checkUsagedSpace.
private boolean checkUsagedSpace(final StoragePool pool) {
final StatsCollector sc = StatsCollector.getInstance();
final double storageUsedThreshold = CapacityManager.StorageCapacityDisableThreshold.valueIn(pool.getDataCenterId());
if (sc != null) {
final long totalSize = pool.getCapacityBytes();
StorageStats stats = sc.getStoragePoolStats(pool.getId());
if (stats == null) {
stats = sc.getStorageStats(pool.getId());
}
if (stats != null) {
final double usedPercentage = (double) stats.getByteUsed() / (double) totalSize;
if (s_logger.isDebugEnabled()) {
s_logger.debug("Checking pool " + pool.getId() + " for storage, totalSize: " + pool.getCapacityBytes() + ", usedBytes: " + stats.getByteUsed() + ", usedPct: " + usedPercentage + ", disable threshold: " + storageUsedThreshold);
}
if (usedPercentage >= storageUsedThreshold) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Insufficient space on pool: " + pool.getId() + " since its usage percentage: " + usedPercentage + " has crossed the pool.storage.capacity.disablethreshold: " + storageUsedThreshold);
}
return false;
}
}
return true;
}
return false;
}
use of com.cloud.legacymodel.storage.StorageStats in project cosmic by MissionCriticalCloud.
the class HostJoinDaoImpl method newHostResponse.
@Override
public HostResponse newHostResponse(final HostJoinVO host, final EnumSet<HostDetails> details) {
final HostResponse hostResponse = new HostResponse();
hostResponse.setId(host.getUuid());
hostResponse.setCapabilities(host.getCapabilities());
hostResponse.setClusterId(host.getClusterUuid());
hostResponse.setCpuSockets(host.getCpuSockets());
hostResponse.setCpuNumber(host.getCpusWithoutHyperThreading());
hostResponse.setCpuNumberHyperThreading(host.getCpus());
hostResponse.setZoneId(host.getZoneUuid());
hostResponse.setDisconnectedOn(host.getDisconnectedOn());
hostResponse.setHypervisor(host.getHypervisorType());
hostResponse.setHostType(host.getType());
hostResponse.setLastPinged(new Date(host.getLastPinged()));
hostResponse.setManagementServerId(host.getManagementServerId());
hostResponse.setName(host.getName());
hostResponse.setPodId(host.getPodUuid());
hostResponse.setRemoved(host.getRemoved());
hostResponse.setState(host.getStatus());
hostResponse.setIpAddress(host.getPrivateIpAddress());
hostResponse.setVersion(host.getVersion());
hostResponse.setCreated(host.getCreated());
final DedicatedResourceVO dedicatedResourceVO = dedicatedResourceDao.findByHostId(host.getId());
if (dedicatedResourceVO != null) {
hostResponse.setDedicated(true);
final DomainVO domainVO = domainDao.findById(dedicatedResourceVO.getDomainId());
if (domainVO != null) {
hostResponse.setDomainId(domainVO.getUuid());
hostResponse.setDomainName(domainVO.getName());
}
final AccountVO accountVO = accountDao.findById(dedicatedResourceVO.getAccountId());
if (accountVO != null) {
hostResponse.setAccountId(accountVO.getUuid());
hostResponse.setAccountName(accountVO.getAccountName());
}
final AffinityGroupVO affinityGroupVO = affinityGroupDao.findById(dedicatedResourceVO.getAffinityGroupId());
if (affinityGroupVO != null) {
hostResponse.setAffinityGroupId(affinityGroupVO.getUuid());
hostResponse.setAffinityGroupName(affinityGroupVO.getName());
}
}
final List<HostGpuGroupsVO> gpuGroups = ApiDBUtils.getGpuGroups(host.getId());
if (gpuGroups != null && !gpuGroups.isEmpty()) {
final List<GpuResponse> gpus = new ArrayList<>();
for (final HostGpuGroupsVO entry : gpuGroups) {
final GpuResponse gpuResponse = new GpuResponse();
gpuResponse.setGpuGroupName(entry.getGroupName());
final List<VGPUTypesVO> vgpuTypes = ApiDBUtils.getVgpus(entry.getId());
if (vgpuTypes != null && !vgpuTypes.isEmpty()) {
final List<VgpuResponse> vgpus = new ArrayList<>();
for (final VGPUTypesVO vgpuType : vgpuTypes) {
final VgpuResponse vgpuResponse = new VgpuResponse();
vgpuResponse.setName(vgpuType.getVgpuType());
vgpuResponse.setVideoRam(vgpuType.getVideoRam());
vgpuResponse.setMaxHeads(vgpuType.getMaxHeads());
vgpuResponse.setMaxResolutionX(vgpuType.getMaxResolutionX());
vgpuResponse.setMaxResolutionY(vgpuType.getMaxResolutionY());
vgpuResponse.setMaxVgpuPerPgpu(vgpuType.getMaxVgpuPerPgpu());
vgpuResponse.setRemainingCapacity(vgpuType.getRemainingCapacity());
vgpuResponse.setmaxCapacity(vgpuType.getMaxCapacity());
vgpus.add(vgpuResponse);
}
gpuResponse.setVgpu(vgpus);
}
gpus.add(gpuResponse);
}
hostResponse.setGpuGroups(gpus);
}
if (details.contains(HostDetails.all) || details.contains(HostDetails.capacity) || details.contains(HostDetails.stats) || details.contains(HostDetails.events)) {
hostResponse.setOsCategoryId(host.getOsCategoryUuid());
hostResponse.setOsCategoryName(host.getOsCategoryName());
hostResponse.setZoneName(host.getZoneName());
hostResponse.setPodName(host.getPodName());
if (host.getClusterId() > 0) {
hostResponse.setClusterName(host.getClusterName());
hostResponse.setClusterType(host.getClusterType().toString());
}
}
final DecimalFormat decimalFormat = new DecimalFormat("#.##");
if (host.getType() == HostType.Routing) {
if (details.contains(HostDetails.all) || details.contains(HostDetails.capacity)) {
// set allocated capacities
final Long mem = host.getMemReservedCapacity() + host.getMemUsedCapacity();
final Long cpu = host.getCpuReservedCapacity() + host.getCpuUsedCapacity();
hostResponse.setMemoryAllocated(mem);
hostResponse.setMemoryTotal(host.getTotalMemory());
final String hostTags = host.getTag();
hostResponse.setHostTags(host.getTag());
final String haTag = ApiDBUtils.getHaTag();
if (haTag != null && !haTag.isEmpty() && hostTags != null && !hostTags.isEmpty()) {
if (haTag.equalsIgnoreCase(hostTags)) {
hostResponse.setHaHost(true);
} else {
hostResponse.setHaHost(false);
}
} else {
hostResponse.setHaHost(false);
}
hostResponse.setHypervisorVersion(host.getHypervisorVersion());
final String cpuAlloc = Float.toString(((float) cpu / (host.getCpus() * CapacityManager.CpuOverprovisioningFactor.valueIn(host.getClusterId()))) * 100f) + "%";
hostResponse.setCpuAllocated(cpuAlloc);
final String cpuWithOverprovisioning = Float.toString(host.getCpus() * CapacityManager.CpuOverprovisioningFactor.valueIn(host.getClusterId()));
hostResponse.setCpuWithOverprovisioning(cpuWithOverprovisioning);
}
if (details.contains(HostDetails.all) || details.contains(HostDetails.stats)) {
// set CPU/RAM/Network stats
final String cpuUsed;
final HostStats hostStats = ApiDBUtils.getHostStatistics(host.getId());
if (hostStats != null) {
final float cpuUtil = (float) hostStats.getCpuUtilization();
cpuUsed = decimalFormat.format(cpuUtil) + "%";
hostResponse.setCpuUsed(cpuUsed);
hostResponse.setMemoryUsed((new Double(hostStats.getUsedMemory())).longValue());
hostResponse.setNetworkKbsRead((new Double(hostStats.getNetworkReadKBs())).longValue());
hostResponse.setNetworkKbsWrite((new Double(hostStats.getNetworkWriteKBs())).longValue());
}
}
if (details.contains(HostDetails.all) && host.getHypervisorType() == HypervisorType.KVM) {
// only kvm has the requirement to return host details
try {
final HostVO h = hostDao.findById(host.getId());
hostDao.loadDetails(h);
final Map<String, String> hostVoDetails;
hostVoDetails = h.getDetails();
hostResponse.setDetails(hostVoDetails);
hostResponse.setHypervisorVersion(h.getDetail("Host.OS") + " " + h.getDetail("Host.OS.Version") + " with kernel " + h.getDetail("Host.OS.Kernel.Version"));
} catch (final Exception e) {
s_logger.debug("failed to get host details", e);
}
}
} else if (host.getType() == HostType.SecondaryStorage) {
final StorageStats secStorageStats = ApiDBUtils.getSecondaryStorageStatistics(host.getId());
if (secStorageStats != null) {
hostResponse.setDiskSizeTotal(secStorageStats.getCapacityBytes());
hostResponse.setDiskSizeAllocated(secStorageStats.getByteUsed());
}
}
hostResponse.setLocalStorageActive(ApiDBUtils.isLocalStorageActiveOnHost(host.getId()));
if (details.contains(HostDetails.all) || details.contains(HostDetails.events)) {
final Set<Event> possibleEvents = host.getStatus().getPossibleEvents();
if ((possibleEvents != null) && !possibleEvents.isEmpty()) {
String events = "";
final Iterator<Event> iter = possibleEvents.iterator();
while (iter.hasNext()) {
final Event event = iter.next();
events += event.toString();
if (iter.hasNext()) {
events += "; ";
}
}
hostResponse.setEvents(events);
}
}
hostResponse.setResourceState(host.getResourceState().toString());
// set async job
if (host.getJobId() != null) {
hostResponse.setJobId(host.getJobUuid());
hostResponse.setJobStatus(host.getJobStatus());
}
hostResponse.setObjectName("host");
return hostResponse;
}
Aggregations