diff --git a/api/src/main/java/org/apache/cloudstack/api/ApiConstants.java b/api/src/main/java/org/apache/cloudstack/api/ApiConstants.java index 0087fee3340..aa4eebc929e 100644 --- a/api/src/main/java/org/apache/cloudstack/api/ApiConstants.java +++ b/api/src/main/java/org/apache/cloudstack/api/ApiConstants.java @@ -256,6 +256,7 @@ public class ApiConstants { public static final String OLD_FORMAT = "oldformat"; public static final String OP = "op"; public static final String OS_CATEGORY_ID = "oscategoryid"; + public static final String OS_CATEGORY_NAME = "oscategoryname"; public static final String OS_ID = "osid"; public static final String OS_TYPE_ID = "ostypeid"; public static final String OS_DISPLAY_NAME = "osdisplayname"; diff --git a/api/src/main/java/org/apache/cloudstack/api/response/UsageRecordResponse.java b/api/src/main/java/org/apache/cloudstack/api/response/UsageRecordResponse.java index 8710790a507..7bcb1afd2d2 100644 --- a/api/src/main/java/org/apache/cloudstack/api/response/UsageRecordResponse.java +++ b/api/src/main/java/org/apache/cloudstack/api/response/UsageRecordResponse.java @@ -16,16 +16,15 @@ // under the License. package org.apache.cloudstack.api.response; -import com.google.gson.annotations.SerializedName; - -import org.apache.cloudstack.api.ApiConstants; - -import com.cloud.serializer.Param; -import org.apache.cloudstack.api.BaseResponseWithTagInformation; - import java.util.LinkedHashSet; import java.util.Set; +import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.BaseResponseWithTagInformation; + +import com.cloud.serializer.Param; +import com.google.gson.annotations.SerializedName; + @SuppressWarnings("unused") public class UsageRecordResponse extends BaseResponseWithTagInformation implements ControlledEntityResponse { @SerializedName(ApiConstants.ACCOUNT) @@ -89,8 +88,20 @@ public class UsageRecordResponse extends BaseResponseWithTagInformation implemen private String templateId; @SerializedName(ApiConstants.OS_TYPE_ID) - @Param(description = "virtual machine os type id") - private Long osTypeId; + @Param(description = "virtual machine os type ID") + private String osTypeId; + + @SerializedName(ApiConstants.OS_DISPLAY_NAME) + @Param(description = "virtual machine os display name") + private String osDisplayName; + + @SerializedName(ApiConstants.OS_CATEGORY_ID) + @Param(description = "virtual machine guest os category ID") + private String osCategoryId; + + @SerializedName(ApiConstants.OS_CATEGORY_NAME) + @Param(description = "virtual machine os category name") + private String osCategoryName; @SerializedName("usageid") @Param(description = "id of the resource") @@ -206,10 +217,22 @@ public class UsageRecordResponse extends BaseResponseWithTagInformation implemen this.templateId = templateId; } - public void setOsTypeId(Long osTypeId) { + public void setOsTypeId(String osTypeId) { this.osTypeId = osTypeId; } + public void setOsDisplayName(String osDisplayName) { + this.osDisplayName = osDisplayName; + } + + public void setOsCategoryId(String osCategoryId) { + this.osCategoryId = osCategoryId; + } + + public void setOsCategoryName(String osCategoryName) { + this.osCategoryName = osCategoryName; + } + public void setUsageId(String usageId) { this.usageId = usageId; } diff --git a/server/src/main/java/com/cloud/api/ApiResponseHelper.java b/server/src/main/java/com/cloud/api/ApiResponseHelper.java index 473c501b52f..67a6709d402 100644 --- a/server/src/main/java/com/cloud/api/ApiResponseHelper.java +++ b/server/src/main/java/com/cloud/api/ApiResponseHelper.java @@ -306,6 +306,7 @@ import com.cloud.storage.DiskOfferingVO; import com.cloud.storage.GuestOS; import com.cloud.storage.GuestOSCategoryVO; import com.cloud.storage.GuestOSHypervisor; +import com.cloud.storage.GuestOsCategory; import com.cloud.storage.ImageStore; import com.cloud.storage.Snapshot; import com.cloud.storage.SnapshotVO; @@ -315,6 +316,8 @@ import com.cloud.storage.UploadVO; import com.cloud.storage.VMTemplateVO; import com.cloud.storage.Volume; import com.cloud.storage.VolumeVO; +import com.cloud.storage.dao.GuestOSCategoryDao; +import com.cloud.storage.dao.GuestOSDao; import com.cloud.storage.dao.VolumeDao; import com.cloud.storage.snapshot.SnapshotPolicy; import com.cloud.storage.snapshot.SnapshotSchedule; @@ -394,6 +397,10 @@ public class ApiResponseHelper implements ResponseGenerator { private VMSnapshotDao vmSnapshotDao; @Inject private BackupOfferingDao backupOfferingDao; + @Inject + private GuestOSCategoryDao _guestOsCategoryDao; + @Inject + private GuestOSDao _guestOsDao; @Override public UserResponse createUserResponse(User user) { @@ -3395,7 +3402,16 @@ public class ApiResponseHelper implements ResponseGenerator { resourceType = ResourceTag.ResourceObjectType.UserVm; usageRecResponse.setUsageId(vm.getUuid()); resourceId = vm.getId(); - usageRecResponse.setOsTypeId(vm.getGuestOSId()); + final GuestOS guestOS = _guestOsDao.findById(vm.getGuestOSId()); + if (guestOS != null) { + usageRecResponse.setOsTypeId(guestOS.getUuid()); + usageRecResponse.setOsDisplayName(guestOS.getDisplayName()); + final GuestOsCategory guestOsCategory = _guestOsCategoryDao.findById(guestOS.getCategoryId()); + if (guestOsCategory != null) { + usageRecResponse.setOsCategoryId(guestOsCategory.getUuid()); + usageRecResponse.setOsCategoryName(guestOsCategory.getName()); + } + } } //Hypervisor Type usageRecResponse.setType(usageRecord.getType());