diff options
author | Jon Marius Venstad <jonmv@users.noreply.github.com> | 2022-11-05 08:02:29 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-05 08:02:29 +0100 |
commit | 08c9f8fe2e8268aa2ca321f2e7f3496e45140231 (patch) | |
tree | 7cd95fe91dd808828a7eac83bcaba3ad5068ed25 | |
parent | 62f86b1196d6f7a616b3b69d701258ed35d00bf0 (diff) | |
parent | 560a6970ebaad3bfd2d1dc250f9b6aca6498b234 (diff) |
Merge pull request #24764 from vespa-engine/jonmv/close-streams-and-add-spammy-log
Close stream, add spammy log
4 files changed, 42 insertions, 11 deletions
diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/application/CompressedApplicationInputStream.java b/configserver/src/main/java/com/yahoo/vespa/config/server/application/CompressedApplicationInputStream.java index 1ac52213323..01dd47765d2 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/application/CompressedApplicationInputStream.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/application/CompressedApplicationInputStream.java @@ -45,14 +45,13 @@ public class CompressedApplicationInputStream implements AutoCloseable { public static CompressedApplicationInputStream createFromCompressedStream(InputStream is, String contentType, long maxSizeInBytes) { try { Options options = Options.standard().maxSize(maxSizeInBytes).allowDotSegment(true); - switch (contentType) { - case ApplicationApiHandler.APPLICATION_X_GZIP: - return new CompressedApplicationInputStream(ArchiveStreamReader.ofTarGzip(is, options)); - case ApplicationApiHandler.APPLICATION_ZIP: - return new CompressedApplicationInputStream(ArchiveStreamReader.ofZip(is, options)); - default: - throw new BadRequestException("Unable to decompress"); - } + return switch (contentType) { + case ApplicationApiHandler.APPLICATION_X_GZIP -> + new CompressedApplicationInputStream(ArchiveStreamReader.ofTarGzip(is, options)); + case ApplicationApiHandler.APPLICATION_ZIP -> + new CompressedApplicationInputStream(ArchiveStreamReader.ofZip(is, options)); + default -> throw new BadRequestException("Unable to decompress"); + }; } catch (UncheckedIOException e) { throw new InternalServerException("Unable to create compressed application stream", e); } diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/ApplicationApiHandler.java b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/ApplicationApiHandler.java index ad68073053d..60c1d75406a 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/ApplicationApiHandler.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/ApplicationApiHandler.java @@ -22,6 +22,8 @@ import com.yahoo.vespa.config.server.tenant.TenantRepository; import org.apache.hc.core5.http.ContentType; import java.io.IOException; +import java.io.InputStream; +import java.io.UncheckedIOException; import java.nio.charset.StandardCharsets; import java.time.Duration; import java.util.List; @@ -80,7 +82,8 @@ public class ApplicationApiHandler extends SessionHandler { if (multipartRequest) { try { Map<String, PartItem> parts = new MultiPartFormParser(request).readParts(); - byte[] params = parts.get(MULTIPART_PARAMS).data().readAllBytes(); + byte[] params; + try (InputStream part = parts.get(MULTIPART_PARAMS).data()) { params = part.readAllBytes(); } ; log.log(Level.FINE, "Deploy parameters: [{0}]", new String(params, StandardCharsets.UTF_8)); prepareParams = PrepareParams.fromJson(params, tenantName, zookeeperBarrierTimeout); PartItem appPackagePart = parts.get(MULTIPART_APPLICATION_PACKAGE); @@ -94,8 +97,13 @@ public class ApplicationApiHandler extends SessionHandler { compressedStream = createFromCompressedStream(request.getData(), request.getHeader(contentTypeHeader), maxApplicationPackageSize); } - PrepareResult result = applicationRepository.deploy(compressedStream, prepareParams); - return new SessionPrepareAndActivateResponse(result, request, prepareParams.getApplicationId(), zone); + try (compressedStream) { + PrepareResult result = applicationRepository.deploy(compressedStream, prepareParams); + return new SessionPrepareAndActivateResponse(result, request, prepareParams.getApplicationId(), zone); + } + catch (IOException e) { + throw new UncheckedIOException(e); + } } @Override diff --git a/container-core/src/main/java/com/yahoo/container/jdisc/utils/MultiPartFormParser.java b/container-core/src/main/java/com/yahoo/container/jdisc/utils/MultiPartFormParser.java index 104d2f8ae4a..964cadb8065 100644 --- a/container-core/src/main/java/com/yahoo/container/jdisc/utils/MultiPartFormParser.java +++ b/container-core/src/main/java/com/yahoo/container/jdisc/utils/MultiPartFormParser.java @@ -9,6 +9,8 @@ import java.io.IOException; import java.io.InputStream; import java.util.Map; import java.util.TreeMap; +import java.util.logging.Level; +import java.util.logging.Logger; /** * Wrapper around Jetty's {@link MultiPartFormInputStream}. @@ -44,6 +46,7 @@ public class MultiPartFormParser { private PartItem(Part servletPart) throws IOException { this(servletPart.getName(), servletPart.getInputStream(), servletPart.getContentType()); + Logger.getLogger(MultiPartFormParser.class.getName()).log(Level.INFO, servletPart.toString()); } public PartItem(String name, InputStream data, String contentType) { diff --git a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/deployment/DeploymentTriggerTest.java b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/deployment/DeploymentTriggerTest.java index ea9cf0385d9..c6bd3848c2b 100644 --- a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/deployment/DeploymentTriggerTest.java +++ b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/deployment/DeploymentTriggerTest.java @@ -2787,4 +2787,25 @@ public class DeploymentTriggerTest { assertThrows(IllegalStateException.class, JobType.fromJobName("staging-test", zones)::zone); } + @Test + void test() { + String deploymentXml = """ + <deployment version="1.0" major-version="8"> + <test/> + <staging/> + <block-change days="mon-sat,sun" hours="20-23" time-zone="Asia/Taipei"/> + <block-change days="mon-sat,sun" hours="0-8" time-zone="Asia/Taipei"/> + <block-change to-date="2022-10-13" hours="0-23"/> + <prod> + <region>aws-us-east-1a</region> + <test>aws-us-east-1a</test> + <delay hours="1"/> + <region>aws-us-west-2a</region> + </prod> + </deployment>"""; + + // TODO jonmv: recreate problem where revision starts, then upgrade, while prod is blocked, + // then both are tested as separate upgrades, but prod-test has them reversed. + } + } |