|
27 | 27 | import javax.naming.ConfigurationException; |
28 | 28 |
|
29 | 29 | import com.cloud.domain.Domain; |
| 30 | +import com.cloud.offerings.NetworkOfferingVO; |
| 31 | +import com.cloud.offerings.dao.NetworkOfferingDao; |
30 | 32 | import org.apache.cloudstack.api.command.admin.usage.GenerateUsageRecordsCmd; |
31 | 33 | import org.apache.cloudstack.api.command.admin.usage.ListUsageRecordsCmd; |
32 | 34 | import org.apache.cloudstack.api.command.admin.usage.RemoveRawUsageRecordsCmd; |
@@ -122,6 +124,8 @@ public class UsageServiceImpl extends ManagerBase implements UsageService, Manag |
122 | 124 | private IPAddressDao _ipDao; |
123 | 125 | @Inject |
124 | 126 | private HostDao _hostDao; |
| 127 | + @Inject |
| 128 | + private NetworkOfferingDao _networkOfferingDao; |
125 | 129 |
|
126 | 130 | public UsageServiceImpl() { |
127 | 131 | } |
@@ -253,6 +257,7 @@ public Pair<List<? extends Usage>, Integer> getUsageRecords(ListUsageRecordsCmd |
253 | 257 | } |
254 | 258 |
|
255 | 259 | Long usageDbId = null; |
| 260 | + boolean offeringExistsForNetworkOfferingType = false; |
256 | 261 |
|
257 | 262 | switch (usageType.intValue()) { |
258 | 263 | case UsageTypes.NETWORK_BYTES_RECEIVED: |
@@ -326,13 +331,19 @@ public Pair<List<? extends Usage>, Integer> getUsageRecords(ListUsageRecordsCmd |
326 | 331 | usageDbId = ip.getId(); |
327 | 332 | } |
328 | 333 | break; |
| 334 | + case UsageTypes.NETWORK_OFFERING: |
| 335 | + NetworkOfferingVO networkOffering = _networkOfferingDao.findByUuidIncludingRemoved(usageId); |
| 336 | + if (networkOffering != null) { |
| 337 | + offeringExistsForNetworkOfferingType = true; |
| 338 | + sc.addAnd("offeringId", SearchCriteria.Op.EQ, networkOffering.getId()); |
| 339 | + } |
329 | 340 | default: |
330 | 341 | break; |
331 | 342 | } |
332 | 343 |
|
333 | 344 | if (usageDbId != null) { |
334 | 345 | sc.addAnd("usageId", SearchCriteria.Op.EQ, usageDbId); |
335 | | - } else { |
| 346 | + } else if (!offeringExistsForNetworkOfferingType) { |
336 | 347 | // return an empty list if usageId was not found |
337 | 348 | return new Pair<List<? extends Usage>, Integer>(new ArrayList<Usage>(), new Integer(0)); |
338 | 349 | } |
|
0 commit comments