Skip to content

Commit 9977d48

Browse files
vishesh92dhslove
authored andcommitted
Allow listing of inactive offerings (apache#8821)
1 parent 8ea0902 commit 9977d48

17 files changed

Lines changed: 251 additions & 40 deletions

File tree

api/src/main/java/org/apache/cloudstack/api/command/admin/offering/UpdateDiskOfferingCmd.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.util.ArrayList;
2020
import java.util.List;
2121

22+
import com.cloud.offering.DiskOffering.State;
2223
import org.apache.cloudstack.api.APICommand;
2324
import org.apache.cloudstack.api.ApiCommandResourceType;
2425
import org.apache.cloudstack.api.ApiConstants;
@@ -27,6 +28,7 @@
2728
import org.apache.cloudstack.api.Parameter;
2829
import org.apache.cloudstack.api.ServerApiException;
2930
import org.apache.cloudstack.api.response.DiskOfferingResponse;
31+
import org.apache.commons.lang3.EnumUtils;
3032
import org.apache.commons.lang3.StringUtils;
3133

3234
import com.cloud.dc.DataCenter;
@@ -121,6 +123,9 @@ public class UpdateDiskOfferingCmd extends BaseCmd {
121123
@Parameter(name = ApiConstants.CACHE_MODE, type = CommandType.STRING, description = "the cache mode to use for this disk offering", since = "4.15")
122124
private String cacheMode;
123125

126+
@Parameter(name = ApiConstants.STATE, type = CommandType.STRING, description = "state of the disk offering")
127+
private String diskOfferingState;
128+
124129
/////////////////////////////////////////////////////
125130
/////////////////// Accessors ///////////////////////
126131
/////////////////////////////////////////////////////
@@ -260,6 +265,13 @@ public Long getIopsWriteRateMax() {
260265
public Long getIopsWriteRateMaxLength() {
261266
return iopsWriteRateMaxLength;
262267
}
268+
public State getState() {
269+
State state = EnumUtils.getEnumIgnoreCase(State.class, diskOfferingState);
270+
if (StringUtils.isNotBlank(diskOfferingState) && state == null) {
271+
throw new InvalidParameterValueException("Invalid state value: " + diskOfferingState);
272+
}
273+
return state;
274+
}
263275

264276
/////////////////////////////////////////////////////
265277
/////////////// API Implementation///////////////////

api/src/main/java/org/apache/cloudstack/api/command/admin/offering/UpdateServiceOfferingCmd.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.util.ArrayList;
2020
import java.util.List;
2121

22+
import com.cloud.offering.ServiceOffering.State;
2223
import org.apache.cloudstack.api.APICommand;
2324
import org.apache.cloudstack.api.ApiCommandResourceType;
2425
import org.apache.cloudstack.api.ApiConstants;
@@ -27,6 +28,7 @@
2728
import org.apache.cloudstack.api.Parameter;
2829
import org.apache.cloudstack.api.ServerApiException;
2930
import org.apache.cloudstack.api.response.ServiceOfferingResponse;
31+
import org.apache.commons.lang3.EnumUtils;
3032
import org.apache.commons.lang3.StringUtils;
3133

3234
import com.cloud.dc.DataCenter;
@@ -82,6 +84,11 @@ public class UpdateServiceOfferingCmd extends BaseCmd {
8284
since = "4.16")
8385
private String hostTags;
8486

87+
@Parameter(name = ApiConstants.STATE,
88+
type = CommandType.STRING,
89+
description = "state of the service offering")
90+
private String serviceOfferingState;
91+
8592
/////////////////////////////////////////////////////
8693
/////////////////// Accessors ///////////////////////
8794
/////////////////////////////////////////////////////
@@ -170,6 +177,14 @@ public String getHostTags() {
170177
return hostTags;
171178
}
172179

180+
public State getState() {
181+
State state = EnumUtils.getEnumIgnoreCase(State.class, serviceOfferingState);
182+
if (StringUtils.isNotBlank(serviceOfferingState) && state == null) {
183+
throw new InvalidParameterValueException("Invalid state value: " + serviceOfferingState);
184+
}
185+
return state;
186+
}
187+
173188
/////////////////////////////////////////////////////
174189
/////////////// API Implementation///////////////////
175190
/////////////////////////////////////////////////////

api/src/main/java/org/apache/cloudstack/api/command/user/offering/ListDiskOfferingsCmd.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,15 @@
1616
// under the License.
1717
package org.apache.cloudstack.api.command.user.offering;
1818

19+
import com.cloud.offering.DiskOffering.State;
20+
import org.apache.cloudstack.api.BaseListProjectAndAccountResourcesCmd;
21+
import org.apache.cloudstack.api.response.StoragePoolResponse;
22+
import org.apache.cloudstack.api.response.VolumeResponse;
23+
import org.apache.cloudstack.api.response.ZoneResponse;
24+
import org.apache.commons.lang3.EnumUtils;
25+
import org.apache.commons.lang3.StringUtils;
26+
import org.apache.log4j.Logger;
27+
1928
import org.apache.cloudstack.api.APICommand;
2029
import org.apache.cloudstack.api.ApiConstants;
2130
import org.apache.cloudstack.api.BaseListProjectAndAccountResourcesCmd;
@@ -27,6 +36,8 @@
2736
import org.apache.cloudstack.api.response.VolumeResponse;
2837
import org.apache.cloudstack.api.response.ZoneResponse;
2938

39+
import static com.cloud.offering.DiskOffering.State.Active;
40+
3041
@APICommand(name = "listDiskOfferings", description = "Lists all available disk offerings.", responseObject = DiskOfferingResponse.class,
3142
requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
3243
public class ListDiskOfferingsCmd extends BaseListProjectAndAccountResourcesCmd {
@@ -70,6 +81,11 @@ public class ListDiskOfferingsCmd extends BaseListProjectAndAccountResourcesCmd
7081
description = "The ID of a virtual machine. Pass this in if you want to see the suitable disk offering that can be used to create and add a disk to the virtual machine. Suitability is returned with suitableforvirtualmachine flag in the response",
7182
since = "4.20.0")
7283
private Long virtualMachineId;
84+
85+
@Parameter(name = ApiConstants.STATE, type = CommandType.STRING,
86+
description = "Filter by state of the disk offering. Defaults to 'Active'. If set to 'all' shows both Active & Inactive offerings.",
87+
since = "4.19")
88+
private String diskOfferingState;
7389

7490
/////////////////////////////////////////////////////
7591
/////////////////// Accessors ///////////////////////
@@ -102,6 +118,17 @@ public String getStorageType() {
102118
public Long getVirtualMachineId() {
103119
return virtualMachineId;
104120
}
121+
122+
public State getState() {
123+
if (StringUtils.isBlank(diskOfferingState)) {
124+
return Active;
125+
}
126+
State state = EnumUtils.getEnumIgnoreCase(State.class, diskOfferingState);
127+
if (!diskOfferingState.equalsIgnoreCase("all") && state == null) {
128+
throw new IllegalArgumentException("Invalid state value: " + diskOfferingState);
129+
}
130+
return state;
131+
}
105132

106133
/////////////////////////////////////////////////////
107134
/////////////// API Implementation///////////////////

api/src/main/java/org/apache/cloudstack/api/command/user/offering/ListServiceOfferingsCmd.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@
1616
// under the License.
1717
package org.apache.cloudstack.api.command.user.offering;
1818

19+
import com.cloud.offering.ServiceOffering.State;
20+
import org.apache.cloudstack.api.BaseListProjectAndAccountResourcesCmd;
21+
import org.apache.cloudstack.api.response.ZoneResponse;
22+
import org.apache.commons.lang3.EnumUtils;
23+
import org.apache.commons.lang3.StringUtils;
24+
import org.apache.log4j.Logger;
25+
1926
import org.apache.cloudstack.api.APICommand;
2027
import org.apache.cloudstack.api.ApiConstants;
2128
import org.apache.cloudstack.api.BaseListProjectAndAccountResourcesCmd;
@@ -26,6 +33,8 @@
2633
import org.apache.cloudstack.api.response.UserVmResponse;
2734
import org.apache.cloudstack.api.response.ZoneResponse;
2835

36+
import static com.cloud.offering.ServiceOffering.State.Active;
37+
2938
@APICommand(name = "listServiceOfferings", description = "Lists all available service offerings.", responseObject = ServiceOfferingResponse.class,
3039
requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
3140
public class ListServiceOfferingsCmd extends BaseListProjectAndAccountResourcesCmd {
@@ -99,6 +108,10 @@ public class ListServiceOfferingsCmd extends BaseListProjectAndAccountResourcesC
99108
since = "4.20.0")
100109
private Long templateId;
101110

111+
@Parameter(name = ApiConstants.STATE, type = CommandType.STRING,
112+
description = "Filter by state of the service offering. Defaults to 'Active'. If set to 'all' shows both Active & Inactive offerings.",
113+
since = "4.19")
114+
private String serviceOfferingState;
102115

103116
/////////////////////////////////////////////////////
104117
/////////////////// Accessors ///////////////////////
@@ -149,6 +162,17 @@ public String getStorageType() {
149162
public Long getTemplateId() {
150163
return templateId;
151164
}
165+
166+
public State getState() {
167+
if (StringUtils.isBlank(serviceOfferingState)) {
168+
return Active;
169+
}
170+
State state = EnumUtils.getEnumIgnoreCase(State.class, serviceOfferingState);
171+
if (!serviceOfferingState.equalsIgnoreCase("all") && state == null) {
172+
throw new IllegalArgumentException("Invalid state value: " + serviceOfferingState);
173+
}
174+
return state;
175+
}
152176

153177
/////////////////////////////////////////////////////
154178
/////////////// API Implementation///////////////////

api/src/main/java/org/apache/cloudstack/api/response/DiskOfferingResponse.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ public class DiskOfferingResponse extends BaseResponseWithAnnotations {
5353
@Param(description = "the name of the disk offering")
5454
private String name;
5555

56+
@SerializedName(ApiConstants.STATE)
57+
@Param(description = "state of the disk offering")
58+
private String state;
59+
5660
@SerializedName(ApiConstants.DISPLAY_TEXT)
5761
@Param(description = "an alternate display text of the disk offering.")
5862
private String displayText;
@@ -234,6 +238,14 @@ public void setName(String name) {
234238
this.name = name;
235239
}
236240

241+
public String getState() {
242+
return state;
243+
}
244+
245+
public void setState(String state) {
246+
this.state = state;
247+
}
248+
237249
public String getDisplayText() {
238250
return displayText;
239251
}

api/src/main/java/org/apache/cloudstack/api/response/ServiceOfferingResponse.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ public class ServiceOfferingResponse extends BaseResponseWithAnnotations {
3737
@Param(description = "the name of the service offering")
3838
private String name;
3939

40+
@SerializedName("state")
41+
@Param(description = "state of the service offering")
42+
private String state;
43+
4044
@SerializedName("displaytext")
4145
@Param(description = "an alternate display text of the service offering.")
4246
private String displayText;
@@ -253,6 +257,14 @@ public void setName(String name) {
253257
this.name = name;
254258
}
255259

260+
public String getState() {
261+
return state;
262+
}
263+
264+
public void setState(String state) {
265+
this.state = state;
266+
}
267+
256268
public Boolean getIsSystem() {
257269
return isSystem;
258270
}

engine/schema/src/main/resources/META-INF/db/views/cloud.disk_offering_view.sql

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,5 @@ FROM
7777
LEFT JOIN
7878
`cloud`.`disk_offering_details` AS `vsphere_storage_policy` ON `vsphere_storage_policy`.`offering_id` = `disk_offering`.`id`
7979
AND `vsphere_storage_policy`.`name` = 'storagepolicy'
80-
WHERE
81-
`disk_offering`.`state`='Active'
8280
GROUP BY
8381
`disk_offering`.`id`;

engine/schema/src/main/resources/META-INF/db/views/cloud.service_offering_view.sql

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ SELECT
2424
`service_offering`.`id` AS `id`,
2525
`service_offering`.`uuid` AS `uuid`,
2626
`service_offering`.`name` AS `name`,
27+
`service_offering`.`state` AS `state`,
2728
`service_offering`.`display_text` AS `display_text`,
2829
`disk_offering`.`provisioning_type` AS `provisioning_type`,
2930
`service_offering`.`created` AS `created`,
@@ -85,7 +86,7 @@ SELECT
8586
FROM
8687
`cloud`.`service_offering`
8788
INNER JOIN
88-
`cloud`.`disk_offering` ON service_offering.disk_offering_id = disk_offering.id AND `disk_offering`.`state`='Active'
89+
`cloud`.`disk_offering` ON service_offering.disk_offering_id = disk_offering.id
8990
LEFT JOIN
9091
`cloud`.`service_offering_details` AS `domain_details` ON `domain_details`.`service_offering_id` = `service_offering`.`id` AND `domain_details`.`name`='domainid'
9192
LEFT JOIN
@@ -109,7 +110,5 @@ FROM
109110
LEFT JOIN
110111
`cloud`.`service_offering_details` AS `vsphere_storage_policy` ON `vsphere_storage_policy`.`service_offering_id` = `service_offering`.`id`
111112
AND `vsphere_storage_policy`.`name` = 'storagepolicy'
112-
WHERE
113-
`service_offering`.`state`='Active'
114113
GROUP BY
115114
`service_offering`.`id`;

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

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3342,14 +3342,18 @@ private Ternary<List<Long>, Integer, String[]> searchForDiskOfferingsIdsAndCount
33423342
Boolean encrypt = cmd.getEncrypt();
33433343
String storageType = cmd.getStorageType();
33443344
final Long vmId = cmd.getVirtualMachineId();
3345+
DiskOffering.State state = cmd.getState();
33453346

33463347
Filter searchFilter = new Filter(DiskOfferingVO.class, "sortKey", SortKeyAscending.value(), cmd.getStartIndex(), cmd.getPageSizeVal());
33473348
searchFilter.addOrderBy(DiskOfferingVO.class, "id", true);
33483349
SearchBuilder<DiskOfferingVO> diskOfferingSearch = _diskOfferingDao.createSearchBuilder();
33493350
diskOfferingSearch.select(null, Func.DISTINCT, diskOfferingSearch.entity().getId()); // select distinct
33503351

33513352
diskOfferingSearch.and("computeOnly", diskOfferingSearch.entity().isComputeOnly(), Op.EQ);
3352-
diskOfferingSearch.and("activeState", diskOfferingSearch.entity().getState(), Op.EQ);
3353+
3354+
if (state != null) {
3355+
diskOfferingSearch.and("state", diskOfferingSearch.entity().getState(), Op.EQ);
3356+
}
33533357

33543358
// Keeping this logic consistent with domain specific zones
33553359
// if a domainId is provided, we just return the disk offering
@@ -3462,7 +3466,10 @@ private Ternary<List<Long>, Integer, String[]> searchForDiskOfferingsIdsAndCount
34623466
SearchCriteria<DiskOfferingVO> sc = diskOfferingSearch.create();
34633467

34643468
sc.setParameters("computeOnly", false);
3465-
sc.setParameters("activeState", DiskOffering.State.Active);
3469+
3470+
if (state != null) {
3471+
sc.setParameters("state", state);
3472+
}
34663473

34673474
if (keyword != null) {
34683475
sc.setParameters("keywordDisplayText", "%" + keyword + "%");
@@ -3634,6 +3641,7 @@ private Pair<List<Long>, Integer> searchForServiceOfferingIdsAndCount(ListServic
36343641
Boolean encryptRoot = cmd.getEncryptRoot();
36353642
String storageType = cmd.getStorageType();
36363643
final Long templateId = cmd.getTemplateId();
3644+
ServiceOffering.State state = cmd.getState();
36373645

36383646
final Account owner = accountMgr.finalizeOwner(caller, accountName, domainId, projectId);
36393647

@@ -3668,7 +3676,10 @@ private Pair<List<Long>, Integer> searchForServiceOfferingIdsAndCount(ListServic
36683676

36693677
SearchBuilder<ServiceOfferingVO> serviceOfferingSearch = _srvOfferingDao.createSearchBuilder();
36703678
serviceOfferingSearch.select(null, Func.DISTINCT, serviceOfferingSearch.entity().getId()); // select distinct
3671-
serviceOfferingSearch.and("activeState", serviceOfferingSearch.entity().getState(), Op.EQ);
3679+
3680+
if (state != null) {
3681+
serviceOfferingSearch.and("state", serviceOfferingSearch.entity().getState(), Op.EQ);
3682+
}
36723683

36733684
if (vmId != null) {
36743685
currentVmOffering = _srvOfferingDao.findByIdIncludingRemoved(vmInstance.getId(), vmInstance.getServiceOfferingId());
@@ -3947,7 +3958,9 @@ private Pair<List<Long>, Integer> searchForServiceOfferingIdsAndCount(ListServic
39473958
}
39483959

39493960
SearchCriteria<ServiceOfferingVO> sc = serviceOfferingSearch.create();
3950-
sc.setParameters("activeState", ServiceOffering.State.Active);
3961+
if (state != null) {
3962+
sc.setParameters("state", state);
3963+
}
39513964

39523965
if (vmId != null) {
39533966
if (!currentVmOffering.isDynamic()) {

server/src/main/java/com/cloud/api/query/dao/DiskOfferingJoinDaoImpl.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ public DiskOfferingResponse newDiskOfferingResponse(DiskOfferingJoinVO offering)
103103
DiskOfferingResponse diskOfferingResponse = new DiskOfferingResponse();
104104
diskOfferingResponse.setId(offering.getUuid());
105105
diskOfferingResponse.setName(offering.getName());
106+
diskOfferingResponse.setState(offering.getState().toString());
106107
diskOfferingResponse.setDisplayText(offering.getDisplayText());
107108
diskOfferingResponse.setProvisioningType(offering.getProvisioningType().toString());
108109
diskOfferingResponse.setCreated(offering.getCreated());

0 commit comments

Comments
 (0)