Skip to content

Commit 83e2101

Browse files
author
Landry JUGE
committed
Apply review feedback on service offering categories
1 parent 505b9c8 commit 83e2101

13 files changed

Lines changed: 169 additions & 16 deletions

File tree

api/src/main/java/org/apache/cloudstack/api/ApiConstants.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,6 @@ public class ApiConstants {
551551
public static final String SERIAL = "serial";
552552
public static final String SERVICE_IP = "serviceip";
553553
public static final String SERVICE_OFFERING_CATEGORY_ID = "categoryid";
554-
public static final String SERVICE_OFFERING_CATEGORY_NAME = "categoryname";
555554
public static final String SERVICE_OFFERING_ID = "serviceofferingid";
556555
public static final String SERVICE_OFFERING_NAME = "serviceofferingname";
557556
public static final String SESSIONKEY = "sessionkey";

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
@APICommand(name = "deleteServiceOfferingCategory",
3131
description = "Deletes a service offering category.",
3232
responseObject = SuccessResponse.class,
33-
since = "4.23.0",
33+
since = "24.0",
3434
requestHasSensitiveInfo = false,
3535
responseHasSensitiveInfo = false)
3636
public class DeleteServiceOfferingCategoryCmd extends BaseCmd {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
@APICommand(name = "listServiceOfferingCategories",
2727
description = "Lists service offering categories.",
2828
responseObject = ServiceOfferingCategoryResponse.class,
29-
since = "4.23.0",
29+
since = "24.0",
3030
requestHasSensitiveInfo = false,
3131
responseHasSensitiveInfo = false)
3232
public class ListServiceOfferingCategoriesCmd extends BaseListCmd {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
@APICommand(name = "updateServiceOfferingCategory",
3131
description = "Updates a service offering category",
3232
responseObject = ServiceOfferingCategoryResponse.class,
33-
since = "4.23.0",
33+
since = "24.0",
3434
requestHasSensitiveInfo = false,
3535
responseHasSensitiveInfo = false)
3636
public class UpdateServiceOfferingCategoryCmd extends BaseCmd {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public class UpdateServiceOfferingCmd extends BaseCmd implements DomainAndZoneId
114114
entityType = ServiceOfferingCategoryResponse.class,
115115
required = false,
116116
description = "the ID of the service offering category to associate",
117-
since = "4.23.0")
117+
since = "24.0")
118118
private Long categoryId;
119119

120120
/////////////////////////////////////////////////////

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ public class ListServiceOfferingsCmd extends BaseListProjectAndAccountResourcesC
129129
type = CommandType.UUID,
130130
entityType = ServiceOfferingCategoryResponse.class,
131131
description = "the ID of the service offering category",
132-
since = "4.23.0")
132+
since = "24.0")
133133
private Long categoryId;
134134

135135
/////////////////////////////////////////////////////

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,11 +287,11 @@ public class ServiceOfferingResponse extends BaseResponseWithAnnotations {
287287
private String leaseExpiryAction;
288288

289289
@SerializedName("categoryid")
290-
@Param(description = "the ID of the service offering category", since = "4.23.0")
290+
@Param(description = "the ID of the service offering category", since = "24.0")
291291
private String categoryId;
292292

293293
@SerializedName("category")
294-
@Param(description = "the name of the service offering category", since = "4.23.0")
294+
@Param(description = "the name of the service offering category", since = "24.0")
295295
private String categoryName;
296296

297297
public ServiceOfferingResponse() {

engine/schema/src/main/resources/META-INF/db/schema-42210to42300.sql

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,10 @@ CREATE TABLE IF NOT EXISTS `cloud`.`service_offering_category` (
2929
CONSTRAINT `uc_service_offering_category__name` UNIQUE (`name`)
3030
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
3131

32-
INSERT INTO `cloud`.`service_offering_category` (id, name, uuid) VALUES (1, 'Default', UUID());
32+
INSERT IGNORE INTO `cloud`.`service_offering_category` (id, name, uuid) VALUES (1, 'Default', UUID());
3333

34-
ALTER TABLE `cloud`.`service_offering` ADD COLUMN `category_id` bigint unsigned NOT NULL DEFAULT 1;
34+
CALL `cloud`.`IDEMPOTENT_ADD_COLUMN`('cloud.service_offering', 'category_id', 'bigint unsigned NOT NULL DEFAULT 1');
35+
CALL `cloud`.`IDEMPOTENT_DROP_FOREIGN_KEY`('cloud.service_offering', 'fk_service_offering__category_id');
3536
ALTER TABLE `cloud`.`service_offering` ADD CONSTRAINT `fk_service_offering__category_id` FOREIGN KEY (`category_id`) REFERENCES `cloud`.`service_offering_category` (`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
3637

3738
CALL `cloud`.`IDEMPOTENT_ADD_COLUMN`('cloud.oauth_provider', 'domain_id', 'bigint unsigned DEFAULT NULL COMMENT "NULL for global provider, domain ID for domain-specific" AFTER `redirect_uri`');

server/src/main/java/com/cloud/configuration/ConfigurationManagerImpl.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3976,6 +3976,13 @@ public ServiceOffering cloneServiceOffering(final CloneServiceOfferingCmd cmd) {
39763976

39773977
final Long diskOfferingId = getOrDefault(cmd.getDiskOfferingId(), sourceOffering.getDiskOfferingId());
39783978

3979+
// validate the overridden category id, otherwise inherit the source offering's category
3980+
final Long cmdCategoryId = cmd.getCategoryId();
3981+
if (cmdCategoryId != null && _serviceOfferingCategoryDao.findById(cmdCategoryId) == null) {
3982+
throw new InvalidParameterValueException("Please specify a valid service offering category id");
3983+
}
3984+
final Long categoryId = getOrDefault(cmdCategoryId, sourceOffering.getCategoryId());
3985+
39793986
return createServiceOffering(userId, systemUse, vmType,
39803987
name, cpuNumber, memory, cpuSpeed, displayText, provisioningType, localStorageRequired,
39813988
offerHa, limitCpuUse, isVolatile, tags, domainIds, zoneIds, hostTag, networkRate,
@@ -3987,7 +3994,7 @@ public ServiceOffering cloneServiceOffering(final CloneServiceOfferingCmd cmd) {
39873994
diskParams.iopsWriteRate, diskParams.iopsWriteRateMax, diskParams.iopsWriteRateMaxLength,
39883995
diskParams.hypervisorSnapshotReserve, diskParams.cacheMode, customParams.storagePolicy, dynamicScalingEnabled,
39893996
diskOfferingId, diskOfferingStrictness, isCustomized, encryptRoot,
3990-
vgpuProfileId, finalGpuCount, gpuDisplay, purgeResources, leaseParams.leaseDuration, leaseParams.leaseExpiryAction, sourceOffering.getCategoryId());
3997+
vgpuProfileId, finalGpuCount, gpuDisplay, purgeResources, leaseParams.leaseDuration, leaseParams.leaseExpiryAction, categoryId);
39913998
}
39923999

39934000
private ServiceOfferingVO getAndValidateSourceOffering(Long sourceOfferingId) {

server/src/test/java/com/cloud/configuration/ConfigurationManagerCloneIntegrationTest.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
import com.cloud.offerings.dao.NetworkOfferingDao;
3131
import com.cloud.offerings.dao.NetworkOfferingServiceMapDao;
3232
import com.cloud.service.ServiceOfferingVO;
33+
import com.cloud.service.ServiceOfferingCategoryVO;
34+
import com.cloud.service.dao.ServiceOfferingCategoryDao;
3335
import com.cloud.service.dao.ServiceOfferingDao;
3436
import com.cloud.service.dao.ServiceOfferingDetailsDao;
3537
import com.cloud.storage.DiskOfferingVO;
@@ -95,6 +97,9 @@ public class ConfigurationManagerCloneIntegrationTest {
9597
@Mock
9698
private ServiceOfferingDetailsDao serviceOfferingDetailsDao;
9799

100+
@Mock
101+
private ServiceOfferingCategoryDao serviceOfferingCategoryDao;
102+
98103
@Mock
99104
private DiskOfferingDao diskOfferingDao;
100105

@@ -167,6 +172,9 @@ public void setUp() {
167172
anyInt(), anyString(), any(), anyLong(), anyBoolean(), anyBoolean());
168173

169174

175+
Mockito.lenient().when(serviceOfferingCategoryDao.findById(anyLong()))
176+
.thenReturn(mock(ServiceOfferingCategoryVO.class));
177+
170178
// User/Account DAO stubs used by createDiskOffering
171179
Mockito.lenient().when(userDao.findById(anyLong())).thenReturn(userVO);
172180
Mockito.lenient().when(userVO.getAccountId()).thenReturn(1L);
@@ -341,6 +349,7 @@ public void testCloneServiceOfferingOverridesProvidedParameters() {
341349
Assert.assertEquals("Cloned offering should override HA", Boolean.FALSE, result.isOfferHA());
342350
}
343351

352+
344353
@Test(expected = InvalidParameterValueException.class)
345354
public void testCloneDiskOfferingFailsWhenSourceNotFound() {
346355
CloneDiskOfferingCmd cmd = mock(CloneDiskOfferingCmd.class);

0 commit comments

Comments
 (0)