Search in sources :

Example 6 with SummedCapacity

use of com.cloud.capacity.dao.CapacityDaoImpl.SummedCapacity in project cloudstack by apache.

the class ApiResponseHelper method createCapacityResponse.

@Override
public List<CapacityResponse> createCapacityResponse(List<? extends Capacity> result, DecimalFormat format) {
    List<CapacityResponse> capacityResponses = new ArrayList<CapacityResponse>();
    for (Capacity summedCapacity : result) {
        CapacityResponse capacityResponse = new CapacityResponse();
        capacityResponse.setCapacityTotal(summedCapacity.getTotalCapacity());
        capacityResponse.setCapacityType(summedCapacity.getCapacityType());
        capacityResponse.setCapacityUsed(summedCapacity.getUsedCapacity());
        if (summedCapacity.getPodId() != null) {
            capacityResponse.setPodId(ApiDBUtils.findPodById(summedCapacity.getPodId()).getUuid());
            HostPodVO pod = ApiDBUtils.findPodById(summedCapacity.getPodId());
            if (pod != null) {
                capacityResponse.setPodId(pod.getUuid());
                capacityResponse.setPodName(pod.getName());
            }
        }
        if (summedCapacity.getClusterId() != null) {
            ClusterVO cluster = ApiDBUtils.findClusterById(summedCapacity.getClusterId());
            if (cluster != null) {
                capacityResponse.setClusterId(cluster.getUuid());
                capacityResponse.setClusterName(cluster.getName());
                if (summedCapacity.getPodId() == null) {
                    HostPodVO pod = ApiDBUtils.findPodById(cluster.getPodId());
                    capacityResponse.setPodId(pod.getUuid());
                    capacityResponse.setPodName(pod.getName());
                }
            }
        }
        DataCenter zone = ApiDBUtils.findZoneById(summedCapacity.getDataCenterId());
        if (zone != null) {
            capacityResponse.setZoneId(zone.getUuid());
            capacityResponse.setZoneName(zone.getName());
        }
        if (summedCapacity.getUsedPercentage() != null) {
            capacityResponse.setPercentUsed(format.format(summedCapacity.getUsedPercentage() * 100f));
        } else if (summedCapacity.getTotalCapacity() != 0) {
            capacityResponse.setPercentUsed(format.format((float) summedCapacity.getUsedCapacity() / (float) summedCapacity.getTotalCapacity() * 100f));
        } else {
            capacityResponse.setPercentUsed(format.format(0L));
        }
        capacityResponse.setObjectName("capacity");
        capacityResponses.add(capacityResponse);
    }
    List<VgpuTypesInfo> gpuCapacities;
    if (result.size() > 1 && (gpuCapacities = ApiDBUtils.getGpuCapacites(result.get(0).getDataCenterId(), result.get(0).getPodId(), result.get(0).getClusterId())) != null) {
        HashMap<String, Long> vgpuVMs = ApiDBUtils.getVgpuVmsCount(result.get(0).getDataCenterId(), result.get(0).getPodId(), result.get(0).getClusterId());
        float capacityUsed = 0;
        long capacityMax = 0;
        for (VgpuTypesInfo capacity : gpuCapacities) {
            if (vgpuVMs.containsKey(capacity.getGroupName().concat(capacity.getModelName()))) {
                capacityUsed += (float) vgpuVMs.get(capacity.getGroupName().concat(capacity.getModelName())) / capacity.getMaxVpuPerGpu();
            }
            if (capacity.getModelName().equals(GPU.GPUType.passthrough.toString())) {
                capacityMax += capacity.getMaxCapacity();
            }
        }
        DataCenter zone = ApiDBUtils.findZoneById(result.get(0).getDataCenterId());
        CapacityResponse capacityResponse = new CapacityResponse();
        if (zone != null) {
            capacityResponse.setZoneId(zone.getUuid());
            capacityResponse.setZoneName(zone.getName());
        }
        if (result.get(0).getPodId() != null) {
            HostPodVO pod = ApiDBUtils.findPodById(result.get(0).getPodId());
            capacityResponse.setPodId(pod.getUuid());
            capacityResponse.setPodName(pod.getName());
        }
        if (result.get(0).getClusterId() != null) {
            ClusterVO cluster = ApiDBUtils.findClusterById(result.get(0).getClusterId());
            capacityResponse.setClusterId(cluster.getUuid());
            capacityResponse.setClusterName(cluster.getName());
        }
        capacityResponse.setCapacityType(Capacity.CAPACITY_TYPE_GPU);
        capacityResponse.setCapacityUsed((long) Math.ceil(capacityUsed));
        capacityResponse.setCapacityTotal(capacityMax);
        if (capacityMax > 0) {
            capacityResponse.setPercentUsed(format.format(capacityUsed / capacityMax * 100f));
        } else {
            capacityResponse.setPercentUsed(format.format(0));
        }
        capacityResponse.setObjectName("capacity");
        capacityResponses.add(capacityResponse);
    }
    return capacityResponses;
}
Also used : ClusterVO(com.cloud.dc.ClusterVO) ArrayList(java.util.ArrayList) HostPodVO(com.cloud.dc.HostPodVO) DataCenter(com.cloud.dc.DataCenter) CapacityResponse(org.apache.cloudstack.api.response.CapacityResponse) SummedCapacity(com.cloud.capacity.dao.CapacityDaoImpl.SummedCapacity) Capacity(com.cloud.capacity.Capacity) VgpuTypesInfo(com.cloud.agent.api.VgpuTypesInfo)

Example 7 with SummedCapacity

use of com.cloud.capacity.dao.CapacityDaoImpl.SummedCapacity in project cloudstack by apache.

the class ApiResponseHelper method createClusterResponse.

@Override
public ClusterResponse createClusterResponse(Cluster cluster, Boolean showCapacities) {
    ClusterResponse clusterResponse = new ClusterResponse();
    clusterResponse.setId(cluster.getUuid());
    clusterResponse.setName(cluster.getName());
    HostPodVO pod = ApiDBUtils.findPodById(cluster.getPodId());
    if (pod != null) {
        clusterResponse.setPodId(pod.getUuid());
        clusterResponse.setPodName(pod.getName());
    }
    DataCenter dc = ApiDBUtils.findZoneById(cluster.getDataCenterId());
    if (dc != null) {
        clusterResponse.setZoneId(dc.getUuid());
        clusterResponse.setZoneName(dc.getName());
    }
    clusterResponse.setHypervisorType(cluster.getHypervisorType().toString());
    clusterResponse.setClusterType(cluster.getClusterType().toString());
    clusterResponse.setAllocationState(cluster.getAllocationState().toString());
    clusterResponse.setManagedState(cluster.getManagedState().toString());
    String cpuOvercommitRatio = ApiDBUtils.findClusterDetails(cluster.getId(), "cpuOvercommitRatio");
    String memoryOvercommitRatio = ApiDBUtils.findClusterDetails(cluster.getId(), "memoryOvercommitRatio");
    clusterResponse.setCpuOvercommitRatio(cpuOvercommitRatio);
    clusterResponse.setMemoryOvercommitRatio(memoryOvercommitRatio);
    clusterResponse.setResourceDetails(_clusterDetailsDao.findDetails(cluster.getId()));
    if (showCapacities != null && showCapacities) {
        List<SummedCapacity> capacities = ApiDBUtils.getCapacityByClusterPodZone(null, null, cluster.getId());
        Set<CapacityResponse> capacityResponses = new HashSet<CapacityResponse>();
        for (SummedCapacity capacity : capacities) {
            CapacityResponse capacityResponse = new CapacityResponse();
            capacityResponse.setCapacityType(capacity.getCapacityType());
            capacityResponse.setCapacityUsed(capacity.getUsedCapacity() + capacity.getReservedCapacity());
            if (capacity.getCapacityType() == Capacity.CAPACITY_TYPE_STORAGE_ALLOCATED) {
                List<SummedCapacity> c = ApiDBUtils.findNonSharedStorageForClusterPodZone(null, null, cluster.getId());
                capacityResponse.setCapacityTotal(capacity.getTotalCapacity() - c.get(0).getTotalCapacity());
                capacityResponse.setCapacityUsed(capacity.getUsedCapacity() - c.get(0).getUsedCapacity());
            } else {
                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);
        }
        // Do it for stats as well.
        capacityResponses.addAll(getStatsCapacityresponse(null, cluster.getId(), pod.getId(), pod.getDataCenterId()));
        clusterResponse.setCapacitites(new ArrayList<CapacityResponse>(capacityResponses));
    }
    clusterResponse.setObjectName("cluster");
    return clusterResponse;
}
Also used : DataCenter(com.cloud.dc.DataCenter) CapacityResponse(org.apache.cloudstack.api.response.CapacityResponse) ClusterResponse(org.apache.cloudstack.api.response.ClusterResponse) SummedCapacity(com.cloud.capacity.dao.CapacityDaoImpl.SummedCapacity) HostPodVO(com.cloud.dc.HostPodVO) HashSet(java.util.HashSet)

Example 8 with SummedCapacity

use of com.cloud.capacity.dao.CapacityDaoImpl.SummedCapacity in project cloudstack by apache.

the class ManagementServerImpl method getStorageUsed.

List<SummedCapacity> getStorageUsed(Long clusterId, Long podId, Long zoneId, Integer capacityType) {
    if (capacityType == null || capacityType == Capacity.CAPACITY_TYPE_SECONDARY_STORAGE) {
        final List<SummedCapacity> list = new ArrayList<SummedCapacity>();
        if (zoneId != null) {
            final DataCenterVO zone = ApiDBUtils.findZoneById(zoneId);
            if (zone == null || zone.getAllocationState() == AllocationState.Disabled) {
                return null;
            }
            List<CapacityVO> capacities = new ArrayList<CapacityVO>();
            capacities.add(_storageMgr.getSecondaryStorageUsedStats(null, zoneId));
            capacities.add(_storageMgr.getStoragePoolUsedStats(null, clusterId, podId, zoneId));
            for (CapacityVO capacity : capacities) {
                if (capacity.getTotalCapacity() != 0) {
                    capacity.setUsedPercentage((float) capacity.getUsedCapacity() / capacity.getTotalCapacity());
                } else {
                    capacity.setUsedPercentage(0);
                }
                final SummedCapacity summedCapacity = new SummedCapacity(capacity.getUsedCapacity(), capacity.getTotalCapacity(), capacity.getUsedPercentage(), capacity.getCapacityType(), capacity.getDataCenterId(), capacity.getPodId(), capacity.getClusterId());
                list.add(summedCapacity);
            }
        } else {
            List<DataCenterVO> dcList = _dcDao.listEnabledZones();
            for (DataCenterVO dc : dcList) {
                List<CapacityVO> capacities = new ArrayList<CapacityVO>();
                capacities.add(_storageMgr.getSecondaryStorageUsedStats(null, dc.getId()));
                capacities.add(_storageMgr.getStoragePoolUsedStats(null, null, null, dc.getId()));
                for (CapacityVO capacity : capacities) {
                    if (capacity.getTotalCapacity() != 0) {
                        capacity.setUsedPercentage((float) capacity.getUsedCapacity() / capacity.getTotalCapacity());
                    } else {
                        capacity.setUsedPercentage(0);
                    }
                    SummedCapacity summedCapacity = new SummedCapacity(capacity.getUsedCapacity(), capacity.getTotalCapacity(), capacity.getUsedPercentage(), capacity.getCapacityType(), capacity.getDataCenterId(), capacity.getPodId(), capacity.getClusterId());
                    list.add(summedCapacity);
                }
            }
        // End of for
        }
        return list;
    }
    return null;
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) CapacityVO(com.cloud.capacity.CapacityVO) ArrayList(java.util.ArrayList) SummedCapacity(com.cloud.capacity.dao.CapacityDaoImpl.SummedCapacity)

Aggregations

SummedCapacity (com.cloud.capacity.dao.CapacityDaoImpl.SummedCapacity)8 ArrayList (java.util.ArrayList)6 CapacityResponse (org.apache.cloudstack.api.response.CapacityResponse)4 CapacityVO (com.cloud.capacity.CapacityVO)3 DataCenter (com.cloud.dc.DataCenter)3 DataCenterVO (com.cloud.dc.DataCenterVO)3 HostPodVO (com.cloud.dc.HostPodVO)3 HashSet (java.util.HashSet)3 ClusterVO (com.cloud.dc.ClusterVO)2 VgpuTypesInfo (com.cloud.agent.api.VgpuTypesInfo)1 Capacity (com.cloud.capacity.Capacity)1 ExcludeList (com.cloud.deploy.DeploymentPlanner.ExcludeList)1 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)1 List (java.util.List)1 ClusterResponse (org.apache.cloudstack.api.response.ClusterResponse)1 PodResponse (org.apache.cloudstack.api.response.PodResponse)1