From 19726b50648b307c01acdb236633e90d804b1352 Mon Sep 17 00:00:00 2001 From: Zygmunt Krynicki Date: Mon, 2 Oct 2023 18:40:10 +0200 Subject: [PATCH] s3: implement artifact range requests The basic itent is to allow expressing an input stream for a fragment that corresponds to a single range request. This patch is not ready to land, because it requires lock-step update in HawkBit proper. The long story short, is that the current abstraction of getFileInputStream is just insufficient to efficiently implement range requests for artifacts. There are two goals for efficiency: - We should not request or discard data we do not need - We read all the data we requested and close the stream properly The second problem is somewhat elusive, since S3 input stream has a close() method that informs us of incorrect usage if not all content is drained, when S3 is sending the content but are are not reading. Corresponging HawkBit change is posted to HawkBit in a separate patch. Fixes: https://github.com/eclipse/hawkbit-extensions/issues/91 Signed-off-by: Zygmunt Krynicki --- .../hawkbit/artifact/repository/S3Artifact.java | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/hawkbit-extension-artifact-repository-s3/src/main/java/org/eclipse/hawkbit/artifact/repository/S3Artifact.java b/hawkbit-extension-artifact-repository-s3/src/main/java/org/eclipse/hawkbit/artifact/repository/S3Artifact.java index 9fe130c..7464329 100644 --- a/hawkbit-extension-artifact-repository-s3/src/main/java/org/eclipse/hawkbit/artifact/repository/S3Artifact.java +++ b/hawkbit-extension-artifact-repository-s3/src/main/java/org/eclipse/hawkbit/artifact/repository/S3Artifact.java @@ -15,6 +15,7 @@ import org.springframework.util.Assert; import com.amazonaws.services.s3.AmazonS3; +import com.amazonaws.services.s3.model.GetObjectRequest; /** * An {@link AbstractDbArtifact} implementation which retrieves the @@ -39,7 +40,18 @@ public class S3Artifact extends AbstractDbArtifact { @Override public InputStream getFileInputStream() { - return amazonS3.getObject(s3Properties.getBucketName(), key).getObjectContent(); + var req = new GetObjectRequest(s3Properties.getBucketName(), key); + var obj = amazonS3.getObject(req); + + return obj.getObjectContent(); + } + + @Override + public InputStream getFileInputStream(long start, long end) { + var req = new GetObjectRequest(s3Properties.getBucketName(), key).withRange(start, end); + var obj = amazonS3.getObject(req); + + return obj.getObjectContent(); } @Override