Skip to content
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

Implement Action Versioning #4986

Open
wants to merge 30 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
1189caf
Implement action versioning
jiangpengcheng Sep 15, 2020
8409b85
Fix tests
jiangpengcheng Sep 28, 2020
7d72c53
Make SemVer sortable
jiangpengcheng Sep 29, 2020
595df67
Updates:
jiangpengcheng Oct 9, 2020
1b2088b
Allow to replace specify version
jiangpengcheng Oct 10, 2020
171b9dc
Fix bug
jiangpengcheng Oct 10, 2020
e69240a
Implement action-version view for memoryDB and cosmosDB
jiangpengcheng Oct 12, 2020
9f5c1d8
Fix view bug
jiangpengcheng Oct 13, 2020
5d041c4
Fix DocumentHandlerTests
jiangpengcheng Oct 13, 2020
a880b97
Ensure data consistency
jiangpengcheng Oct 29, 2020
d1b2c54
Add deleteAll parameter for action#remove
jiangpengcheng Oct 29, 2020
2b1c4e8
Add deleteOld parameter for action#create
jiangpengcheng Oct 29, 2020
e030b4b
Revert "Allow to replace specify version"
jiangpengcheng Nov 3, 2020
4d0e220
add default version feature
jiangpengcheng Nov 3, 2020
af0d7c2
Some updates:
jiangpengcheng Nov 11, 2020
5e4bc9f
Fix format style
jiangpengcheng Nov 11, 2020
4dc8147
Fix test
jiangpengcheng Nov 13, 2020
ef1711c
Remove some useless code
jiangpengcheng Nov 16, 2020
5278fdc
Fix bug
jiangpengcheng Nov 16, 2020
f2b348a
Fix rebase error
jiangpengcheng May 8, 2021
becdb02
Fix tests error
jiangpengcheng May 8, 2021
6fe1d7f
Fix tests
jiangpengcheng May 8, 2021
a3939ed
Use version mappings to get doc id from an version
jiangpengcheng May 10, 2021
fc564c9
Update some return errors
jiangpengcheng May 12, 2021
9fad6e3
Rebase master
jiangpengcheng May 12, 2021
0205d2e
Fix rebase errors
jiangpengcheng Jun 3, 2021
54cb3de
Merge branch 'master' into feature/implement_code_versioning
bdoyle0182 Feb 15, 2023
6a41968
Update Actions.scala
bdoyle0182 Feb 15, 2023
482c05e
fix compilation w/ new scheduler code
Feb 15, 2023
cc56908
fix versioned action read on fpcs invoker
Feb 16, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Remove some useless code
  • Loading branch information
jiangpengcheng committed Jun 3, 2021
commit ef1711c7ad2fe9dc3924cf1731c0380357895799
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"reduce": "_count"
},
"action-versions": {
"map": "function (doc) {\n var isAction = function (doc) { return (doc.exec !== undefined) };\n if (isAction(doc)) try {\n var value = {\n _id: doc.namespace + \"/\" + doc.name + \"/default\",\n namespace: doc.namespace,\n name: doc.name,\n id: doc._id,\n version: doc.version\n };\n emit([doc.namespace + \"/\" + doc.name], value);\n } catch (e) {}\n}"
"map": "function (doc) {\n var isAction = function (doc) { return (doc.exec !== undefined) };\n if (isAction(doc)) try {\n var value = {\n _id: doc.namespace + \"/\" + doc.name + \"/default\",\n namespace: doc.namespace,\n name: doc.name,\n version: doc.version\n };\n emit([doc.namespace + \"/\" + doc.name], value);\n } catch (e) {}\n}"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ object WhisksHandler extends SimpleHandler {
val FULL_NAME = "fullname"
private val commonFields = Set("namespace", "name", "version", "publish", "annotations", "updated")
private val actionFields = commonFields ++ Set("limits", "exec.binary")
private val actionVersionFields = commonFields ++ Set("_id", "id")
private val actionVersionFields = commonFields ++ Set("_id")
private val packageFields = commonFields ++ Set("binding")
private val packagePublicFields = commonFields
private val ruleFields = commonFields
Expand Down Expand Up @@ -308,7 +308,7 @@ object WhisksHandler extends SimpleHandler {
private def computeActionVersionsView(js: JsObject): JsObject = {
val base = js.fields.filterKeys(actionVersionFields).toMap
val defaultId = js.fields("namespace") + "/" + js.fields("name") + "/default"
JsObject(base + ("_id" -> JsString(defaultId), "id" -> js.fields("_id")))
JsObject(base + ("_id" -> JsString(defaultId)))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -360,15 +360,9 @@ case class ExecutableWhiskActionMetaData(namespace: EntityPath,

}

case class WhiskActionVersion(id: String, namespace: EntityPath, name: EntityName, version: SemVer)

object WhiskActionVersion {
val serdes = jsonFormat(WhiskActionVersion.apply, "id", "namespace", "name", "version")
}

case class WhiskActionVersionList(namespace: EntityPath,
name: EntityName,
versions: Map[SemVer, String],
versions: List[SemVer],
defaultVersion: Option[SemVer]) {
def matchedDocId(version: Option[SemVer]): Option[DocId] = {
version match {
Expand All @@ -377,7 +371,7 @@ case class WhiskActionVersionList(namespace: EntityPath,
case None if defaultVersion.nonEmpty =>
Some(DocId(s"$namespace/$name@${defaultVersion.get}"))
case None if versions.nonEmpty =>
Some(DocId(versions.maxBy(_._1)._2))
Some(DocId(s"$namespace/$name@${versions.max}"))
case _ =>
None
}
Expand Down Expand Up @@ -418,19 +412,21 @@ object WhiskActionVersionList extends MultipleReadersSingleWriterCache[WhiskActi
val values = result.map { row =>
row.fields("value").asJsObject()
}
val mappings = values
.map(WhiskActionVersion.serdes.read(_))
.map { actionVersion =>
(actionVersion.version, actionVersion.id)
}
.toMap
val versions = values.map { value =>
Try { value.fields.get("version").map(_.convertTo[SemVer]) } getOrElse None
}

val defaultVersion = if (result.nonEmpty) {
result.head.fields.get("doc") match {
case Some(value) => Try { value.asJsObject.fields.get("default").map(_.convertTo[SemVer]) } getOrElse None
case None => None
}
} else None
WhiskActionVersionList(action.namespace.toPath, action.name, mappings, defaultVersion)
WhiskActionVersionList(
action.namespace.toPath,
action.name,
versions.filter(_.nonEmpty).map(_.get),
defaultVersion)
},
fromCache)
}
Expand All @@ -445,7 +441,7 @@ object WhiskActionVersionList extends MultipleReadersSingleWriterCache[WhiskActi
case None if res.defaultVersion.nonEmpty =>
Some(DocId(action.copy(version = res.defaultVersion).asString))
case None if res.versions.nonEmpty =>
Some(DocId(res.versions.maxBy(_._1)._2))
Some(DocId(action.copy(version = Some(res.versions.max)).asString))
case _ =>
None
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ trait WhiskActionsApi extends WhiskCollectionAPI with PostActionActivation with
} match {
case Success(version) =>
onComplete(WhiskActionVersionList.get(entityName, entityStore, false)) {
case Success(result) if (result.versions.keys.toVector.contains(version)) =>
case Success(result) if (result.versions.contains(version)) =>
val dv = WhiskActionDefaultVersion(entityName.path, entityName.name, Some(version))
putEntity(
WhiskActionDefaultVersion,
Expand Down Expand Up @@ -274,7 +274,7 @@ trait WhiskActionsApi extends WhiskCollectionAPI with PostActionActivation with
postProcess = Some { action: WhiskAction =>
// delete oldest version when created successfully
if (result.versions.size >= actionMaxVersionLimit) {
val id = result.versions.minBy(_._1)._2
val id = entityName.copy(version = Some(result.versions.min)).asString
WhiskAction.get(entityStore, DocId(id)) flatMap { entity =>
WhiskAction.del(entityStore, DocInfo ! (id, entity.rev.rev)).map(_ => entity)
} andThen {
Expand Down Expand Up @@ -433,12 +433,12 @@ trait WhiskActionsApi extends WhiskCollectionAPI with PostActionActivation with
WhiskAction.del(entityStore, entity.docinfo).map(_ => entity)
})
else
results.versions.values
.map { id =>
WhiskAction.get(entityStore, DocId(id)) flatMap { entity =>
WhiskAction.del(entityStore, DocInfo ! (id, entity.rev.rev)).map(_ => entity)
}
results.versions.map { version =>
val id = entityName.copy(version = Some(version)).asString
WhiskAction.get(entityStore, DocId(id)) flatMap { entity =>
WhiskAction.del(entityStore, DocInfo ! (id, entity.rev.rev)).map(_ => entity)
}
}
val deleteFuture = Future.sequence(fs).andThen {
case _ =>
WhiskActionVersionList
Expand Down
1 change: 0 additions & 1 deletion tests/src/test/scala/common/WskCliOperations.scala
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,6 @@ class CliActionOperations(override val wsk: RunCliCmd)
web: Option[String] = None,
websecure: Option[String] = None,
deleteOld: Boolean = true,
defaultVersion: Option[String] = None,
expectedExitCode: Int = SUCCESS_EXIT)(implicit wp: WskProps): RunResult = {
val params = Seq(noun, if (!update) "create" else "update", "--auth", wp.authKey, fqn(name)) ++ {
artifact map { Seq(_) } getOrElse Seq.empty
Expand Down
1 change: 0 additions & 1 deletion tests/src/test/scala/common/WskOperations.scala
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,6 @@ trait ActionOperations extends DeleteFromCollectionOperations with ListOrGetFrom
web: Option[String] = None,
websecure: Option[String] = None,
deleteOld: Boolean = true,
defaultVersion: Option[String] = None,
expectedExitCode: Int = SUCCESS_EXIT)(implicit wp: WskProps): RunResult

def invoke(name: String,
Expand Down
6 changes: 1 addition & 5 deletions tests/src/test/scala/common/rest/WskRestOperations.scala
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,6 @@ class RestActionOperations(implicit val actorSystem: ActorSystem)
web: Option[String] = None,
websecure: Option[String] = None,
deleteOld: Boolean = true,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • New options (deleteAll, deleteOld) need to be documented
  • Swagger JSON file need to be updated

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

document is updated, and I will update the swagger json soon

defaultVersion: Option[String] = None,
expectedExitCode: Int = OK.intValue)(implicit wp: WskProps): RestResult = {

val (namespace, actionName) = getNamespaceEntityName(name)
Expand Down Expand Up @@ -373,11 +372,8 @@ class RestActionOperations(implicit val actorSystem: ActorSystem)
}

val path = Path(s"$basePath/namespaces/$namespace/$noun/$actionName")
val paramemters =
Map("overwrite" -> update.toString, "deleteOld" -> deleteOld.toString) ++ defaultVersion.map(version =>
("defaultVersion" -> version))
val resp =
if (update) requestEntity(PUT, path, paramemters, Some(JsObject(body).toString))
if (update) requestEntity(PUT, path, Map("overwrite" -> "true"), Some(JsObject(body).toString))
else requestEntity(PUT, path, body = Some(JsObject(body).toString))
val rr = new RestResult(resp.status, getTransactionId(resp), getRespData(resp))
validateStatusCode(expectedExitCode, rr.statusCode.intValue)
Expand Down
20 changes: 0 additions & 20 deletions tests/src/test/scala/system/basic/WskActionTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -83,26 +83,6 @@ class WskActionTests extends TestHelpers with WskTestHelpers with JsHelpers with
expectedExitCode = NotFound.intValue)
}

it should "invoke the default version of an action if version parameter is not provided" in withAssetCleaner(wskprops) {
(wp, assetHelper) =>
val name = "defaultVersion"
assetHelper.withCleaner(wsk.action, name) { (action, _) =>
action.create(name, Some(TestUtils.getTestActionFilename("hello.js")))
action.create(name, Some(TestUtils.getTestActionFilename("echo.js")))
}

// set the default version
wsk.action.create(name, Some(TestUtils.getTestActionFilename("hello.js")), defaultVersion = Some("0.0.2"))

// invoke the default version
val run = wsk.action.invoke(name, Map("payload" -> "world".toJson))
withActivation(wsk.activation, run) { activation =>
activation.response.status shouldBe "success"
activation.response.result shouldBe Some(JsObject("payload" -> "world".toJson))
activation.logs.get.mkString(" ") shouldBe empty
}
}

it should "invoke an action returning a promise" in withAssetCleaner(wskprops) { (wp, assetHelper) =>
val name = "hello promise"
assetHelper.withCleaner(wsk.action, name) { (action, _) =>
Expand Down