chetanmeh commented on a change in pull request #4584: OpenWhisk User Events URL: https://github.com/apache/openwhisk/pull/4584#discussion_r326119356
########## File path: common/scala/src/main/scala/org/apache/openwhisk/core/connector/Message.scala ########## @@ -195,34 +198,59 @@ object EventMessageBody extends DefaultJsonProtocol { case class Activation(name: String, statusCode: Int, - duration: Long, - waitTime: Long, - initTime: Long, + duration: Duration, + waitTime: Duration, + initTime: Duration, kind: String, conductor: Boolean, memory: Int, causedBy: Option[String]) extends EventMessageBody { - val typeName = "Activation" + val typeName = Activation.typeName override def serialize = toJson.compactPrint + def entityPath = EntityPath(name).toFullyQualifiedEntityName def toJson = Activation.activationFormat.write(this) + + def status: String = statusForCode(statusCode) + + def isColdStart: Boolean = initTime != Duration.Zero + + def namespace: String = entityPath.path.root.name + + def action: String = entityPath.fullPath.relativePath.get.namespace + } object Activation extends DefaultJsonProtocol { + + val typeName = "Activation" def parse(msg: String) = Try(activationFormat.read(msg.parseJson)) + + private implicit val durationFormat = new RootJsonFormat[Duration] { + override def write(obj: Duration): JsValue = obj match { + case o if o.isFinite => JsNumber(o.toMillis) + case _ => JsNumber.zero + } + + override def read(json: JsValue): Duration = json match { + case JsNumber(n) if n <= 0 => Duration.Zero + case JsNumber(n) => toDuration(n.longValue) + } + } + implicit val activationFormat = jsonFormat( Activation.apply _, "name", - "statusCode", - "duration", - "waitTime", - "initTime", - "kind", - "conductor", - "memory", - "causedBy") + WhiskActivation.statusCodeAnnotation, Review comment: This can be avoided as it does not serve much purpose to use those annotations value as constant (some are not annotation also like memory). So it would be fine to revert to preexisting way ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services