From 3f1e9098b449e97b3d4f51d17393383415811e18 Mon Sep 17 00:00:00 2001 From: Wei Zhou Date: Tue, 6 Oct 2020 07:13:11 +0000 Subject: [PATCH 1/2] server: Fix some cpuspeed issues while create service offering Only the following offerings are accepted (1) fixed offering: cpunumber, memory, must be specified. cpuspeed should be specified example: create serviceoffering displaytext=offering-fix name=offering-fix cpunumber=1 memory=1024 cpuspeed=1000 (should not work) create serviceoffering displaytext=offering-fix name=offering-fix cpunumber=1 memory=1024 (but works in 4.14, fixed by this commit) (2) unconstrained offering: cpunumber, memory must be null cpuspeed must be null example: create serviceoffering displaytext=offering-unconstrained name=offering-unconstrained (should not work) create serviceoffering displaytext=offering-unconstrained name=offering-unconstrained cpunumber=1 create serviceoffering displaytext=offering-unconstrained name=offering-unconstrained memory=1024 create serviceoffering displaytext=offering-unconstrained name=offering-unconstrained cpuspeed=1000 (but works in 4.14, fixed by this commit) (3) constrained offering: cpunumber, memory must be null mincpunumber, maxcpunumber, minmemory, maxmemory, cpuspeed must be specified example:create serviceoffering displaytext=offering-constrained name=offering-constrained mincpunumber=1 maxcpunumber=2 minmemory=1024 maxmemory=2048 cpuspeed=1000 (should not work) create serviceoffering displaytext=offering-constrained name=offering-constrained mincpunumber=1 maxcpunumber=2 minmemory=1024 maxmemory=2048 (but works in 4.14, fixed by this commit) --- .../com/cloud/configuration/ConfigurationManagerImpl.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/server/src/main/java/com/cloud/configuration/ConfigurationManagerImpl.java b/server/src/main/java/com/cloud/configuration/ConfigurationManagerImpl.java index 7e9c9d39c2b1..b4154d1a7be4 100755 --- a/server/src/main/java/com/cloud/configuration/ConfigurationManagerImpl.java +++ b/server/src/main/java/com/cloud/configuration/ConfigurationManagerImpl.java @@ -2319,9 +2319,9 @@ public ServiceOffering createServiceOffering(final CreateServiceOfferingCmd cmd) throw new InvalidParameterValueException("For creating a custom compute offering cpu and memory all should be null"); } // if any of them is null, then all of them shoull be null - if (maxCPU == null || minCPU == null || maxMemory == null || minMemory == null) { - if (maxCPU != null || minCPU != null || maxMemory != null || minMemory != null) { - throw new InvalidParameterValueException("For creating a custom compute offering min/max cpu and min/max memory should all be specified"); + if (maxCPU == null || minCPU == null || maxMemory == null || minMemory == null || cpuSpeed == null) { + if (maxCPU != null || minCPU != null || maxMemory != null || minMemory != null || cpuSpeed != null) { + throw new InvalidParameterValueException("For creating a custom compute offering min/max cpu and min/max memory/cpu speed should all be null or all specified"); } } else { if (cpuSpeed != null && (cpuSpeed.intValue() < 0 || cpuSpeed.longValue() > Integer.MAX_VALUE)) { @@ -2343,7 +2343,7 @@ public ServiceOffering createServiceOffering(final CreateServiceOfferingCmd cmd) if (cpuNumber != null && (cpuNumber.intValue() <= 0 || cpuNumber.longValue() > Integer.MAX_VALUE)) { throw new InvalidParameterValueException("Failed to create service offering " + offeringName + ": specify the cpu number value between 1 and " + Integer.MAX_VALUE); } - if (cpuSpeed != null && (cpuSpeed.intValue() < 0 || cpuSpeed.longValue() > Integer.MAX_VALUE)) { + if (cpuSpeed == null || (cpuSpeed.intValue() < 0 || cpuSpeed.longValue() > Integer.MAX_VALUE)) { throw new InvalidParameterValueException("Failed to create service offering " + offeringName + ": specify the cpu speed value between 0 and " + Integer.MAX_VALUE); } if (memory != null && (memory.intValue() < 32 || memory.longValue() > Integer.MAX_VALUE)) { From 5f2f58c0e2e2612238340caf2e3b152cbfd2872d Mon Sep 17 00:00:00 2001 From: Wei Zhou Date: Fri, 9 Oct 2020 19:33:08 +0000 Subject: [PATCH 2/2] #4376 Remove unnecessary null check on cpuSpeed --- .../java/com/cloud/configuration/ConfigurationManagerImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/src/main/java/com/cloud/configuration/ConfigurationManagerImpl.java b/server/src/main/java/com/cloud/configuration/ConfigurationManagerImpl.java index b4154d1a7be4..5534b749348f 100755 --- a/server/src/main/java/com/cloud/configuration/ConfigurationManagerImpl.java +++ b/server/src/main/java/com/cloud/configuration/ConfigurationManagerImpl.java @@ -2324,7 +2324,7 @@ public ServiceOffering createServiceOffering(final CreateServiceOfferingCmd cmd) throw new InvalidParameterValueException("For creating a custom compute offering min/max cpu and min/max memory/cpu speed should all be null or all specified"); } } else { - if (cpuSpeed != null && (cpuSpeed.intValue() < 0 || cpuSpeed.longValue() > Integer.MAX_VALUE)) { + if (cpuSpeed.intValue() < 0 || cpuSpeed.longValue() > Integer.MAX_VALUE) { throw new InvalidParameterValueException("Failed to create service offering " + offeringName + ": specify the cpu speed value between 1 and " + Integer.MAX_VALUE); } if ((maxCPU <= 0 || maxCPU.longValue() > Integer.MAX_VALUE) || (minCPU <= 0 || minCPU.longValue() > Integer.MAX_VALUE ) ) {