Skip to content

Commit f653e61

Browse files
Anurag Awasthiyadvr
authored andcommitted
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.
1 parent bc05bd1 commit f653e61

5 files changed

Lines changed: 55 additions & 9 deletions

File tree

api/src/main/java/com/cloud/network/vpc/VpcProvisioningService.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
import java.util.List;
2121
import java.util.Map;
2222

23+
import org.apache.cloudstack.api.command.admin.vpc.UpdateVPCOfferingCmd;
24+
2325
import com.cloud.utils.Pair;
2426

2527
public interface VpcProvisioningService {
@@ -40,13 +42,13 @@ Pair<List<? extends VpcOffering>,Integer> listVpcOfferings(Long id, String name,
4042
*/
4143
public boolean deleteVpcOffering(long offId);
4244

45+
@Deprecated
46+
public VpcOffering updateVpcOffering(long vpcOffId, String vpcOfferingName, String displayText, String state);
47+
4348
/**
44-
* @param vpcOffId
45-
* @param vpcOfferingName
46-
* @param displayText
47-
* @param state
49+
* @param vpcOfferingCmd
4850
* @return
4951
*/
50-
public VpcOffering updateVpcOffering(long vpcOffId, String vpcOfferingName, String displayText, String state);
52+
public VpcOffering updateVpcOffering(final UpdateVPCOfferingCmd vpcOfferingCmd);
5153

5254
}

api/src/main/java/org/apache/cloudstack/api/command/admin/vpc/UpdateVPCOfferingCmd.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ public class UpdateVPCOfferingCmd extends BaseAsyncCmd {
5252
@Parameter(name = ApiConstants.STATE, type = CommandType.STRING, description = "update state for the VPC offering; " + "supported states - Enabled/Disabled")
5353
private String state;
5454

55+
@Parameter(name = ApiConstants.SORT_KEY, type = CommandType.INTEGER, description = "sort key of the VPC offering, integer")
56+
private Integer sortKey;
57+
5558
/////////////////////////////////////////////////////
5659
/////////////////// Accessors ///////////////////////
5760
/////////////////////////////////////////////////////
@@ -72,6 +75,11 @@ public String getState() {
7275
return state;
7376
}
7477

78+
public Integer getSortKey() {
79+
return sortKey;
80+
}
81+
82+
7583
/////////////////////////////////////////////////////
7684
/////////////// API Implementation///////////////////
7785
/////////////////////////////////////////////////////
@@ -87,7 +95,7 @@ public long getEntityOwnerId() {
8795

8896
@Override
8997
public void execute() {
90-
VpcOffering result = _vpcProvSvc.updateVpcOffering(getId(), getVpcOfferingName(), getDisplayText(), getState());
98+
VpcOffering result = _vpcProvSvc.updateVpcOffering(this);
9199
if (result != null) {
92100
VpcOfferingResponse response = _responseGenerator.createVpcOfferingResponse(result);
93101
response.setResponseName(getCommandName());

engine/schema/src/main/java/com/cloud/network/vpc/VpcOfferingVO.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ public class VpcOfferingVO implements VpcOffering {
7676
@Column(name = "redundant_router_service")
7777
boolean redundantRouter = false;
7878

79+
@Column(name = "sort_key")
80+
int sortKey;
81+
7982
public VpcOfferingVO() {
8083
this.uuid = UUID.randomUUID().toString();
8184
}
@@ -183,4 +186,12 @@ public boolean getRedundantRouter() {
183186
return this.redundantRouter;
184187
}
185188

189+
public void setSortKey(int key) {
190+
sortKey = key;
191+
}
192+
193+
public int getSortKey() {
194+
return sortKey;
195+
}
196+
186197
}

engine/schema/src/main/resources/META-INF/db/schema-41200to41300.sql

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ INSERT IGNORE INTO `cloud`.`guest_os_hypervisor` (uuid,hypervisor_type, hypervis
2626
-- DPDK client and server mode support
2727
ALTER TABLE `cloud`.`service_offering_details` CHANGE COLUMN `value` `value` TEXT NOT NULL;
2828

29+
ALTER TABLE `cloud`.`vpc_offerings` ADD COLUMN `sort_key` int(32) NOT NULL default 0 COMMENT 'sort key used for customising sort method';
30+
2931
-- Add `sort_key` column to data_center
3032
ALTER TABLE `cloud`.`data_center` ADD COLUMN `sort_key` INT(32) NOT NULL DEFAULT 0;
3133

@@ -67,4 +69,4 @@ CREATE VIEW `cloud`.`data_center_view` AS
6769
left join
6870
`cloud`.`dedicated_resources` ON data_center.id = dedicated_resources.data_center_id
6971
left join
70-
`cloud`.`affinity_group` ON dedicated_resources.affinity_group_id = affinity_group.id;
72+
`cloud`.`affinity_group` ON dedicated_resources.affinity_group_id = affinity_group.id;

server/src/main/java/com/cloud/network/vpc/VpcManagerImpl.java

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import javax.naming.ConfigurationException;
4040

4141
import org.apache.cloudstack.acl.ControlledEntity.ACLType;
42+
import org.apache.cloudstack.api.command.admin.vpc.UpdateVPCOfferingCmd;
4243
import org.apache.cloudstack.api.command.user.vpc.ListPrivateGatewaysCmd;
4344
import org.apache.cloudstack.api.command.user.vpc.ListStaticRoutesCmd;
4445
import org.apache.cloudstack.context.CallContext;
@@ -579,7 +580,9 @@ public Map<Service, Set<Provider>> getVpcOffSvcProvidersMap(final long vpcOffId)
579580
@Override
580581
public Pair<List<? extends VpcOffering>, Integer> listVpcOfferings(final Long id, final String name, final String displayText, final List<String> supportedServicesStr,
581582
final Boolean isDefault, final String keyword, final String state, final Long startIndex, final Long pageSizeVal) {
582-
final Filter searchFilter = new Filter(VpcOfferingVO.class, "created", false, null, null);
583+
Boolean isAscending = Boolean.parseBoolean(_configDao.getValue("sortkey.algorithm"));
584+
isAscending = isAscending == null ? Boolean.TRUE : isAscending;
585+
final Filter searchFilter = new Filter(VpcOfferingVO.class, "sortKey", isAscending, null, null);
583586
final SearchCriteria<VpcOfferingVO> sc = _vpcOffDao.createSearchCriteria();
584587

585588
if (keyword != null) {
@@ -692,7 +695,23 @@ public boolean deleteVpcOffering(final long offId) {
692695

693696
@Override
694697
@ActionEvent(eventType = EventTypes.EVENT_VPC_OFFERING_UPDATE, eventDescription = "updating vpc offering")
695-
public VpcOffering updateVpcOffering(final long vpcOffId, final String vpcOfferingName, final String displayText, final String state) {
698+
public VpcOffering updateVpcOffering(long vpcOffId, String vpcOfferingName, String displayText, String state) {
699+
return updateVpcOfferingInternal(vpcOffId, vpcOfferingName, displayText, state, null);
700+
}
701+
702+
@Override
703+
@ActionEvent(eventType = EventTypes.EVENT_VPC_OFFERING_UPDATE, eventDescription = "updating vpc offering")
704+
public VpcOffering updateVpcOffering(final UpdateVPCOfferingCmd vpcOfferingCmd) {
705+
final long vpcOffId = vpcOfferingCmd.getId();
706+
final String vpcOfferingName = vpcOfferingCmd.getVpcOfferingName();
707+
final String displayText = vpcOfferingCmd.getDisplayText();
708+
final String state = vpcOfferingCmd.getState();
709+
final Integer sortKey = vpcOfferingCmd.getSortKey();
710+
711+
return updateVpcOfferingInternal(vpcOffId, vpcOfferingName, displayText, state, sortKey);
712+
}
713+
714+
private VpcOffering updateVpcOfferingInternal(long vpcOffId, String vpcOfferingName, String displayText, String state, Integer sortKey) {
696715
CallContext.current().setEventDetails(" Id: " + vpcOffId);
697716

698717
// Verify input parameters
@@ -724,6 +743,10 @@ public VpcOffering updateVpcOffering(final long vpcOffId, final String vpcOfferi
724743
}
725744
}
726745

746+
if (sortKey != null) {
747+
offering.setSortKey(sortKey);
748+
}
749+
727750
if (_vpcOffDao.update(vpcOffId, offering)) {
728751
s_logger.debug("Updated VPC offeirng id=" + vpcOffId);
729752
return _vpcOffDao.findById(vpcOffId);

0 commit comments

Comments
 (0)