Bug 13599: Used IdentityDao to map usage records to correct UUIDs

Status 13599: resolved fixed
Reviewed-By: Nitin
This commit is contained in:
kishan 2012-02-10 16:34:02 +05:30
parent c7337f00be
commit 9a6e0abe8c
2 changed files with 110 additions and 53 deletions

View File

@ -41,6 +41,8 @@ import com.cloud.server.api.response.UsageRecordResponse;
import com.cloud.usage.UsageTypes;
import com.cloud.usage.UsageVO;
import com.cloud.user.Account;
import com.cloud.uuididentity.dao.IdentityDao;
import com.cloud.uuididentity.dao.IdentityDaoImpl;
@Implementation(description="Lists usage records for accounts", responseObject=UsageRecordResponse.class)
public class GetUsageRecordsCmd extends BaseListCmd {
@ -218,7 +220,8 @@ public class GetUsageRecordsCmd extends BaseListCmd {
@Override
public void execute(){
ManagementServerExt _mgrExt = (ManagementServerExt)_mgr;
List<UsageVO> usageRecords = _mgrExt.getUsageRecords(this);
List<UsageVO> usageRecords = _mgrExt.getUsageRecords(this);
IdentityDao identityDao = new IdentityDaoImpl();
ListResponse<UsageRecordResponse> response = new ListResponse<UsageRecordResponse>();
List<UsageRecordResponse> usageResponses = new ArrayList<UsageRecordResponse>();
for (Object usageRecordGeneric : usageRecords) {
@ -244,18 +247,79 @@ public class GetUsageRecordsCmd extends BaseListCmd {
usageRecResponse.setUsage(usageRecord.getUsageDisplay());
usageRecResponse.setUsageType(usageRecord.getUsageType());
usageRecResponse.setVirtualMachineId(usageRecord.getVmInstanceId());
usageRecResponse.setVmName(usageRecord.getVmName());
usageRecResponse.setServiceOfferingId(usageRecord.getOfferingId());
usageRecResponse.setTemplateId(usageRecord.getTemplateId());
usageRecResponse.setUsageId(usageRecord.getUsageId());
if(usageRecord.getUsageType() == UsageTypes.IP_ADDRESS){
usageRecResponse.setVmName(usageRecord.getVmName());
usageRecResponse.setTemplateId(usageRecord.getTemplateId());
if(usageRecord.getUsageType() == UsageTypes.RUNNING_VM || usageRecord.getUsageType() == UsageTypes.ALLOCATED_VM){
//Service Offering Id
usageRecResponse.setOfferingId(identityDao.getIdentityUuid("disk_offering", usageRecord.getOfferingId().toString()));
//VM Instance ID
usageRecResponse.setUsageId(identityDao.getIdentityUuid("vm_instance", usageRecord.getUsageId().toString()));
//Hypervisor Type
usageRecResponse.setType(usageRecord.getType());
} else if(usageRecord.getUsageType() == UsageTypes.IP_ADDRESS){
//isSourceNAT
usageRecResponse.setSourceNat((usageRecord.getType().equals("SourceNat"))?true:false);
//isElastic
usageRecResponse.setElastic((usageRecord.getSize() == 1)?true:false);
} else {
usageRecResponse.setType(usageRecord.getType());
//IP Address ID
usageRecResponse.setUsageId(identityDao.getIdentityUuid("user_ip_address", usageRecord.getUsageId().toString()));
} else if(usageRecord.getUsageType() == UsageTypes.NETWORK_BYTES_SENT || usageRecord.getUsageType() == UsageTypes.NETWORK_BYTES_RECEIVED){
//Device Type
usageRecResponse.setType(usageRecord.getType());
if(usageRecord.getType().equals("DomainRouter")){
//Domain Router Id
usageRecResponse.setUsageId(identityDao.getIdentityUuid("vm_instance", usageRecord.getUsageId().toString()));
} else {
//External Device Host Id
usageRecResponse.setUsageId(identityDao.getIdentityUuid("host", usageRecord.getUsageId().toString()));
}
//Network ID
usageRecResponse.setNetworkId(identityDao.getIdentityUuid("networks", usageRecord.getNetworkId().toString()));
} else if(usageRecord.getUsageType() == UsageTypes.VOLUME){
//Volume ID
usageRecResponse.setUsageId(identityDao.getIdentityUuid("volumes", usageRecord.getUsageId().toString()));
//Volume Size
usageRecResponse.setSize(usageRecord.getSize());
}
//Disk Offering Id
if(usageRecord.getOfferingId() != null){
usageRecResponse.setOfferingId(identityDao.getIdentityUuid("disk_offering", usageRecord.getOfferingId().toString()));
}
} else if(usageRecord.getUsageType() == UsageTypes.TEMPLATE || usageRecord.getUsageType() == UsageTypes.ISO){
//Template/ISO ID
usageRecResponse.setUsageId(identityDao.getIdentityUuid("vm_template", usageRecord.getUsageId().toString()));
//Template/ISO Size
usageRecResponse.setSize(usageRecord.getSize());
} else if(usageRecord.getUsageType() == UsageTypes.SNAPSHOT){
//Snapshot ID
usageRecResponse.setUsageId(identityDao.getIdentityUuid("snapshots", usageRecord.getUsageId().toString()));
//Snapshot Size
usageRecResponse.setSize(usageRecord.getSize());
} else if(usageRecord.getUsageType() == UsageTypes.LOAD_BALANCER_POLICY){
//Load Balancer Policy ID
usageRecResponse.setUsageId(usageRecord.getUsageId().toString());
} else if(usageRecord.getUsageType() == UsageTypes.PORT_FORWARDING_RULE){
//Port Forwarding Rule ID
usageRecResponse.setUsageId(usageRecord.getUsageId().toString());
} else if(usageRecord.getUsageType() == UsageTypes.NETWORK_OFFERING){
//Network Offering Id
usageRecResponse.setOfferingId(identityDao.getIdentityUuid("network_offerings", usageRecord.getOfferingId().toString()));
//is Default
usageRecResponse.setDefault((usageRecord.getUsageId() == 1)? true:false);
} else if(usageRecord.getUsageType() == UsageTypes.VPN_USERS){
//VPN User ID
usageRecResponse.setUsageId(usageRecord.getUsageId().toString());
}
if (usageRecord.getRawUsage() != null) {
DecimalFormat decimalFormat = new DecimalFormat("###########.######");
usageRecResponse.setRawUsage(decimalFormat.format(usageRecord.getRawUsage()));

View File

@ -34,75 +34,72 @@ public class UsageRecordResponse extends BaseResponse implements ControlledEntit
@SerializedName(ApiConstants.ACCOUNT_ID) @Param(description="the user account Id")
private IdentityProxy accountId = new IdentityProxy("account");
@SerializedName(ApiConstants.PROJECT_ID) @Param(description="the project id of the ipaddress")
@SerializedName(ApiConstants.PROJECT_ID) @Param(description="the project id of the resource")
private IdentityProxy projectId = new IdentityProxy("projects");
@SerializedName(ApiConstants.PROJECT) @Param(description="the project name of the address")
@SerializedName(ApiConstants.PROJECT) @Param(description="the project name of the resource")
private String projectName;
@SerializedName(ApiConstants.DOMAIN_ID) @Param(description="the domain ID number")
@SerializedName(ApiConstants.DOMAIN_ID) @Param(description="the domain ID")
private IdentityProxy domainId = new IdentityProxy("domain");
@SerializedName(ApiConstants.DOMAIN) @Param(description="the domain the public IP address is associated with")
@SerializedName(ApiConstants.DOMAIN) @Param(description="the domain the resource is associated with")
private String domainName;
@SerializedName(ApiConstants.ZONE_ID) @Param(description="the zone ID number")
@SerializedName(ApiConstants.ZONE_ID) @Param(description="the zone ID")
private IdentityProxy zoneId = new IdentityProxy("data_center");
@SerializedName(ApiConstants.DESCRIPTION) @Param(description="description of account, including account name, service offering, and template")
@SerializedName(ApiConstants.DESCRIPTION) @Param(description="description of the usage record")
private String description;
@SerializedName("usage") @Param(description="usage in hours")
private String usage;
@SerializedName("usagetype") @Param(description="usage type")
@SerializedName("usagetype") @Param(description="usage type ID")
private Integer usageType;
@SerializedName("rawusage") @Param(description="raw usage in hours")
private String rawUsage;
@SerializedName(ApiConstants.VIRTUAL_MACHINE_ID) @Param(description="virtual machine ID number")
@SerializedName(ApiConstants.VIRTUAL_MACHINE_ID) @Param(description="virtual machine ID")
private IdentityProxy virtualMachineId = new IdentityProxy("vm_instance");
@SerializedName(ApiConstants.NAME) @Param(description="virtual machine name")
private String vmName;
@SerializedName("offeringid") @Param(description="service offering ID number")
private IdentityProxy serviceOfferingId = new IdentityProxy("disk_offering");
@SerializedName("offeringid") @Param(description="offering ID")
private String offeringId;
@SerializedName(ApiConstants.TEMPLATE_ID) @Param(description="template ID number")
@SerializedName(ApiConstants.TEMPLATE_ID) @Param(description="template ID")
private IdentityProxy templateId = new IdentityProxy("vm_template");
@SerializedName("usageid") @Param(description="id of the usage entity")
private Long usageId;
@SerializedName("usageid") @Param(description="id of the resource")
private String usageId;
@SerializedName(ApiConstants.TYPE) @Param(description="type")
@SerializedName(ApiConstants.TYPE) @Param(description="resource type")
private String type;
@SerializedName(ApiConstants.SIZE)
@SerializedName(ApiConstants.SIZE) @Param(description="resource size")
private Long size;
@SerializedName(ApiConstants.START_DATE) @Param(description="start date of account")
@SerializedName(ApiConstants.START_DATE) @Param(description="start date of the usage record")
private String startDate;
@SerializedName(ApiConstants.END_DATE) @Param(description="end date of account")
@SerializedName(ApiConstants.END_DATE) @Param(description="end date of the usage record")
private String endDate;
@SerializedName(ApiConstants.IP_ADDRESS) @Param(description="the IP address")
private String ipAddress;
@SerializedName("assigneddate") @Param(description="the assign date of the account")
private String assignedDate;
@SerializedName("releaseddate") @Param(description="the release date of the account")
private String releasedDate;
@SerializedName("issourcenat") @Param(description="source Nat flag for IPAddress")
@SerializedName("issourcenat") @Param(description="True if the IPAddress is source NAT")
private Boolean isSourceNat;
@SerializedName("iselastic") @Param(description="Elastic flag for IPAddress")
@SerializedName("iselastic") @Param(description="True if the IPAddress is elastic")
private Boolean isElastic;
@SerializedName("networkid") @Param(description="id of the network")
private String networkId;
@SerializedName("isdefault") @Param(description="True if the resource is default")
private Boolean isDefault;
@Override
public void setAccountName(String accountName) {
this.accountName = accountName;
@ -145,15 +142,15 @@ public class UsageRecordResponse extends BaseResponse implements ControlledEntit
this.vmName = vmName;
}
public void setServiceOfferingId(Long serviceOfferingId) {
this.serviceOfferingId.setValue(serviceOfferingId);
public void setOfferingId(String offeringId) {
this.offeringId = offeringId;
}
public void setTemplateId(Long templateId) {
this.templateId.setValue(templateId);
}
public void setUsageId(Long usageId) {
public void setUsageId(String usageId) {
this.usageId = usageId;
}
@ -173,18 +170,6 @@ public class UsageRecordResponse extends BaseResponse implements ControlledEntit
this.endDate = endDate;
}
public void setIpAddress(String ipAddress) {
this.ipAddress = ipAddress;
}
public void setAssignedDate(String assignedDate) {
this.assignedDate = assignedDate;
}
public void setReleasedDate(String releasedDate) {
this.releasedDate = releasedDate;
}
public void setSourceNat(Boolean isSourceNat) {
this.isSourceNat = isSourceNat;
}
@ -207,4 +192,12 @@ public class UsageRecordResponse extends BaseResponse implements ControlledEntit
public void setDomainName(String domainName) {
this.domainName = domainName;
}
public void setNetworkId(String networkId) {
this.networkId = networkId;
}
public void setDefault(Boolean isDefault) {
this.isDefault = isDefault;
}
}