List usage records for network offering (usage type 13) when offering id is specified in usage id (#10852)

This commit is contained in:
Suresh Kumar Anaparti 2025-05-14 13:55:11 +05:30 committed by GitHub
parent 8d3ae3e057
commit a4cce70e28
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -27,6 +27,8 @@ import javax.inject.Inject;
import javax.naming.ConfigurationException;
import com.cloud.domain.Domain;
import com.cloud.offerings.NetworkOfferingVO;
import com.cloud.offerings.dao.NetworkOfferingDao;
import org.apache.cloudstack.api.command.admin.usage.GenerateUsageRecordsCmd;
import org.apache.cloudstack.api.command.admin.usage.ListUsageRecordsCmd;
import org.apache.cloudstack.api.command.admin.usage.RemoveRawUsageRecordsCmd;
@ -122,6 +124,8 @@ public class UsageServiceImpl extends ManagerBase implements UsageService, Manag
private IPAddressDao _ipDao;
@Inject
private HostDao _hostDao;
@Inject
private NetworkOfferingDao _networkOfferingDao;
public UsageServiceImpl() {
}
@ -253,6 +257,7 @@ public class UsageServiceImpl extends ManagerBase implements UsageService, Manag
}
Long usageDbId = null;
boolean offeringExistsForNetworkOfferingType = false;
switch (usageType.intValue()) {
case UsageTypes.NETWORK_BYTES_RECEIVED:
@ -326,13 +331,19 @@ public class UsageServiceImpl extends ManagerBase implements UsageService, Manag
usageDbId = ip.getId();
}
break;
case UsageTypes.NETWORK_OFFERING:
NetworkOfferingVO networkOffering = _networkOfferingDao.findByUuidIncludingRemoved(usageId);
if (networkOffering != null) {
offeringExistsForNetworkOfferingType = true;
sc.addAnd("offeringId", SearchCriteria.Op.EQ, networkOffering.getId());
}
default:
break;
}
if (usageDbId != null) {
sc.addAnd("usageId", SearchCriteria.Op.EQ, usageDbId);
} else {
} else if (!offeringExistsForNetworkOfferingType) {
// return an empty list if usageId was not found
return new Pair<List<? extends Usage>, Integer>(new ArrayList<Usage>(), new Integer(0));
}