Search in sources :

Example 1 with CapacityResponse

use of com.cloud.api.response.CapacityResponse in project cosmic by MissionCriticalCloud.

the class ApiResponseHelper method createClusterResponse.

@Override
public ClusterResponse createClusterResponse(final Cluster cluster, final Boolean showCapacities) {
    final ClusterResponse clusterResponse = new ClusterResponse();
    clusterResponse.setId(cluster.getUuid());
    clusterResponse.setName(cluster.getName());
    final HostPodVO pod = ApiDBUtils.findPodById(cluster.getPodId());
    if (pod != null) {
        clusterResponse.setPodId(pod.getUuid());
        clusterResponse.setPodName(pod.getName());
    }
    final 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());
    final String cpuOvercommitRatio = ApiDBUtils.findClusterDetails(cluster.getId(), "cpuOvercommitRatio");
    final String memoryOvercommitRatio = ApiDBUtils.findClusterDetails(cluster.getId(), "memoryOvercommitRatio");
    clusterResponse.setCpuOvercommitRatio(cpuOvercommitRatio);
    clusterResponse.setMemoryOvercommitRatio(memoryOvercommitRatio);
    if (showCapacities != null && showCapacities) {
        final List<SummedCapacity> capacities = ApiDBUtils.getCapacityByClusterPodZone(null, null, cluster.getId());
        final Set<CapacityResponse> capacityResponses = new HashSet<>();
        for (final SummedCapacity capacity : capacities) {
            final CapacityResponse capacityResponse = new CapacityResponse();
            capacityResponse.setCapacityType(capacity.getCapacityType());
            capacityResponse.setCapacityUsed(capacity.getUsedCapacity() + capacity.getReservedCapacity());
            if (capacity.getCapacityType() == Capacity.CAPACITY_TYPE_STORAGE_ALLOCATED) {
                final 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.setPercentageAllocated(s_percentFormat.format((float) capacityResponse.getCapacityUsed() / (float) capacityResponse.getCapacityTotal() * 100f));
            } else {
                capacityResponse.setPercentageAllocated(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<>(capacityResponses));
    }
    clusterResponse.setObjectName("cluster");
    return clusterResponse;
}
Also used : DataCenter(com.cloud.dc.DataCenter) CapacityResponse(com.cloud.api.response.CapacityResponse) ClusterResponse(com.cloud.api.response.ClusterResponse) SummedCapacity(com.cloud.capacity.dao.CapacityDaoImpl.SummedCapacity) HostPodVO(com.cloud.dc.HostPodVO) HashSet(java.util.HashSet)

Example 2 with CapacityResponse

use of com.cloud.api.response.CapacityResponse in project cosmic by MissionCriticalCloud.

the class ApiResponseHelper method createCapacityResponse.

@Override
public List<CapacityResponse> createCapacityResponse(final List<? extends Capacity> result, final DecimalFormat format) {
    final List<CapacityResponse> capacityResponses = new ArrayList<>();
    for (final Capacity summedCapacity : result) {
        final 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());
            final HostPodVO pod = ApiDBUtils.findPodById(summedCapacity.getPodId());
            if (pod != null) {
                capacityResponse.setPodId(pod.getUuid());
                capacityResponse.setPodName(pod.getName());
            }
        }
        if (summedCapacity.getClusterId() != null) {
            final ClusterVO cluster = ApiDBUtils.findClusterById(summedCapacity.getClusterId());
            if (cluster != null) {
                capacityResponse.setClusterId(cluster.getUuid());
                capacityResponse.setClusterName(cluster.getName());
                if (summedCapacity.getPodId() == null) {
                    final HostPodVO pod = ApiDBUtils.findPodById(cluster.getPodId());
                    capacityResponse.setPodId(pod.getUuid());
                    capacityResponse.setPodName(pod.getName());
                }
            }
        }
        final DataCenter zone = ApiDBUtils.findZoneById(summedCapacity.getDataCenterId());
        if (zone != null) {
            capacityResponse.setZoneId(zone.getUuid());
            capacityResponse.setZoneName(zone.getName());
        }
        if (summedCapacity.getUsedPercentage() != null) {
            capacityResponse.setPercentageAllocated(format.format(summedCapacity.getUsedPercentage() * 100f));
        } else if (summedCapacity.getTotalCapacity() != 0) {
            capacityResponse.setPercentageAllocated(format.format((float) summedCapacity.getUsedCapacity() / (float) summedCapacity.getTotalCapacity() * 100f));
        } else {
            capacityResponse.setPercentageAllocated(format.format(0L));
        }
        capacityResponse.setObjectName("capacity");
        capacityResponses.add(capacityResponse);
    }
    final List<VgpuTypesInfo> gpuCapacities;
    if (result.size() > 1 && (gpuCapacities = ApiDBUtils.getGpuCapacites(result.get(0).getDataCenterId(), result.get(0).getPodId(), result.get(0).getClusterId())) != null) {
        final 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 (final 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();
            }
        }
        final DataCenter zone = ApiDBUtils.findZoneById(result.get(0).getDataCenterId());
        final CapacityResponse capacityResponse = new CapacityResponse();
        if (zone != null) {
            capacityResponse.setZoneId(zone.getUuid());
            capacityResponse.setZoneName(zone.getName());
        }
        if (result.get(0).getPodId() != null) {
            final HostPodVO pod = ApiDBUtils.findPodById(result.get(0).getPodId());
            capacityResponse.setPodId(pod.getUuid());
            capacityResponse.setPodName(pod.getName());
        }
        if (result.get(0).getClusterId() != null) {
            final 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.setPercentageAllocated(format.format(capacityUsed / capacityMax * 100f));
        } else {
            capacityResponse.setPercentageAllocated(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(com.cloud.api.response.CapacityResponse) SummedCapacity(com.cloud.capacity.dao.CapacityDaoImpl.SummedCapacity) Capacity(com.cloud.capacity.Capacity) VgpuTypesInfo(com.cloud.agent.api.VgpuTypesInfo)

Example 3 with CapacityResponse

use of com.cloud.api.response.CapacityResponse in project cosmic by MissionCriticalCloud.

the class ApiResponseHelper method getStatsCapacityresponse.

private static List<CapacityResponse> getStatsCapacityresponse(final Long poolId, final Long clusterId, final Long podId, final Long zoneId) {
    final List<CapacityVO> capacities = new ArrayList<>();
    capacities.add(ApiDBUtils.getStoragePoolUsedStats(poolId, clusterId, podId, zoneId));
    if (clusterId == null && podId == null) {
        capacities.add(ApiDBUtils.getSecondaryStorageUsedStats(poolId, zoneId));
    }
    final List<CapacityResponse> capacityResponses = new ArrayList<>();
    for (final CapacityVO capacity : capacities) {
        final CapacityResponse capacityResponse = new CapacityResponse();
        capacityResponse.setCapacityType(capacity.getCapacityType());
        capacityResponse.setCapacityUsed(capacity.getUsedCapacity());
        capacityResponse.setCapacityTotal(capacity.getTotalCapacity());
        if (capacityResponse.getCapacityTotal() != 0) {
            capacityResponse.setPercentageAllocated(s_percentFormat.format((float) capacityResponse.getCapacityUsed() / (float) capacityResponse.getCapacityTotal() * 100f));
        } else {
            capacityResponse.setPercentageAllocated(s_percentFormat.format(0L));
        }
        capacityResponses.add(capacityResponse);
    }
    return capacityResponses;
}
Also used : CapacityResponse(com.cloud.api.response.CapacityResponse) CapacityVO(com.cloud.capacity.CapacityVO) ArrayList(java.util.ArrayList)

Example 4 with CapacityResponse

use of com.cloud.api.response.CapacityResponse in project cosmic by MissionCriticalCloud.

the class ApiResponseHelper method getDataCenterCapacityResponse.

public static List<CapacityResponse> getDataCenterCapacityResponse(final Long zoneId) {
    final List<SummedCapacity> capacities = ApiDBUtils.getCapacityByClusterPodZone(zoneId, null, null);
    final Set<CapacityResponse> capacityResponses = new HashSet<>();
    for (final SummedCapacity capacity : capacities) {
        final CapacityResponse capacityResponse = new CapacityResponse();
        capacityResponse.setCapacityType(capacity.getCapacityType());
        capacityResponse.setCapacityUsed(capacity.getUsedCapacity() + capacity.getReservedCapacity());
        if (capacity.getCapacityType() == Capacity.CAPACITY_TYPE_STORAGE_ALLOCATED) {
            final List<SummedCapacity> c = ApiDBUtils.findNonSharedStorageForClusterPodZone(zoneId, null, null);
            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.setPercentageAllocated(s_percentFormat.format((float) capacityResponse.getCapacityUsed() / (float) capacityResponse.getCapacityTotal() * 100f));
        } else {
            capacityResponse.setPercentageAllocated(s_percentFormat.format(0L));
        }
        capacityResponses.add(capacityResponse);
    }
    // Do it for stats as well.
    capacityResponses.addAll(getStatsCapacityresponse(null, null, null, zoneId));
    return new ArrayList<>(capacityResponses);
}
Also used : CapacityResponse(com.cloud.api.response.CapacityResponse) ArrayList(java.util.ArrayList) SummedCapacity(com.cloud.capacity.dao.CapacityDaoImpl.SummedCapacity) HashSet(java.util.HashSet)

Example 5 with CapacityResponse

use of com.cloud.api.response.CapacityResponse in project cosmic by MissionCriticalCloud.

the class ApiResponseHelper method createPodResponse.

@Override
public PodResponse createPodResponse(final Pod pod, final Boolean showCapacities) {
    String[] ipRange = new String[2];
    if (pod.getDescription() != null && pod.getDescription().length() > 0) {
        ipRange = pod.getDescription().split("-");
    } else {
        ipRange[0] = pod.getDescription();
    }
    final PodResponse podResponse = new PodResponse();
    podResponse.setId(pod.getUuid());
    podResponse.setName(pod.getName());
    final DataCenter zone = ApiDBUtils.findZoneById(pod.getDataCenterId());
    if (zone != null) {
        podResponse.setZoneId(zone.getUuid());
        podResponse.setZoneName(zone.getName());
    }
    podResponse.setNetmask(NetUtils.getCidrNetmask(pod.getCidrSize()));
    podResponse.setStartIp(ipRange[0]);
    podResponse.setEndIp(ipRange.length > 1 && ipRange[1] != null ? ipRange[1] : "");
    podResponse.setGateway(pod.getGateway());
    podResponse.setAllocationState(pod.getAllocationState().toString());
    if (showCapacities != null && showCapacities) {
        final List<SummedCapacity> capacities = ApiDBUtils.getCapacityByClusterPodZone(null, pod.getId(), null);
        final Set<CapacityResponse> capacityResponses = new HashSet<>();
        for (final SummedCapacity capacity : capacities) {
            final CapacityResponse capacityResponse = new CapacityResponse();
            capacityResponse.setCapacityType(capacity.getCapacityType());
            capacityResponse.setCapacityUsed(capacity.getUsedCapacity() + capacity.getReservedCapacity());
            if (capacity.getCapacityType() == Capacity.CAPACITY_TYPE_STORAGE_ALLOCATED) {
                final List<SummedCapacity> c = ApiDBUtils.findNonSharedStorageForClusterPodZone(null, pod.getId(), null);
                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.setPercentageAllocated(s_percentFormat.format((float) capacityResponse.getCapacityUsed() / (float) capacityResponse.getCapacityTotal() * 100f));
            } else {
                capacityResponse.setPercentageAllocated(s_percentFormat.format(0L));
            }
            capacityResponses.add(capacityResponse);
        }
        // Do it for stats as well.
        capacityResponses.addAll(getStatsCapacityresponse(null, null, pod.getId(), pod.getDataCenterId()));
        podResponse.setCapacitites(new ArrayList<>(capacityResponses));
    }
    podResponse.setObjectName("pod");
    return podResponse;
}
Also used : DataCenter(com.cloud.dc.DataCenter) CapacityResponse(com.cloud.api.response.CapacityResponse) SummedCapacity(com.cloud.capacity.dao.CapacityDaoImpl.SummedCapacity) PodResponse(com.cloud.api.response.PodResponse) HashSet(java.util.HashSet)

Aggregations

CapacityResponse (com.cloud.api.response.CapacityResponse)5 SummedCapacity (com.cloud.capacity.dao.CapacityDaoImpl.SummedCapacity)4 DataCenter (com.cloud.dc.DataCenter)3 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 HostPodVO (com.cloud.dc.HostPodVO)2 VgpuTypesInfo (com.cloud.agent.api.VgpuTypesInfo)1 ClusterResponse (com.cloud.api.response.ClusterResponse)1 PodResponse (com.cloud.api.response.PodResponse)1 Capacity (com.cloud.capacity.Capacity)1 CapacityVO (com.cloud.capacity.CapacityVO)1 ClusterVO (com.cloud.dc.ClusterVO)1