Search in sources :

Example 1 with HostStats

use of com.cloud.host.HostStats 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()));
    Long mshostId = host.getManagementServerId();
    if (mshostId != null) {
        ManagementServerHostVO managementServer = managementServerHostDao.findByMsid(host.getManagementServerId());
        if (managementServer != null) {
            hostResponse.setManagementServerId(managementServer.getUuid());
        }
    }
    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.setGpuGroup(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) {
        float cpuOverprovisioningFactor = ApiDBUtils.getCpuOverprovisioningFactor(host.getClusterId());
        hostResponse.setCpuNumber((int) (host.getCpus() * cpuOverprovisioningFactor));
        if (details.contains(HostDetails.all) || details.contains(HostDetails.capacity)) {
            // set allocated capacities
            Long mem = host.getMemReservedCapacity() + host.getMemUsedCapacity();
            Long cpu = host.getCpuReservedCapacity() + host.getCpuUsedCapacity();
            Float memWithOverprovisioning = host.getTotalMemory() * ApiDBUtils.getMemOverprovisioningFactor(host.getClusterId());
            hostResponse.setMemoryTotal(memWithOverprovisioning.longValue());
            hostResponse.setMemWithOverprovisioning(decimalFormat.format(memWithOverprovisioning));
            hostResponse.setMemoryAllocated(mem);
            hostResponse.setMemoryAllocatedBytes(mem);
            String memoryAllocatedPercentage = decimalFormat.format((float) mem / memWithOverprovisioning * 100.0f) + "%";
            hostResponse.setMemoryAllocatedPercentage(memoryAllocatedPercentage);
            String hostTags = host.getTag();
            hostResponse.setHostTags(hostTags);
            hostResponse.setHaHost(containsHostHATag(hostTags));
            hostResponse.setHypervisorVersion(host.getHypervisorVersion());
            float cpuWithOverprovisioning = host.getCpus() * host.getSpeed() * cpuOverprovisioningFactor;
            hostResponse.setCpuAllocatedValue(cpu);
            String cpuAllocated = calculateResourceAllocatedPercentage(cpu, cpuWithOverprovisioning);
            hostResponse.setCpuAllocated(cpuAllocated);
            hostResponse.setCpuAllocatedPercentage(cpuAllocated);
            hostResponse.setCpuAllocatedWithOverprovisioning(cpuAllocated);
            hostResponse.setCpuWithOverprovisioning(decimalFormat.format(cpuWithOverprovisioning));
        }
        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.setCpuAverageLoad(hostStats.getLoadAverage());
                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.setHostHAResponse(haConfigDao.findHAResource(host.getId(), HAResource.ResourceType.Host));
    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.setHasAnnotation(annotationDao.hasAnnotations(host.getUuid(), AnnotationService.EntityType.HOST.name(), accountManager.isRootAdmin(CallContext.current().getCallingAccount().getId())));
    hostResponse.setAnnotation(host.getAnnotation());
    hostResponse.setLastAnnotated(host.getLastAnnotated());
    hostResponse.setUsername(host.getUsername());
    hostResponse.setObjectName("host");
    return hostResponse;
}
Also used : DecimalFormat(java.text.DecimalFormat) ArrayList(java.util.ArrayList) GpuResponse(org.apache.cloudstack.api.response.GpuResponse) HostResponse(org.apache.cloudstack.api.response.HostResponse) VgpuResponse(org.apache.cloudstack.api.response.VgpuResponse) VGPUTypesVO(com.cloud.gpu.VGPUTypesVO) StorageStats(com.cloud.storage.StorageStats) HostGpuGroupsVO(com.cloud.gpu.HostGpuGroupsVO) Date(java.util.Date) ManagementServerHostVO(com.cloud.cluster.ManagementServerHostVO) HostStats(com.cloud.host.HostStats)

Example 2 with HostStats

use of com.cloud.host.HostStats 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.getCpuUsedCapacity();
            hostResponse.setMemoryTotal(host.getTotalMemory());
            Float memWithOverprovisioning = host.getTotalMemory() * ApiDBUtils.getMemOverprovisioningFactor(host.getClusterId());
            hostResponse.setMemWithOverprovisioning(decimalFormat.format(memWithOverprovisioning));
            String memoryAllocatedPercentage = decimalFormat.format((float) mem / memWithOverprovisioning * 100.0f) + "%";
            hostResponse.setMemoryAllocated(memoryAllocatedPercentage);
            hostResponse.setMemoryAllocatedPercentage(memoryAllocatedPercentage);
            hostResponse.setMemoryAllocatedBytes(mem);
            String hostTags = host.getTag();
            hostResponse.setHostTags(hostTags);
            hostResponse.setHaHost(containsHostHATag(hostTags));
            hostResponse.setHypervisorVersion(host.getHypervisorVersion());
            hostResponse.setCpuAllocatedValue(cpu);
            String cpuAlloc = decimalFormat.format(((float) cpu / (float) (host.getCpus() * host.getSpeed())) * 100f) + "%";
            hostResponse.setCpuAllocated(cpuAlloc);
            hostResponse.setCpuAllocatedPercentage(cpuAlloc);
            float cpuWithOverprovisioning = host.getCpus() * host.getSpeed() * ApiDBUtils.getCpuOverprovisioningFactor(host.getClusterId());
            hostResponse.setCpuAllocatedWithOverprovisioning(calculateResourceAllocatedPercentage(cpu, cpuWithOverprovisioning));
            hostResponse.setCpuWithOverprovisioning(decimalFormat.format(cpuWithOverprovisioning));
        }
        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;
}
Also used : StorageStats(com.cloud.storage.StorageStats) DecimalFormat(java.text.DecimalFormat) HostForMigrationResponse(org.apache.cloudstack.api.response.HostForMigrationResponse) Date(java.util.Date) HostStats(com.cloud.host.HostStats)

Example 3 with HostStats

use of com.cloud.host.HostStats in project cloudstack by apache.

the class MetricsServiceImpl method updateHostMetrics.

private void updateHostMetrics(final Metrics metrics, final HostJoinVO host) {
    metrics.incrTotalHosts();
    metrics.addCpuAllocated(host.getCpuReservedCapacity() + host.getCpuUsedCapacity());
    metrics.addMemoryAllocated(host.getMemReservedCapacity() + host.getMemUsedCapacity());
    final HostStats hostStats = ApiDBUtils.getHostStatistics(host.getId());
    if (hostStats != null) {
        metrics.addCpuUsedPercentage(hostStats.getCpuUtilization());
        metrics.addMemoryUsed((long) hostStats.getUsedMemory());
        metrics.setMaximumCpuUsage(hostStats.getCpuUtilization());
        metrics.setMaximumMemoryUsage((long) hostStats.getUsedMemory());
    }
}
Also used : HostStats(com.cloud.host.HostStats)

Example 4 with HostStats

use of com.cloud.host.HostStats 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.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() == Host.Type.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() == Hypervisor.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() == Host.Type.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<com.cloud.host.Status.Event> possibleEvents = host.getStatus().getPossibleEvents();
        if ((possibleEvents != null) && !possibleEvents.isEmpty()) {
            String events = "";
            final Iterator<com.cloud.host.Status.Event> iter = possibleEvents.iterator();
            while (iter.hasNext()) {
                final 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
    if (host.getJobId() != null) {
        hostResponse.setJobId(host.getJobUuid());
        hostResponse.setJobStatus(host.getJobStatus());
    }
    hostResponse.setObjectName("host");
    return hostResponse;
}
Also used : DecimalFormat(java.text.DecimalFormat) ArrayList(java.util.ArrayList) GpuResponse(com.cloud.api.response.GpuResponse) AccountVO(com.cloud.user.AccountVO) HostResponse(com.cloud.api.response.HostResponse) VgpuResponse(com.cloud.api.response.VgpuResponse) AffinityGroupVO(com.cloud.affinity.AffinityGroupVO) VGPUTypesVO(com.cloud.gpu.VGPUTypesVO) StorageStats(com.cloud.storage.StorageStats) HostGpuGroupsVO(com.cloud.gpu.HostGpuGroupsVO) Date(java.util.Date) HostVO(com.cloud.host.HostVO) DomainVO(com.cloud.domain.DomainVO) DedicatedResourceVO(com.cloud.dc.DedicatedResourceVO) HostStats(com.cloud.host.HostStats)

Example 5 with HostStats

use of com.cloud.host.HostStats in project cosmic by MissionCriticalCloud.

the class HostJoinDaoImpl method newHostForMigrationResponse.

@Override
public HostForMigrationResponse newHostForMigrationResponse(final HostJoinVO host, final EnumSet<HostDetails> details) {
    final 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.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());
        }
    }
    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() == Host.Type.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.getCpuReservedCapacity();
            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 = decimalFormat.format(((float) cpu / (float) host.getCpus()) * 100f) + "%";
            hostResponse.setCpuAllocated(cpuAlloc);
            final String cpuWithOverprovisioning = Float.toString(host.getCpus() * ApiDBUtils.getCpuOverprovisioningFactor(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());
            }
        }
    } else if (host.getType() == Host.Type.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<com.cloud.host.Status.Event> possibleEvents = host.getStatus().getPossibleEvents();
        if ((possibleEvents != null) && !possibleEvents.isEmpty()) {
            String events = "";
            final Iterator<com.cloud.host.Status.Event> iter = possibleEvents.iterator();
            while (iter.hasNext()) {
                final 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;
}
Also used : AffinityGroupVO(com.cloud.affinity.AffinityGroupVO) StorageStats(com.cloud.storage.StorageStats) DecimalFormat(java.text.DecimalFormat) HostForMigrationResponse(com.cloud.api.response.HostForMigrationResponse) AccountVO(com.cloud.user.AccountVO) Date(java.util.Date) DomainVO(com.cloud.domain.DomainVO) DedicatedResourceVO(com.cloud.dc.DedicatedResourceVO) HostStats(com.cloud.host.HostStats)

Aggregations

HostStats (com.cloud.host.HostStats)5 StorageStats (com.cloud.storage.StorageStats)4 DecimalFormat (java.text.DecimalFormat)4 Date (java.util.Date)4 AffinityGroupVO (com.cloud.affinity.AffinityGroupVO)2 DedicatedResourceVO (com.cloud.dc.DedicatedResourceVO)2 DomainVO (com.cloud.domain.DomainVO)2 HostGpuGroupsVO (com.cloud.gpu.HostGpuGroupsVO)2 VGPUTypesVO (com.cloud.gpu.VGPUTypesVO)2 AccountVO (com.cloud.user.AccountVO)2 ArrayList (java.util.ArrayList)2 GpuResponse (com.cloud.api.response.GpuResponse)1 HostForMigrationResponse (com.cloud.api.response.HostForMigrationResponse)1 HostResponse (com.cloud.api.response.HostResponse)1 VgpuResponse (com.cloud.api.response.VgpuResponse)1 ManagementServerHostVO (com.cloud.cluster.ManagementServerHostVO)1 HostVO (com.cloud.host.HostVO)1 GpuResponse (org.apache.cloudstack.api.response.GpuResponse)1 HostForMigrationResponse (org.apache.cloudstack.api.response.HostForMigrationResponse)1 HostResponse (org.apache.cloudstack.api.response.HostResponse)1