use of org.apache.cloudstack.api.response.CapacityResponse in project cloudstack by apache.
the class ApiResponseHelper method getDataCenterCapacityResponse.
public static List<CapacityResponse> getDataCenterCapacityResponse(Long zoneId) {
List<SummedCapacity> capacities = ApiDBUtils.getCapacityByClusterPodZone(zoneId, null, null);
Set<CapacityResponse> capacityResponses = new HashSet<CapacityResponse>();
for (SummedCapacity capacity : capacities) {
CapacityResponse capacityResponse = new CapacityResponse();
capacityResponse.setCapacityType(capacity.getCapacityType());
capacityResponse.setCapacityName(CapacityVO.getCapacityName(capacity.getCapacityType()));
capacityResponse.setCapacityUsed(capacity.getUsedCapacity() + capacity.getReservedCapacity());
if (capacity.getCapacityType() == Capacity.CAPACITY_TYPE_STORAGE_ALLOCATED) {
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.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, null, null, zoneId));
return new ArrayList<CapacityResponse>(capacityResponses);
}
use of org.apache.cloudstack.api.response.CapacityResponse in project cloudstack by apache.
the class ApiResponseHelper method getStatsCapacityresponse.
private static List<CapacityResponse> getStatsCapacityresponse(Long poolId, Long clusterId, Long podId, Long zoneId) {
List<CapacityVO> capacities = new ArrayList<CapacityVO>();
capacities.add(ApiDBUtils.getStoragePoolUsedStats(poolId, clusterId, podId, zoneId));
if (clusterId == null && podId == null) {
capacities.add(ApiDBUtils.getSecondaryStorageUsedStats(poolId, zoneId));
}
List<CapacityResponse> capacityResponses = new ArrayList<CapacityResponse>();
for (CapacityVO capacity : capacities) {
CapacityResponse capacityResponse = new CapacityResponse();
capacityResponse.setCapacityType(capacity.getCapacityType());
capacityResponse.setCapacityName(CapacityVO.getCapacityName(capacity.getCapacityType()));
capacityResponse.setCapacityUsed(capacity.getUsedCapacity());
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);
}
return capacityResponses;
}
use of org.apache.cloudstack.api.response.CapacityResponse 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());
if (summedCapacity.getAllocatedCapacity() != null) {
capacityResponse.setCapacityAllocated(summedCapacity.getAllocatedCapacity());
}
capacityResponse.setCapacityType(summedCapacity.getCapacityType());
capacityResponse.setCapacityName(CapacityVO.getCapacityName(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.setCapacityName(CapacityVO.getCapacityName(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;
}
use of org.apache.cloudstack.api.response.CapacityResponse 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.setCapacityName(CapacityVO.getCapacityName(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.setHasAnnotation(annotationDao.hasAnnotations(cluster.getUuid(), AnnotationService.EntityType.CLUSTER.name(), _accountMgr.isRootAdmin(CallContext.current().getCallingAccount().getId())));
clusterResponse.setObjectName("cluster");
return clusterResponse;
}
use of org.apache.cloudstack.api.response.CapacityResponse in project cloudstack by apache.
the class ApiResponseHelper method createPodResponse.
@Override
public PodResponse createPodResponse(Pod pod, Boolean showCapacities) {
String[] ipRange = new String[2];
List<String> startIps = new ArrayList<String>();
List<String> endIps = new ArrayList<String>();
List<String> forSystemVms = new ArrayList<String>();
List<String> vlanIds = new ArrayList<String>();
List<IpRangeResponse> ipRanges = new ArrayList<>();
if (pod.getDescription() != null && pod.getDescription().length() > 0) {
final String[] existingPodIpRanges = pod.getDescription().split(",");
for (String podIpRange : existingPodIpRanges) {
IpRangeResponse ipRangeResponse = new IpRangeResponse();
final String[] existingPodIpRange = podIpRange.split("-");
String startIp = ((existingPodIpRange.length > 0) && (existingPodIpRange[0] != null)) ? existingPodIpRange[0] : "";
ipRangeResponse.setStartIp(startIp);
startIps.add(startIp);
String endIp = ((existingPodIpRange.length > 1) && (existingPodIpRange[1] != null)) ? existingPodIpRange[1] : "";
ipRangeResponse.setEndIp(endIp);
endIps.add(endIp);
String forSystemVm = (existingPodIpRange.length > 2) && (existingPodIpRange[2] != null) ? existingPodIpRange[2] : "0";
ipRangeResponse.setForSystemVms(forSystemVm);
forSystemVms.add(forSystemVm);
String vlanId = (existingPodIpRange.length > 3) && (existingPodIpRange[3] != null && !existingPodIpRange[3].equals("untagged")) ? BroadcastDomainType.Vlan.toUri(existingPodIpRange[3]).toString() : BroadcastDomainType.Vlan.toUri(Vlan.UNTAGGED).toString();
ipRangeResponse.setVlanId(vlanId);
vlanIds.add(vlanId);
ipRanges.add(ipRangeResponse);
}
}
PodResponse podResponse = new PodResponse();
podResponse.setId(pod.getUuid());
podResponse.setName(pod.getName());
DataCenter zone = ApiDBUtils.findZoneById(pod.getDataCenterId());
if (zone != null) {
podResponse.setZoneId(zone.getUuid());
podResponse.setZoneName(zone.getName());
}
podResponse.setNetmask(NetUtils.getCidrNetmask(pod.getCidrSize()));
podResponse.setIpRanges(ipRanges);
podResponse.setStartIp(startIps);
podResponse.setEndIp(endIps);
podResponse.setForSystemVms(forSystemVms);
podResponse.setVlanId(vlanIds);
podResponse.setGateway(pod.getGateway());
podResponse.setAllocationState(pod.getAllocationState().toString());
if (showCapacities != null && showCapacities) {
List<SummedCapacity> capacities = ApiDBUtils.getCapacityByClusterPodZone(null, pod.getId(), null);
Set<CapacityResponse> capacityResponses = new HashSet<CapacityResponse>();
for (SummedCapacity capacity : capacities) {
CapacityResponse capacityResponse = new CapacityResponse();
capacityResponse.setCapacityType(capacity.getCapacityType());
capacityResponse.setCapacityName(CapacityVO.getCapacityName(capacity.getCapacityType()));
capacityResponse.setCapacityUsed(capacity.getUsedCapacity() + capacity.getReservedCapacity());
if (capacity.getCapacityType() == Capacity.CAPACITY_TYPE_STORAGE_ALLOCATED) {
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.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, null, pod.getId(), pod.getDataCenterId()));
podResponse.setCapacities(new ArrayList<CapacityResponse>(capacityResponses));
}
podResponse.setHasAnnotation(annotationDao.hasAnnotations(pod.getUuid(), AnnotationService.EntityType.POD.name(), _accountMgr.isRootAdmin(CallContext.current().getCallingAccount().getId())));
podResponse.setObjectName("pod");
return podResponse;
}
Aggregations