Skip to content

Commit

Permalink
Build hotfix
Browse files Browse the repository at this point in the history
  • Loading branch information
KineticCookie committed Dec 25, 2017
1 parent 7e601fe commit 894e889
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 16 deletions.
2 changes: 2 additions & 0 deletions manager/src/main/resources/db/migration/V2__contracts.sql
Expand Up @@ -19,3 +19,5 @@ ALTER TABLE hydro_serving.model ADD COLUMN model_contract TEXT NOT NULL DEFAULT
ALTER TABLE hydro_serving.model_runtime DROP COLUMN input_fields;
ALTER TABLE hydro_serving.model_runtime DROP COLUMN output_fields;
ALTER TABLE hydro_serving.model_runtime ADD COLUMN model_contract TEXT NOT NULL DEFAULT '';

ALTER TABLE hydro_serving.model_build ADD COLUMN runtime_type_id BIGINT REFERENCES hydro_serving.runtime_type;
Expand Up @@ -18,7 +18,7 @@ trait ManagerJsonSupport extends CommonJsonSupport {
implicit val buildModelRequestFormat = jsonFormat4(BuildModelRequest.apply)
implicit val buildModelByNameRequest = jsonFormat4(BuildModelByNameRequest.apply)

implicit val modelBuildFormat = jsonFormat9(ModelBuild)
implicit val modelBuildFormat = jsonFormat10(ModelBuild)

implicit val modelServiceInstanceFormat = jsonFormat8(ModelServiceInstance)

Expand Down
Expand Up @@ -51,7 +51,8 @@ case class ModelBuild(
status: ModelBuildStatus,
statusText: Option[String],
logsUrl: Option[String],
modelRuntime: Option[ModelRuntime]
modelRuntime: Option[ModelRuntime],
runtimeType: Option[RuntimeType]
)

case class ModelFile(
Expand Down
Expand Up @@ -4,7 +4,7 @@ import java.time.LocalDateTime

import io.hydrosphere.serving.manager.db.Tables
import io.hydrosphere.serving.manager.model.ModelBuildStatus.ModelBuildStatus
import io.hydrosphere.serving.model.ModelRuntime
import io.hydrosphere.serving.model.{ModelRuntime, RuntimeType}
import io.hydrosphere.serving.manager.model.{Model, ModelBuild, ModelBuildStatus}
import io.hydrosphere.serving.manager.repository._
import org.apache.logging.log4j.scala.Logging
Expand Down Expand Up @@ -39,7 +39,7 @@ class ModelBuildRepositoryImpl(
case Some(r) => Some(r.id)
case _ => None
})
).map(s => mapFromDb(s, Some(entity.model), entity.modelRuntime))
).map(s => mapFromDb(s, Some(entity.model), entity.modelRuntime, entity.runtimeType))

override def get(id: Long): Future[Option[ModelBuild]] =
db.run(
Expand All @@ -49,6 +49,8 @@ class ModelBuildRepositoryImpl(
.on({ case (mb, m) => mb.modelId === m.modelId })
.joinLeft(Tables.ModelRuntime)
.on({ case ((mb, m), mr) => mb.runtimeId === mr.runtimeId })
.joinLeft(Tables.RuntimeType)
.on({ case (((mb, _), _), mrt) => mb.runtimeTypeId === mrt.runtimeTypeId })
.result.headOption
).map(m => mapFromDb(m))

Expand All @@ -66,6 +68,8 @@ class ModelBuildRepositoryImpl(
.on({ case (mb, m) => mb.modelId === m.modelId })
.joinLeft(Tables.ModelRuntime)
.on({ case ((mb, m), mr) => mb.runtimeId === mr.runtimeId })
.joinLeft(Tables.RuntimeType)
.on({ case (((mb, _), _), mrt) => mb.runtimeTypeId === mrt.runtimeTypeId })
.result
).map(s => mapFromDb(s))

Expand All @@ -77,6 +81,8 @@ class ModelBuildRepositoryImpl(
.on({ case (mb, m) => mb.modelId === m.modelId })
.joinLeft(Tables.ModelRuntime)
.on({ case ((mb, m), mr) => mb.runtimeId === mr.runtimeId })
.joinLeft(Tables.RuntimeType)
.on({ case (((mb, _), _), mrt) => mb.runtimeTypeId === mrt.runtimeTypeId })
.result
).map(s => mapFromDb(s))

Expand All @@ -89,6 +95,8 @@ class ModelBuildRepositoryImpl(
.on({ case (mb, m) => mb.modelId === m.modelId })
.joinLeft(Tables.ModelRuntime)
.on({ case ((mb, m), mr) => mb.runtimeId === mr.runtimeId })
.joinLeft(Tables.RuntimeType)
.on({ case (((mb, _), _), mrt) => mb.runtimeTypeId === mrt.runtimeTypeId })
.take(maximum)
.result
).map(s => mapFromDb(s))
Expand All @@ -114,34 +122,39 @@ class ModelBuildRepositoryImpl(
.on({ case (mb, m) => mb.modelId === m.modelId })
.joinLeft(Tables.ModelRuntime)
.on({ case ((mb, _), mr) => mb.runtimeId === mr.runtimeId })
.distinctOn(_._1._1.modelId)
.joinLeft(Tables.RuntimeType)
.on({ case (((mb, _), _), mrt) => mb.runtimeTypeId === mrt.runtimeTypeId })
.distinctOn(_._1._1._1.modelId)
.result
).map(s => mapFromDb(s))
}

object ModelBuildRepositoryImpl {

def mapFromDb(model: Option[((Tables.ModelBuild#TableElementType, Option[Tables.Model#TableElementType]), Option[Tables.ModelRuntime#TableElementType])]): Option[ModelBuild] =
def mapFromDb(model: Option[(((Tables.ModelBuild#TableElementType, Option[Tables.Model#TableElementType]), Option[Tables.ModelRuntime#TableElementType]), Option[Tables.RuntimeType#TableElementType])]): Option[ModelBuild] =
model.map {
case ((modelBuild, maybeModel), maybeModelRuntime) =>
case (((modelBuild, maybeModel), maybeModelRuntime), maybeRuntimeType) =>
mapFromDb(
modelBuild,
maybeModel.map(ModelRepositoryImpl.mapFromDb),
maybeModelRuntime.map(t => ModelRuntimeRepositoryImpl.mapFromDb(t, None))
maybeModelRuntime.map(t => ModelRuntimeRepositoryImpl.mapFromDb(t, None)),
maybeRuntimeType.map(RuntimeTypeRepositoryImpl.mapFromDb)
)
}

def mapFromDb(tuples: Seq[((Tables.ModelBuild#TableElementType, Option[Tables.Model#TableElementType]), Option[Tables.ModelRuntime#TableElementType])]): Seq[ModelBuild] = {
def mapFromDb(tuples: Seq[(((Tables.ModelBuild#TableElementType, Option[Tables.Model#TableElementType]), Option[Tables.ModelRuntime#TableElementType]), Option[Tables.RuntimeType#TableElementType])]): Seq[ModelBuild] = {
tuples.map {
case ((modelBuild, maybeModel), maybeModelRuntime) =>
case (((modelBuild, maybeModel), maybeModelRuntime), maybeRuntimeType) =>
mapFromDb(
modelBuild,
maybeModel.map(ModelRepositoryImpl.mapFromDb),
maybeModelRuntime.map(t => ModelRuntimeRepositoryImpl.mapFromDb(t, None)))
maybeModelRuntime.map(t => ModelRuntimeRepositoryImpl.mapFromDb(t, None)),
maybeRuntimeType.map(RuntimeTypeRepositoryImpl.mapFromDb)
)
}
}

def mapFromDb(modelBuild: Tables.ModelBuild#TableElementType, model: Option[Model], modelRuntime: Option[ModelRuntime]): ModelBuild = {
def mapFromDb(modelBuild: Tables.ModelBuild#TableElementType, model: Option[Model], modelRuntime: Option[ModelRuntime], runtimeType: Option[RuntimeType]): ModelBuild = {
ModelBuild(
id = modelBuild.modelBuildId,
model = model.getOrElse(throw new RuntimeException()),
Expand All @@ -151,7 +164,8 @@ object ModelBuildRepositoryImpl {
statusText = modelBuild.statusText,
logsUrl = modelBuild.logsUrl,
modelRuntime = modelRuntime,
modelVersion = modelBuild.modelVersion
modelVersion = modelBuild.modelVersion,
runtimeType = runtimeType
)
}
}
Expand Up @@ -257,7 +257,8 @@ class ModelManagementServiceImpl(
status = ModelBuildStatus.STARTED,
statusText = None,
logsUrl = None,
modelRuntime = None
modelRuntime = None,
runtimeType = runtimeType
)).flatMap { modelBuid =>
buildModelRuntime(modelBuid, script).transform(
runtime => {
Expand Down
Expand Up @@ -25,8 +25,8 @@ class LocalModelBuildService(
val dockerFile = script.replaceAll("\\{" + SCRIPT_VAL_MODEL_PATH + "\\}", modelDir)
.replaceAll("\\{" + SCRIPT_VAL_MODEL_VERSION + "\\}", modelBuild.modelVersion)
.replaceAll("\\{" + SCRIPT_VAL_MODEL_NAME + "\\}", modelBuild.model.name)
.replaceAll("\\{" + SCRIPT_VAL_RUNTIME_IMAGE + "\\}", modelBuild.modelRuntime.flatMap(_.runtimeType).get.name)
.replaceAll("\\{" + SCRIPT_VAL_RUNTIME_VERSION + "\\}", modelBuild.modelRuntime.flatMap(_.runtimeType).get.version)
.replaceAll("\\{" + SCRIPT_VAL_RUNTIME_IMAGE + "\\}", modelBuild.runtimeType.map(_.name).get)
.replaceAll("\\{" + SCRIPT_VAL_RUNTIME_VERSION + "\\}", modelBuild.runtimeType.map(_.version).get)

val tmpPath = Files.createTempDirectory(s"hydroserving-${modelBuild.id}")
try {
Expand Down

0 comments on commit 894e889

Please sign in to comment.