3434import com .cloud .api .query .ViewResponseHelper ;
3535import com .cloud .api .query .vo .AccountJoinVO ;
3636import com .cloud .api .query .vo .UserAccountJoinVO ;
37+ import com .cloud .configuration .Resource ;
3738import com .cloud .configuration .Resource .ResourceType ;
3839import com .cloud .user .Account ;
3940import com .cloud .user .AccountManager ;
@@ -85,9 +86,9 @@ public AccountResponse newAccountResponse(ResponseView view, EnumSet<DomainDetai
8586
8687 //get resource limits for projects
8788 long projectLimit = ApiDBUtils .findCorrectResourceLimit (account .getProjectLimit (), account .getId (), ResourceType .project );
88- String projectLimitDisplay = (fullView || projectLimit == -1 ) ? "Unlimited" : String .valueOf (projectLimit );
89+ String projectLimitDisplay = (fullView || projectLimit == -1 ) ? Resource . UNLIMITED : String .valueOf (projectLimit );
8990 long projectTotal = (account .getProjectTotal () == null ) ? 0 : account .getProjectTotal ();
90- String projectAvail = (fullView || projectLimit == -1 ) ? "Unlimited" : String .valueOf (projectLimit - projectTotal );
91+ String projectAvail = (fullView || projectLimit == -1 ) ? Resource . UNLIMITED : String .valueOf (projectLimit - projectTotal );
9192 accountResponse .setProjectLimit (projectLimitDisplay );
9293 accountResponse .setProjectTotal (projectTotal );
9394 accountResponse .setProjectAvailable (projectAvail );
@@ -118,15 +119,15 @@ public AccountResponse newAccountResponse(ResponseView view, EnumSet<DomainDetai
118119 public void setResourceLimits (AccountJoinVO account , boolean fullView , ResourceLimitAndCountResponse response ) {
119120 // Get resource limits and counts
120121 long vmLimit = ApiDBUtils .findCorrectResourceLimit (account .getVmLimit (), account .getId (), ResourceType .user_vm );
121- String vmLimitDisplay = (fullView || vmLimit == -1 ) ? "Unlimited" : String .valueOf (vmLimit );
122+ String vmLimitDisplay = (fullView || vmLimit == -1 ) ? Resource . UNLIMITED : String .valueOf (vmLimit );
122123 long vmTotal = (account .getVmTotal () == null ) ? 0 : account .getVmTotal ();
123- String vmAvail = (fullView || vmLimit == -1 ) ? "Unlimited" : String .valueOf (vmLimit - vmTotal );
124+ String vmAvail = (fullView || vmLimit == -1 ) ? Resource . UNLIMITED : String .valueOf (vmLimit - vmTotal );
124125 response .setVmLimit (vmLimitDisplay );
125126 response .setVmTotal (vmTotal );
126127 response .setVmAvailable (vmAvail );
127128
128129 long ipLimit = ApiDBUtils .findCorrectResourceLimit (account .getIpLimit (), account .getId (), ResourceType .public_ip );
129- String ipLimitDisplay = (fullView || ipLimit == -1 ) ? "Unlimited" : String .valueOf (ipLimit );
130+ String ipLimitDisplay = (fullView || ipLimit == -1 ) ? Resource . UNLIMITED : String .valueOf (ipLimit );
130131 long ipTotal = (account .getIpTotal () == null ) ? 0 : account .getIpTotal ();
131132
132133 Long ips = ipLimit - ipTotal ;
@@ -139,32 +140,32 @@ public void setResourceLimits(AccountJoinVO account, boolean fullView, ResourceL
139140 unlimited = false ;
140141 }
141142
142- String ipAvail = ((fullView || ipLimit == -1 ) && unlimited ) ? "Unlimited" : String .valueOf (ips );
143+ String ipAvail = ((fullView || ipLimit == -1 ) && unlimited ) ? Resource . UNLIMITED : String .valueOf (ips );
143144
144145 response .setIpLimit (ipLimitDisplay );
145146 response .setIpTotal (ipTotal );
146147 response .setIpAvailable (ipAvail );
147148
148149 long volumeLimit = ApiDBUtils .findCorrectResourceLimit (account .getVolumeLimit (), account .getId (), ResourceType .volume );
149- String volumeLimitDisplay = (fullView || volumeLimit == -1 ) ? "Unlimited" : String .valueOf (volumeLimit );
150+ String volumeLimitDisplay = (fullView || volumeLimit == -1 ) ? Resource . UNLIMITED : String .valueOf (volumeLimit );
150151 long volumeTotal = (account .getVolumeTotal () == null ) ? 0 : account .getVolumeTotal ();
151- String volumeAvail = (fullView || volumeLimit == -1 ) ? "Unlimited" : String .valueOf (volumeLimit - volumeTotal );
152+ String volumeAvail = (fullView || volumeLimit == -1 ) ? Resource . UNLIMITED : String .valueOf (volumeLimit - volumeTotal );
152153 response .setVolumeLimit (volumeLimitDisplay );
153154 response .setVolumeTotal (volumeTotal );
154155 response .setVolumeAvailable (volumeAvail );
155156
156157 long snapshotLimit = ApiDBUtils .findCorrectResourceLimit (account .getSnapshotLimit (), account .getId (), ResourceType .snapshot );
157- String snapshotLimitDisplay = (fullView || snapshotLimit == -1 ) ? "Unlimited" : String .valueOf (snapshotLimit );
158+ String snapshotLimitDisplay = (fullView || snapshotLimit == -1 ) ? Resource . UNLIMITED : String .valueOf (snapshotLimit );
158159 long snapshotTotal = (account .getSnapshotTotal () == null ) ? 0 : account .getSnapshotTotal ();
159- String snapshotAvail = (fullView || snapshotLimit == -1 ) ? "Unlimited" : String .valueOf (snapshotLimit - snapshotTotal );
160+ String snapshotAvail = (fullView || snapshotLimit == -1 ) ? Resource . UNLIMITED : String .valueOf (snapshotLimit - snapshotTotal );
160161 response .setSnapshotLimit (snapshotLimitDisplay );
161162 response .setSnapshotTotal (snapshotTotal );
162163 response .setSnapshotAvailable (snapshotAvail );
163164
164165 Long templateLimit = ApiDBUtils .findCorrectResourceLimit (account .getTemplateLimit (), account .getId (), ResourceType .template );
165- String templateLimitDisplay = (fullView || templateLimit == -1 ) ? "Unlimited" : String .valueOf (templateLimit );
166+ String templateLimitDisplay = (fullView || templateLimit == -1 ) ? Resource . UNLIMITED : String .valueOf (templateLimit );
166167 Long templateTotal = (account .getTemplateTotal () == null ) ? 0 : account .getTemplateTotal ();
167- String templateAvail = (fullView || templateLimit == -1 ) ? "Unlimited" : String .valueOf (templateLimit - templateTotal );
168+ String templateAvail = (fullView || templateLimit == -1 ) ? Resource . UNLIMITED : String .valueOf (templateLimit - templateTotal );
168169 response .setTemplateLimit (templateLimitDisplay );
169170 response .setTemplateTotal (templateTotal );
170171 response .setTemplateAvailable (templateAvail );
@@ -175,55 +176,55 @@ public void setResourceLimits(AccountJoinVO account, boolean fullView, ResourceL
175176
176177 //get resource limits for networks
177178 long networkLimit = ApiDBUtils .findCorrectResourceLimit (account .getNetworkLimit (), account .getId (), ResourceType .network );
178- String networkLimitDisplay = (fullView || networkLimit == -1 ) ? "Unlimited" : String .valueOf (networkLimit );
179+ String networkLimitDisplay = (fullView || networkLimit == -1 ) ? Resource . UNLIMITED : String .valueOf (networkLimit );
179180 long networkTotal = (account .getNetworkTotal () == null ) ? 0 : account .getNetworkTotal ();
180- String networkAvail = (fullView || networkLimit == -1 ) ? "Unlimited" : String .valueOf (networkLimit - networkTotal );
181+ String networkAvail = (fullView || networkLimit == -1 ) ? Resource . UNLIMITED : String .valueOf (networkLimit - networkTotal );
181182 response .setNetworkLimit (networkLimitDisplay );
182183 response .setNetworkTotal (networkTotal );
183184 response .setNetworkAvailable (networkAvail );
184185
185186 //get resource limits for vpcs
186187 long vpcLimit = ApiDBUtils .findCorrectResourceLimit (account .getVpcLimit (), account .getId (), ResourceType .vpc );
187- String vpcLimitDisplay = (fullView || vpcLimit == -1 ) ? "Unlimited" : String .valueOf (vpcLimit );
188+ String vpcLimitDisplay = (fullView || vpcLimit == -1 ) ? Resource . UNLIMITED : String .valueOf (vpcLimit );
188189 long vpcTotal = (account .getVpcTotal () == null ) ? 0 : account .getVpcTotal ();
189- String vpcAvail = (fullView || vpcLimit == -1 ) ? "Unlimited" : String .valueOf (vpcLimit - vpcTotal );
190+ String vpcAvail = (fullView || vpcLimit == -1 ) ? Resource . UNLIMITED : String .valueOf (vpcLimit - vpcTotal );
190191 response .setVpcLimit (vpcLimitDisplay );
191192 response .setVpcTotal (vpcTotal );
192193 response .setVpcAvailable (vpcAvail );
193194
194195 //get resource limits for cpu cores
195196 long cpuLimit = ApiDBUtils .findCorrectResourceLimit (account .getCpuLimit (), account .getId (), ResourceType .cpu );
196- String cpuLimitDisplay = (fullView || cpuLimit == -1 ) ? "Unlimited" : String .valueOf (cpuLimit );
197+ String cpuLimitDisplay = (fullView || cpuLimit == -1 ) ? Resource . UNLIMITED : String .valueOf (cpuLimit );
197198 long cpuTotal = (account .getCpuTotal () == null ) ? 0 : account .getCpuTotal ();
198- String cpuAvail = (fullView || cpuLimit == -1 ) ? "Unlimited" : String .valueOf (cpuLimit - cpuTotal );
199+ String cpuAvail = (fullView || cpuLimit == -1 ) ? Resource . UNLIMITED : String .valueOf (cpuLimit - cpuTotal );
199200 response .setCpuLimit (cpuLimitDisplay );
200201 response .setCpuTotal (cpuTotal );
201202 response .setCpuAvailable (cpuAvail );
202203
203204 //get resource limits for memory
204205 long memoryLimit = ApiDBUtils .findCorrectResourceLimit (account .getMemoryLimit (), account .getId (), ResourceType .memory );
205- String memoryLimitDisplay = (fullView || memoryLimit == -1 ) ? "Unlimited" : String .valueOf (memoryLimit );
206+ String memoryLimitDisplay = (fullView || memoryLimit == -1 ) ? Resource . UNLIMITED : String .valueOf (memoryLimit );
206207 long memoryTotal = (account .getMemoryTotal () == null ) ? 0 : account .getMemoryTotal ();
207- String memoryAvail = (fullView || memoryLimit == -1 ) ? "Unlimited" : String .valueOf (memoryLimit - memoryTotal );
208+ String memoryAvail = (fullView || memoryLimit == -1 ) ? Resource . UNLIMITED : String .valueOf (memoryLimit - memoryTotal );
208209 response .setMemoryLimit (memoryLimitDisplay );
209210 response .setMemoryTotal (memoryTotal );
210211 response .setMemoryAvailable (memoryAvail );
211212
212213 //get resource limits for primary storage space and convert it from Bytes to GiB
213214 long primaryStorageLimit = ApiDBUtils .findCorrectResourceLimit (account .getPrimaryStorageLimit (), account .getId (), ResourceType .primary_storage );
214- String primaryStorageLimitDisplay = (fullView || primaryStorageLimit == -1 ) ? "Unlimited" : String .valueOf (primaryStorageLimit / ResourceType .bytesToGiB );
215+ String primaryStorageLimitDisplay = (fullView || primaryStorageLimit == -1 ) ? Resource . UNLIMITED : String .valueOf (primaryStorageLimit / ResourceType .bytesToGiB );
215216 long primaryStorageTotal = (account .getPrimaryStorageTotal () == null ) ? 0 : (account .getPrimaryStorageTotal () / ResourceType .bytesToGiB );
216- String primaryStorageAvail = (fullView || primaryStorageLimit == -1 ) ? "Unlimited" : String .valueOf ((primaryStorageLimit / ResourceType .bytesToGiB ) - primaryStorageTotal );
217+ String primaryStorageAvail = (fullView || primaryStorageLimit == -1 ) ? Resource . UNLIMITED : String .valueOf ((primaryStorageLimit / ResourceType .bytesToGiB ) - primaryStorageTotal );
217218
218219 response .setPrimaryStorageLimit (primaryStorageLimitDisplay );
219220 response .setPrimaryStorageTotal (primaryStorageTotal );
220221 response .setPrimaryStorageAvailable (primaryStorageAvail );
221222
222223 //get resource limits for secondary storage space and convert it from Bytes to GiB
223224 long secondaryStorageLimit = ApiDBUtils .findCorrectResourceLimit (account .getSecondaryStorageLimit (), account .getId (), ResourceType .secondary_storage );
224- String secondaryStorageLimitDisplay = (fullView || secondaryStorageLimit == -1 ) ? "Unlimited" : String .valueOf (secondaryStorageLimit / ResourceType .bytesToGiB );
225+ String secondaryStorageLimitDisplay = (fullView || secondaryStorageLimit == -1 ) ? Resource . UNLIMITED : String .valueOf (secondaryStorageLimit / ResourceType .bytesToGiB );
225226 float secondaryStorageTotal = (account .getSecondaryStorageTotal () == null ) ? 0 : (account .getSecondaryStorageTotal () / (ResourceType .bytesToGiB * 1f ));
226- String secondaryStorageAvail = (fullView || secondaryStorageLimit == -1 ) ? "Unlimited" : String .valueOf ((secondaryStorageLimit / ResourceType .bytesToGiB )
227+ String secondaryStorageAvail = (fullView || secondaryStorageLimit == -1 ) ? Resource . UNLIMITED : String .valueOf (( ( double ) secondaryStorageLimit / ResourceType .bytesToGiB )
227228 - secondaryStorageTotal );
228229
229230 response .setSecondaryStorageLimit (secondaryStorageLimitDisplay );
0 commit comments