Skip to content

Commit 296a507

Browse files
Decouple service offering and disk offering states
1 parent 5dc5cc7 commit 296a507

File tree

9 files changed

+26
-25
lines changed

9 files changed

+26
-25
lines changed

api/src/main/java/com/cloud/offering/ServiceOffering.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,9 @@ enum StorageType {
113113

114114
boolean isDynamic();
115115

116-
void setState(DiskOffering.State state);
116+
void setState(ServiceOffering.State state);
117117

118-
DiskOffering.State getState();
118+
ServiceOffering.State getState();
119119

120120
void setName(String name);
121121

engine/schema/src/main/java/com/cloud/service/ServiceOfferingVO.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
import javax.persistence.Enumerated;
3333
import javax.persistence.EnumType;
3434

35-
import com.cloud.offering.DiskOffering;
3635
import com.cloud.offering.ServiceOffering;
3736
import com.cloud.storage.Storage.ProvisioningType;
3837
import com.cloud.utils.db.GenericDao;
@@ -71,7 +70,7 @@ public class ServiceOfferingVO implements ServiceOffering {
7170

7271
@Enumerated(EnumType.STRING)
7372
@Column(name = "state")
74-
DiskOffering.State state = DiskOffering.State.Active;
73+
ServiceOffering.State state = ServiceOffering.State.Active;
7574

7675
@Column(name = "disk_offering_id")
7776
private Long diskOfferingId;
@@ -149,6 +148,8 @@ public ServiceOfferingVO(String name, Integer cpu, Integer ramSize, Integer spee
149148
this.vmType = vmType == null ? null : vmType.toString().toLowerCase();
150149
uuid = UUID.randomUUID().toString();
151150
this.systemUse = systemUse;
151+
this.name = name;
152+
this.displayText = displayText;
152153
}
153154

154155
public ServiceOfferingVO(String name, Integer cpu, Integer ramSize, Integer speed, Integer rateMbps, Integer multicastRateMbps, boolean offerHA,
@@ -168,6 +169,8 @@ public ServiceOfferingVO(String name, Integer cpu, Integer ramSize, Integer spee
168169
this.deploymentPlanner = deploymentPlanner;
169170
uuid = UUID.randomUUID().toString();
170171
this.systemUse = systemUse;
172+
this.name = name;
173+
this.displayText = displayText;
171174
}
172175

173176
public ServiceOfferingVO(ServiceOfferingVO offering) {
@@ -387,12 +390,12 @@ public Date getCreated() {
387390
}
388391

389392
@Override
390-
public DiskOffering.State getState() {
393+
public ServiceOffering.State getState() {
391394
return state;
392395
}
393396

394397
@Override
395-
public void setState(DiskOffering.State state) {
398+
public void setState(ServiceOffering.State state) {
396399
this.state = state;
397400
}
398401

engine/schema/src/main/resources/META-INF/db/schema-41510to41600.sql

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ ALTER TABLE `cloud`.`disk_offering` DROP COLUMN `type`;
3939

4040
ALTER TABLE `cloud`.`vm_instance` DROP COLUMN `disk_offering_id`;
4141

42+
UPDATE `cloud`.`service_offering` so, `cloud`.`disk_offering` do SET so.`name` = do.`name`, so.`display_text` = do.`display_text` WHERE so.`id` = do.`id`;
43+
4244
DROP VIEW IF EXISTS `cloud`.`user_vm_view`;
4345
CREATE
4446
VIEW `user_vm_view` AS
@@ -287,15 +289,15 @@ DROP VIEW IF EXISTS `cloud`.`service_offering_view`;
287289
CREATE VIEW `cloud`.`service_offering_view` AS
288290
SELECT
289291
`service_offering`.`id` AS `id`,
290-
`disk_offering`.`uuid` AS `uuid`,
291-
`disk_offering`.`name` AS `name`,
292-
`disk_offering`.`display_text` AS `display_text`,
292+
`service_offering`.`uuid` AS `uuid`,
293+
`service_offering`.`name` AS `name`,
294+
`service_offering`.`display_text` AS `display_text`,
293295
`disk_offering`.`provisioning_type` AS `provisioning_type`,
294-
`disk_offering`.`created` AS `created`,
296+
`service_offering`.`created` AS `created`,
295297
`disk_offering`.`tags` AS `tags`,
296-
`disk_offering`.`removed` AS `removed`,
298+
`service_offering`.`removed` AS `removed`,
297299
`disk_offering`.`use_local_storage` AS `use_local_storage`,
298-
`disk_offering`.`system_use` AS `system_use`,
300+
`service_offering`.`system_use` AS `system_use`,
299301
`disk_offering`.`customized_iops` AS `customized_iops`,
300302
`disk_offering`.`min_iops` AS `min_iops`,
301303
`disk_offering`.`max_iops` AS `max_iops`,
@@ -342,7 +344,7 @@ CREATE VIEW `cloud`.`service_offering_view` AS
342344
FROM
343345
`cloud`.`service_offering`
344346
INNER JOIN
345-
`cloud`.`disk_offering_view` AS `disk_offering` ON service_offering.id = disk_offering.id
347+
`cloud`.`disk_offering_view` AS `disk_offering` ON service_offering.disk_offering_id = disk_offering.id
346348
LEFT JOIN
347349
`cloud`.`service_offering_details` AS `domain_details` ON `domain_details`.`service_offering_id` = `disk_offering`.`id` AND `domain_details`.`name`='domainid'
348350
LEFT JOIN

framework/quota/src/main/java/org/apache/cloudstack/quota/vo/ServiceOfferingVO.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
import javax.persistence.Enumerated;
3333
import javax.persistence.Transient;
3434

35-
import com.cloud.offering.DiskOffering;
3635
import com.cloud.offering.ServiceOffering;
3736
import com.cloud.utils.db.GenericDao;
3837

@@ -69,7 +68,7 @@ public class ServiceOfferingVO implements ServiceOffering {
6968

7069
@Enumerated(EnumType.STRING)
7170
@Column(name = "state")
72-
DiskOffering.State state = DiskOffering.State.Active;
71+
ServiceOffering.State state = ServiceOffering.State.Active;
7372

7473
@Column(name = "disk_offering_id")
7574
private Long diskOfferingId;
@@ -333,12 +332,12 @@ public Date getCreated() {
333332
}
334333

335334
@Override
336-
public DiskOffering.State getState() {
335+
public ServiceOffering.State getState() {
337336
return state;
338337
}
339338

340339
@Override
341-
public void setState(DiskOffering.State state) {
340+
public void setState(ServiceOffering.State state) {
342341
this.state = state;
343342
}
344343

plugins/network-elements/internal-loadbalancer/src/test/java/org/apache/cloudstack/internallbvmmgr/InternalLBVMManagerTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ private static ServiceOfferingVO setId(final ServiceOfferingVO vo, final long id
341341
final ServiceOfferingVO voToReturn = vo;
342342
final Class<?> c = voToReturn.getClass();
343343
try {
344-
final Field f = c.getSuperclass().getDeclaredField("id");
344+
final Field f = c.getDeclaredField("id");
345345
f.setAccessible(true);
346346
f.setLong(voToReturn, id);
347347
} catch (final NoSuchFieldException ex) {

plugins/network-elements/internal-loadbalancer/src/test/java/org/apache/cloudstack/internallbvmmgr/InternalLBVMServiceTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ private static ServiceOfferingVO setId(final ServiceOfferingVO vo, final long id
251251
final ServiceOfferingVO voToReturn = vo;
252252
final Class<?> c = voToReturn.getClass();
253253
try {
254-
final Field f = c.getSuperclass().getDeclaredField("id");
254+
final Field f = c.getDeclaredField("id");
255255
f.setAccessible(true);
256256
f.setLong(voToReturn, id);
257257
} catch (final NoSuchFieldException ex) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3473,7 +3473,7 @@ public boolean deleteServiceOffering(final DeleteServiceOfferingCmd cmd) {
34733473
throw new InvalidParameterValueException(String.format("Unable to delete service offering: %s by user: %s because it is not root-admin or domain-admin", offering.getUuid(), user.getUuid()));
34743474
}
34753475

3476-
offering.setState(DiskOffering.State.Inactive);
3476+
offering.setState(ServiceOffering.State.Inactive);
34773477
if (_serviceOfferingDao.update(offeringId, offering)) {
34783478
CallContext.current().setEventDetails("Service offering id=" + offeringId);
34793479
return true;

server/src/main/java/com/cloud/vm/UserVmManagerImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1065,7 +1065,7 @@ public UserVm upgradeVirtualMachine(UpgradeVMCmd cmd) throws ResourceAllocationE
10651065
// Check resource limits for CPU and Memory.
10661066
Map<String, String> customParameters = cmd.getDetails();
10671067
ServiceOfferingVO newServiceOffering = _offeringDao.findById(svcOffId);
1068-
if (newServiceOffering.getState() == DiskOffering.State.Inactive) {
1068+
if (newServiceOffering.getState() == ServiceOffering.State.Inactive) {
10691069
throw new InvalidParameterValueException(String.format("Unable to upgrade virtual machine %s with an inactive service offering %s", vmInstance.getUuid(), newServiceOffering.getUuid()));
10701070
}
10711071
if (newServiceOffering.isDynamic()) {

server/src/test/java/com/cloud/vm/UserVmManagerImplTest.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -208,12 +208,9 @@ private ServiceOfferingVO getSvcoffering(int ramSize) {
208208
boolean ha = false;
209209
boolean useLocalStorage = false;
210210

211-
DiskOfferingVO diskOfferingVO = new DiskOfferingVO(name, displayText, Storage.ProvisioningType.THIN, false, null, false, false, false, true);
212-
diskOfferingVO = diskOfferingDao.persistDefaultDiskOffering(diskOfferingVO);
213-
214211
ServiceOfferingVO serviceOffering = new ServiceOfferingVO(name, cpu, ramSize, speed, null, null, ha, displayText, Storage.ProvisioningType.THIN, useLocalStorage, false, null, false, null,
215212
false);
216-
serviceOffering.setDiskOfferingId(diskOfferingVO.getId());
213+
serviceOffering.setDiskOfferingId(1l);
217214
return serviceOffering;
218215
}
219216

0 commit comments

Comments
 (0)