diff options
7 files changed, 58 insertions, 6 deletions
diff --git a/config-model/src/main/java/com/yahoo/vespa/model/VespaModelFactory.java b/config-model/src/main/java/com/yahoo/vespa/model/VespaModelFactory.java index 9e867a4c3bc..28ff8dff620 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/VespaModelFactory.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/VespaModelFactory.java @@ -25,6 +25,7 @@ import com.yahoo.config.model.api.ValidationParameters; import com.yahoo.config.model.application.provider.ApplicationPackageXmlFilesValidator; import com.yahoo.config.model.builder.xml.ConfigModelBuilder; import com.yahoo.config.model.deploy.DeployState; +import com.yahoo.config.provision.QuotaExceededException; import com.yahoo.config.provision.TransientException; import com.yahoo.config.provision.Zone; import com.yahoo.vespa.config.VespaVersion; @@ -222,7 +223,7 @@ public class VespaModelFactory implements ModelFactory { Exceptions.toMessageString(e)); else rethrowUnlessIgnoreErrors(e, validationParameters.ignoreValidationErrors()); - } catch (IllegalArgumentException | TransientException e) { + } catch (IllegalArgumentException | TransientException | QuotaExceededException e) { rethrowUnlessIgnoreErrors(e, validationParameters.ignoreValidationErrors()); } catch (Exception e) { throw new RuntimeException(e); diff --git a/config-model/src/main/java/com/yahoo/vespa/model/application/validation/QuotaValidator.java b/config-model/src/main/java/com/yahoo/vespa/model/application/validation/QuotaValidator.java index 475a4174f9a..5405a528150 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/application/validation/QuotaValidator.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/application/validation/QuotaValidator.java @@ -6,6 +6,7 @@ import com.yahoo.config.provision.Capacity; import com.yahoo.config.provision.ClusterResources; import com.yahoo.config.provision.ClusterSpec; import com.yahoo.config.provision.NodeResources; +import com.yahoo.config.provision.QuotaExceededException; import com.yahoo.config.provision.SystemName; import com.yahoo.vespa.model.VespaModel; @@ -80,19 +81,19 @@ public class QuotaValidator extends Validator { if (!invalidClusters.isEmpty()) { var clusterNames = String.join(", ", invalidClusters); - throw new IllegalArgumentException("Clusters " + clusterNames + " exceeded max cluster size of " + maxClusterSize); + throw new QuotaExceededException("Clusters " + clusterNames + " exceeded max cluster size of " + maxClusterSize); } } private static void throwIfBudgetNegative(double spend, BigDecimal budget, SystemName systemName) { if (budget.doubleValue() < 0) { - throw new IllegalArgumentException(quotaMessage("Please free up some capacity.", systemName, spend, budget, true)); + throw new QuotaExceededException(quotaMessage("Please free up some capacity.", systemName, spend, budget, true)); } } private static void throwIfBudgetExceeded(double spend, BigDecimal budget, SystemName systemName, boolean actual) { if (budget.doubleValue() < spend) { - throw new IllegalArgumentException(quotaMessage("Contact support to upgrade your plan.", systemName, spend, budget, actual)); + throw new QuotaExceededException(quotaMessage("Contact support to upgrade your plan.", systemName, spend, budget, actual)); } } diff --git a/config-provisioning/src/main/java/com/yahoo/config/provision/QuotaExceededException.java b/config-provisioning/src/main/java/com/yahoo/config/provision/QuotaExceededException.java new file mode 100644 index 00000000000..12289f44c6a --- /dev/null +++ b/config-provisioning/src/main/java/com/yahoo/config/provision/QuotaExceededException.java @@ -0,0 +1,17 @@ +// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.config.provision; + +/** + * @author hmusum + */ +public class QuotaExceededException extends RuntimeException { + + public QuotaExceededException(Throwable t) { + super(t); + } + + public QuotaExceededException(String message) { + super(message); + } + +} diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/http/HttpErrorResponse.java b/configserver/src/main/java/com/yahoo/vespa/config/server/http/HttpErrorResponse.java index 3b5269cdf11..c87d77eaf07 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/http/HttpErrorResponse.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/http/HttpErrorResponse.java @@ -53,7 +53,8 @@ public class HttpErrorResponse extends HttpResponse { LOAD_BALANCER_NOT_READY, CONFIG_NOT_CONVERGED, REINDEXING_STATUS_UNAVAILABLE, - PRECONDITION_FAILED + PRECONDITION_FAILED, + QUOTA_EXCEEDED } public static HttpErrorResponse notFoundError(String msg) { @@ -120,6 +121,10 @@ public class HttpErrorResponse extends HttpResponse { return new HttpErrorResponse(PRECONDITION_FAILED, ErrorCode.PRECONDITION_FAILED.name(), msg); } + public static HttpResponse quotaExceeded(String msg) { + return new HttpErrorResponse(BAD_REQUEST, ErrorCode.QUOTA_EXCEEDED.name(), msg); + } + @Override public void render(OutputStream stream) throws IOException { new JsonFormat(true).encode(stream, slime); diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/http/HttpHandler.java b/configserver/src/main/java/com/yahoo/vespa/config/server/http/HttpHandler.java index a0e814f32d8..58651af54f3 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/http/HttpHandler.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/http/HttpHandler.java @@ -5,6 +5,7 @@ import com.yahoo.config.provision.ApplicationLockException; import com.yahoo.config.provision.CertificateNotReadyException; import com.yahoo.config.provision.NodeAllocationException; import com.yahoo.config.provision.ParentHostUnavailableException; +import com.yahoo.config.provision.QuotaExceededException; import com.yahoo.config.provision.exception.ActivationConflictException; import com.yahoo.config.provision.exception.LoadBalancerServiceException; import com.yahoo.container.jdisc.HttpRequest; @@ -73,6 +74,8 @@ public class HttpHandler extends ThreadedHttpRequestHandler { return HttpErrorResponse.reindexingStatusUnavailable(getMessage(e, request)); } catch (PreconditionFailedException e) { return HttpErrorResponse.preconditionFailed(getMessage(e, request)); + } catch (QuotaExceededException e) { + return HttpErrorResponse.quotaExceeded(getMessage(e, request)); } catch (Exception e) { log.log(Level.WARNING, "Unexpected exception handling a config server request", e); return HttpErrorResponse.internalServerError(getMessage(e, request)); diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/modelfactory/ModelsBuilder.java b/configserver/src/main/java/com/yahoo/vespa/config/server/modelfactory/ModelsBuilder.java index bd1837707d9..4faa475fa08 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/modelfactory/ModelsBuilder.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/modelfactory/ModelsBuilder.java @@ -14,6 +14,7 @@ import com.yahoo.config.provision.ApplicationId; import com.yahoo.config.provision.ApplicationLockException; import com.yahoo.config.provision.DockerImage; import com.yahoo.config.provision.NodeAllocationException; +import com.yahoo.config.provision.QuotaExceededException; import com.yahoo.config.provision.TransientException; import com.yahoo.config.provision.Zone; import com.yahoo.vespa.config.server.http.InternalServerException; @@ -122,7 +123,7 @@ public abstract class ModelsBuilder<MODELRESULT extends ModelResult> { buildLatestModelForThisMajor, majorVersion)); buildLatestModelForThisMajor = false; // We have successfully built latest model version, do it only for this major } - catch (NodeAllocationException | ApplicationLockException | TransientException e) { + catch (NodeAllocationException | ApplicationLockException | TransientException | QuotaExceededException e) { // Don't wrap this exception, and don't try to load other model versions as this is (most likely) // caused by the state of the system, not the model version/application combination throw e; diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/deploy/HostedDeployNodeAllocationTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/deploy/HostedDeployNodeAllocationTest.java index e546569b255..e9dca44ed81 100644 --- a/configserver/src/test/java/com/yahoo/vespa/config/server/deploy/HostedDeployNodeAllocationTest.java +++ b/configserver/src/test/java/com/yahoo/vespa/config/server/deploy/HostedDeployNodeAllocationTest.java @@ -4,14 +4,17 @@ package com.yahoo.vespa.config.server.deploy; import com.yahoo.component.Version; import com.yahoo.config.model.api.HostProvisioner; import com.yahoo.config.model.api.ModelFactory; +import com.yahoo.config.model.api.Quota; import com.yahoo.config.provision.Capacity; import com.yahoo.config.provision.ClusterMembership; import com.yahoo.config.provision.ClusterSpec; import com.yahoo.config.provision.HostSpec; import com.yahoo.config.provision.NodeResources; import com.yahoo.config.provision.ProvisionLogger; +import com.yahoo.config.provision.QuotaExceededException; import com.yahoo.config.provision.Zone; import com.yahoo.vespa.config.server.MockProvisioner; +import com.yahoo.vespa.config.server.session.PrepareParams; import org.junit.Rule; import org.junit.Test; import org.junit.rules.TemporaryFolder; @@ -24,6 +27,7 @@ import java.util.stream.Collectors; import static com.yahoo.vespa.config.server.deploy.DeployTester.createHostedModelFactory; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; public class HostedDeployNodeAllocationTest { @@ -50,6 +54,26 @@ public class HostedDeployNodeAllocationTest { assertEquals(resources(2), get("host4", hosts).advertisedResources()); } + @Test + public void testExceedsQuota() { + List<ModelFactory> modelFactories = List.of(createHostedModelFactory(Version.fromString("7.2")), + createHostedModelFactory(Version.fromString("7.3"))); + var provisioner = new VersionProvisioner(); + DeployTester tester = new DeployTester.Builder(temporaryFolder).modelFactories(modelFactories) + .provisioner(new MockProvisioner().hostProvisioner(provisioner)) + .hostedConfigserverConfig(Zone.defaultZone()) + .build(); + + try { + tester.deployApp("src/test/apps/hosted/", new PrepareParams.Builder() + .vespaVersion("7.3") + .quota(new Quota(Optional.of(4), Optional.of(0)))); + fail("Expected to get a QuotaExceededException"); + } catch (QuotaExceededException e) { + assertEquals("main: The resources used cost $1.02 but your quota is $0.00: Contact support to upgrade your plan.", e.getMessage()); + } + } + private HostSpec get(String hostname, Set<HostSpec> hosts) { return hosts.stream().filter(host -> host.hostname().equals(hostname)).findAny().orElseThrow(); } |