This is an automated email from the ASF dual-hosted git repository. markusthoemmes 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 fb4b2ce Add type property to entity documents. (#3164) fb4b2ce is described below commit fb4b2ce556aedb0b3d1721b711f4721b4e15bc21 Author: Chetan Mehrotra <chet...@apache.org> AuthorDate: Fri Jan 12 14:41:21 2018 +0530 Add type property to entity documents. (#3164) --- .../main/scala/whisk/core/entity/WhiskAction.scala | 2 +- .../scala/whisk/core/entity/WhiskActivation.scala | 2 +- .../main/scala/whisk/core/entity/WhiskEntity.scala | 7 ++++-- .../scala/whisk/core/entity/WhiskPackage.scala | 2 +- .../main/scala/whisk/core/entity/WhiskRule.scala | 2 +- .../scala/whisk/core/entity/WhiskTrigger.scala | 2 +- .../controller/test/ControllerTestCommon.scala | 3 ++- .../whisk/core/entity/test/MigrationEntities.scala | 4 ++-- .../whisk/core/entity/test/WhiskEntityTests.scala | 28 ++++++++++++++++++++++ 9 files changed, 42 insertions(+), 10 deletions(-) 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 194f774..904cd62 100644 --- a/common/scala/src/main/scala/whisk/core/entity/WhiskAction.scala +++ b/common/scala/src/main/scala/whisk/core/entity/WhiskAction.scala @@ -71,7 +71,7 @@ case class WhiskActionPut(exec: Option[Exec] = None, } } -abstract class WhiskActionLike(override val name: EntityName) extends WhiskEntity(name) { +abstract class WhiskActionLike(override val name: EntityName) extends WhiskEntity(name, "action") { def exec: Exec def parameters: Parameters def limits: ActionLimits diff --git a/common/scala/src/main/scala/whisk/core/entity/WhiskActivation.scala b/common/scala/src/main/scala/whisk/core/entity/WhiskActivation.scala index 11caf3e..7556abb 100644 --- a/common/scala/src/main/scala/whisk/core/entity/WhiskActivation.scala +++ b/common/scala/src/main/scala/whisk/core/entity/WhiskActivation.scala @@ -68,7 +68,7 @@ case class WhiskActivation(namespace: EntityPath, publish: Boolean = false, annotations: Parameters = Parameters(), duration: Option[Long] = None) - extends WhiskEntity(EntityName(activationId.asString)) { + extends WhiskEntity(EntityName(activationId.asString), "activation") { require(cause != null, "cause undefined") require(start != null, "start undefined") diff --git a/common/scala/src/main/scala/whisk/core/entity/WhiskEntity.scala b/common/scala/src/main/scala/whisk/core/entity/WhiskEntity.scala index 8bafd94..501f597 100644 --- a/common/scala/src/main/scala/whisk/core/entity/WhiskEntity.scala +++ b/common/scala/src/main/scala/whisk/core/entity/WhiskEntity.scala @@ -41,7 +41,7 @@ import whisk.http.Messages * @throws IllegalArgumentException if any argument is undefined */ @throws[IllegalArgumentException] -abstract class WhiskEntity protected[entity] (en: EntityName) extends WhiskDocument { +abstract class WhiskEntity protected[entity] (en: EntityName, val entityType: String) extends WhiskDocument { val namespace: EntityPath val name = en @@ -64,7 +64,10 @@ abstract class WhiskEntity protected[entity] (en: EntityName) extends WhiskDocum * Returns a JSON object with the fields specific to this abstract class. */ protected def entityDocumentRecord: JsObject = - JsObject("name" -> JsString(name.toString), "updated" -> JsNumber(updated.toEpochMilli())) + JsObject( + "name" -> JsString(name.toString), + "updated" -> JsNumber(updated.toEpochMilli()), + "entityType" -> JsString(entityType)) override def toDocumentRecord: JsObject = { val extraFields = entityDocumentRecord.fields diff --git a/common/scala/src/main/scala/whisk/core/entity/WhiskPackage.scala b/common/scala/src/main/scala/whisk/core/entity/WhiskPackage.scala index d730d33..92b0e56 100644 --- a/common/scala/src/main/scala/whisk/core/entity/WhiskPackage.scala +++ b/common/scala/src/main/scala/whisk/core/entity/WhiskPackage.scala @@ -71,7 +71,7 @@ case class WhiskPackage(namespace: EntityPath, version: SemVer = SemVer(), publish: Boolean = false, annotations: Parameters = Parameters()) - extends WhiskEntity(name) { + extends WhiskEntity(name, "package") { require(binding != null || (binding map { _ != null } getOrElse true), "binding undefined") diff --git a/common/scala/src/main/scala/whisk/core/entity/WhiskRule.scala b/common/scala/src/main/scala/whisk/core/entity/WhiskRule.scala index 550d1bd..b064e32 100644 --- a/common/scala/src/main/scala/whisk/core/entity/WhiskRule.scala +++ b/common/scala/src/main/scala/whisk/core/entity/WhiskRule.scala @@ -76,7 +76,7 @@ case class WhiskRule(namespace: EntityPath, version: SemVer = SemVer(), publish: Boolean = false, annotations: Parameters = Parameters()) - extends WhiskEntity(name) { + extends WhiskEntity(name, "rule") { def withStatus(s: Status) = WhiskRuleResponse(namespace, name, s, trigger, action, version, publish, annotations) diff --git a/common/scala/src/main/scala/whisk/core/entity/WhiskTrigger.scala b/common/scala/src/main/scala/whisk/core/entity/WhiskTrigger.scala index ec10579..7883c70 100644 --- a/common/scala/src/main/scala/whisk/core/entity/WhiskTrigger.scala +++ b/common/scala/src/main/scala/whisk/core/entity/WhiskTrigger.scala @@ -67,7 +67,7 @@ case class WhiskTrigger(namespace: EntityPath, publish: Boolean = false, annotations: Parameters = Parameters(), rules: Option[Map[FullyQualifiedEntityName, ReducedRule]] = None) - extends WhiskEntity(name) { + extends WhiskEntity(name, "trigger") { require(limits != null, "limits undefined") diff --git a/tests/src/test/scala/whisk/core/controller/test/ControllerTestCommon.scala b/tests/src/test/scala/whisk/core/controller/test/ControllerTestCommon.scala index 1370964..28f4bb9 100644 --- a/tests/src/test/scala/whisk/core/controller/test/ControllerTestCommon.scala +++ b/tests/src/test/scala/whisk/core/controller/test/ControllerTestCommon.scala @@ -165,7 +165,8 @@ protected trait ControllerTestCommon version: SemVer = SemVer(), publish: Boolean = false, annotations: Parameters = Parameters()) - extends WhiskEntity(name) { + extends WhiskEntity(name, "badEntity") { + override def toJson = BadEntity.serdes.write(this).asJsObject } diff --git a/tests/src/test/scala/whisk/core/entity/test/MigrationEntities.scala b/tests/src/test/scala/whisk/core/entity/test/MigrationEntities.scala index 5d9983f..4c65f79 100644 --- a/tests/src/test/scala/whisk/core/entity/test/MigrationEntities.scala +++ b/tests/src/test/scala/whisk/core/entity/test/MigrationEntities.scala @@ -37,7 +37,7 @@ case class OldWhiskRule(namespace: EntityPath, version: SemVer = SemVer(), publish: Boolean = false, annotations: Parameters = Parameters()) - extends WhiskEntity(name) { + extends WhiskEntity(name, "rule") { def toJson = OldWhiskRule.serdes.write(this).asJsObject @@ -72,7 +72,7 @@ case class OldWhiskTrigger(namespace: EntityPath, version: SemVer = SemVer(), publish: Boolean = false, annotations: Parameters = Parameters()) - extends WhiskEntity(name) { + extends WhiskEntity(name, "trigger") { def toJson = OldWhiskTrigger.serdes.write(this).asJsObject diff --git a/tests/src/test/scala/whisk/core/entity/test/WhiskEntityTests.scala b/tests/src/test/scala/whisk/core/entity/test/WhiskEntityTests.scala index 55d8ca9..1812f5a 100644 --- a/tests/src/test/scala/whisk/core/entity/test/WhiskEntityTests.scala +++ b/tests/src/test/scala/whisk/core/entity/test/WhiskEntityTests.scala @@ -33,10 +33,14 @@ import whisk.core.entity.WhiskActivation import whisk.core.entity.Subject import whisk.core.entity.ActivationId import java.time.Instant + +import spray.json.JsString import whisk.core.entity.ActivationLogs import whisk.core.entity.WhiskTrigger import whisk.core.entity.ReducedRule import whisk.core.entity.Status +import whisk.core.entity.WhiskEntity +import whisk.core.entity.WhiskRule @RunWith(classOf[JUnitRunner]) class WhiskEntityTests extends FlatSpec with ExecHelpers with Matchers { @@ -134,4 +138,28 @@ class WhiskEntityTests extends FlatSpec with ExecHelpers with Matchers { rulesRemoved.rules shouldBe None rulesRemoved.rev shouldBe trigger.rev } + + behavior of "WhiskEntity" + + it should "define the entityType property in its json representation" in { + def assertType(d: WhiskEntity, entityType: String) = { + d.toDocumentRecord.fields("entityType") shouldBe JsString(entityType) + } + + val action = WhiskAction(namespace, name, jsDefault("code"), Parameters()) + assertType(action, "action") + + val activation = WhiskActivation(namespace, name, Subject(), ActivationId(), Instant.now(), Instant.now()) + assertType(activation, "activation") + + val whiskPackage = WhiskPackage(namespace, name) + assertType(whiskPackage, "package") + + val rule = + WhiskRule(namespace, name, FullyQualifiedEntityName(namespace, name), FullyQualifiedEntityName(namespace, name)) + assertType(rule, "rule") + + val trigger = WhiskTrigger(namespace, name) + assertType(trigger, "trigger") + } } -- To stop receiving notification emails like this one, please contact ['"commits@openwhisk.apache.org" <commits@openwhisk.apache.org>'].