Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3198,14 +3198,8 @@ public ServiceOffering createServiceOffering(final CreateServiceOfferingCmd cmd)
final String offeringName = cmd.getServiceOfferingName();

final String name = cmd.getServiceOfferingName();
if (name == null || name.length() == 0) {
throw new InvalidParameterValueException("Failed to create service offering: specify the name that has non-zero length");
}

final String displayText = cmd.getDisplayText();
if (displayText == null || displayText.length() == 0) {
throw new InvalidParameterValueException("Failed to create service offering " + name + ": specify the display text that has non-zero length");
}
checkNameAndText(name, displayText);

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

checkSpeedOnConstrainedOffering(cmd.isCustomized(), cpuSpeed, offeringName, maxCPU, minCPU, maxMemory, minMemory);

// Check if service offering is Custom,
// If Customized, the following conditions must hold
// 1. cpuNumber, cpuSpeed and memory should be all null
Expand Down Expand Up @@ -3382,6 +3378,28 @@ public ServiceOffering createServiceOffering(final CreateServiceOfferingCmd cmd)
cmd.getDiskOfferingStrictness(), cmd.isCustomized(), cmd.getEncryptRoot(), cmd.isPurgeResources());
}

private static void checkNameAndText(String name, String displayText) {
if (name == null || name.length() == 0) {
throw new InvalidParameterValueException("Failed to create service offering: specify the name that has non-zero length");
}

if (displayText == null || displayText.length() == 0) {
throw new InvalidParameterValueException("Failed to create service offering " + name + ": specify the display text that has non-zero length");
}
}

private static void checkSpeedOnConstrainedOffering(boolean customised, Integer cpuSpeed, String offeringName, Integer maxCPU, Integer minCPU, Integer maxMemory, Integer minMemory) {
// Check for the combination of zero speed and custom or constrained offering
if (cpuSpeed != null && cpuSpeed.intValue() == 0) {
if (customised) {
throw new InvalidParameterValueException("Failed to create service offering " + offeringName + ": cpu speed cannot be zero for custom offerings");
}
if (maxCPU != null || minCPU != null || maxMemory != null || minMemory != null) {
throw new InvalidParameterValueException("Failed to create service offering " + offeringName + ": cpu speed cannot be zero for constrained offerings");
}
}
}

protected ServiceOfferingVO createServiceOffering(final long userId, final boolean isSystem, final VirtualMachine.Type vmType,
final String name, final Integer cpu, final Integer ramSize, final Integer speed, final String displayText, final String provisioningType, final boolean localStorageRequired,
final boolean offerHA, final boolean limitResourceUse, final boolean volatileVm, String tags, final List<Long> domainIds, List<Long> zoneIds, final String hostTag,
Expand Down