Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/depconf ref #83

Merged
merged 6 commits into from
Apr 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions project/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ object Dependencies {
val fs2 = "2.4.4"
val enumeratumV = "1.6.0"
val mockitoScalaV = "1.16.3"
val monocleV = "3.0.0-M4"

lazy val awsDependencies = Seq(
"com.amazonaws" % "aws-java-sdk-ecs" % awsSdkVersion,
Expand Down Expand Up @@ -95,6 +96,9 @@ object Dependencies {
akkaCirceDependencies ++
enumeratumDependencies ++
Seq(
// "com.github.julien-truffaut" %% "monocle-core" % monocleV,
// "com.github.julien-truffaut" %% "monocle-macro" % monocleV, // only for Scala 2.13
"org.typelevel" %% "kittens" % "2.2.1",
"org.typelevel" %% "cats-effect" % catsV,
"org.tpolecat" %% "doobie-core" % "0.9.0",
"org.tpolecat" %% "doobie-postgres" % "0.9.0",
Expand Down
45 changes: 4 additions & 41 deletions src/main/resources/application.conf
Original file line number Diff line number Diff line change
Expand Up @@ -17,54 +17,17 @@ application {

cloud-driver {
type = "docker"
network-name = "bridge"
// type = "kubernetes"
// proxy-host = "localhost"
// proxy-port = 8001
// kube-namespace = "serving"
// kube-registry-secret-name = "regcred"


// region = "eu-west-1"
// cluster = "hydro-ne-hydro"
// account-id = "060183668755"
// memory-reservation = 200
// internal-domain-name = "kek"
// vpc-id = "123"
// logging = {
// driver = "awslogs"
// }
//
// monitoring {
// host = localhost
// port = 9998
// http-port = 9999
// }

// gateway {
// host = localhost
// port = 19091
// http-port = 19090
// }
}
network-name = "demo_hydronet"
}

docker-repository {
type = "local"

// type="ecs"

// type = "remote"
// host = "docker.hydrosphere.io"
// username = ""
// password = ""
// pull-host = "localhost"
}


database {
jdbc-url = "jdbc:postgresql://127.0.0.1:5432/docker"
jdbc-url = "jdbc:postgresql://postgres:5432/docker"
username = "docker"
password = "docker"
maximum-pool-size = 10
leak-detection-threshold = 15
}
}
33 changes: 16 additions & 17 deletions src/main/scala/io/hydrosphere/serving/manager/App.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package io.hydrosphere.serving.manager

import java.nio.charset.StandardCharsets
import akka.actor.ActorSystem
import akka.stream.ActorMaterializer
import akka.util.Timeout
Expand Down Expand Up @@ -37,15 +36,14 @@ import io.hydrosphere.serving.manager.domain.deploy_config.{
import io.hydrosphere.serving.manager.domain.image.ImageRepository
import io.hydrosphere.serving.manager.domain.model_version.ModelVersionEvents
import io.hydrosphere.serving.manager.domain.monitoring.MetricSpecEvents
import io.hydrosphere.serving.manager.domain.servable.ServableEvents
import io.hydrosphere.serving.manager.domain.servable.{ServableEvents, ServableRepository}
import io.hydrosphere.serving.manager.infrastructure.db.Database
import io.hydrosphere.serving.manager.infrastructure.db.repository._
import io.hydrosphere.serving.manager.infrastructure.docker.DockerdClient
import io.hydrosphere.serving.manager.infrastructure.grpc.{GrpcChannel, PredictionClient}
import io.hydrosphere.serving.manager.infrastructure.grpc.GrpcChannel
import io.hydrosphere.serving.manager.infrastructure.storage.StorageOps
import io.hydrosphere.serving.manager.util.random.RNG
import io.hydrosphere.serving.manager.util.{FileUtils, UUIDGenerator}
import org.apache.commons.io.IOUtils
import io.hydrosphere.serving.manager.util.UUIDGenerator

import scala.concurrent.ExecutionContext
import scala.concurrent.duration._
Expand All @@ -69,10 +67,9 @@ object App {
implicit val timeout = Timeout(5.minute)
implicit val serviceExecutionContext = ExecutionContext.global
implicit val grpcCtor = GrpcChannel.plaintextFactory[F]
// implicit val predictionCtor = PredictionClient.clientCtor[F](grpcCtor)
implicit val storageOps = StorageOps.default[F]
implicit val uuidGen = UUIDGenerator.default[F]()
implicit val dc = dockerClient
implicit val storageOps = StorageOps.default[F]
implicit val uuidGen = UUIDGenerator.default[F]()
implicit val dc = dockerClient
for {
rngF <- Resource.liftF(RNG.default[F])
cloudDriver =
Expand All @@ -98,14 +95,16 @@ object App {
implicit val (servablePub, servableSub) = servablePubSub
implicit val (metricPub, metricSub) = monitoringPubSub
implicit val (depPub, depSUb) = depPubSub
implicit val hsRepo = new DBDeploymentConfigurationRepository()
implicit val modelRepo = DBModelRepository.make()
implicit val modelVersionRepo = DBModelVersionRepository.make()
implicit val servableRepo = DBServableRepository.make()
implicit val appRepo = DBApplicationRepository.make()
implicit val buildLogRepo = DBBuildLogRepository.make()
implicit val monitoringRepo = DBMonitoringRepository.make()
implicit val imageRepo = ImageRepository.fromConfig(dockerClient, config.dockerRepository)
implicit val hsRepo =
DeploymentConfigurationRepository.make(config.defaultDeploymentConfiguration)
implicit val modelRepo = DBModelRepository.make()
implicit val modelVersionRepo = DBModelVersionRepository.make()
implicit val servableRepo = DBServableRepository.make(config.defaultDeploymentConfiguration)
implicit val appRepo = DBApplicationRepository.make(config.defaultDeploymentConfiguration)
implicit val buildLogRepo = DBBuildLogRepository.make()
implicit val monitoringRepo =
DBMonitoringRepository.make(config.defaultDeploymentConfiguration)
implicit val imageRepo = ImageRepository.fromConfig(dockerClient, config.dockerRepository)

Resource.liftF(Core.make[F](config))
}
Expand Down
5 changes: 2 additions & 3 deletions src/main/scala/io/hydrosphere/serving/manager/Boot.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,16 @@ package io.hydrosphere.serving.manager
import cats.effect._
import cats.implicits._
import com.spotify.docker.client.DefaultDockerClient
import io.hydrosphere.serving.manager.config.{DockerClientConfig, ManagerConfiguration}
import io.hydrosphere.serving.manager.config.ManagerConfiguration
import io.hydrosphere.serving.manager.infrastructure.docker.DockerdClient
import io.hydrosphere.serving.manager.util.ReflectionUtils
import org.apache.logging.log4j.scala.Logging

object Boot extends IOApp with Logging {
override def run(args: List[String]): IO[ExitCode] =
IO.suspend {
for {
configuration <- ManagerConfiguration.load[IO]()
_ <- IO(logger.info(s"Config loaded:\n${ReflectionUtils.prettyPrint(configuration)}"))
_ <- IO(logger.info(configuration.show))
dockerClient <- IO(DefaultDockerClient.fromEnv().readTimeoutMillis(60 * 60 * 1000).build())
wrappedClient <- DockerdClient.create[IO](dockerClient)
_ <- App.make[IO](configuration, wrappedClient).use { app =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ case class ServableView(
status: Servable.Status,
fullName: String,
metadata: Map[String, String],
deploymentConfiguration: Option[DeploymentConfiguration]
deploymentConfiguration: DeploymentConfiguration
)

object ServableView {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
package io.hydrosphere.serving.manager.config

import cats.Show
import cats.derived.semiauto

case class ApplicationConfig(
port: Int,
grpcPort: Int
port: Int,
grpcPort: Int
)

object ApplicationConfig {
implicit val appConf: Show[ApplicationConfig] = semiauto.show
}
Original file line number Diff line number Diff line change
@@ -1,45 +1,27 @@
package io.hydrosphere.serving.manager.config

import com.amazonaws.regions.Regions
import cats.Show
import cats.derived.semiauto

sealed trait CloudDriverConfiguration {
def loggingConfiguration: Option[ModelLoggingConfiguration]
}

object CloudDriverConfiguration {
case class Swarm(
networkName: String,
loggingConfiguration: Option[ModelLoggingConfiguration]
) extends CloudDriverConfiguration

case class Docker(
networkName: String,
loggingConfiguration: Option[ModelLoggingConfiguration]
) extends CloudDriverConfiguration

case class Local(
loggingConfiguration: Option[ModelLoggingConfiguration],
monitoring: Option[LocalDockerCloudDriverServiceConfiguration],
profiler: Option[LocalDockerCloudDriverServiceConfiguration],
gateway: Option[LocalDockerCloudDriverServiceConfiguration]
networkName: String,
loggingConfiguration: Option[ModelLoggingConfiguration]
) extends CloudDriverConfiguration

case class Ecs(
region: Regions,
cluster: String,
accountId: String,
loggingConfiguration: Option[ModelLoggingConfiguration],
memoryReservation: Int = 200,
internalDomainName: String,
vpcId: String
) extends CloudDriverConfiguration

case class Kubernetes(
proxyHost: String,
proxyPort: Int,
kubeNamespace: String,
kubeRegistrySecretName: String,
loggingConfiguration: Option[ModelLoggingConfiguration]
proxyHost: String,
proxyPort: Int,
kubeNamespace: String,
kubeRegistrySecretName: String,
loggingConfiguration: Option[ModelLoggingConfiguration]
) extends CloudDriverConfiguration
}

implicit val dockerShow: Show[Docker] = semiauto.show
implicit val localShow: Show[Kubernetes] = semiauto.show
implicit val cd: Show[CloudDriverConfiguration] = semiauto.show
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package io.hydrosphere.serving.manager.config

import io.circe.generic.JsonCodec
import io.hydrosphere.serving.manager.domain.deploy_config._

/**
* Used only to define a deployment configuration in manager's config files.
* Name is hardcoded as [[DEFAULT_DEPLOYMENT_CONFIG_NAME]]
*
* @param container
* @param pod
* @param deployment
* @param hpa
*/
@JsonCodec
final case class DefaultDeploymentConfiguration(
container: Option[K8sContainerConfig],
pod: Option[K8sPodConfig],
deployment: Option[K8sDeploymentConfig],
hpa: Option[K8sHorizontalPodAutoscalerConfig]
) {
def toDC: DeploymentConfiguration =
DeploymentConfiguration(
name = DEFAULT_DEPLOYMENT_CONFIG_NAME,
container = container,
pod = pod,
deployment = deployment,
hpa = hpa
)
}
Original file line number Diff line number Diff line change
@@ -1,23 +1,30 @@
package io.hydrosphere.serving.manager.config

import cats.Show
import cats.derived.semiauto
import com.amazonaws.regions.Regions
import io.hydrosphere.serving.manager.util.Secret

sealed trait DockerRepositoryConfiguration

object DockerRepositoryConfiguration {
case object Local extends DockerRepositoryConfiguration

case class Ecs(
region: Regions,
accountId: String
region: Regions,
accountId: String
) extends DockerRepositoryConfiguration

case class Remote(
host: String,
username: Option[String],
password: Option[String],
pullHost: Option[String],
imagePrefix: Option[String]
) extends DockerRepositoryConfiguration
host: String,
username: Option[String],
password: Option[Secret[String]],
pullHost: Option[String],
imagePrefix: Option[String]
) extends DockerRepositoryConfiguration

implicit val regions: Show[Regions] = Show.fromToString
implicit val ecs: Show[Ecs] = semiauto.show
implicit val remote: Show[Remote] = semiauto.show
implicit val dr: Show[DockerRepositoryConfiguration] = semiauto.show
}
Original file line number Diff line number Diff line change
@@ -1,27 +1,32 @@
package io.hydrosphere.serving.manager.config

import cats.Show
import cats.derived.semiauto
import com.zaxxer.hikari.HikariConfig
import io.hydrosphere.serving.manager.util.Secret

case class HikariConfiguration(
jdbcUrl: String,
username: String,
password: String,
driverClassname: String = "org.postgresql.Driver",
maximumPoolSize: Int,
initializationFailTimeout: Long = 20000L,
leakDetectionThreshold: Long = 15000L
jdbcUrl: String,
username: String,
password: Secret[String],
driverClassname: String = "org.postgresql.Driver",
maximumPoolSize: Int,
initializationFailTimeout: Long = 20000L,
leakDetectionThreshold: Long = 15000L
)

object HikariConfiguration {
def toConfig(config: HikariConfiguration): HikariConfig = {
val hikariConfig = new HikariConfig()
hikariConfig.setJdbcUrl(config.jdbcUrl)
hikariConfig.setUsername(config.username)
hikariConfig.setPassword(config.password)
hikariConfig.setDriverClassName(config.driverClassname)
hikariConfig.setMaximumPoolSize(config.maximumPoolSize)
hikariConfig.setInitializationFailTimeout(config.initializationFailTimeout)
hikariConfig.setLeakDetectionThreshold(config.leakDetectionThreshold)
hikariConfig
}
}
implicit val db: Show[HikariConfiguration] = semiauto.show

def toConfig(config: HikariConfiguration): HikariConfig = {
val hikariConfig = new HikariConfig()
hikariConfig.setJdbcUrl(config.jdbcUrl)
hikariConfig.setUsername(config.username)
hikariConfig.setPassword(config.password.value)
hikariConfig.setDriverClassName(config.driverClassname)
hikariConfig.setMaximumPoolSize(config.maximumPoolSize)
hikariConfig.setInitializationFailTimeout(config.initializationFailTimeout)
hikariConfig.setLeakDetectionThreshold(config.leakDetectionThreshold)
hikariConfig
}
}

This file was deleted.

Loading