server: support sort_key for vpc_offerings table (#3268)

Fixes #2742

UI Supported ordering VPC Offerings but the API did not have that
support implemented. This makes the change in updateVPCOfferings
and listVPCOfferings API calls, along with necessary database
changes for supporting sorting of VPC Offerings.
This commit is contained in:
Anurag Awasthi 2019-06-26 08:02:19 +05:30 committed by Rohit Yadav
parent bc05bd1a0e
commit f653e6149c
5 changed files with 57 additions and 11 deletions

View File

@ -20,6 +20,8 @@ package com.cloud.network.vpc;
import java.util.List;
import java.util.Map;
import org.apache.cloudstack.api.command.admin.vpc.UpdateVPCOfferingCmd;
import com.cloud.utils.Pair;
public interface VpcProvisioningService {
@ -40,13 +42,13 @@ public interface VpcProvisioningService {
*/
public boolean deleteVpcOffering(long offId);
/**
* @param vpcOffId
* @param vpcOfferingName
* @param displayText
* @param state
* @return
*/
@Deprecated
public VpcOffering updateVpcOffering(long vpcOffId, String vpcOfferingName, String displayText, String state);
/**
* @param vpcOfferingCmd
* @return
*/
public VpcOffering updateVpcOffering(final UpdateVPCOfferingCmd vpcOfferingCmd);
}

View File

@ -52,6 +52,9 @@ public class UpdateVPCOfferingCmd extends BaseAsyncCmd {
@Parameter(name = ApiConstants.STATE, type = CommandType.STRING, description = "update state for the VPC offering; " + "supported states - Enabled/Disabled")
private String state;
@Parameter(name = ApiConstants.SORT_KEY, type = CommandType.INTEGER, description = "sort key of the VPC offering, integer")
private Integer sortKey;
/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
/////////////////////////////////////////////////////
@ -72,6 +75,11 @@ public class UpdateVPCOfferingCmd extends BaseAsyncCmd {
return state;
}
public Integer getSortKey() {
return sortKey;
}
/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////
@ -87,7 +95,7 @@ public class UpdateVPCOfferingCmd extends BaseAsyncCmd {
@Override
public void execute() {
VpcOffering result = _vpcProvSvc.updateVpcOffering(getId(), getVpcOfferingName(), getDisplayText(), getState());
VpcOffering result = _vpcProvSvc.updateVpcOffering(this);
if (result != null) {
VpcOfferingResponse response = _responseGenerator.createVpcOfferingResponse(result);
response.setResponseName(getCommandName());

View File

@ -76,6 +76,9 @@ public class VpcOfferingVO implements VpcOffering {
@Column(name = "redundant_router_service")
boolean redundantRouter = false;
@Column(name = "sort_key")
int sortKey;
public VpcOfferingVO() {
this.uuid = UUID.randomUUID().toString();
}
@ -183,4 +186,12 @@ public class VpcOfferingVO implements VpcOffering {
return this.redundantRouter;
}
public void setSortKey(int key) {
sortKey = key;
}
public int getSortKey() {
return sortKey;
}
}

View File

@ -26,6 +26,8 @@ INSERT IGNORE INTO `cloud`.`guest_os_hypervisor` (uuid,hypervisor_type, hypervis
-- DPDK client and server mode support
ALTER TABLE `cloud`.`service_offering_details` CHANGE COLUMN `value` `value` TEXT NOT NULL;
ALTER TABLE `cloud`.`vpc_offerings` ADD COLUMN `sort_key` int(32) NOT NULL default 0 COMMENT 'sort key used for customising sort method';
-- Add `sort_key` column to data_center
ALTER TABLE `cloud`.`data_center` ADD COLUMN `sort_key` INT(32) NOT NULL DEFAULT 0;
@ -67,4 +69,4 @@ CREATE VIEW `cloud`.`data_center_view` AS
left join
`cloud`.`dedicated_resources` ON data_center.id = dedicated_resources.data_center_id
left join
`cloud`.`affinity_group` ON dedicated_resources.affinity_group_id = affinity_group.id;
`cloud`.`affinity_group` ON dedicated_resources.affinity_group_id = affinity_group.id;

View File

@ -39,6 +39,7 @@ import javax.inject.Inject;
import javax.naming.ConfigurationException;
import org.apache.cloudstack.acl.ControlledEntity.ACLType;
import org.apache.cloudstack.api.command.admin.vpc.UpdateVPCOfferingCmd;
import org.apache.cloudstack.api.command.user.vpc.ListPrivateGatewaysCmd;
import org.apache.cloudstack.api.command.user.vpc.ListStaticRoutesCmd;
import org.apache.cloudstack.context.CallContext;
@ -579,7 +580,9 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis
@Override
public Pair<List<? extends VpcOffering>, Integer> listVpcOfferings(final Long id, final String name, final String displayText, final List<String> supportedServicesStr,
final Boolean isDefault, final String keyword, final String state, final Long startIndex, final Long pageSizeVal) {
final Filter searchFilter = new Filter(VpcOfferingVO.class, "created", false, null, null);
Boolean isAscending = Boolean.parseBoolean(_configDao.getValue("sortkey.algorithm"));
isAscending = isAscending == null ? Boolean.TRUE : isAscending;
final Filter searchFilter = new Filter(VpcOfferingVO.class, "sortKey", isAscending, null, null);
final SearchCriteria<VpcOfferingVO> sc = _vpcOffDao.createSearchCriteria();
if (keyword != null) {
@ -692,7 +695,23 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis
@Override
@ActionEvent(eventType = EventTypes.EVENT_VPC_OFFERING_UPDATE, eventDescription = "updating vpc offering")
public VpcOffering updateVpcOffering(final long vpcOffId, final String vpcOfferingName, final String displayText, final String state) {
public VpcOffering updateVpcOffering(long vpcOffId, String vpcOfferingName, String displayText, String state) {
return updateVpcOfferingInternal(vpcOffId, vpcOfferingName, displayText, state, null);
}
@Override
@ActionEvent(eventType = EventTypes.EVENT_VPC_OFFERING_UPDATE, eventDescription = "updating vpc offering")
public VpcOffering updateVpcOffering(final UpdateVPCOfferingCmd vpcOfferingCmd) {
final long vpcOffId = vpcOfferingCmd.getId();
final String vpcOfferingName = vpcOfferingCmd.getVpcOfferingName();
final String displayText = vpcOfferingCmd.getDisplayText();
final String state = vpcOfferingCmd.getState();
final Integer sortKey = vpcOfferingCmd.getSortKey();
return updateVpcOfferingInternal(vpcOffId, vpcOfferingName, displayText, state, sortKey);
}
private VpcOffering updateVpcOfferingInternal(long vpcOffId, String vpcOfferingName, String displayText, String state, Integer sortKey) {
CallContext.current().setEventDetails(" Id: " + vpcOffId);
// Verify input parameters
@ -724,6 +743,10 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis
}
}
if (sortKey != null) {
offering.setSortKey(sortKey);
}
if (_vpcOffDao.update(vpcOffId, offering)) {
s_logger.debug("Updated VPC offeirng id=" + vpcOffId);
return _vpcOffDao.findById(vpcOffId);