Skip to content

Commit 0bb1650

Browse files
Add deleteAll parameter for action#remove
1 parent 5a124e8 commit 0bb1650

File tree

3 files changed

+26
-14
lines changed

3 files changed

+26
-14
lines changed

common/scala/src/main/scala/org/apache/openwhisk/core/entity/WhiskAction.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,8 @@ case class WhiskActionVersionList(namespace: EntityPath, name: EntityName, versi
378378
}
379379

380380
object WhiskActionVersionList extends MultipleReadersSingleWriterCache[WhiskActionVersionList, DocInfo] {
381-
lazy val viewName = WhiskQueries.entitiesView(collection = "action-versions").name
381+
val collectionName = "action-versions"
382+
lazy val viewName = WhiskQueries.entitiesView(collection = collectionName).name
382383

383384
def cacheKey(action: FullyQualifiedEntityName): CacheKey = {
384385
CacheKey(action.fullPath.asString)

core/controller/src/main/scala/org/apache/openwhisk/core/controller/Actions.scala

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ trait WhiskActionsApi extends WhiskCollectionAPI with PostActionActivation with
372372
* - 500 Internal Server Error
373373
*/
374374
override def remove(user: Identity, entityName: FullyQualifiedEntityName)(implicit transid: TransactionId) = {
375-
parameter('version.as[SemVer] ?) { version =>
375+
parameter('version.as[SemVer] ?, 'deleteAll ? false) { (version, deleteAll) =>
376376
onComplete(WhiskActionVersionList.get(entityName, entityStore)) {
377377
case Success(results) =>
378378
version match {
@@ -387,6 +387,10 @@ trait WhiskActionsApi extends WhiskCollectionAPI with PostActionActivation with
387387
WhiskActionVersionList.deleteCache(entityName)
388388
complete(OK, action)
389389
})
390+
case None if (!deleteAll && results.versions.size > 1) =>
391+
terminate(
392+
Forbidden,
393+
s"[DEL] entity version not provided, you need to specify deleteAll=true to delete all versions for action $entityName")
390394
case None =>
391395
val fs =
392396
if (results.versions.isEmpty)

tests/src/test/scala/org/apache/openwhisk/core/controller/test/ActionsApiTests.scala

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -575,8 +575,13 @@ class ActionsApiTests extends ControllerTestCommon with WhiskActionsApi {
575575
response should be(action3)
576576
}
577577

578-
// it should delete all actions if version is not specified
578+
// it should return 403 error when try to delete multi versions without specify deleteAll=true
579579
Delete(s"$collectionPath/${action.name}") ~> Route.seal(routes(creds)) ~> check {
580+
status should be(Forbidden)
581+
}
582+
583+
// it should delete all actions if version is not specified and deleteAll is passed as true
584+
Delete(s"$collectionPath/${action.name}?deleteAll=true") ~> Route.seal(routes(creds)) ~> check {
580585
status should be(OK)
581586
val response = responseAs[WhiskAction]
582587
response should be(action3)
@@ -951,7 +956,8 @@ class ActionsApiTests extends ControllerTestCommon with WhiskActionsApi {
951956
Some(action.limits.timeout),
952957
Some(action.limits.memory),
953958
Some(action.limits.logs),
954-
Some(action.limits.concurrency))))
959+
Some(action.limits.concurrency))),
960+
Some(action.version))
955961

956962
// first request invalidates any previous entries and caches new result
957963
Put(s"$collectionPath/${action.name}", content) ~> Route.seal(routes(creds)(transid())) ~> check {
@@ -1004,12 +1010,12 @@ class ActionsApiTests extends ControllerTestCommon with WhiskActionsApi {
10041010
action.exec,
10051011
action.parameters,
10061012
action.limits,
1007-
action.version.upPatch,
1013+
action.version,
10081014
action.publish,
10091015
action.annotations ++ systemAnnotations(kind)))
10101016
}
10111017
stream.toString should include(s"entity exists, will try to update '$action'")
1012-
stream.toString should include(s"caching ${CacheKey(action.copy(version = action.version.upPatch))}")
1018+
stream.toString should include(s"caching ${CacheKey(action)}")
10131019
stream.reset()
10141020

10151021
// delete should invalidate cache for all versions
@@ -1024,12 +1030,11 @@ class ActionsApiTests extends ControllerTestCommon with WhiskActionsApi {
10241030
action.exec,
10251031
action.parameters,
10261032
action.limits,
1027-
action.version.upPatch,
1033+
action.version,
10281034
action.publish,
10291035
action.annotations ++ systemAnnotations(kind)))
10301036
}
10311037
stream.toString should include(s"invalidating ${CacheKey(action)}")
1032-
stream.toString should include(s"invalidating ${CacheKey(action.copy(version = action.version.upPatch))}")
10331038
stream.reset()
10341039
}
10351040
}
@@ -1343,7 +1348,8 @@ class ActionsApiTests extends ControllerTestCommon with WhiskActionsApi {
13431348
Some(action.limits.timeout),
13441349
Some(action.limits.memory),
13451350
Some(action.limits.logs),
1346-
Some(action.limits.concurrency))))
1351+
Some(action.limits.concurrency))),
1352+
Some(action.version))
13471353
val name = action.name
13481354
val cacheKey = s"${CacheKey(action)}".replace("(", "\\(").replace(")", "\\)")
13491355
val expectedPutLog =
@@ -1369,7 +1375,7 @@ class ActionsApiTests extends ControllerTestCommon with WhiskActionsApi {
13691375
action.exec,
13701376
action.parameters,
13711377
action.limits,
1372-
action.version.upPatch,
1378+
action.version,
13731379
action.publish,
13741380
action.annotations ++ systemAnnotations(kind)))
13751381
}
@@ -1388,7 +1394,7 @@ class ActionsApiTests extends ControllerTestCommon with WhiskActionsApi {
13881394
action.exec,
13891395
action.parameters,
13901396
action.limits,
1391-
action.version.upPatch,
1397+
action.version,
13921398
action.publish,
13931399
action.annotations ++ systemAnnotations(kind)))
13941400
}
@@ -1410,7 +1416,8 @@ class ActionsApiTests extends ControllerTestCommon with WhiskActionsApi {
14101416
Some(actionOldSchema.limits.timeout),
14111417
Some(actionOldSchema.limits.memory),
14121418
Some(actionOldSchema.limits.logs),
1413-
Some(actionOldSchema.limits.concurrency))))
1419+
Some(actionOldSchema.limits.concurrency))),
1420+
Some(actionOldSchema.version))
14141421
val expectedPutLog =
14151422
Seq(s"uploading attachment '[\\w-/:]+' of document 'id: ${actionOldSchema.namespace}/${actionOldSchema.name}")
14161423
.mkString("(?s).*")
@@ -1436,7 +1443,7 @@ class ActionsApiTests extends ControllerTestCommon with WhiskActionsApi {
14361443
actionNewSchema.exec,
14371444
actionOldSchema.parameters,
14381445
actionOldSchema.limits,
1439-
actionOldSchema.version.upPatch,
1446+
actionOldSchema.version,
14401447
actionOldSchema.publish,
14411448
actionOldSchema.annotations ++ systemAnnotations(NODEJS10, create = false)))
14421449
}
@@ -1461,7 +1468,7 @@ class ActionsApiTests extends ControllerTestCommon with WhiskActionsApi {
14611468
actionNewSchema.exec,
14621469
actionOldSchema.parameters,
14631470
actionOldSchema.limits,
1464-
actionOldSchema.version.upPatch,
1471+
actionOldSchema.version,
14651472
actionOldSchema.publish,
14661473
actionOldSchema.annotations ++ systemAnnotations(NODEJS10, create = false)))
14671474
}

0 commit comments

Comments
 (0)