You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwhisk.apache.org by ra...@apache.org on 2018/08/22 17:44:03 UTC
[incubator-openwhisk] branch master updated: Support storing
attachment in a sub folder in S3 bucket (#3983)
This is an automated email from the ASF dual-hosted git repository.
rabbah pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-openwhisk.git
The following commit(s) were added to refs/heads/master by this push:
new 411cde3 Support storing attachment in a sub folder in S3 bucket (#3983)
411cde3 is described below
commit 411cde39ce5b3dce82fc54a77450bdbb1fe173f2
Author: Chetan Mehrotra <ch...@apache.org>
AuthorDate: Wed Aug 22 23:13:58 2018 +0530
Support storing attachment in a sub folder in S3 bucket (#3983)
---
common/scala/src/main/resources/s3-reference.conf | 7 ++++
.../whisk/core/database/s3/S3AttachmentStore.scala | 7 ++--
.../scala/whisk/core/database/s3/S3Minio.scala | 7 ++++
.../whisk/core/database/s3/S3WithPrefixTests.scala | 39 ++++++++++++++++++++++
4 files changed, 58 insertions(+), 2 deletions(-)
diff --git a/common/scala/src/main/resources/s3-reference.conf b/common/scala/src/main/resources/s3-reference.conf
index 92bc23e..1413096 100644
--- a/common/scala/src/main/resources/s3-reference.conf
+++ b/common/scala/src/main/resources/s3-reference.conf
@@ -3,6 +3,13 @@
whisk {
s3 {
+
+ # Name of S3 bucket
+ # bucket =
+
+ # Folder path within the bucket (optional)
+ # prefix =
+
# See https://developer.lightbend.com/docs/alpakka/current/s3.html#usage
alpakka {
# whether the buffer request chunks (up to 5MB each) to "memory" or "disk"
diff --git a/common/scala/src/main/scala/whisk/core/database/s3/S3AttachmentStore.scala b/common/scala/src/main/scala/whisk/core/database/s3/S3AttachmentStore.scala
index fee6c5f..e02f49b 100644
--- a/common/scala/src/main/scala/whisk/core/database/s3/S3AttachmentStore.scala
+++ b/common/scala/src/main/scala/whisk/core/database/s3/S3AttachmentStore.scala
@@ -38,9 +38,10 @@ import scala.reflect.ClassTag
object S3AttachmentStoreProvider extends AttachmentStoreProvider {
val alpakkaConfigKey = s"${ConfigKeys.s3}.alpakka"
- case class S3Config(bucket: String) {
+ case class S3Config(bucket: String, prefix: Option[String]) {
def prefixFor[D](implicit tag: ClassTag[D]): String = {
- tag.runtimeClass.getSimpleName.toLowerCase
+ val className = tag.runtimeClass.getSimpleName.toLowerCase
+ prefix.map(p => s"$p/$className").getOrElse(className)
}
}
@@ -69,6 +70,8 @@ class S3AttachmentStore(client: S3Client, bucket: String, prefix: String)(implic
override protected[core] implicit val executionContext: ExecutionContext = system.dispatcher
+ logging.info(this, s"Initializing S3AttachmentStore with bucket=[$bucket], prefix=[$prefix]")
+
override protected[core] def attach(
docId: DocId,
name: String,
diff --git a/tests/src/test/scala/whisk/core/database/s3/S3Minio.scala b/tests/src/test/scala/whisk/core/database/s3/S3Minio.scala
index 0c59e68..34c6a47 100644
--- a/tests/src/test/scala/whisk/core/database/s3/S3Minio.scala
+++ b/tests/src/test/scala/whisk/core/database/s3/S3Minio.scala
@@ -56,6 +56,7 @@ trait S3Minio extends FlatSpec with BeforeAndAfterAll with StreamLogging {
| endpoint-url = "http://localhost:$port"
| }
| bucket = "$bucket"
+ | $prefixConfig
| }
|}
""".stripMargin).withFallback(ConfigFactory.load())
@@ -67,6 +68,12 @@ trait S3Minio extends FlatSpec with BeforeAndAfterAll with StreamLogging {
private val port = freePort()
private val bucket = "test-ow-travis"
+ private def prefixConfig = {
+ if (bucketPrefix.nonEmpty) s"prefix = $bucketPrefix" else ""
+ }
+
+ protected def bucketPrefix: String = ""
+
override protected def beforeAll(): Unit = {
super.beforeAll()
dockerExec(
diff --git a/tests/src/test/scala/whisk/core/database/s3/S3WithPrefixTests.scala b/tests/src/test/scala/whisk/core/database/s3/S3WithPrefixTests.scala
new file mode 100644
index 0000000..eb4add7
--- /dev/null
+++ b/tests/src/test/scala/whisk/core/database/s3/S3WithPrefixTests.scala
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package whisk.core.database.s3
+import org.junit.runner.RunWith
+import org.scalatest.junit.JUnitRunner
+import whisk.core.database.s3.S3AttachmentStoreProvider.S3Config
+import whisk.core.entity.WhiskEntity
+
+@RunWith(classOf[JUnitRunner])
+class S3WithPrefixTests extends S3AttachmentStoreMinioTests {
+ override protected val bucketPrefix: String = "master"
+
+ behavior of "S3Config"
+
+ it should "work with none prefix" in {
+ val config = S3Config("foo", None)
+ config.prefixFor[WhiskEntity] shouldBe "whiskentity"
+ }
+
+ it should "work with optional prefix" in {
+ val config = S3Config("foo", Some("bar"))
+ config.prefixFor[WhiskEntity] shouldBe "bar/whiskentity"
+ }
+}