Skip to content

Commit

Permalink
server: Replace Hashtable with LinkedHashMap in createIsoResponse (ap…
Browse files Browse the repository at this point in the history
…ache#7844)

* Replace Hashtable with LinkedHashMap in createIsoResponse

This change replaces the use of Hashtable with LinkedHashMap in the `createIsoResponse` method of `ViewResponseHelper`.
 The reason for this modification is to maintain the insertion order of entries, which isn't the case with Hashtable.
  This could lead to more predictable results and behaviors in calling methods.

* Replace Hashtable with LinkedHashMap in view response creation methods

Changed Hashtable to LinkedHashMap in various response creation methods within ViewResponseHelper class.
This modification ensures an ordered iteration which is beneficial for scenarios where the insertion order of responses needs to be maintained consistently.

---------

Co-authored-by: Sina Kashipazha <[email protected]>
  • Loading branch information
CharlesQueiroz and soreana authored Aug 16, 2023
1 parent cf249f6 commit e8b4911
Showing 1 changed file with 14 additions and 15 deletions.
29 changes: 14 additions & 15 deletions server/src/main/java/com/cloud/api/query/ViewResponseHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import java.util.Collections;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -150,7 +149,7 @@ public static List<UserVmResponse> createUserVmResponse(ResponseView view, Strin
public static List<UserVmResponse> createUserVmResponse(ResponseView view, String objectName, Set<VMDetails> details, Boolean accumulateStats, Boolean showUserData,
UserVmJoinVO... userVms) {
Account caller = CallContext.current().getCallingAccount();
Hashtable<Long, UserVmResponse> vmDataList = new Hashtable<Long, UserVmResponse>();
LinkedHashMap<Long, UserVmResponse> vmDataList = new LinkedHashMap<>();
// Initialise the vmdatalist with the input data

for (UserVmJoinVO userVm : userVms) {
Expand All @@ -169,7 +168,7 @@ public static List<UserVmResponse> createUserVmResponse(ResponseView view, Strin

public static List<DomainRouterResponse> createDomainRouterResponse(DomainRouterJoinVO... routers) {
Account caller = CallContext.current().getCallingAccount();
Hashtable<Long, DomainRouterResponse> vrDataList = new Hashtable<Long, DomainRouterResponse>();
LinkedHashMap<Long, DomainRouterResponse> vrDataList = new LinkedHashMap<>();
// Initialise the vrdatalist with the input data
for (DomainRouterJoinVO vr : routers) {
DomainRouterResponse vrData = vrDataList.get(vr.getId());
Expand All @@ -187,7 +186,7 @@ public static List<DomainRouterResponse> createDomainRouterResponse(DomainRouter

public static List<SecurityGroupResponse> createSecurityGroupResponses(List<SecurityGroupJoinVO> securityGroups) {
Account caller = CallContext.current().getCallingAccount();
Hashtable<Long, SecurityGroupResponse> vrDataList = new Hashtable<Long, SecurityGroupResponse>();
LinkedHashMap<Long, SecurityGroupResponse> vrDataList = new LinkedHashMap<>();
// Initialise the vrdatalist with the input data
for (SecurityGroupJoinVO vr : securityGroups) {
SecurityGroupResponse vrData = vrDataList.get(vr.getId());
Expand All @@ -205,7 +204,7 @@ public static List<SecurityGroupResponse> createSecurityGroupResponses(List<Secu
}

public static List<ProjectResponse> createProjectResponse(EnumSet<DomainDetails> details, ProjectJoinVO... projects) {
Hashtable<Long, ProjectResponse> prjDataList = new Hashtable<Long, ProjectResponse>();
LinkedHashMap<Long, ProjectResponse> prjDataList = new LinkedHashMap<>();
// Initialise the prjdatalist with the input data
for (ProjectJoinVO p : projects) {
ProjectResponse pData = prjDataList.get(p.getId());
Expand Down Expand Up @@ -247,7 +246,7 @@ public static List<ProjectInvitationResponse> createProjectInvitationResponse(Pr
}

public static List<HostResponse> createHostResponse(EnumSet<HostDetails> details, HostJoinVO... hosts) {
Hashtable<Long, HostResponse> vrDataList = new Hashtable<Long, HostResponse>();
LinkedHashMap<Long, HostResponse> vrDataList = new LinkedHashMap<>();
// Initialise the vrdatalist with the input data
for (HostJoinVO vr : hosts) {
HostResponse vrData = ApiDBUtils.newHostResponse(vr, details);
Expand All @@ -257,7 +256,7 @@ public static List<HostResponse> createHostResponse(EnumSet<HostDetails> details
}

public static List<HostForMigrationResponse> createHostForMigrationResponse(EnumSet<HostDetails> details, HostJoinVO... hosts) {
Hashtable<Long, HostForMigrationResponse> vrDataList = new Hashtable<Long, HostForMigrationResponse>();
LinkedHashMap<Long, HostForMigrationResponse> vrDataList = new LinkedHashMap<>();
// Initialise the vrdatalist with the input data
for (HostJoinVO vr : hosts) {
HostForMigrationResponse vrData = ApiDBUtils.newHostForMigrationResponse(vr, details);
Expand All @@ -267,7 +266,7 @@ public static List<HostForMigrationResponse> createHostForMigrationResponse(Enum
}

public static List<VolumeResponse> createVolumeResponse(ResponseView view, VolumeJoinVO... volumes) {
Hashtable<Long, VolumeResponse> vrDataList = new Hashtable<Long, VolumeResponse>();
LinkedHashMap<Long, VolumeResponse> vrDataList = new LinkedHashMap<>();
DecimalFormat df = new DecimalFormat("0.0%");
for (VolumeJoinVO vr : volumes) {
VolumeResponse vrData = vrDataList.get(vr.getId());
Expand Down Expand Up @@ -308,7 +307,7 @@ public static List<VolumeResponse> createVolumeResponse(ResponseView view, Volum
}

public static List<StoragePoolResponse> createStoragePoolResponse(StoragePoolJoinVO... pools) {
Hashtable<Long, StoragePoolResponse> vrDataList = new Hashtable<Long, StoragePoolResponse>();
LinkedHashMap<Long, StoragePoolResponse> vrDataList = new LinkedHashMap<>();
// Initialise the vrdatalist with the input data
for (StoragePoolJoinVO vr : pools) {
StoragePoolResponse vrData = vrDataList.get(vr.getId());
Expand Down Expand Up @@ -345,7 +344,7 @@ public static List<HostTagResponse> createHostTagResponse(HostTagVO... hostTags)
}

public static List<ImageStoreResponse> createImageStoreResponse(ImageStoreJoinVO... stores) {
Hashtable<Long, ImageStoreResponse> vrDataList = new Hashtable<Long, ImageStoreResponse>();
LinkedHashMap<Long, ImageStoreResponse> vrDataList = new LinkedHashMap<>();
// Initialise the vrdatalist with the input data
for (ImageStoreJoinVO vr : stores) {
ImageStoreResponse vrData = vrDataList.get(vr.getId());
Expand All @@ -362,7 +361,7 @@ public static List<ImageStoreResponse> createImageStoreResponse(ImageStoreJoinVO
}

public static List<StoragePoolResponse> createStoragePoolForMigrationResponse(StoragePoolJoinVO... pools) {
Hashtable<Long, StoragePoolResponse> vrDataList = new Hashtable<Long, StoragePoolResponse>();
LinkedHashMap<Long, StoragePoolResponse> vrDataList = new LinkedHashMap<>();
// Initialise the vrdatalist with the input data
for (StoragePoolJoinVO vr : pools) {
StoragePoolResponse vrData = vrDataList.get(vr.getId());
Expand Down Expand Up @@ -577,7 +576,7 @@ public static List<ZoneResponse> createDataCenterResponse(ResponseView view, Boo
}

public static List<TemplateResponse> createTemplateResponse(EnumSet<ApiConstants.DomainDetails> detailsView, ResponseView view, TemplateJoinVO... templates) {
LinkedHashMap<String, TemplateResponse> vrDataList = new LinkedHashMap<String, TemplateResponse>();
LinkedHashMap<String, TemplateResponse> vrDataList = new LinkedHashMap<>();
for (TemplateJoinVO vr : templates) {
TemplateResponse vrData = vrDataList.get(vr.getTempZonePair());
if (vrData == null) {
Expand All @@ -594,7 +593,7 @@ public static List<TemplateResponse> createTemplateResponse(EnumSet<ApiConstants
}

public static List<TemplateResponse> createTemplateUpdateResponse(ResponseView view, TemplateJoinVO... templates) {
Hashtable<Long, TemplateResponse> vrDataList = new Hashtable<Long, TemplateResponse>();
LinkedHashMap<Long, TemplateResponse> vrDataList = new LinkedHashMap<>();
for (TemplateJoinVO vr : templates) {
TemplateResponse vrData = vrDataList.get(vr.getId());
if (vrData == null) {
Expand All @@ -610,7 +609,7 @@ public static List<TemplateResponse> createTemplateUpdateResponse(ResponseView v
}

public static List<TemplateResponse> createIsoResponse(ResponseView view, TemplateJoinVO... templates) {
Hashtable<String, TemplateResponse> vrDataList = new Hashtable<>();
LinkedHashMap<String, TemplateResponse> vrDataList = new LinkedHashMap<>();
for (TemplateJoinVO vr : templates) {
TemplateResponse vrData = vrDataList.get(vr.getTempZonePair());
if (vrData == null) {
Expand All @@ -626,7 +625,7 @@ public static List<TemplateResponse> createIsoResponse(ResponseView view, Templa
}

public static List<AffinityGroupResponse> createAffinityGroupResponses(List<AffinityGroupJoinVO> groups) {
Hashtable<Long, AffinityGroupResponse> vrDataList = new Hashtable<Long, AffinityGroupResponse>();
LinkedHashMap<Long, AffinityGroupResponse> vrDataList = new LinkedHashMap<>();
for (AffinityGroupJoinVO vr : groups) {
AffinityGroupResponse vrData = vrDataList.get(vr.getId());
if (vrData == null) {
Expand Down

0 comments on commit e8b4911

Please sign in to comment.