use of com.cloud.storage.StorageStats in project cloudstack by apache.
the class StoragePoolJoinDaoImpl method newStoragePoolResponse.
@Override
public StoragePoolResponse newStoragePoolResponse(StoragePoolJoinVO pool) {
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());
}
long allocatedSize = pool.getUsedCapacity() + pool.getReservedCapacity();
poolResponse.setDiskSizeTotal(pool.getCapacityBytes());
poolResponse.setDiskSizeAllocated(allocatedSize);
poolResponse.setCapacityIops(pool.getCapacityIops());
// TODO: StatsCollector does not persist data
StorageStats stats = ApiDBUtils.getStoragePoolStatistics(pool.getId());
if (stats != null) {
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.storage.StorageStats in project cloudstack by apache.
the class StoragePoolJoinDaoImpl method newStoragePoolForMigrationResponse.
@Override
public StoragePoolResponse newStoragePoolForMigrationResponse(StoragePoolJoinVO pool) {
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());
}
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
StorageStats stats = ApiDBUtils.getStoragePoolStatistics(pool.getId());
if (stats != null) {
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.storage.StorageStats in project cloudstack by apache.
the class HostJoinDaoImpl method newHostResponse.
@Override
public HostResponse newHostResponse(HostJoinVO host, EnumSet<HostDetails> details) {
HostResponse hostResponse = new HostResponse();
hostResponse.setId(host.getUuid());
hostResponse.setCapabilities(host.getCapabilities());
hostResponse.setClusterId(host.getClusterUuid());
hostResponse.setCpuSockets(host.getCpuSockets());
hostResponse.setCpuNumber(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.setCpuSpeed(host.getSpeed());
hostResponse.setState(host.getStatus());
hostResponse.setIpAddress(host.getPrivateIpAddress());
hostResponse.setVersion(host.getVersion());
hostResponse.setCreated(host.getCreated());
List<HostGpuGroupsVO> gpuGroups = ApiDBUtils.getGpuGroups(host.getId());
if (gpuGroups != null && !gpuGroups.isEmpty()) {
List<GpuResponse> gpus = new ArrayList<GpuResponse>();
for (HostGpuGroupsVO entry : gpuGroups) {
GpuResponse gpuResponse = new GpuResponse();
gpuResponse.setGpuGroupName(entry.getGroupName());
List<VGPUTypesVO> vgpuTypes = ApiDBUtils.getVgpus(entry.getId());
if (vgpuTypes != null && !vgpuTypes.isEmpty()) {
List<VgpuResponse> vgpus = new ArrayList<VgpuResponse>();
for (VGPUTypesVO vgpuType : vgpuTypes) {
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());
}
}
DecimalFormat decimalFormat = new DecimalFormat("#.##");
if (host.getType() == Host.Type.Routing) {
if (details.contains(HostDetails.all) || details.contains(HostDetails.capacity)) {
// set allocated capacities
Long mem = host.getMemReservedCapacity() + host.getMemUsedCapacity();
Long cpu = host.getCpuReservedCapacity() + host.getCpuUsedCapacity();
hostResponse.setMemoryTotal(mem);
Float totalMemorywithOverprovisioning = new Float((host.getTotalMemory() * ApiDBUtils.getMemOverprovisioningFactor(host.getClusterId())));
hostResponse.setMemWithOverprovisioning(totalMemorywithOverprovisioning.toString());
hostResponse.setMemoryAllocated(mem);
String hostTags = host.getTag();
hostResponse.setHostTags(host.getTag());
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());
Float cpuWithOverprovisioning = new Float(host.getCpus() * host.getSpeed() * ApiDBUtils.getCpuOverprovisioningFactor(host.getClusterId()));
String cpuAlloc = decimalFormat.format(((float) cpu / cpuWithOverprovisioning * 100f)) + "%";
hostResponse.setCpuAllocated(cpuAlloc);
hostResponse.setCpuWithOverprovisioning(cpuWithOverprovisioning.toString());
}
if (details.contains(HostDetails.all) || details.contains(HostDetails.stats)) {
// set CPU/RAM/Network stats
String cpuUsed = null;
HostStats hostStats = ApiDBUtils.getHostStatistics(host.getId());
if (hostStats != null) {
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() == Hypervisor.HypervisorType.KVM) {
//only kvm has the requirement to return host details
try {
hostResponse.setDetails(hostDetailsDao.findDetails(host.getId()));
} catch (Exception e) {
s_logger.debug("failed to get host details", e);
}
}
} else if (host.getType() == Host.Type.SecondaryStorage) {
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)) {
Set<com.cloud.host.Status.Event> possibleEvents = host.getStatus().getPossibleEvents();
if ((possibleEvents != null) && !possibleEvents.isEmpty()) {
String events = "";
Iterator<com.cloud.host.Status.Event> iter = possibleEvents.iterator();
while (iter.hasNext()) {
com.cloud.host.Status.Event event = iter.next();
events += event.toString();
if (iter.hasNext()) {
events += "; ";
}
}
hostResponse.setEvents(events);
}
}
hostResponse.setOutOfBandManagementResponse(outOfBandManagementDao.findByHost(host.getId()));
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;
}
use of com.cloud.storage.StorageStats in project cloudstack by apache.
the class HostJoinDaoImpl method newHostForMigrationResponse.
@Override
public HostForMigrationResponse newHostForMigrationResponse(HostJoinVO host, EnumSet<HostDetails> details) {
HostForMigrationResponse hostResponse = new HostForMigrationResponse();
hostResponse.setId(host.getUuid());
hostResponse.setCapabilities(host.getCapabilities());
hostResponse.setClusterId(host.getClusterUuid());
hostResponse.setCpuNumber(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.setCpuSpeed(host.getSpeed());
hostResponse.setState(host.getStatus());
hostResponse.setIpAddress(host.getPrivateIpAddress());
hostResponse.setVersion(host.getVersion());
hostResponse.setCreated(host.getCreated());
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());
}
}
DecimalFormat decimalFormat = new DecimalFormat("#.##");
if (host.getType() == Host.Type.Routing) {
if (details.contains(HostDetails.all) || details.contains(HostDetails.capacity)) {
// set allocated capacities
Long mem = host.getMemReservedCapacity() + host.getMemUsedCapacity();
Long cpu = host.getCpuReservedCapacity() + host.getCpuReservedCapacity();
hostResponse.setMemoryTotal(mem);
Float memWithOverprovisioning = new Float((host.getTotalMemory() * ApiDBUtils.getMemOverprovisioningFactor(host.getClusterId())));
hostResponse.setMemWithOverprovisioning(memWithOverprovisioning.toString());
hostResponse.setMemoryAllocated(decimalFormat.format((float) mem / memWithOverprovisioning * 100f).toString() + "%");
String hostTags = host.getTag();
hostResponse.setHostTags(host.getTag());
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());
Float cpuWithOverprovisioning = new Float(host.getCpus() * host.getSpeed() * ApiDBUtils.getCpuOverprovisioningFactor(host.getClusterId()));
String cpuAlloc = decimalFormat.format(((float) cpu / cpuWithOverprovisioning * 100f)).toString() + "%";
hostResponse.setCpuAllocated(cpuAlloc);
hostResponse.setCpuWithOverprovisioning(cpuWithOverprovisioning.toString());
}
if (details.contains(HostDetails.all) || details.contains(HostDetails.stats)) {
// set CPU/RAM/Network stats
String cpuUsed = null;
HostStats hostStats = ApiDBUtils.getHostStatistics(host.getId());
if (hostStats != null) {
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());
}
}
} else if (host.getType() == Host.Type.SecondaryStorage) {
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)) {
Set<com.cloud.host.Status.Event> possibleEvents = host.getStatus().getPossibleEvents();
if ((possibleEvents != null) && !possibleEvents.isEmpty()) {
String events = "";
Iterator<com.cloud.host.Status.Event> iter = possibleEvents.iterator();
while (iter.hasNext()) {
com.cloud.host.Status.Event event = iter.next();
events += event.toString();
if (iter.hasNext()) {
events += "; ";
}
}
hostResponse.setEvents(events);
}
}
hostResponse.setResourceState(host.getResourceState().toString());
// set async job
hostResponse.setJobId(host.getJobUuid());
hostResponse.setJobStatus(host.getJobStatus());
hostResponse.setObjectName("host");
return hostResponse;
}
Aggregations