|
44 | 44 | import com.cloud.api.query.vo.AccountJoinVO; |
45 | 45 | import com.cloud.api.query.vo.AsyncJobJoinVO; |
46 | 46 | import com.cloud.api.query.vo.ControlledViewEntity; |
| 47 | +import com.cloud.api.query.vo.DataCenterJoinVO; |
47 | 48 | import com.cloud.api.query.vo.DiskOfferingJoinVO; |
48 | 49 | import com.cloud.api.query.vo.DomainRouterJoinVO; |
49 | 50 | import com.cloud.api.query.vo.EventJoinVO; |
@@ -717,77 +718,42 @@ public PodResponse createPodResponse(Pod pod, Boolean showCapacities) { |
717 | 718 |
|
718 | 719 | @Override |
719 | 720 | public ZoneResponse createZoneResponse(DataCenter dataCenter, Boolean showCapacities) { |
720 | | - Account account = UserContext.current().getCaller(); |
721 | | - ZoneResponse zoneResponse = new ZoneResponse(); |
722 | | - zoneResponse.setId(dataCenter.getUuid()); |
723 | | - zoneResponse.setName(dataCenter.getName()); |
724 | | - zoneResponse.setSecurityGroupsEnabled(ApiDBUtils.isSecurityGroupEnabledInZone(dataCenter.getId())); |
725 | | - zoneResponse.setLocalStorageEnabled(dataCenter.isLocalStorageEnabled()); |
726 | | - |
727 | | - if ((dataCenter.getDescription() != null) && !dataCenter.getDescription().equalsIgnoreCase("null")) { |
728 | | - zoneResponse.setDescription(dataCenter.getDescription()); |
729 | | - } |
730 | | - |
731 | | - if ((account == null) || (account.getType() == Account.ACCOUNT_TYPE_ADMIN)) { |
732 | | - zoneResponse.setDns1(dataCenter.getDns1()); |
733 | | - zoneResponse.setDns2(dataCenter.getDns2()); |
734 | | - zoneResponse.setInternalDns1(dataCenter.getInternalDns1()); |
735 | | - zoneResponse.setInternalDns2(dataCenter.getInternalDns2()); |
736 | | - // FIXME zoneResponse.setVlan(dataCenter.get.getVnet()); |
737 | | - zoneResponse.setGuestCidrAddress(dataCenter.getGuestNetworkCidr()); |
738 | | - } |
| 721 | + DataCenterJoinVO vOffering = ApiDBUtils.newDataCenterView(dataCenter); |
| 722 | + return ApiDBUtils.newDataCenterResponse(vOffering, showCapacities); |
| 723 | + } |
739 | 724 |
|
740 | | - if (showCapacities != null && showCapacities) { |
741 | | - List<SummedCapacity> capacities = ApiDBUtils.getCapacityByClusterPodZone(dataCenter.getId(), null, null); |
742 | | - Set<CapacityResponse> capacityResponses = new HashSet<CapacityResponse>(); |
743 | | - float cpuOverprovisioningFactor = ApiDBUtils.getCpuOverprovisioningFactor(); |
| 725 | + public static List<CapacityResponse> getDataCenterCapacityResponse(Long zoneId){ |
| 726 | + List<SummedCapacity> capacities = ApiDBUtils.getCapacityByClusterPodZone(zoneId, null, null); |
| 727 | + Set<CapacityResponse> capacityResponses = new HashSet<CapacityResponse>(); |
| 728 | + float cpuOverprovisioningFactor = ApiDBUtils.getCpuOverprovisioningFactor(); |
744 | 729 |
|
745 | | - for (SummedCapacity capacity : capacities) { |
746 | | - CapacityResponse capacityResponse = new CapacityResponse(); |
747 | | - capacityResponse.setCapacityType(capacity.getCapacityType()); |
748 | | - capacityResponse.setCapacityUsed(capacity.getUsedCapacity()); |
749 | | - if (capacity.getCapacityType() == Capacity.CAPACITY_TYPE_CPU) { |
750 | | - capacityResponse.setCapacityTotal(new Long((long) (capacity.getTotalCapacity() * cpuOverprovisioningFactor))); |
751 | | - } else if (capacity.getCapacityType() == Capacity.CAPACITY_TYPE_STORAGE_ALLOCATED) { |
752 | | - List<SummedCapacity> c = ApiDBUtils.findNonSharedStorageForClusterPodZone(dataCenter.getId(), null, null); |
753 | | - capacityResponse.setCapacityTotal(capacity.getTotalCapacity() - c.get(0).getTotalCapacity()); |
754 | | - capacityResponse.setCapacityUsed(capacity.getUsedCapacity() - c.get(0).getUsedCapacity()); |
755 | | - } else { |
756 | | - capacityResponse.setCapacityTotal(capacity.getTotalCapacity()); |
757 | | - } |
758 | | - if (capacityResponse.getCapacityTotal() != 0) { |
759 | | - capacityResponse.setPercentUsed(s_percentFormat.format((float) capacityResponse.getCapacityUsed() / (float) capacityResponse.getCapacityTotal() * 100f)); |
760 | | - } else { |
761 | | - capacityResponse.setPercentUsed(s_percentFormat.format(0L)); |
762 | | - } |
763 | | - capacityResponses.add(capacityResponse); |
| 730 | + for (SummedCapacity capacity : capacities) { |
| 731 | + CapacityResponse capacityResponse = new CapacityResponse(); |
| 732 | + capacityResponse.setCapacityType(capacity.getCapacityType()); |
| 733 | + capacityResponse.setCapacityUsed(capacity.getUsedCapacity()); |
| 734 | + if (capacity.getCapacityType() == Capacity.CAPACITY_TYPE_CPU) { |
| 735 | + capacityResponse.setCapacityTotal(new Long((long) (capacity.getTotalCapacity() * cpuOverprovisioningFactor))); |
| 736 | + } else if (capacity.getCapacityType() == Capacity.CAPACITY_TYPE_STORAGE_ALLOCATED) { |
| 737 | + List<SummedCapacity> c = ApiDBUtils.findNonSharedStorageForClusterPodZone(zoneId, null, null); |
| 738 | + capacityResponse.setCapacityTotal(capacity.getTotalCapacity() - c.get(0).getTotalCapacity()); |
| 739 | + capacityResponse.setCapacityUsed(capacity.getUsedCapacity() - c.get(0).getUsedCapacity()); |
| 740 | + } else { |
| 741 | + capacityResponse.setCapacityTotal(capacity.getTotalCapacity()); |
764 | 742 | } |
765 | | - // Do it for stats as well. |
766 | | - capacityResponses.addAll(getStatsCapacityresponse(null, null, null, dataCenter.getId())); |
767 | | - |
768 | | - zoneResponse.setCapacitites(new ArrayList<CapacityResponse>(capacityResponses)); |
769 | | - } |
770 | | - |
771 | | - // set network domain info |
772 | | - zoneResponse.setDomain(dataCenter.getDomain()); |
773 | | - |
774 | | - // set domain info |
775 | | - Long domainId = dataCenter.getDomainId(); |
776 | | - if (domainId != null) { |
777 | | - Domain domain = ApiDBUtils.findDomainById(domainId); |
778 | | - zoneResponse.setDomainId(domain.getId()); |
779 | | - zoneResponse.setDomainName(domain.getName()); |
| 743 | + if (capacityResponse.getCapacityTotal() != 0) { |
| 744 | + capacityResponse.setPercentUsed(s_percentFormat.format((float) capacityResponse.getCapacityUsed() / (float) capacityResponse.getCapacityTotal() * 100f)); |
| 745 | + } else { |
| 746 | + capacityResponse.setPercentUsed(s_percentFormat.format(0L)); |
| 747 | + } |
| 748 | + capacityResponses.add(capacityResponse); |
780 | 749 | } |
| 750 | + // Do it for stats as well. |
| 751 | + capacityResponses.addAll(getStatsCapacityresponse(null, null, null, zoneId)); |
781 | 752 |
|
782 | | - zoneResponse.setType(dataCenter.getNetworkType().toString()); |
783 | | - zoneResponse.setAllocationState(dataCenter.getAllocationState().toString()); |
784 | | - zoneResponse.setZoneToken(dataCenter.getZoneToken()); |
785 | | - zoneResponse.setDhcpProvider(dataCenter.getDhcpProvider()); |
786 | | - zoneResponse.setObjectName("zone"); |
787 | | - return zoneResponse; |
| 753 | + return new ArrayList<CapacityResponse>(capacityResponses); |
788 | 754 | } |
789 | 755 |
|
790 | | - private List<CapacityResponse> getStatsCapacityresponse(Long poolId, Long clusterId, Long podId, Long zoneId) { |
| 756 | + private static List<CapacityResponse> getStatsCapacityresponse(Long poolId, Long clusterId, Long podId, Long zoneId) { |
791 | 757 | List<CapacityVO> capacities = new ArrayList<CapacityVO>(); |
792 | 758 | capacities.add(ApiDBUtils.getStoragePoolUsedStats(poolId, clusterId, podId, zoneId)); |
793 | 759 | if (clusterId == null && podId == null) { |
|
0 commit comments