Skip to content

Commit a9c44af

Browse files
Remove some useless code
1 parent e3c44da commit a9c44af

File tree

8 files changed

+23
-53
lines changed

8 files changed

+23
-53
lines changed

ansible/files/whisks_design_document_for_entities_db_v2.1.0.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"reduce": "_count"
2424
},
2525
"action-versions": {
26-
"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}"
26+
"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}"
2727
}
2828
}
2929
}

common/scala/src/main/scala/org/apache/openwhisk/core/database/DocumentHandler.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ object WhisksHandler extends SimpleHandler {
211211
val FULL_NAME = "fullname"
212212
private val commonFields = Set("namespace", "name", "version", "publish", "annotations", "updated")
213213
private val actionFields = commonFields ++ Set("limits", "exec.binary")
214-
private val actionVersionFields = commonFields ++ Set("_id", "id")
214+
private val actionVersionFields = commonFields ++ Set("_id")
215215
private val packageFields = commonFields ++ Set("binding")
216216
private val packagePublicFields = commonFields
217217
private val ruleFields = commonFields
@@ -308,7 +308,7 @@ object WhisksHandler extends SimpleHandler {
308308
private def computeActionVersionsView(js: JsObject): JsObject = {
309309
val base = js.fields.filterKeys(actionVersionFields).toMap
310310
val defaultId = js.fields("namespace") + "/" + js.fields("name") + "/default"
311-
JsObject(base + ("_id" -> JsString(defaultId), "id" -> js.fields("_id")))
311+
JsObject(base + ("_id" -> JsString(defaultId)))
312312
}
313313
}
314314

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

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -360,15 +360,9 @@ case class ExecutableWhiskActionMetaData(namespace: EntityPath,
360360

361361
}
362362

363-
case class WhiskActionVersion(id: String, namespace: EntityPath, name: EntityName, version: SemVer)
364-
365-
object WhiskActionVersion {
366-
val serdes = jsonFormat(WhiskActionVersion.apply, "id", "namespace", "name", "version")
367-
}
368-
369363
case class WhiskActionVersionList(namespace: EntityPath,
370364
name: EntityName,
371-
versions: Map[SemVer, String],
365+
versions: List[SemVer],
372366
defaultVersion: Option[SemVer]) {
373367
def matchedDocId(version: Option[SemVer]): Option[DocId] = {
374368
version match {
@@ -377,7 +371,7 @@ case class WhiskActionVersionList(namespace: EntityPath,
377371
case None if defaultVersion.nonEmpty =>
378372
Some(DocId(s"$namespace/$name@${defaultVersion.get}"))
379373
case None if versions.nonEmpty =>
380-
Some(DocId(versions.maxBy(_._1)._2))
374+
Some(DocId(s"$namespace/$name@${versions.max}"))
381375
case _ =>
382376
None
383377
}
@@ -418,19 +412,21 @@ object WhiskActionVersionList extends MultipleReadersSingleWriterCache[WhiskActi
418412
val values = result.map { row =>
419413
row.fields("value").asJsObject()
420414
}
421-
val mappings = values
422-
.map(WhiskActionVersion.serdes.read(_))
423-
.map { actionVersion =>
424-
(actionVersion.version, actionVersion.id)
425-
}
426-
.toMap
415+
val versions = values.map { value =>
416+
Try { value.fields.get("version").map(_.convertTo[SemVer]) } getOrElse None
417+
}
418+
427419
val defaultVersion = if (result.nonEmpty) {
428420
result.head.fields.get("doc") match {
429421
case Some(value) => Try { value.asJsObject.fields.get("default").map(_.convertTo[SemVer]) } getOrElse None
430422
case None => None
431423
}
432424
} else None
433-
WhiskActionVersionList(action.namespace.toPath, action.name, mappings, defaultVersion)
425+
WhiskActionVersionList(
426+
action.namespace.toPath,
427+
action.name,
428+
versions.filter(_.nonEmpty).map(_.get),
429+
defaultVersion)
434430
},
435431
fromCache)
436432
}
@@ -445,7 +441,7 @@ object WhiskActionVersionList extends MultipleReadersSingleWriterCache[WhiskActi
445441
case None if res.defaultVersion.nonEmpty =>
446442
Some(DocId(action.copy(version = res.defaultVersion).asString))
447443
case None if res.versions.nonEmpty =>
448-
Some(DocId(res.versions.maxBy(_._1)._2))
444+
Some(DocId(action.copy(version = Some(res.versions.max)).asString))
449445
case _ =>
450446
None
451447
}

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ trait WhiskActionsApi extends WhiskCollectionAPI with PostActionActivation with
228228
} match {
229229
case Success(version) =>
230230
onComplete(WhiskActionVersionList.get(entityName, entityStore, false)) {
231-
case Success(result) if (result.versions.keys.toVector.contains(version)) =>
231+
case Success(result) if (result.versions.contains(version)) =>
232232
val dv = WhiskActionDefaultVersion(entityName.path, entityName.name, Some(version))
233233
putEntity(
234234
WhiskActionDefaultVersion,
@@ -274,7 +274,7 @@ trait WhiskActionsApi extends WhiskCollectionAPI with PostActionActivation with
274274
postProcess = Some { action: WhiskAction =>
275275
// delete oldest version when created successfully
276276
if (result.versions.size >= actionMaxVersionLimit) {
277-
val id = result.versions.minBy(_._1)._2
277+
val id = entityName.copy(version = Some(result.versions.min)).asString
278278
WhiskAction.get(entityStore, DocId(id)) flatMap { entity =>
279279
WhiskAction.del(entityStore, DocInfo ! (id, entity.rev.rev)).map(_ => entity)
280280
} andThen {
@@ -433,12 +433,12 @@ trait WhiskActionsApi extends WhiskCollectionAPI with PostActionActivation with
433433
WhiskAction.del(entityStore, entity.docinfo).map(_ => entity)
434434
})
435435
else
436-
results.versions.values
437-
.map { id =>
438-
WhiskAction.get(entityStore, DocId(id)) flatMap { entity =>
439-
WhiskAction.del(entityStore, DocInfo ! (id, entity.rev.rev)).map(_ => entity)
440-
}
436+
results.versions.map { version =>
437+
val id = entityName.copy(version = Some(version)).asString
438+
WhiskAction.get(entityStore, DocId(id)) flatMap { entity =>
439+
WhiskAction.del(entityStore, DocInfo ! (id, entity.rev.rev)).map(_ => entity)
441440
}
441+
}
442442
val deleteFuture = Future.sequence(fs).andThen {
443443
case _ =>
444444
WhiskActionVersionList

tests/src/test/scala/common/WskCliOperations.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,6 @@ class CliActionOperations(override val wsk: RunCliCmd)
207207
web: Option[String] = None,
208208
websecure: Option[String] = None,
209209
deleteOld: Boolean = true,
210-
defaultVersion: Option[String] = None,
211210
expectedExitCode: Int = SUCCESS_EXIT)(implicit wp: WskProps): RunResult = {
212211
val params = Seq(noun, if (!update) "create" else "update", "--auth", wp.authKey, fqn(name)) ++ {
213212
artifact map { Seq(_) } getOrElse Seq.empty

tests/src/test/scala/common/WskOperations.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,6 @@ trait ActionOperations extends DeleteFromCollectionOperations with ListOrGetFrom
246246
web: Option[String] = None,
247247
websecure: Option[String] = None,
248248
deleteOld: Boolean = true,
249-
defaultVersion: Option[String] = None,
250249
expectedExitCode: Int = SUCCESS_EXIT)(implicit wp: WskProps): RunResult
251250

252251
def invoke(name: String,

tests/src/test/scala/common/rest/WskRestOperations.scala

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,6 @@ class RestActionOperations(implicit val actorSystem: ActorSystem)
276276
web: Option[String] = None,
277277
websecure: Option[String] = None,
278278
deleteOld: Boolean = true,
279-
defaultVersion: Option[String] = None,
280279
expectedExitCode: Int = OK.intValue)(implicit wp: WskProps): RestResult = {
281280

282281
val (namespace, actionName) = getNamespaceEntityName(name)
@@ -373,11 +372,8 @@ class RestActionOperations(implicit val actorSystem: ActorSystem)
373372
}
374373

375374
val path = Path(s"$basePath/namespaces/$namespace/$noun/$actionName")
376-
val paramemters =
377-
Map("overwrite" -> update.toString, "deleteOld" -> deleteOld.toString) ++ defaultVersion.map(version =>
378-
("defaultVersion" -> version))
379375
val resp =
380-
if (update) requestEntity(PUT, path, paramemters, Some(JsObject(body).toString))
376+
if (update) requestEntity(PUT, path, Map("overwrite" -> "true"), Some(JsObject(body).toString))
381377
else requestEntity(PUT, path, body = Some(JsObject(body).toString))
382378
val rr = new RestResult(resp.status, getTransactionId(resp), getRespData(resp))
383379
validateStatusCode(expectedExitCode, rr.statusCode.intValue)

tests/src/test/scala/system/basic/WskActionTests.scala

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -83,26 +83,6 @@ class WskActionTests extends TestHelpers with WskTestHelpers with JsHelpers with
8383
expectedExitCode = NotFound.intValue)
8484
}
8585

86-
it should "invoke the default version of an action if version parameter is not provided" in withAssetCleaner(wskprops) {
87-
(wp, assetHelper) =>
88-
val name = "defaultVersion"
89-
assetHelper.withCleaner(wsk.action, name) { (action, _) =>
90-
action.create(name, Some(TestUtils.getTestActionFilename("hello.js")))
91-
action.create(name, Some(TestUtils.getTestActionFilename("echo.js")))
92-
}
93-
94-
// set the default version
95-
wsk.action.create(name, Some(TestUtils.getTestActionFilename("hello.js")), defaultVersion = Some("0.0.2"))
96-
97-
// invoke the default version
98-
val run = wsk.action.invoke(name, Map("payload" -> "world".toJson))
99-
withActivation(wsk.activation, run) { activation =>
100-
activation.response.status shouldBe "success"
101-
activation.response.result shouldBe Some(JsObject("payload" -> "world".toJson))
102-
activation.logs.get.mkString(" ") shouldBe empty
103-
}
104-
}
105-
10686
it should "invoke an action returning a promise" in withAssetCleaner(wskprops) { (wp, assetHelper) =>
10787
val name = "hello promise"
10888
assetHelper.withCleaner(wsk.action, name) { (action, _) =>

0 commit comments

Comments
 (0)