|
28 | 28 |
|
29 | 29 | import com.cloud.domain.Domain; |
30 | 30 | import com.cloud.utils.DateUtil; |
| 31 | +import com.cloud.offerings.NetworkOfferingVO; |
| 32 | +import com.cloud.offerings.dao.NetworkOfferingDao; |
31 | 33 | import org.apache.cloudstack.api.command.admin.usage.GenerateUsageRecordsCmd; |
32 | 34 | import org.apache.cloudstack.api.command.admin.usage.ListUsageRecordsCmd; |
33 | 35 | import org.apache.cloudstack.api.command.admin.usage.RemoveRawUsageRecordsCmd; |
@@ -121,6 +123,8 @@ public class UsageServiceImpl extends ManagerBase implements UsageService, Manag |
121 | 123 | private IPAddressDao _ipDao; |
122 | 124 | @Inject |
123 | 125 | private HostDao _hostDao; |
| 126 | + @Inject |
| 127 | + private NetworkOfferingDao _networkOfferingDao; |
124 | 128 |
|
125 | 129 | public UsageServiceImpl() { |
126 | 130 | } |
@@ -245,6 +249,7 @@ public Pair<List<? extends Usage>, Integer> getUsageRecords(ListUsageRecordsCmd |
245 | 249 | } |
246 | 250 |
|
247 | 251 | Long usageDbId = null; |
| 252 | + boolean offeringExistsForNetworkOfferingType = false; |
248 | 253 |
|
249 | 254 | switch (usageType.intValue()) { |
250 | 255 | case UsageTypes.NETWORK_BYTES_RECEIVED: |
@@ -318,13 +323,19 @@ public Pair<List<? extends Usage>, Integer> getUsageRecords(ListUsageRecordsCmd |
318 | 323 | usageDbId = ip.getId(); |
319 | 324 | } |
320 | 325 | break; |
| 326 | + case UsageTypes.NETWORK_OFFERING: |
| 327 | + NetworkOfferingVO networkOffering = _networkOfferingDao.findByUuidIncludingRemoved(usageId); |
| 328 | + if (networkOffering != null) { |
| 329 | + offeringExistsForNetworkOfferingType = true; |
| 330 | + sc.addAnd("offeringId", SearchCriteria.Op.EQ, networkOffering.getId()); |
| 331 | + } |
321 | 332 | default: |
322 | 333 | break; |
323 | 334 | } |
324 | 335 |
|
325 | 336 | if (usageDbId != null) { |
326 | 337 | sc.addAnd("usageId", SearchCriteria.Op.EQ, usageDbId); |
327 | | - } else { |
| 338 | + } else if (!offeringExistsForNetworkOfferingType) { |
328 | 339 | // return an empty list if usageId was not found |
329 | 340 | return new Pair<List<? extends Usage>, Integer>(new ArrayList<Usage>(), new Integer(0)); |
330 | 341 | } |
|
0 commit comments