Skip to content

Commit d681dfa

Browse files
author
Daan Hoogland
committed
constrained offerings should not have cpu speed of 0
1 parent b394b5b commit d681dfa

File tree

1 file changed

+25
-7
lines changed

1 file changed

+25
-7
lines changed

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

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3198,14 +3198,8 @@ public ServiceOffering createServiceOffering(final CreateServiceOfferingCmd cmd)
31983198
final String offeringName = cmd.getServiceOfferingName();
31993199

32003200
final String name = cmd.getServiceOfferingName();
3201-
if (name == null || name.length() == 0) {
3202-
throw new InvalidParameterValueException("Failed to create service offering: specify the name that has non-zero length");
3203-
}
3204-
32053201
final String displayText = cmd.getDisplayText();
3206-
if (displayText == null || displayText.length() == 0) {
3207-
throw new InvalidParameterValueException("Failed to create service offering " + name + ": specify the display text that has non-zero length");
3208-
}
3202+
checkNameAndText(name, displayText);
32093203

32103204
final Integer cpuNumber = cmd.getCpuNumber();
32113205
final Integer cpuSpeed = cmd.getCpuSpeed();
@@ -3217,6 +3211,8 @@ public ServiceOffering createServiceOffering(final CreateServiceOfferingCmd cmd)
32173211
Integer maxMemory = cmd.getMaxMemory();
32183212
Integer minMemory = cmd.getMinMemory();
32193213

3214+
checkSpeedOnConstrainedOffering(cmd.isCustomized(), cpuSpeed, offeringName, maxCPU, minCPU, maxMemory, minMemory);
3215+
32203216
// Check if service offering is Custom,
32213217
// If Customized, the following conditions must hold
32223218
// 1. cpuNumber, cpuSpeed and memory should be all null
@@ -3382,6 +3378,28 @@ public ServiceOffering createServiceOffering(final CreateServiceOfferingCmd cmd)
33823378
cmd.getDiskOfferingStrictness(), cmd.isCustomized(), cmd.getEncryptRoot(), cmd.isPurgeResources());
33833379
}
33843380

3381+
private static void checkNameAndText(String name, String displayText) {
3382+
if (name == null || name.length() == 0) {
3383+
throw new InvalidParameterValueException("Failed to create service offering: specify the name that has non-zero length");
3384+
}
3385+
3386+
if (displayText == null || displayText.length() == 0) {
3387+
throw new InvalidParameterValueException("Failed to create service offering " + name + ": specify the display text that has non-zero length");
3388+
}
3389+
}
3390+
3391+
private static void checkSpeedOnConstrainedOffering(boolean customised, Integer cpuSpeed, String offeringName, Integer maxCPU, Integer minCPU, Integer maxMemory, Integer minMemory) {
3392+
// Check for the combination of zero speed and custom or constrained offering
3393+
if (cpuSpeed != null && cpuSpeed.intValue() == 0) {
3394+
if (customised) {
3395+
throw new InvalidParameterValueException("Failed to create service offering " + offeringName + ": cpu speed cannot be zero for custom offerings");
3396+
}
3397+
if (maxCPU != null || minCPU != null || maxMemory != null || minMemory != null) {
3398+
throw new InvalidParameterValueException("Failed to create service offering " + offeringName + ": cpu speed cannot be zero for constrained offerings");
3399+
}
3400+
}
3401+
}
3402+
33853403
protected ServiceOfferingVO createServiceOffering(final long userId, final boolean isSystem, final VirtualMachine.Type vmType,
33863404
final String name, final Integer cpu, final Integer ramSize, final Integer speed, final String displayText, final String provisioningType, final boolean localStorageRequired,
33873405
final boolean offerHA, final boolean limitResourceUse, final boolean volatileVm, String tags, final List<Long> domainIds, List<Long> zoneIds, final String hostTag,

0 commit comments

Comments
 (0)