Skip to content

Commit b8f8321

Browse files
authored
Allow listing of inactive offerings (#8821)
1 parent f2da882 commit b8f8321

17 files changed

Lines changed: 242 additions & 41 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
import org.apache.log4j.Logger;
3234

@@ -123,6 +125,9 @@ public class UpdateDiskOfferingCmd extends BaseCmd {
123125
@Parameter(name = ApiConstants.CACHE_MODE, type = CommandType.STRING, description = "the cache mode to use for this disk offering", since = "4.15")
124126
private String cacheMode;
125127

128+
@Parameter(name = ApiConstants.STATE, type = CommandType.STRING, description = "state of the disk offering")
129+
private String diskOfferingState;
130+
126131
/////////////////////////////////////////////////////
127132
/////////////////// Accessors ///////////////////////
128133
/////////////////////////////////////////////////////
@@ -262,6 +267,13 @@ public Long getIopsWriteRateMax() {
262267
public Long getIopsWriteRateMaxLength() {
263268
return iopsWriteRateMaxLength;
264269
}
270+
public State getState() {
271+
State state = EnumUtils.getEnumIgnoreCase(State.class, diskOfferingState);
272+
if (StringUtils.isNotBlank(diskOfferingState) && state == null) {
273+
throw new InvalidParameterValueException("Invalid state value: " + diskOfferingState);
274+
}
275+
return state;
276+
}
265277

266278
/////////////////////////////////////////////////////
267279
/////////////// 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
import org.apache.log4j.Logger;
3234

@@ -84,6 +86,11 @@ public class UpdateServiceOfferingCmd extends BaseCmd {
8486
since = "4.16")
8587
private String hostTags;
8688

89+
@Parameter(name = ApiConstants.STATE,
90+
type = CommandType.STRING,
91+
description = "state of the service offering")
92+
private String serviceOfferingState;
93+
8794
/////////////////////////////////////////////////////
8895
/////////////////// Accessors ///////////////////////
8996
/////////////////////////////////////////////////////
@@ -172,6 +179,14 @@ public String getHostTags() {
172179
return hostTags;
173180
}
174181

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

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

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

19+
import com.cloud.offering.DiskOffering.State;
1920
import org.apache.cloudstack.api.BaseListProjectAndAccountResourcesCmd;
2021
import org.apache.cloudstack.api.response.StoragePoolResponse;
2122
import org.apache.cloudstack.api.response.VolumeResponse;
2223
import org.apache.cloudstack.api.response.ZoneResponse;
24+
import org.apache.commons.lang3.EnumUtils;
25+
import org.apache.commons.lang3.StringUtils;
2326
import org.apache.log4j.Logger;
2427

2528
import org.apache.cloudstack.api.APICommand;
@@ -29,6 +32,8 @@
2932
import org.apache.cloudstack.api.response.DiskOfferingResponse;
3033
import org.apache.cloudstack.api.response.ListResponse;
3134

35+
import static com.cloud.offering.DiskOffering.State.Active;
36+
3237
@APICommand(name = "listDiskOfferings", description = "Lists all available disk offerings.", responseObject = DiskOfferingResponse.class,
3338
requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
3439
public class ListDiskOfferingsCmd extends BaseListProjectAndAccountResourcesCmd {
@@ -67,6 +72,11 @@ public class ListDiskOfferingsCmd extends BaseListProjectAndAccountResourcesCmd
6772
since = "4.19")
6873
private String storageType;
6974

75+
@Parameter(name = ApiConstants.STATE, type = CommandType.STRING,
76+
description = "Filter by state of the disk offering. Defaults to 'Active'. If set to 'all' shows both Active & Inactive offerings.",
77+
since = "4.19")
78+
private String diskOfferingState;
79+
7080
/////////////////////////////////////////////////////
7181
/////////////////// Accessors ///////////////////////
7282
/////////////////////////////////////////////////////
@@ -95,6 +105,17 @@ public String getStorageType() {
95105
return storageType;
96106
}
97107

108+
public State getState() {
109+
if (StringUtils.isBlank(diskOfferingState)) {
110+
return Active;
111+
}
112+
State state = EnumUtils.getEnumIgnoreCase(State.class, diskOfferingState);
113+
if (!diskOfferingState.equalsIgnoreCase("all") && state == null) {
114+
throw new IllegalArgumentException("Invalid state value: " + diskOfferingState);
115+
}
116+
return state;
117+
}
118+
98119
/////////////////////////////////////////////////////
99120
/////////////// API Implementation///////////////////
100121
/////////////////////////////////////////////////////

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

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,22 @@
1616
// under the License.
1717
package org.apache.cloudstack.api.command.user.offering;
1818

19+
import com.cloud.offering.ServiceOffering.State;
1920
import org.apache.cloudstack.api.BaseListProjectAndAccountResourcesCmd;
2021
import org.apache.cloudstack.api.response.ZoneResponse;
22+
import org.apache.commons.lang3.EnumUtils;
23+
import org.apache.commons.lang3.StringUtils;
2124
import org.apache.log4j.Logger;
2225

2326
import org.apache.cloudstack.api.APICommand;
2427
import org.apache.cloudstack.api.ApiConstants;
2528
import org.apache.cloudstack.api.Parameter;
26-
import org.apache.cloudstack.api.BaseCmd.CommandType;
2729
import org.apache.cloudstack.api.response.ListResponse;
2830
import org.apache.cloudstack.api.response.ServiceOfferingResponse;
2931
import org.apache.cloudstack.api.response.UserVmResponse;
3032

33+
import static com.cloud.offering.ServiceOffering.State.Active;
34+
3135
@APICommand(name = "listServiceOfferings", description = "Lists all available service offerings.", responseObject = ServiceOfferingResponse.class,
3236
requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
3337
public class ListServiceOfferingsCmd extends BaseListProjectAndAccountResourcesCmd {
@@ -95,6 +99,11 @@ public class ListServiceOfferingsCmd extends BaseListProjectAndAccountResourcesC
9599
since = "4.19")
96100
private String storageType;
97101

102+
@Parameter(name = ApiConstants.STATE, type = CommandType.STRING,
103+
description = "Filter by state of the service offering. Defaults to 'Active'. If set to 'all' shows both Active & Inactive offerings.",
104+
since = "4.19")
105+
private String serviceOfferingState;
106+
98107
/////////////////////////////////////////////////////
99108
/////////////////// Accessors ///////////////////////
100109
/////////////////////////////////////////////////////
@@ -141,6 +150,17 @@ public String getStorageType() {
141150
return storageType;
142151
}
143152

153+
public State getState() {
154+
if (StringUtils.isBlank(serviceOfferingState)) {
155+
return Active;
156+
}
157+
State state = EnumUtils.getEnumIgnoreCase(State.class, serviceOfferingState);
158+
if (!serviceOfferingState.equalsIgnoreCase("all") && state == null) {
159+
throw new IllegalArgumentException("Invalid state value: " + serviceOfferingState);
160+
}
161+
return state;
162+
}
163+
144164
/////////////////////////////////////////////////////
145165
/////////////// API Implementation///////////////////
146166
/////////////////////////////////////////////////////

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;
@@ -226,6 +230,14 @@ public void setName(String name) {
226230
this.name = name;
227231
}
228232

233+
public String getState() {
234+
return state;
235+
}
236+
237+
public void setState(String state) {
238+
this.state = state;
239+
}
240+
229241
public String getDisplayText() {
230242
return displayText;
231243
}

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;
@@ -249,6 +253,14 @@ public void setName(String name) {
249253
this.name = name;
250254
}
251255

256+
public String getState() {
257+
return state;
258+
}
259+
260+
public void setState(String state) {
261+
this.state = state;
262+
}
263+
252264
public Boolean getIsSystem() {
253265
return isSystem;
254266
}

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
@@ -76,7 +76,5 @@ FROM
7676
LEFT JOIN
7777
`cloud`.`disk_offering_details` AS `vsphere_storage_policy` ON `vsphere_storage_policy`.`offering_id` = `disk_offering`.`id`
7878
AND `vsphere_storage_policy`.`name` = 'storagepolicy'
79-
WHERE
80-
`disk_offering`.`state`='Active'
8179
GROUP BY
8280
`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`,
@@ -84,7 +85,7 @@ SELECT
8485
FROM
8586
`cloud`.`service_offering`
8687
INNER JOIN
87-
`cloud`.`disk_offering` ON service_offering.disk_offering_id = disk_offering.id AND `disk_offering`.`state`='Active'
88+
`cloud`.`disk_offering` ON service_offering.disk_offering_id = disk_offering.id
8889
LEFT JOIN
8990
`cloud`.`service_offering_details` AS `domain_details` ON `domain_details`.`service_offering_id` = `service_offering`.`id` AND `domain_details`.`name`='domainid'
9091
LEFT JOIN
@@ -108,7 +109,5 @@ FROM
108109
LEFT JOIN
109110
`cloud`.`service_offering_details` AS `vsphere_storage_policy` ON `vsphere_storage_policy`.`service_offering_id` = `service_offering`.`id`
110111
AND `vsphere_storage_policy`.`name` = 'storagepolicy'
111-
WHERE
112-
`service_offering`.`state`='Active'
113112
GROUP BY
114113
`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
@@ -3332,14 +3332,18 @@ private Ternary<List<Long>, Integer, String[]> searchForDiskOfferingsIdsAndCount
33323332
Long storagePoolId = cmd.getStoragePoolId();
33333333
Boolean encrypt = cmd.getEncrypt();
33343334
String storageType = cmd.getStorageType();
3335+
DiskOffering.State state = cmd.getState();
33353336

33363337
Filter searchFilter = new Filter(DiskOfferingVO.class, "sortKey", SortKeyAscending.value(), cmd.getStartIndex(), cmd.getPageSizeVal());
33373338
searchFilter.addOrderBy(DiskOfferingVO.class, "id", true);
33383339
SearchBuilder<DiskOfferingVO> diskOfferingSearch = _diskOfferingDao.createSearchBuilder();
33393340
diskOfferingSearch.select(null, Func.DISTINCT, diskOfferingSearch.entity().getId()); // select distinct
33403341

33413342
diskOfferingSearch.and("computeOnly", diskOfferingSearch.entity().isComputeOnly(), Op.EQ);
3342-
diskOfferingSearch.and("activeState", diskOfferingSearch.entity().getState(), Op.EQ);
3343+
3344+
if (state != null) {
3345+
diskOfferingSearch.and("state", diskOfferingSearch.entity().getState(), Op.EQ);
3346+
}
33433347

33443348
// Keeping this logic consistent with domain specific zones
33453349
// if a domainId is provided, we just return the disk offering
@@ -3452,7 +3456,10 @@ private Ternary<List<Long>, Integer, String[]> searchForDiskOfferingsIdsAndCount
34523456
SearchCriteria<DiskOfferingVO> sc = diskOfferingSearch.create();
34533457

34543458
sc.setParameters("computeOnly", false);
3455-
sc.setParameters("activeState", DiskOffering.State.Active);
3459+
3460+
if (state != null) {
3461+
sc.setParameters("state", state);
3462+
}
34563463

34573464
if (keyword != null) {
34583465
sc.setParameters("keywordDisplayText", "%" + keyword + "%");
@@ -3595,6 +3602,7 @@ private Pair<List<Long>, Integer> searchForServiceOfferingIdsAndCount(ListServic
35953602
Integer cpuSpeed = cmd.getCpuSpeed();
35963603
Boolean encryptRoot = cmd.getEncryptRoot();
35973604
String storageType = cmd.getStorageType();
3605+
ServiceOffering.State state = cmd.getState();
35983606

35993607
final Account owner = accountMgr.finalizeOwner(caller, accountName, domainId, projectId);
36003608

@@ -3629,7 +3637,10 @@ private Pair<List<Long>, Integer> searchForServiceOfferingIdsAndCount(ListServic
36293637

36303638
SearchBuilder<ServiceOfferingVO> serviceOfferingSearch = _srvOfferingDao.createSearchBuilder();
36313639
serviceOfferingSearch.select(null, Func.DISTINCT, serviceOfferingSearch.entity().getId()); // select distinct
3632-
serviceOfferingSearch.and("activeState", serviceOfferingSearch.entity().getState(), Op.EQ);
3640+
3641+
if (state != null) {
3642+
serviceOfferingSearch.and("state", serviceOfferingSearch.entity().getState(), Op.EQ);
3643+
}
36333644

36343645
if (vmId != null) {
36353646
currentVmOffering = _srvOfferingDao.findByIdIncludingRemoved(vmInstance.getId(), vmInstance.getServiceOfferingId());
@@ -3908,7 +3919,9 @@ private Pair<List<Long>, Integer> searchForServiceOfferingIdsAndCount(ListServic
39083919
}
39093920

39103921
SearchCriteria<ServiceOfferingVO> sc = serviceOfferingSearch.create();
3911-
sc.setParameters("activeState", ServiceOffering.State.Active);
3922+
if (state != null) {
3923+
sc.setParameters("state", state);
3924+
}
39123925

39133926
if (vmId != null) {
39143927
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
@@ -105,6 +105,7 @@ public DiskOfferingResponse newDiskOfferingResponse(DiskOfferingJoinVO offering)
105105
DiskOfferingResponse diskOfferingResponse = new DiskOfferingResponse();
106106
diskOfferingResponse.setId(offering.getUuid());
107107
diskOfferingResponse.setName(offering.getName());
108+
diskOfferingResponse.setState(offering.getState().toString());
108109
diskOfferingResponse.setDisplayText(offering.getDisplayText());
109110
diskOfferingResponse.setProvisioningType(offering.getProvisioningType().toString());
110111
diskOfferingResponse.setCreated(offering.getCreated());

0 commit comments

Comments
 (0)