Skip to content

Commit 92edf56

Browse files
author
frank
committed
Bug 7883 - Add support to allow admins to sort templates, isos, offerings...
status 7883: resolved fixed
1 parent f5d56b3 commit 92edf56

15 files changed

Lines changed: 129 additions & 15 deletions

File tree

‎api/src/com/cloud/api/ApiConstants.java‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,5 +270,6 @@ public class ApiConstants {
270270
public static final String ACTIVE_ONLY = "activeonly";
271271
public static final String TOKEN = "token";
272272
public static final String ACCEPT = "accept";
273+
public static final String SORT_KEY = "sortkey";
273274

274275
}

‎api/src/com/cloud/api/commands/UpdateDiskOfferingCmd.java‎

100644100755
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ public class UpdateDiskOfferingCmd extends BaseCmd{
4747

4848
@Parameter(name=ApiConstants.NAME, type=CommandType.STRING, description="updates name of the disk offering with this value")
4949
private String diskOfferingName;
50+
51+
@Parameter(name=ApiConstants.SORT_KEY, type=CommandType.INTEGER, description="sort key of the disk offering, integer")
52+
private Integer sortKey;
5053

5154
/////////////////////////////////////////////////////
5255
/////////////////// Accessors ///////////////////////
@@ -63,6 +66,10 @@ public Long getId() {
6366
public String getDiskOfferingName() {
6467
return diskOfferingName;
6568
}
69+
70+
public Integer getSortKey() {
71+
return sortKey;
72+
}
6673

6774

6875
/////////////////////////////////////////////////////

‎api/src/com/cloud/api/commands/UpdateNetworkOfferingCmd.java‎

100644100755
Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import com.cloud.api.Implementation;
2929
import com.cloud.api.Parameter;
3030
import com.cloud.api.ServerApiException;
31+
import com.cloud.api.BaseCmd.CommandType;
3132
import com.cloud.api.response.NetworkOfferingResponse;
3233
import com.cloud.offering.NetworkOffering;
3334
import com.cloud.offering.NetworkOffering.Availability;
@@ -53,7 +54,10 @@ public class UpdateNetworkOfferingCmd extends BaseCmd {
5354
private String displayText;
5455

5556
@Parameter(name=ApiConstants.AVAILABILITY, type=CommandType.STRING, description="the availability of network offering. Default value is Required for Guest Virtual network offering; Optional for Guest Direct network offering")
56-
private String availability;
57+
private String availability;
58+
59+
@Parameter(name=ApiConstants.SORT_KEY, type=CommandType.INTEGER, description="sort key of the network offering, integer")
60+
private Integer sortKey;
5761

5862
/////////////////////////////////////////////////////
5963
/////////////////// Accessors ///////////////////////
@@ -74,6 +78,10 @@ public Long getId() {
7478
public String getAvailability() {
7579
return availability == null ? Availability.Required.toString() : availability;
7680
}
81+
82+
public Integer getSortKey() {
83+
return sortKey;
84+
}
7785

7886
/////////////////////////////////////////////////////
7987
/////////////// API Implementation///////////////////

‎api/src/com/cloud/api/commands/UpdateServiceOfferingCmd.java‎

100644100755
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import com.cloud.api.Implementation;
2626
import com.cloud.api.Parameter;
2727
import com.cloud.api.ServerApiException;
28+
import com.cloud.api.BaseCmd.CommandType;
2829
import com.cloud.api.response.ServiceOfferingResponse;
2930
import com.cloud.offering.ServiceOffering;
3031
import com.cloud.user.Account;
@@ -48,6 +49,8 @@ public class UpdateServiceOfferingCmd extends BaseCmd {
4849
@Parameter(name=ApiConstants.NAME, type=CommandType.STRING, description="the name of the service offering to be updated")
4950
private String serviceOfferingName;
5051

52+
@Parameter(name=ApiConstants.SORT_KEY, type=CommandType.INTEGER, description="sort key of the service offering, integer")
53+
private Integer sortKey;
5154
/////////////////////////////////////////////////////
5255
/////////////////// Accessors ///////////////////////
5356
/////////////////////////////////////////////////////
@@ -64,7 +67,9 @@ public String getServiceOfferingName() {
6467
return serviceOfferingName;
6568
}
6669

67-
70+
public Integer getSortKey() {
71+
return sortKey;
72+
}
6873

6974
/////////////////////////////////////////////////////
7075
/////////////// API Implementation///////////////////

‎api/src/com/cloud/api/commands/UpdateTemplateOrIsoCmd.java‎

100644100755
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import com.cloud.api.BaseCmd;
2525
import com.cloud.api.IdentityMapper;
2626
import com.cloud.api.Parameter;
27+
import com.cloud.api.BaseCmd.CommandType;
2728

2829
public abstract class UpdateTemplateOrIsoCmd extends BaseCmd {
2930
public static final Logger s_logger = Logger.getLogger(UpdateIsoCmd.class.getName());
@@ -53,6 +54,9 @@ public abstract class UpdateTemplateOrIsoCmd extends BaseCmd {
5354

5455
@Parameter(name=ApiConstants.PASSWORD_ENABLED, type=CommandType.BOOLEAN, description="true if the image supports the password reset feature; default is false")
5556
private Boolean passwordEnabled;
57+
58+
@Parameter(name=ApiConstants.SORT_KEY, type=CommandType.INTEGER, description="sort key of the template, integer")
59+
private Integer sortKey;
5660

5761
/////////////////////////////////////////////////////
5862
/////////////////// Accessors ///////////////////////
@@ -85,4 +89,8 @@ public Boolean isPasswordEnabled() {
8589
public String getFormat() {
8690
return format;
8791
}
92+
93+
public Integer getSortKey() {
94+
return sortKey;
95+
}
8896
}

‎client/tomcatconf/commands.properties.in‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,6 @@ listAlerts=com.cloud.api.commands.ListAlertsCmd;3
175175

176176
#### system capacity commands
177177
listCapacity=com.cloud.api.commands.ListCapacityCmd;3
178-
listCapacityByType=com.cloud.api.commands.ListCapacityByTypeCmd;3
179178

180179
#### host commands
181180
addHost=com.cloud.api.commands.AddHostCmd;3

‎core/src/com/cloud/storage/DiskOfferingVO.java‎

100644100755
Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,13 @@ public enum Type {
9898
@Column(name="uuid")
9999
private String uuid;
100100

101+
@Column(name="sort_key")
102+
int sortKey;
103+
101104
public DiskOfferingVO() {
102105
this.uuid = UUID.randomUUID().toString();
103-
}
104-
106+
}
107+
105108
public DiskOfferingVO(Long domainId, String name, String displayText, long diskSize, String tags, boolean isCustomized) {
106109
this.domainId = domainId;
107110
this.name = name;
@@ -300,5 +303,13 @@ public String getUuid() {
300303

301304
public void setUuid(String uuid) {
302305
this.uuid = uuid;
306+
}
307+
308+
public void setSortKey(int key) {
309+
sortKey = key;
310+
}
311+
312+
public int getSortKey() {
313+
return sortKey;
303314
}
304315
}

‎core/src/com/cloud/storage/VMTemplateVO.java‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,9 @@ public class VMTemplateVO implements VirtualMachineTemplate, Identity {
123123
private String uuid;
124124

125125

126+
@Column(name="sort_key")
127+
int sortKey;
128+
126129
@Override
127130
public String getUniqueName() {
128131
return uniqueName;
@@ -433,5 +436,13 @@ public String toString() {
433436
public void setRemoved(Date removed) {
434437
this.removed = removed;
435438
}
439+
440+
public void setSortKey(int key) {
441+
sortKey = key;
442+
}
443+
444+
public int getSortKey() {
445+
return sortKey;
446+
}
436447

437448
}

‎server/src/com/cloud/configuration/Config.java‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,8 @@ public enum Config {
216216
ElasticLoadBalancerVmCpuMhz("Advanced", ManagementServer.class, Integer.class, "network.loadbalancer.basiczone.elb.vm.cpu.mhz", "128", "CPU speed for the elastic load balancer vm", null),
217217
ElasticLoadBalancerVmNumVcpu("Advanced", ManagementServer.class, Integer.class, "network.loadbalancer.basiczone.elb.vm.vcpu.num", "1", "Number of VCPU for the elastic load balancer vm", null),
218218
ElasticLoadBalancerVmGcInterval("Advanced", ManagementServer.class, Integer.class, "network.loadbalancer.basiczone.elb.gc.interval.minutes", "30", "Garbage collection interval to destroy unused ELB vms in minutes. Minimum of 5", null),
219-
219+
SortKeyAlgorithm("Advanced", ManagementServer.class, Boolean.class, "sortkey.algorithm", "false", "Sort algorithm for those who use sort key(template, disk offering, service offering, network offering), true means ascending sort while false means descending sort", null),
220+
220221
// Ovm
221222
OvmPublicNetwork("Advanced", ManagementServer.class, String.class, "ovm.public.network.device", null, "Specify the public bridge on host for public network", null),
222223
OvmPrivateNetwork("Advanced", ManagementServer.class, String.class, "ovm.private.network.device", null, "Specify the private bridge on host for private network", null),

‎server/src/com/cloud/configuration/ConfigurationManagerImpl.java‎

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1709,6 +1709,7 @@ public ServiceOffering updateServiceOffering(UpdateServiceOfferingCmd cmd) {
17091709
String displayText = cmd.getDisplayText();
17101710
Long id = cmd.getId();
17111711
String name = cmd.getServiceOfferingName();
1712+
Integer sortKey = cmd.getSortKey();
17121713
Long userId = UserContext.current().getCallerUserId();
17131714

17141715
if (userId == null) {
@@ -1736,6 +1737,10 @@ public ServiceOffering updateServiceOffering(UpdateServiceOfferingCmd cmd) {
17361737
if (displayText != null) {
17371738
offering.setDisplayText(displayText);
17381739
}
1740+
1741+
if (sortKey != null) {
1742+
offering.setSortKey(sortKey);
1743+
}
17391744

17401745
// Note: tag editing commented out for now; keeping the code intact, might need to re-enable in next releases
17411746
// if (tags != null)
@@ -1823,6 +1828,7 @@ public DiskOffering updateDiskOffering(UpdateDiskOfferingCmd cmd) {
18231828
Long diskOfferingId = cmd.getId();
18241829
String name = cmd.getDiskOfferingName();
18251830
String displayText = cmd.getDisplayText();
1831+
Integer sortKey = cmd.getSortKey();
18261832

18271833
// Check if diskOffering exists
18281834
DiskOffering diskOfferingHandle = getDiskOffering(diskOfferingId);
@@ -1831,7 +1837,7 @@ public DiskOffering updateDiskOffering(UpdateDiskOfferingCmd cmd) {
18311837
throw new InvalidParameterValueException("Unable to find disk offering by id " + diskOfferingId);
18321838
}
18331839

1834-
boolean updateNeeded = (name != null || displayText != null);
1840+
boolean updateNeeded = (name != null || displayText != null || sortKey != null);
18351841
if (!updateNeeded) {
18361842
return _diskOfferingDao.findById(diskOfferingId);
18371843
}
@@ -1845,6 +1851,10 @@ public DiskOffering updateDiskOffering(UpdateDiskOfferingCmd cmd) {
18451851
if (displayText != null) {
18461852
diskOffering.setDisplayText(displayText);
18471853
}
1854+
1855+
if (sortKey != null) {
1856+
diskOffering.setSortKey(sortKey);
1857+
}
18481858

18491859
// Note: tag editing commented out for now;keeping the code intact, might need to re-enable in next releases
18501860
// if (tags != null)
@@ -2944,7 +2954,9 @@ public NetworkOfferingVO createNetworkOffering(long userId, String name, String
29442954

29452955
@Override
29462956
public List<? extends NetworkOffering> searchForNetworkOfferings(ListNetworkOfferingsCmd cmd) {
2947-
Filter searchFilter = new Filter(NetworkOfferingVO.class, "created", false, cmd.getStartIndex(), cmd.getPageSizeVal());
2957+
Boolean isAscending = Boolean.parseBoolean(_configDao.getValue("sortkey.algorithm"));
2958+
isAscending = (isAscending == null ? true : isAscending);
2959+
Filter searchFilter = new Filter(NetworkOfferingVO.class, "sortKey", isAscending, cmd.getStartIndex(), cmd.getPageSizeVal());
29482960
SearchCriteria<NetworkOfferingVO> sc = _networkOfferingDao.createSearchCriteria();
29492961

29502962
Object id = cmd.getId();
@@ -3054,6 +3066,7 @@ public NetworkOffering updateNetworkOffering(UpdateNetworkOfferingCmd cmd) {
30543066
Long id = cmd.getId();
30553067
String name = cmd.getNetworkOfferingName();
30563068
String availabilityStr = cmd.getAvailability();
3069+
Integer sortKey = cmd.getSortKey();
30573070
Availability availability = null;
30583071
UserContext.current().setEventDetails(" Id: "+id);
30593072

@@ -3082,6 +3095,10 @@ public NetworkOffering updateNetworkOffering(UpdateNetworkOfferingCmd cmd) {
30823095
if (displayText != null) {
30833096
offering.setDisplayText(displayText);
30843097
}
3098+
3099+
if (sortKey != null) {
3100+
offering.setSortKey(sortKey);
3101+
}
30853102

30863103
// Verify availability
30873104
if (availabilityStr != null) {

0 commit comments

Comments
 (0)