Skip to content

Commit

Permalink
s3: implement artifact range requests
Browse files Browse the repository at this point in the history
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: eclipse-hawkbit#91
Signed-off-by: Zygmunt Krynicki <[email protected]>
  • Loading branch information
zyga committed Oct 2, 2023
1 parent 2332a90 commit 19726b5
Showing 1 changed file with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 19726b5

Please sign in to comment.