You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@openwhisk.apache.org by GitBox <gi...@apache.org> on 2018/03/06 18:50:01 UTC
[GitHub] rabbah closed pull request #3366: Adds method deleteAttachments to ArtifactStore
rabbah closed pull request #3366: Adds method deleteAttachments to ArtifactStore
URL: https://github.com/apache/incubator-openwhisk/pull/3366
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git a/common/scala/src/main/scala/whisk/core/database/ArtifactStore.scala b/common/scala/src/main/scala/whisk/core/database/ArtifactStore.scala
index 33ea80589e..631f60ad1c 100644
--- a/common/scala/src/main/scala/whisk/core/database/ArtifactStore.scala
+++ b/common/scala/src/main/scala/whisk/core/database/ArtifactStore.scala
@@ -129,6 +129,11 @@ trait ArtifactStore[DocumentAbstraction] {
protected[core] def readAttachment[T](doc: DocInfo, name: String, sink: Sink[ByteString, Future[T]])(
implicit transid: TransactionId): Future[(ContentType, T)]
+ /**
+ * Deletes all attachments linked to given document
+ */
+ protected[core] def deleteAttachments[T](doc: DocInfo)(implicit transid: TransactionId): Future[Boolean]
+
/** Shut it down. After this invocation, every other call is invalid. */
def shutdown(): Unit
}
diff --git a/common/scala/src/main/scala/whisk/core/database/CouchDbRestStore.scala b/common/scala/src/main/scala/whisk/core/database/CouchDbRestStore.scala
index efc03cca85..d55db6505a 100644
--- a/common/scala/src/main/scala/whisk/core/database/CouchDbRestStore.scala
+++ b/common/scala/src/main/scala/whisk/core/database/CouchDbRestStore.scala
@@ -456,6 +456,11 @@ class CouchDbRestStore[DocumentAbstraction <: DocumentSerializer](dbProtocol: St
ErrorLevel))
}
+ override protected[core] def deleteAttachments[T](doc: DocInfo)(implicit transid: TransactionId): Future[Boolean] =
+ // NOTE: this method is not intended for standalone use for CouchDB.
+ // To delete attachments, it is expected that the entire document is deleted.
+ Future.successful(true)
+
override def shutdown(): Unit = {
Await.ready(client.shutdown(), 1.minute)
}
diff --git a/common/scala/src/main/scala/whisk/core/database/DocumentFactory.scala b/common/scala/src/main/scala/whisk/core/database/DocumentFactory.scala
index 59e04879fb..b6e346ba4b 100644
--- a/common/scala/src/main/scala/whisk/core/database/DocumentFactory.scala
+++ b/common/scala/src/main/scala/whisk/core/database/DocumentFactory.scala
@@ -227,4 +227,18 @@ trait DocumentFactory[W <: DocumentRevisionProvider] extends MultipleReadersSing
case Failure(t) => Future.failed(t)
}
}
+
+ def deleteAttachments[Wsuper >: W](db: ArtifactStore[Wsuper], doc: DocInfo)(
+ implicit transid: TransactionId): Future[Boolean] = {
+ Try {
+ require(db != null, "db defined")
+ require(doc != null, "doc undefined")
+ } map { _ =>
+ implicit val ec = db.executionContext
+ db.deleteAttachments(doc)
+ } match {
+ case Success(f) => f
+ case Failure(t) => Future.failed(t)
+ }
+ }
}
diff --git a/common/scala/src/main/scala/whisk/core/entity/WhiskAction.scala b/common/scala/src/main/scala/whisk/core/entity/WhiskAction.scala
index 92b7db3231..07b9efeb94 100644
--- a/common/scala/src/main/scala/whisk/core/entity/WhiskAction.scala
+++ b/common/scala/src/main/scala/whisk/core/entity/WhiskAction.scala
@@ -376,6 +376,24 @@ object WhiskAction extends DocumentFactory[WhiskAction] with WhiskEntityQueries[
}
}
+ override def del[Wsuper >: WhiskAction](db: ArtifactStore[Wsuper], doc: DocInfo)(
+ implicit transid: TransactionId,
+ notifier: Option[CacheChangeNotification]): Future[Boolean] = {
+ Try {
+ require(db != null, "db undefined")
+ require(doc != null, "doc undefined")
+ }.map { _ =>
+ val fa = super.del(db, doc)
+ implicit val ec = db.executionContext
+ fa.flatMap { _ =>
+ super.deleteAttachments(db, doc)
+ }
+ } match {
+ case Success(f) => f
+ case Failure(f) => Future.failed(f)
+ }
+ }
+
/**
* Resolves an action name if it is contained in a package.
* Look up the package to determine if it is a binding or the actual package.
diff --git a/tests/build.gradle b/tests/build.gradle
index 9d68ed2c6d..70eaa309c2 100644
--- a/tests/build.gradle
+++ b/tests/build.gradle
@@ -66,7 +66,8 @@ dependencies {
compile 'org.scalamock:scalamock-scalatest-support_2.11:3.4.2'
compile 'com.typesafe.akka:akka-testkit_2.11:2.4.16'
compile 'com.typesafe.akka:akka-http-testkit_2.11:10.0.10'
- compile 'com.github.java-json-tools:json-schema-validator:2.2.8';
+ compile 'com.github.java-json-tools:json-schema-validator:2.2.8'
+ compile "org.mockito:mockito-core:2.15.0"
compile project(':common:scala')
compile project(':core:controller')
diff --git a/tests/src/test/scala/whisk/core/entity/test/DatastoreTests.scala b/tests/src/test/scala/whisk/core/entity/test/DatastoreTests.scala
index ec4a998bfe..601efec157 100644
--- a/tests/src/test/scala/whisk/core/entity/test/DatastoreTests.scala
+++ b/tests/src/test/scala/whisk/core/entity/test/DatastoreTests.scala
@@ -19,18 +19,17 @@ package whisk.core.entity.test
import java.time.Instant
-import scala.Vector
import scala.concurrent.Await
-
import org.junit.runner.RunWith
import org.scalatest.BeforeAndAfterEach
import org.scalatest.BeforeAndAfterAll
import org.scalatest.FlatSpec
import org.scalatest.junit.JUnitRunner
-
import akka.stream.ActorMaterializer
import common.StreamLogging
import common.WskActorSystem
+import org.scalatest.mockito.MockitoSugar
+import org.mockito.Mockito._
import whisk.core.WhiskConfig
import whisk.core.database.DocumentConflictException
import whisk.core.database.CacheChangeNotification
@@ -46,6 +45,7 @@ class DatastoreTests
with WskActorSystem
with DbUtils
with ExecHelpers
+ with MockitoSugar
with StreamLogging {
implicit val materializer = ActorMaterializer()
@@ -208,6 +208,19 @@ class DatastoreTests
putGetCheck(datastore, revAction, WhiskAction)
}
+ it should "delete action attachments" in {
+ implicit val tid = transid()
+ implicit val basename = EntityName("attachment action")
+ val javaAction =
+ WhiskAction(namespace, aname, javaDefault("ZHViZWU=", Some("hello")), annotations = Parameters("exec", "java"))
+ val docinfo = putGetCheck(datastore, javaAction, WhiskAction, false)._2.docinfo
+
+ val proxy = spy(datastore)
+ Await.result(WhiskAction.del(proxy, docinfo), dbOpTimeout)
+
+ verify(proxy).deleteAttachments(docinfo)
+ }
+
it should "update trigger with a revision" in {
implicit val tid = transid()
implicit val basename = EntityName("update trigger")
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services