[GitHub] markusthoemmes commented on a change in pull request #3669: Make stemcells configurable by deployment
markusthoemmes commented on a change in pull request #3669: Make stemcells configurable by deployment URL: https://github.com/apache/incubator-openwhisk/pull/3669#discussion_r190335820 ## File path: common/scala/src/main/scala/whisk/core/entity/ExecManifest.scala ## @@ -285,6 +309,24 @@ protected[core] object ExecManifest { private val defaultSplitter = "([a-z0-9]+):default".r } + protected[entity] implicit val stemCellSerdes = new RootJsonFormat[StemCell] { +def write(cell: StemCell) = + JsObject("count" -> JsNumber(cell.count), "memory" -> JsString(cell.memory.toString)) + +def read(value: JsValue): StemCell = { + Try { +value.asJsObject.getFields("count", "memory") match { + case Seq(JsNumber(count), JsString(memory)) => +require(count.isWhole && count.intValue > 0, "stem cell count must be whole number greater than zero") +StemCell(count.intValue, ByteSize.fromString(memory)) +} + } match { +case Success(c) => c +case Failure(t) => throw t + } Review comment: Why even wrap in a `Try` then? This should be equivalent without the `Try` + `match` This is an automated message from the Apache Git Service. To respond to the message, please log on 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
[GitHub] markusthoemmes commented on a change in pull request #3669: Make stemcells configurable by deployment
markusthoemmes commented on a change in pull request #3669: Make stemcells configurable by deployment URL: https://github.com/apache/incubator-openwhisk/pull/3669#discussion_r190341384 ## File path: common/scala/src/main/scala/whisk/core/entity/ExecManifest.scala ## @@ -262,13 +283,16 @@ protected[core] object ExecManifest { } } -val manifests: Map[String, RuntimeManifest] = { - runtimes.flatMap { -_.versions.map { m => - m.kind -> m -} - }.toMap -} +/** + * Collects all runtimes for which there is a stemcell configuration defined + * + * @return list of runtime manifests with stemcell configurations + */ +def stemcells[T](f: (RuntimeManifest, List[StemCell]) => List[T]): List[T] = { + manifests.collect { +case (_, m @ RuntimeManifest(_, _, _, _, _, _, _, Some(stemCells))) if stemCells.nonEmpty => f(m, stemCells) + } +}.flatten.toList Review comment: Would it make sense to make this "just" return `List[(RuntimeManifest, List[StemCell])]` to enable the same functionality but with more flexibility and clarity? This is an automated message from the Apache Git Service. To respond to the message, please log on 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
[GitHub] markusthoemmes commented on a change in pull request #3669: Make stemcells configurable by deployment
markusthoemmes commented on a change in pull request #3669: Make stemcells configurable by deployment URL: https://github.com/apache/incubator-openwhisk/pull/3669#discussion_r190336091 ## File path: common/scala/src/main/scala/whisk/core/entity/ExecManifest.scala ## @@ -285,6 +309,24 @@ protected[core] object ExecManifest { private val defaultSplitter = "([a-z0-9]+):default".r } + protected[entity] implicit val stemCellSerdes = new RootJsonFormat[StemCell] { Review comment: Doesn't a default `jsonFormat` work here? Meanwhile there should be a JsonFormat for `ByteSize`? This is an automated message from the Apache Git Service. To respond to the message, please log on 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
[GitHub] markusthoemmes commented on a change in pull request #3669: Make stemcells configurable by deployment
markusthoemmes commented on a change in pull request #3669: Make stemcells configurable by deployment URL: https://github.com/apache/incubator-openwhisk/pull/3669#discussion_r190343332 ## File path: common/scala/src/main/scala/whisk/core/entity/ExecManifest.scala ## @@ -262,13 +283,16 @@ protected[core] object ExecManifest { } } -val manifests: Map[String, RuntimeManifest] = { - runtimes.flatMap { -_.versions.map { m => - m.kind -> m -} - }.toMap -} +/** + * Collects all runtimes for which there is a stemcell configuration defined + * + * @return list of runtime manifests with stemcell configurations + */ +def stemcells[T](f: (RuntimeManifest, List[StemCell]) => List[T]): List[T] = { + manifests.collect { +case (_, m @ RuntimeManifest(_, _, _, _, _, _, _, Some(stemCells))) if stemCells.nonEmpty => f(m, stemCells) + } Review comment: If my suggestion below is adopted, this can be simplified to: ```scala manifests.filter(_._2.stemCells.map(_.nonEmpty).getOrElse(false)) ``` This is an automated message from the Apache Git Service. To respond to the message, please log on 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