Search in sources :

Example 6 with StorageStats

use of com.cloud.legacymodel.storage.StorageStats 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.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());
        }
    }
    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.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() == 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
    hostResponse.setJobId(host.getJobUuid());
    hostResponse.setJobStatus(host.getJobStatus());
    hostResponse.setObjectName("host");
    return hostResponse;
}
Also used : AffinityGroupVO(com.cloud.affinity.AffinityGroupVO) StorageStats(com.cloud.legacymodel.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) Event(com.cloud.model.enumeration.Event) DedicatedResourceVO(com.cloud.dc.DedicatedResourceVO) HostStats(com.cloud.legacymodel.dc.HostStats)

Example 7 with StorageStats

use of com.cloud.legacymodel.storage.StorageStats in project cosmic by MissionCriticalCloud.

the class StorageManagerImpl method getSecondaryStorageUsedStats.

@Override
public CapacityVO getSecondaryStorageUsedStats(final Long hostId, final Long zoneId) {
    final SearchCriteria<HostVO> sc = this._hostDao.createSearchCriteria();
    if (zoneId != null) {
        sc.addAnd("dataCenterId", SearchCriteria.Op.EQ, zoneId);
    }
    final List<Long> hosts = new ArrayList<>();
    if (hostId != null) {
        hosts.add(hostId);
    } else {
        final List<DataStore> stores = this._dataStoreMgr.getImageStoresByScope(new ZoneScope(zoneId));
        if (stores != null) {
            for (final DataStore store : stores) {
                hosts.add(store.getId());
            }
        }
    }
    final CapacityVO capacity = new CapacityVO(hostId, zoneId, null, null, 0, 0, Capacity.CAPACITY_TYPE_SECONDARY_STORAGE);
    for (final Long id : hosts) {
        final StorageStats stats = ApiDBUtils.getSecondaryStorageStatistics(id);
        if (stats == null) {
            continue;
        }
        capacity.setUsedCapacity(stats.getByteUsed() + capacity.getUsedCapacity());
        capacity.setTotalCapacity(stats.getCapacityBytes() + capacity.getTotalCapacity());
    }
    return capacity;
}
Also used : ZoneScope(com.cloud.engine.subsystem.api.storage.ZoneScope) StorageStats(com.cloud.legacymodel.storage.StorageStats) DataStore(com.cloud.engine.subsystem.api.storage.DataStore) CapacityVO(com.cloud.capacity.CapacityVO) ArrayList(java.util.ArrayList) HostVO(com.cloud.host.HostVO)

Aggregations

StorageStats (com.cloud.legacymodel.storage.StorageStats)7 ArrayList (java.util.ArrayList)3 AffinityGroupVO (com.cloud.affinity.AffinityGroupVO)2 StoragePoolResponse (com.cloud.api.response.StoragePoolResponse)2 CapacityVO (com.cloud.capacity.CapacityVO)2 DedicatedResourceVO (com.cloud.dc.DedicatedResourceVO)2 DomainVO (com.cloud.domain.DomainVO)2 HostVO (com.cloud.host.HostVO)2 HostStats (com.cloud.legacymodel.dc.HostStats)2 Event (com.cloud.model.enumeration.Event)2 AccountVO (com.cloud.user.AccountVO)2 DecimalFormat (java.text.DecimalFormat)2 Date (java.util.Date)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 DataStore (com.cloud.engine.subsystem.api.storage.DataStore)1 ZoneScope (com.cloud.engine.subsystem.api.storage.ZoneScope)1 HostGpuGroupsVO (com.cloud.gpu.HostGpuGroupsVO)1