Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions api/src/main/java/com/cloud/dc/DataCenter.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@
// under the License.
package com.cloud.dc;

import com.cloud.org.Grouping;
import java.util.Map;

import org.apache.cloudstack.acl.InfrastructureEntity;
import org.apache.cloudstack.kernel.Partition;

import java.util.Map;
import com.cloud.org.Grouping;

/**
*
Expand Down Expand Up @@ -80,4 +81,6 @@ public enum NetworkType {
String getZoneToken();

boolean isLocalStorageEnabled();

int getSortKey();
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ public class UpdateZoneCmd extends BaseCmd {
@Parameter(name = ApiConstants.LOCAL_STORAGE_ENABLED, type = CommandType.BOOLEAN, description = "true if local storage offering enabled, false otherwise")
private Boolean localStorageEnabled;

@Parameter(name = ApiConstants.SORT_KEY, type = CommandType.INTEGER, description = "sort key of the disk offering, integer")
private Integer sortKey;

/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
/////////////////////////////////////////////////////
Expand Down Expand Up @@ -163,6 +166,10 @@ public Boolean getLocalStorageEnabled() {
return localStorageEnabled;
}

public Integer getSortKey() {
return sortKey;
}

/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,12 @@
public interface QueryService {

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

ConfigKey<Boolean> SortKeyAscending = new ConfigKey<>("Advanced", Boolean.class, "sortkey.algorithm", "true",
"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);

ListResponse<UserResponse> searchForUsers(ListUsersCmd cmd) throws PermissionDeniedException;

ListResponse<EventResponse> searchForEvents(ListEventsCmd cmd);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,9 @@
// under the License.
package org.apache.cloudstack.engine.datacenter.entity.api.db;

import com.cloud.network.Network.Provider;
import com.cloud.org.Grouping;
import com.cloud.utils.NumbersUtil;
import com.cloud.utils.db.GenericDao;
import com.cloud.utils.db.StateMachine;
import org.apache.cloudstack.api.Identity;
import org.apache.cloudstack.engine.datacenter.entity.api.DataCenterResourceEntity.State;
import org.apache.cloudstack.engine.datacenter.entity.api.DataCenterResourceEntity.State.Event;
import java.util.Date;
import java.util.Map;
import java.util.UUID;

import javax.persistence.Column;
import javax.persistence.Entity;
Expand All @@ -37,9 +32,16 @@
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;
import java.util.Date;
import java.util.Map;
import java.util.UUID;

import org.apache.cloudstack.api.Identity;
import org.apache.cloudstack.engine.datacenter.entity.api.DataCenterResourceEntity.State;
import org.apache.cloudstack.engine.datacenter.entity.api.DataCenterResourceEntity.State.Event;

import com.cloud.network.Network.Provider;
import com.cloud.org.Grouping;
import com.cloud.utils.NumbersUtil;
import com.cloud.utils.db.GenericDao;
import com.cloud.utils.db.StateMachine;

@Entity
@Table(name = "data_center")
Expand Down Expand Up @@ -140,6 +142,9 @@ public class EngineDataCenterVO implements EngineDataCenter, Identity {
@Column(name = "is_local_storage_enabled")
boolean localStorageEnabled;

@Column(name = "sort_key")
int sortKey;

//orchestration
@Column(name = "owner")
private String owner = null;
Expand Down Expand Up @@ -389,6 +394,10 @@ public void setLocalStorageEnabled(boolean enabled) {
this.localStorageEnabled = enabled;
}

public int getSortKey() {
return sortKey;
}

@Override
public Map<String, String> getDetails() {
return details;
Expand Down
27 changes: 20 additions & 7 deletions engine/schema/src/main/java/com/cloud/dc/DataCenterVO.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@
// under the License.
package com.cloud.dc;

import com.cloud.network.Network.Provider;
import com.cloud.org.Grouping;
import com.cloud.utils.NumbersUtil;
import com.cloud.utils.db.GenericDao;
import java.util.Date;
import java.util.Map;
import java.util.UUID;

import javax.persistence.Column;
import javax.persistence.Entity;
Expand All @@ -31,9 +30,11 @@
import javax.persistence.Table;
import javax.persistence.TableGenerator;
import javax.persistence.Transient;
import java.util.Date;
import java.util.Map;
import java.util.UUID;

import com.cloud.network.Network.Provider;
import com.cloud.org.Grouping;
import com.cloud.utils.NumbersUtil;
import com.cloud.utils.db.GenericDao;

@Entity
@Table(name = "data_center")
Expand Down Expand Up @@ -134,6 +135,9 @@ public class DataCenterVO implements DataCenter {
@Column(name = "is_local_storage_enabled")
boolean localStorageEnabled;

@Column(name = "sort_key")
int sortKey;

@Override
public String getDnsProvider() {
return dnsProvider;
Expand Down Expand Up @@ -363,6 +367,15 @@ public void setLocalStorageEnabled(boolean enabled) {
this.localStorageEnabled = enabled;
}

@Override
public int getSortKey() {
return sortKey;
}

public void setSortKey(int newSortKey) {
sortKey = newSortKey;
}

@Override
public Map<String, String> getDetails() {
return details;
Expand Down
23 changes: 10 additions & 13 deletions server/src/main/java/com/cloud/api/query/QueryManagerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@

import javax.inject.Inject;

import com.cloud.cluster.ManagementServerHostVO;
import com.cloud.cluster.dao.ManagementServerHostDao;
import org.apache.cloudstack.acl.ControlledEntity.ACLType;
import org.apache.cloudstack.affinity.AffinityGroupDomainMapVO;
import org.apache.cloudstack.affinity.AffinityGroupResponse;
Expand Down Expand Up @@ -156,6 +154,8 @@
import com.cloud.api.query.vo.UserAccountJoinVO;
import com.cloud.api.query.vo.UserVmJoinVO;
import com.cloud.api.query.vo.VolumeJoinVO;
import com.cloud.cluster.ManagementServerHostVO;
import com.cloud.cluster.dao.ManagementServerHostDao;
import com.cloud.dc.DedicatedResourceVO;
import com.cloud.dc.dao.DedicatedResourceDao;
import com.cloud.domain.Domain;
Expand Down Expand Up @@ -2508,9 +2508,7 @@ private Pair<List<DiskOfferingJoinVO>, Integer> searchForDiskOfferingsInternal(L
// till
// root

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

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

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

VMTemplateVO template = null;

Boolean isAscending = Boolean.parseBoolean(_configDao.getValue("sortkey.algorithm"));
isAscending = (isAscending == null ? Boolean.TRUE : isAscending);
Filter searchFilter = new Filter(TemplateJoinVO.class, "sortKey", isAscending, startIndex, pageSize);
searchFilter.addOrderBy(TemplateJoinVO.class, "tempZonePair", isAscending);
Filter searchFilter = new Filter(TemplateJoinVO.class, "sortKey", SortKeyAscending.value(), startIndex, pageSize);
searchFilter.addOrderBy(TemplateJoinVO.class, "tempZonePair", SortKeyAscending.value());

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

@Override
public ConfigKey<?>[] getConfigKeys() {
return new ConfigKey<?>[] {AllowUserViewDestroyedVM};
return new ConfigKey<?>[] {
AllowUserViewDestroyedVM,
SortKeyAscending
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ public class DataCenterJoinVO extends BaseViewVO implements InternalIdentity, Id
@Column(name = "account_id")
private long accountId;

@Column(name = "sort_key")
private int sortKey;

public DataCenterJoinVO() {
}

Expand Down Expand Up @@ -221,4 +224,8 @@ public String getAffinityGroupUuid() {
public long getAccountId() {
return accountId;
}

public int getSortKey() {
return sortKey;
}
}
8 changes: 0 additions & 8 deletions server/src/main/java/com/cloud/configuration/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -995,14 +995,6 @@ public enum Config {
"30",
"Garbage collection interval to destroy unused ELB vms in minutes. Minimum of 5",
null),
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),
EnableEC2API("Advanced", ManagementServer.class, Boolean.class, "enable.ec2.api", "false", "enable EC2 API on CloudStack", null),
EnableS3API("Advanced", ManagementServer.class, Boolean.class, "enable.s3.api", "false", "enable Amazon S3 API on CloudStack", null),
RecreateSystemVmEnabled(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@
import javax.inject.Inject;
import javax.naming.ConfigurationException;

import com.google.common.collect.Sets;

import org.apache.cloudstack.acl.SecurityChecker;
import org.apache.cloudstack.affinity.AffinityGroup;
import org.apache.cloudstack.affinity.AffinityGroupService;
Expand Down Expand Up @@ -232,6 +230,7 @@
import com.google.common.base.MoreObjects;
import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
import com.google.common.collect.Sets;

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

int sortKey = cmd.getSortKey() != null ? cmd.getSortKey() : zone.getSortKey();

// validate network domain
if (networkDomain != null && !networkDomain.isEmpty()) {
if (!NetUtils.verifyDomainName(networkDomain)) {
Expand All @@ -1942,6 +1943,7 @@ public DataCenter editZone(final UpdateZoneCmd cmd) {
zone.setInternalDns1(internalDns1);
zone.setInternalDns2(internalDns2);
zone.setGuestNetworkCidr(guestCidr);
zone.setSortKey(sortKey);
if (localStorageEnabled != null) {
zone.setLocalStorageEnabled(localStorageEnabled.booleanValue());
}
Expand Down
18 changes: 18 additions & 0 deletions ui/scripts/cloudStack.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,24 @@
}
});

// Update global pagesize for sort key in UI
$.ajax({
type: 'GET',
url: createURL('listConfigurations'),
data: {name: 'sortkey.algorithm'},
dataType: 'json',
async: false,
success: function(data, textStatus, xhr) {
if (data && data.listconfigurationsresponse && data.listconfigurationsresponse.configuration) {
var config = data.listconfigurationsresponse.configuration[0];
if (config && config.name == 'sortkey.algorithm') {
g_sortKeyIsAscending = config.value == 'true';
}
}
},
error: function(xhr) { // ignore any errors, fallback to the default
}
});

// Populate IDP list
$.ajax({
Expand Down
3 changes: 2 additions & 1 deletion ui/scripts/sharedFunctions.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ var g_cloudstackversion = null;
var g_queryAsyncJobResultInterval = 3000;
var g_idpList = null;
var g_appendIdpDomain = false;
var g_sortKeyIsAscending = false;

//keyboard keycode
var keycode_Enter = 13;
Expand Down Expand Up @@ -2412,7 +2413,7 @@ cloudStack.api = {
url: createURL(updateCommand),
data: {
id: args.context[objType].id,
sortKey: args.index
sortKey: g_sortKeyIsAscending ? (-1 * args.index) : args.index
},
success: function(json) {
args.response.success();
Expand Down
2 changes: 2 additions & 0 deletions ui/scripts/system.js
Original file line number Diff line number Diff line change
Expand Up @@ -7883,6 +7883,8 @@
}
},

reorder: cloudStack.api.actions.sort('updateZone', 'physicalResources'),

dataProvider: function (args) {
var array1 =[];
if (args.filterBy != null) {
Expand Down