Skip to content

Commit eee2df3

Browse files
Anurag Awasthiyadvr
authored andcommitted
server: add support for sorting zones in UI/api
This adds support to allow admins to sort zones, and based on the sorted order the zones will be listed in UI and API. Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>
1 parent 34030be commit eee2df3

File tree

12 files changed

+99
-45
lines changed

12 files changed

+99
-45
lines changed

api/src/main/java/com/cloud/dc/DataCenter.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,12 @@
1616
// under the License.
1717
package com.cloud.dc;
1818

19-
import com.cloud.org.Grouping;
19+
import java.util.Map;
20+
2021
import org.apache.cloudstack.acl.InfrastructureEntity;
2122
import org.apache.cloudstack.kernel.Partition;
2223

23-
import java.util.Map;
24+
import com.cloud.org.Grouping;
2425

2526
/**
2627
*
@@ -80,4 +81,6 @@ public enum NetworkType {
8081
String getZoneToken();
8182

8283
boolean isLocalStorageEnabled();
84+
85+
int getSortKey();
8386
}

api/src/main/java/org/apache/cloudstack/api/command/admin/zone/UpdateZoneCmd.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ public class UpdateZoneCmd extends BaseCmd {
9595
@Parameter(name = ApiConstants.LOCAL_STORAGE_ENABLED, type = CommandType.BOOLEAN, description = "true if local storage offering enabled, false otherwise")
9696
private Boolean localStorageEnabled;
9797

98+
@Parameter(name = ApiConstants.SORT_KEY, type = CommandType.INTEGER, description = "sort key of the disk offering, integer")
99+
private Integer sortKey;
100+
98101
/////////////////////////////////////////////////////
99102
/////////////////// Accessors ///////////////////////
100103
/////////////////////////////////////////////////////
@@ -163,6 +166,10 @@ public Boolean getLocalStorageEnabled() {
163166
return localStorageEnabled;
164167
}
165168

169+
public Integer getSortKey() {
170+
return sortKey;
171+
}
172+
166173
/////////////////////////////////////////////////////
167174
/////////////// API Implementation///////////////////
168175
/////////////////////////////////////////////////////

api/src/main/java/org/apache/cloudstack/query/QueryService.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,12 @@
8585
public interface QueryService {
8686

8787
// Config keys
88-
static final ConfigKey<Boolean> AllowUserViewDestroyedVM = new ConfigKey<Boolean>("Advanced", Boolean.class, "allow.user.view.destroyed.vm", "false",
88+
ConfigKey<Boolean> AllowUserViewDestroyedVM = new ConfigKey<>("Advanced", Boolean.class, "allow.user.view.destroyed.vm", "false",
8989
"Determines whether users can view their destroyed or expunging vm ", true, ConfigKey.Scope.Account);
9090

91+
ConfigKey<Boolean> SortKeyAscending = new ConfigKey<>("Advanced", Boolean.class, "sortkey.algorithm", "true",
92+
"Sort algorithm for those who use sort key(template, disk offering, service offering, network offering, zones), true means ascending sort while false means descending sort", true, ConfigKey.Scope.Global);
93+
9194
ListResponse<UserResponse> searchForUsers(ListUsersCmd cmd) throws PermissionDeniedException;
9295

9396
ListResponse<EventResponse> searchForEvents(ListEventsCmd cmd);

engine/orchestration/src/main/java/org/apache/cloudstack/engine/datacenter/entity/api/db/EngineDataCenterVO.java

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,9 @@
1616
// under the License.
1717
package org.apache.cloudstack.engine.datacenter.entity.api.db;
1818

19-
import com.cloud.network.Network.Provider;
20-
import com.cloud.org.Grouping;
21-
import com.cloud.utils.NumbersUtil;
22-
import com.cloud.utils.db.GenericDao;
23-
import com.cloud.utils.db.StateMachine;
24-
import org.apache.cloudstack.api.Identity;
25-
import org.apache.cloudstack.engine.datacenter.entity.api.DataCenterResourceEntity.State;
26-
import org.apache.cloudstack.engine.datacenter.entity.api.DataCenterResourceEntity.State.Event;
19+
import java.util.Date;
20+
import java.util.Map;
21+
import java.util.UUID;
2722

2823
import javax.persistence.Column;
2924
import javax.persistence.Entity;
@@ -37,9 +32,16 @@
3732
import javax.persistence.Temporal;
3833
import javax.persistence.TemporalType;
3934
import javax.persistence.Transient;
40-
import java.util.Date;
41-
import java.util.Map;
42-
import java.util.UUID;
35+
36+
import org.apache.cloudstack.api.Identity;
37+
import org.apache.cloudstack.engine.datacenter.entity.api.DataCenterResourceEntity.State;
38+
import org.apache.cloudstack.engine.datacenter.entity.api.DataCenterResourceEntity.State.Event;
39+
40+
import com.cloud.network.Network.Provider;
41+
import com.cloud.org.Grouping;
42+
import com.cloud.utils.NumbersUtil;
43+
import com.cloud.utils.db.GenericDao;
44+
import com.cloud.utils.db.StateMachine;
4345

4446
@Entity
4547
@Table(name = "data_center")
@@ -140,6 +142,9 @@ public class EngineDataCenterVO implements EngineDataCenter, Identity {
140142
@Column(name = "is_local_storage_enabled")
141143
boolean localStorageEnabled;
142144

145+
@Column(name = "sort_key")
146+
int sortKey;
147+
143148
//orchestration
144149
@Column(name = "owner")
145150
private String owner = null;
@@ -389,6 +394,10 @@ public void setLocalStorageEnabled(boolean enabled) {
389394
this.localStorageEnabled = enabled;
390395
}
391396

397+
public int getSortKey() {
398+
return sortKey;
399+
}
400+
392401
@Override
393402
public Map<String, String> getDetails() {
394403
return details;

engine/schema/src/main/java/com/cloud/dc/DataCenterVO.java

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,9 @@
1616
// under the License.
1717
package com.cloud.dc;
1818

19-
import com.cloud.network.Network.Provider;
20-
import com.cloud.org.Grouping;
21-
import com.cloud.utils.NumbersUtil;
22-
import com.cloud.utils.db.GenericDao;
19+
import java.util.Date;
20+
import java.util.Map;
21+
import java.util.UUID;
2322

2423
import javax.persistence.Column;
2524
import javax.persistence.Entity;
@@ -31,9 +30,11 @@
3130
import javax.persistence.Table;
3231
import javax.persistence.TableGenerator;
3332
import javax.persistence.Transient;
34-
import java.util.Date;
35-
import java.util.Map;
36-
import java.util.UUID;
33+
34+
import com.cloud.network.Network.Provider;
35+
import com.cloud.org.Grouping;
36+
import com.cloud.utils.NumbersUtil;
37+
import com.cloud.utils.db.GenericDao;
3738

3839
@Entity
3940
@Table(name = "data_center")
@@ -134,6 +135,9 @@ public class DataCenterVO implements DataCenter {
134135
@Column(name = "is_local_storage_enabled")
135136
boolean localStorageEnabled;
136137

138+
@Column(name = "sort_key")
139+
int sortKey;
140+
137141
@Override
138142
public String getDnsProvider() {
139143
return dnsProvider;
@@ -363,6 +367,15 @@ public void setLocalStorageEnabled(boolean enabled) {
363367
this.localStorageEnabled = enabled;
364368
}
365369

370+
@Override
371+
public int getSortKey() {
372+
return sortKey;
373+
}
374+
375+
public void setSortKey(int newSortKey) {
376+
sortKey = newSortKey;
377+
}
378+
366379
@Override
367380
public Map<String, String> getDetails() {
368381
return details;

server/src/main/java/com/cloud/api/query/QueryManagerImpl.java

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@
2525

2626
import javax.inject.Inject;
2727

28-
import com.cloud.cluster.ManagementServerHostVO;
29-
import com.cloud.cluster.dao.ManagementServerHostDao;
3028
import org.apache.cloudstack.acl.ControlledEntity.ACLType;
3129
import org.apache.cloudstack.affinity.AffinityGroupDomainMapVO;
3230
import org.apache.cloudstack.affinity.AffinityGroupResponse;
@@ -156,6 +154,8 @@
156154
import com.cloud.api.query.vo.UserAccountJoinVO;
157155
import com.cloud.api.query.vo.UserVmJoinVO;
158156
import com.cloud.api.query.vo.VolumeJoinVO;
157+
import com.cloud.cluster.ManagementServerHostVO;
158+
import com.cloud.cluster.dao.ManagementServerHostDao;
159159
import com.cloud.dc.DedicatedResourceVO;
160160
import com.cloud.dc.dao.DedicatedResourceDao;
161161
import com.cloud.domain.Domain;
@@ -2508,9 +2508,7 @@ private Pair<List<DiskOfferingJoinVO>, Integer> searchForDiskOfferingsInternal(L
25082508
// till
25092509
// root
25102510

2511-
Boolean isAscending = Boolean.parseBoolean(_configDao.getValue("sortkey.algorithm"));
2512-
isAscending = (isAscending == null ? true : isAscending);
2513-
Filter searchFilter = new Filter(DiskOfferingJoinVO.class, "sortKey", isAscending, cmd.getStartIndex(), cmd.getPageSizeVal());
2511+
Filter searchFilter = new Filter(DiskOfferingJoinVO.class, "sortKey", SortKeyAscending.value(), cmd.getStartIndex(), cmd.getPageSizeVal());
25142512
SearchCriteria<DiskOfferingJoinVO> sc = _diskOfferingJoinDao.createSearchCriteria();
25152513
sc.addAnd("type", Op.EQ, DiskOfferingVO.Type.Disk);
25162514

@@ -2650,9 +2648,7 @@ private Pair<List<ServiceOfferingJoinVO>, Integer> searchForServiceOfferingsInte
26502648
// their domains+parent domains ... all the way
26512649
// till
26522650
// root
2653-
Boolean isAscending = Boolean.parseBoolean(_configDao.getValue("sortkey.algorithm"));
2654-
isAscending = (isAscending == null ? true : isAscending);
2655-
Filter searchFilter = new Filter(ServiceOfferingJoinVO.class, "sortKey", isAscending, cmd.getStartIndex(), cmd.getPageSizeVal());
2651+
Filter searchFilter = new Filter(ServiceOfferingJoinVO.class, "sortKey", SortKeyAscending.value(), cmd.getStartIndex(), cmd.getPageSizeVal());
26562652

26572653
Account caller = CallContext.current().getCallingAccount();
26582654
Object name = cmd.getServiceOfferingName();
@@ -3086,10 +3082,8 @@ private Pair<List<TemplateJoinVO>, Integer> searchForTemplatesInternal(Long temp
30863082

30873083
VMTemplateVO template = null;
30883084

3089-
Boolean isAscending = Boolean.parseBoolean(_configDao.getValue("sortkey.algorithm"));
3090-
isAscending = (isAscending == null ? Boolean.TRUE : isAscending);
3091-
Filter searchFilter = new Filter(TemplateJoinVO.class, "sortKey", isAscending, startIndex, pageSize);
3092-
searchFilter.addOrderBy(TemplateJoinVO.class, "tempZonePair", isAscending);
3085+
Filter searchFilter = new Filter(TemplateJoinVO.class, "sortKey", SortKeyAscending.value(), startIndex, pageSize);
3086+
searchFilter.addOrderBy(TemplateJoinVO.class, "tempZonePair", SortKeyAscending.value());
30933087

30943088
SearchBuilder<TemplateJoinVO> sb = _templateJoinDao.createSearchBuilder();
30953089
sb.select(null, Func.DISTINCT, sb.entity().getTempZonePair()); // select distinct (templateId, zoneId) pair
@@ -3714,6 +3708,9 @@ public String getConfigComponentName() {
37143708

37153709
@Override
37163710
public ConfigKey<?>[] getConfigKeys() {
3717-
return new ConfigKey<?>[] {AllowUserViewDestroyedVM};
3711+
return new ConfigKey<?>[] {
3712+
AllowUserViewDestroyedVM,
3713+
SortKeyAscending
3714+
};
37183715
}
37193716
}

server/src/main/java/com/cloud/api/query/vo/DataCenterJoinVO.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,9 @@ public class DataCenterJoinVO extends BaseViewVO implements InternalIdentity, Id
117117
@Column(name = "account_id")
118118
private long accountId;
119119

120+
@Column(name = "sort_key")
121+
private int sortKey;
122+
120123
public DataCenterJoinVO() {
121124
}
122125

@@ -221,4 +224,8 @@ public String getAffinityGroupUuid() {
221224
public long getAccountId() {
222225
return accountId;
223226
}
227+
228+
public int getSortKey() {
229+
return sortKey;
230+
}
224231
}

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

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -995,14 +995,6 @@ public enum Config {
995995
"30",
996996
"Garbage collection interval to destroy unused ELB vms in minutes. Minimum of 5",
997997
null),
998-
SortKeyAlgorithm(
999-
"Advanced",
1000-
ManagementServer.class,
1001-
Boolean.class,
1002-
"sortkey.algorithm",
1003-
"false",
1004-
"Sort algorithm for those who use sort key(template, disk offering, service offering, network offering), true means ascending sort while false means descending sort",
1005-
null),
1006998
EnableEC2API("Advanced", ManagementServer.class, Boolean.class, "enable.ec2.api", "false", "enable EC2 API on CloudStack", null),
1007999
EnableS3API("Advanced", ManagementServer.class, Boolean.class, "enable.s3.api", "false", "enable Amazon S3 API on CloudStack", null),
10081000
RecreateSystemVmEnabled(

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@
3535
import javax.inject.Inject;
3636
import javax.naming.ConfigurationException;
3737

38-
import com.google.common.collect.Sets;
39-
4038
import org.apache.cloudstack.acl.SecurityChecker;
4139
import org.apache.cloudstack.affinity.AffinityGroup;
4240
import org.apache.cloudstack.affinity.AffinityGroupService;
@@ -232,6 +230,7 @@
232230
import com.google.common.base.MoreObjects;
233231
import com.google.common.base.Preconditions;
234232
import com.google.common.base.Strings;
233+
import com.google.common.collect.Sets;
235234

236235
public class ConfigurationManagerImpl extends ManagerBase implements ConfigurationManager, ConfigurationService, Configurable {
237236
public static final Logger s_logger = Logger.getLogger(ConfigurationManagerImpl.class);
@@ -1920,6 +1919,8 @@ public DataCenter editZone(final UpdateZoneCmd cmd) {
19201919
guestCidr = zone.getGuestNetworkCidr();
19211920
}
19221921

1922+
int sortKey = cmd.getSortKey() != null ? cmd.getSortKey() : zone.getSortKey();
1923+
19231924
// validate network domain
19241925
if (networkDomain != null && !networkDomain.isEmpty()) {
19251926
if (!NetUtils.verifyDomainName(networkDomain)) {
@@ -1942,6 +1943,7 @@ public DataCenter editZone(final UpdateZoneCmd cmd) {
19421943
zone.setInternalDns1(internalDns1);
19431944
zone.setInternalDns2(internalDns2);
19441945
zone.setGuestNetworkCidr(guestCidr);
1946+
zone.setSortKey(sortKey);
19451947
if (localStorageEnabled != null) {
19461948
zone.setLocalStorageEnabled(localStorageEnabled.booleanValue());
19471949
}

ui/scripts/cloudStack.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,24 @@
187187
}
188188
});
189189

190+
// Update global pagesize for sort key in UI
191+
$.ajax({
192+
type: 'GET',
193+
url: createURL('listConfigurations'),
194+
data: {name: 'sortkey.algorithm'},
195+
dataType: 'json',
196+
async: false,
197+
success: function(data, textStatus, xhr) {
198+
if (data && data.listconfigurationsresponse && data.listconfigurationsresponse.configuration) {
199+
var config = data.listconfigurationsresponse.configuration[0];
200+
if (config && config.name == 'sortkey.algorithm') {
201+
g_sortKeyIsAscending = config.value == 'true';
202+
}
203+
}
204+
},
205+
error: function(xhr) { // ignore any errors, fallback to the default
206+
}
207+
});
190208

191209
// Populate IDP list
192210
$.ajax({

0 commit comments

Comments
 (0)