Skip to content

Commit 5a1cb60

Browse files
sureshanapartidhslove
authored andcommitted
List usage records for network offering (usage type 13) when offering id is specified in usage id (apache#10852)
1 parent 139e3b2 commit 5a1cb60

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

server/src/main/java/com/cloud/usage/UsageServiceImpl.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828

2929
import com.cloud.domain.Domain;
3030
import com.cloud.utils.DateUtil;
31+
import com.cloud.offerings.NetworkOfferingVO;
32+
import com.cloud.offerings.dao.NetworkOfferingDao;
3133
import org.apache.cloudstack.api.command.admin.usage.GenerateUsageRecordsCmd;
3234
import org.apache.cloudstack.api.command.admin.usage.ListUsageRecordsCmd;
3335
import org.apache.cloudstack.api.command.admin.usage.RemoveRawUsageRecordsCmd;
@@ -121,6 +123,8 @@ public class UsageServiceImpl extends ManagerBase implements UsageService, Manag
121123
private IPAddressDao _ipDao;
122124
@Inject
123125
private HostDao _hostDao;
126+
@Inject
127+
private NetworkOfferingDao _networkOfferingDao;
124128

125129
public UsageServiceImpl() {
126130
}
@@ -245,6 +249,7 @@ public Pair<List<? extends Usage>, Integer> getUsageRecords(ListUsageRecordsCmd
245249
}
246250

247251
Long usageDbId = null;
252+
boolean offeringExistsForNetworkOfferingType = false;
248253

249254
switch (usageType.intValue()) {
250255
case UsageTypes.NETWORK_BYTES_RECEIVED:
@@ -318,13 +323,19 @@ public Pair<List<? extends Usage>, Integer> getUsageRecords(ListUsageRecordsCmd
318323
usageDbId = ip.getId();
319324
}
320325
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+
}
321332
default:
322333
break;
323334
}
324335

325336
if (usageDbId != null) {
326337
sc.addAnd("usageId", SearchCriteria.Op.EQ, usageDbId);
327-
} else {
338+
} else if (!offeringExistsForNetworkOfferingType) {
328339
// return an empty list if usageId was not found
329340
return new Pair<List<? extends Usage>, Integer>(new ArrayList<Usage>(), new Integer(0));
330341
}

0 commit comments

Comments
 (0)