You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@openwhisk.apache.org by GitBox <gi...@apache.org> on 2020/05/08 05:39:22 UTC

[GitHub] [openwhisk] ningyougang commented on a change in pull request #4871: Adjust prewarm container dynamically

ningyougang commented on a change in pull request #4871:
URL: https://github.com/apache/openwhisk/pull/4871#discussion_r421949078



##########
File path: common/scala/src/main/scala/org/apache/openwhisk/core/entity/ExecManifest.scala
##########
@@ -344,9 +373,37 @@ protected[core] object ExecManifest {
 
   protected[entity] implicit val imageNameSerdes: RootJsonFormat[ImageName] = jsonFormat4(ImageName.apply)
 
-  protected[entity] implicit val stemCellSerdes: RootJsonFormat[StemCell] = {
+  protected[entity] implicit val ttlSerdes: RootJsonFormat[Duration] = new RootJsonFormat[Duration] {
+    override def write(duration: Duration): JsValue = JsString(duration.toString)
+
+    override def read(value: JsValue): Duration = value match {
+      case JsString(s) => Duration(s)
+      case _ =>
+        deserializationError("time unit not supported. Only milliseconds, seconds, minutes, hours, days are supported")
+    }
+  }
+
+  protected[entity] implicit val reactivePrewarmingConfigSerdes: RootJsonFormat[ReactivePrewarmingConfig] = jsonFormat5(
+    ReactivePrewarmingConfig.apply)
+
+  protected[entity] implicit val stemCellSerdes = new RootJsonFormat[StemCell] {
     import org.apache.openwhisk.core.entity.size.serdes
-    jsonFormat2(StemCell.apply)
+    import org.apache.openwhisk.core.entity.size.SizeInt
+    val defaultSerdes = jsonFormat3(StemCell.apply)
+    override def read(value: JsValue): StemCell = {
+      val fields = value.asJsObject.fields
+      val initialCount =
+        fields
+          .get("initialCount")
+          .orElse(fields.get("count"))
+          .map(_.convertTo[Int])
+          .getOrElse(1)
+      val memory = fields.get("memory").map(_.convertTo[ByteSize]).getOrElse(256.MB)

Review comment:
       I changed from `.getOrElse(1)` to `.get` and changed from `.getOrElse(256.MB)` to `.get` as well.
   Because the these two values is must required.
   If didn't give value in runtime.json, the invoker can't be started. e.g. invoker reported below error
   ```
   [2020-05-08T14:36:44.095Z] [ERROR] [#tid_sid_unknown] [Invoker] Invalid runtimes manifest: java.lang.IllegalArgumentException: requirement failed: initialCount must be positive
   [2020-05-08T14:34:55.912Z] [ERROR] [#tid_sid_unknown] [Invoker] Invalid runtimes manifest: java.lang.IllegalArgumentException: Size Unit not supported. Only "B", "K[B]", "M[B]" and "G[B]" are supported.
   ```
   
   




----------------------------------------------------------------
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:
users@infra.apache.org