-
Notifications
You must be signed in to change notification settings - Fork 74
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Replace alpakka S3 with fs2-aws and minio with localstack #4852
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
9ce2551
Read file using fs2-aws
dantb d786398
Use S3 storage client to fetch files
shinyhappydan 2aa48cf
Use same group size as the previous implementation
shinyhappydan 465ac16
WIP - multipart S3 upload
dantb 79c1581
WIP - check object existence, fetch metadata for file size, refactor
dantb 914877c
Use S3 base endpoint for absolute path
dantb 7aa18fc
Remove alpakka s3 dependency
dantb c17d447
Tidy
dantb bbab68b
Tidy integration test debugging
dantb b48bd2c
Merge branch 'master' into s3-readfile-fs2
shinyhappydan e02e2bc
Don't error when uploading an empty file (calling .lastOrError)
shinyhappydan 6f28dbc
Fix bug in file size calculation
shinyhappydan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 19 additions & 27 deletions
46
...pfl/bluebrain/nexus/delta/plugins/storage/storages/operations/s3/S3StorageFetchFile.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,37 @@ | ||
package ch.epfl.bluebrain.nexus.delta.plugins.storage.storages.operations.s3 | ||
|
||
import akka.actor.ActorSystem | ||
import akka.http.scaladsl.model.Uri | ||
import akka.stream.alpakka.s3.scaladsl.S3 | ||
import akka.stream.alpakka.s3.{S3Attributes, S3Exception} | ||
import akka.stream.scaladsl.Sink | ||
import akka.stream.scaladsl.Source | ||
import akka.util.ByteString | ||
import cats.effect.IO | ||
import ch.epfl.bluebrain.nexus.delta.plugins.storage.files.model.FileAttributes | ||
import ch.epfl.bluebrain.nexus.delta.plugins.storage.storages.StoragesConfig.StorageTypeConfig | ||
import ch.epfl.bluebrain.nexus.delta.plugins.storage.storages.model.StorageValue.S3StorageValue | ||
import ch.epfl.bluebrain.nexus.delta.plugins.storage.storages.operations.FetchFile | ||
import ch.epfl.bluebrain.nexus.delta.plugins.storage.storages.operations.StorageFileRejection.FetchFileRejection._ | ||
import ch.epfl.bluebrain.nexus.delta.plugins.storage.storages.operations.s3.client.S3StorageClient | ||
import ch.epfl.bluebrain.nexus.delta.sdk.AkkaSource | ||
import ch.epfl.bluebrain.nexus.delta.sdk.stream.StreamConverter | ||
|
||
import java.net.URLDecoder | ||
import java.nio.charset.StandardCharsets.UTF_8 | ||
import scala.concurrent.duration.DurationInt | ||
|
||
final class S3StorageFetchFile(value: S3StorageValue, config: StorageTypeConfig)(implicit | ||
as: ActorSystem | ||
) extends FetchFile { | ||
|
||
private val s3Attributes = S3Attributes.settings(value.alpakkaSettings(config)) | ||
final class S3StorageFetchFile(client: S3StorageClient, bucket: String) extends FetchFile { | ||
|
||
override def apply(attributes: FileAttributes): IO[AkkaSource] = | ||
apply(attributes.path) | ||
|
||
override def apply(path: Uri.Path): IO[AkkaSource] = | ||
IO.fromFuture( | ||
IO.delay( | ||
S3.download(value.bucket, URLDecoder.decode(path.toString, UTF_8.toString)) | ||
.withAttributes(s3Attributes) | ||
.runWith(Sink.head) | ||
override def apply(path: Uri.Path): IO[AkkaSource] = { | ||
IO.delay( | ||
Source.fromGraph( | ||
StreamConverter( | ||
client | ||
.readFile(bucket, URLDecoder.decode(path.toString, UTF_8.toString)) | ||
.groupWithin(8192, 1.second) | ||
.map(bytes => ByteString(bytes.toArray)) | ||
) | ||
) | ||
).redeemWith( | ||
{ | ||
case err: S3Exception => IO.raiseError(UnexpectedFetchError(path.toString, err.toString())) | ||
case err => IO.raiseError(UnexpectedFetchError(path.toString, err.getMessage)) | ||
}, | ||
{ | ||
case Some((source, _)) => IO.pure(source: AkkaSource) | ||
case None => IO.raiseError(FileNotFound(path.toString())) | ||
} | ||
) | ||
).recoverWith { err => | ||
IO.raiseError(UnexpectedFetchError(path.toString, err.getMessage)) | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Didn't get round to it yet but I was planning to pull out the file operations like
SaveFile
- it will need some refactoring to the interface. The clients should really be abstracted away from here