diff options
author | Harald Musum <musum@yahooinc.com> | 2022-10-13 10:42:59 +0200 |
---|---|---|
committer | Harald Musum <musum@yahooinc.com> | 2022-10-13 10:42:59 +0200 |
commit | c395db94a96842eb163f70ece707b47107e60811 (patch) | |
tree | 12899dc423b8c432716a4e55de0c3195b976df85 /configserver | |
parent | 9259007b603c4f5ec98597a4e1bf63e23cb660a6 (diff) |
Only rethrow IOException as RuntimeException when creating session
Otherwise we will return responses as internal server instead of e.g.
invalid application package.
Also throw more precise InvalidApplicationException if validating
file extensions fail.
Diffstat (limited to 'configserver')
6 files changed, 52 insertions, 5 deletions
diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/http/InvalidApplicationException.java b/configserver/src/main/java/com/yahoo/vespa/config/server/http/InvalidApplicationException.java index 70cc89c08af..49776ebdb1b 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/http/InvalidApplicationException.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/http/InvalidApplicationException.java @@ -6,9 +6,9 @@ package com.yahoo.vespa.config.server.http; */ public class InvalidApplicationException extends IllegalArgumentException { - public InvalidApplicationException(String message) { - super(message); - } + public InvalidApplicationException(String message) { super(message); } + + public InvalidApplicationException(Throwable t) { super(t); } public InvalidApplicationException(String message, Throwable e) { super(message, e); diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/session/SessionRepository.java b/configserver/src/main/java/com/yahoo/vespa/config/server/session/SessionRepository.java index 9e7af5a44a3..97cebbbe174 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/session/SessionRepository.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/session/SessionRepository.java @@ -30,6 +30,7 @@ import com.yahoo.vespa.config.server.configchange.ConfigChangeActions; import com.yahoo.vespa.config.server.deploy.TenantFileSystemDirs; import com.yahoo.vespa.config.server.filedistribution.FileDirectory; import com.yahoo.vespa.config.server.filedistribution.FileDistributionFactory; +import com.yahoo.vespa.config.server.http.InvalidApplicationException; import com.yahoo.vespa.config.server.http.UnknownVespaVersionException; import com.yahoo.vespa.config.server.modelfactory.ActivatedModelsBuilder; import com.yahoo.vespa.config.server.modelfactory.AllocatedHostsFromAllModels; @@ -727,7 +728,7 @@ public class SessionRepository { UnboundStringFlag flag = PermanentFlags.APPLICATION_FILES_WITH_UNKNOWN_EXTENSION; String value = flag.bindTo(flagSource).with(APPLICATION_ID, applicationId.serializedForm()).value(); switch (value) { - case "FAIL" -> throw e; + case "FAIL" -> throw new InvalidApplicationException(e); case "LOG" -> deployLogger.ifPresent(logger -> logger.logApplicationPackage(Level.WARNING, e.getMessage())); default -> log.log(Level.WARNING, "Unknown value for flag " + flag.id() + ": " + value); } @@ -754,7 +755,7 @@ public class SessionRepository { waiter.awaitCompletion(Duration.ofSeconds(Math.min(120, timeoutBudget.timeLeft().getSeconds()))); addLocalSession(session); return session; - } catch (Exception e) { + } catch (IOException e) { throw new RuntimeException("Error creating session " + sessionId, e); } } diff --git a/configserver/src/test/apps/hosted-invalid-file-extension/deployment.xml b/configserver/src/test/apps/hosted-invalid-file-extension/deployment.xml new file mode 100644 index 00000000000..43bc1496b2c --- /dev/null +++ b/configserver/src/test/apps/hosted-invalid-file-extension/deployment.xml @@ -0,0 +1,7 @@ +<!-- Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. --> +<deployment version='1.0'> + <prod> + <region active="true">us-north-1</region> + <region active="true">us-north-2</region> + </prod> +</deployment> diff --git a/configserver/src/test/apps/hosted-invalid-file-extension/schemas/file-with-invalid.extension b/configserver/src/test/apps/hosted-invalid-file-extension/schemas/file-with-invalid.extension new file mode 100644 index 00000000000..e69de29bb2d --- /dev/null +++ b/configserver/src/test/apps/hosted-invalid-file-extension/schemas/file-with-invalid.extension diff --git a/configserver/src/test/apps/hosted-invalid-file-extension/services.xml b/configserver/src/test/apps/hosted-invalid-file-extension/services.xml new file mode 100644 index 00000000000..08b1d5d01c2 --- /dev/null +++ b/configserver/src/test/apps/hosted-invalid-file-extension/services.xml @@ -0,0 +1,16 @@ +<?xml version="1.0" encoding="utf-8" ?> +<!-- Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. --> +<services version="1.0"> + + <container version="1.0"> + <http> + <filtering> + <access-control domain="myDomain" write="true" /> + </filtering> + <server id="foo"/> + </http> + <search/> + <nodes count='1'/> + </container> + +</services> diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/deploy/HostedDeployTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/deploy/HostedDeployTest.java index 6d4217d3df4..f2bf31a53e4 100644 --- a/configserver/src/test/java/com/yahoo/vespa/config/server/deploy/HostedDeployTest.java +++ b/configserver/src/test/java/com/yahoo/vespa/config/server/deploy/HostedDeployTest.java @@ -1,6 +1,7 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa.config.server.deploy; +import com.yahoo.cloud.config.ConfigserverConfig; import com.yahoo.component.Version; import com.yahoo.config.application.api.ValidationId; import com.yahoo.config.model.api.ConfigChangeAction; @@ -36,6 +37,7 @@ import org.junit.Rule; import org.junit.Test; import org.junit.rules.TemporaryFolder; +import java.nio.file.Files; import java.time.Clock; import java.time.Duration; import java.time.Instant; @@ -49,6 +51,7 @@ import java.util.stream.IntStream; import static com.yahoo.vespa.config.server.deploy.DeployTester.CountingModelFactory; import static com.yahoo.vespa.config.server.deploy.DeployTester.createFailingModelFactory; import static com.yahoo.vespa.config.server.deploy.DeployTester.createHostedModelFactory; +import static com.yahoo.yolean.Exceptions.uncheck; import static java.util.stream.Collectors.toList; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -489,6 +492,26 @@ public class HostedDeployTest { } @Test + public void testThatAppWithFilesWithInvalidFileExtensionFails() { + DeployTester tester = new DeployTester.Builder(temporaryFolder) + .configserverConfig(new ConfigserverConfig(new ConfigserverConfig.Builder() + .hostedVespa(true) + .configServerDBDir(uncheck(() -> Files.createTempDirectory("serverdb")).toString()) + .configDefinitionsDir(uncheck(() -> Files.createTempDirectory("configdefinitions")).toString()) + .fileReferencesDir(uncheck(() -> Files.createTempDirectory("configdefinitions")).toString()))) + .modelFactory(createHostedModelFactory(Version.fromString("8.7.6"), Clock.systemUTC())) + .build(); + System.out.println("hostedvespa=" + tester.applicationRepository().configserverConfig().hostedVespa()); + try { + tester.deployApp("src/test/apps/hosted-invalid-file-extension/", "8.7.6"); + fail(); + } catch (InvalidApplicationException e) { + assertEquals("java.lang.IllegalArgumentException: File in application package with unknown extension: schemas/file-with-invalid.extension, please delete or move file to another directory.", + e.getMessage()); + } + } + + @Test public void testRedeployWithCloudAccount() { CloudAccount cloudAccount = new CloudAccount("012345678912"); DeployTester tester = new DeployTester.Builder(temporaryFolder) |