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

Update to libats 2.x #157

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
63 changes: 25 additions & 38 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ name := "campaigner"
organization := "com.advancedtelematic"
scalaVersion := "2.12.10"

resolvers += "sonatype-releases" at "https://s01.oss.sonatype.org/content/repositories/releases"
resolvers += "sonatype-snapshots" at "https://s01.oss.sonatype.org/content/repositories/snapshots"

scalacOptions := Seq(
"-feature",
"-unchecked",
Expand All @@ -18,15 +21,11 @@ scalacOptions := Seq(
// allow imports in the console on a single line
scalacOptions in (Compile, console) ~= (_ filterNot (_ == "-Ywarn-unused-import"))

resolvers += "ATS Releases" at "https://nexus.ota.here.com/content/repositories/releases"

resolvers += "ATS Snapshots" at "https://nexus.ota.here.com/content/repositories/snapshots"

libraryDependencies ++= {
val akkaV = "2.6.5"
val akkaHttpV = "10.1.12"
val libatsV = "0.4.0-8-g8c1c7f3"
val libtufV = "0.7.1-6-gd36661d"
val akkaV = "2.6.17"
val akkaHttpV = "10.2.6"
val libatsV = "2.0.3"
val libtufV = "1.0.0"
val scalaTestV = "3.0.8"
val slickV = "3.2.0"

Expand All @@ -41,50 +40,38 @@ libraryDependencies ++= {
"com.typesafe.slick" %% "slick" % slickV,
"com.typesafe.slick" %% "slick-hikaricp" % slickV,
"org.mariadb.jdbc" % "mariadb-java-client" % "2.4.4",
"com.advancedtelematic" %% "libats" % libatsV,
"com.advancedtelematic" %% "libats-http" % libatsV,
"com.advancedtelematic" %% "libats-http-tracing" % libatsV,
"com.advancedtelematic" %% "libats-auth" % libatsV,
"com.advancedtelematic" %% "libats-messaging" % libatsV,
"com.advancedtelematic" %% "libats-messaging-datatype" % libatsV,
"com.advancedtelematic" %% "libats-metrics" % libatsV,
"com.advancedtelematic" %% "libats-metrics-akka" % libatsV,
"com.advancedtelematic" %% "libats-metrics-kafka" % libatsV,
"com.advancedtelematic" %% "libats-metrics-prometheus" % libatsV,
"com.advancedtelematic" %% "libats-slick" % libatsV,
"com.advancedtelematic" %% "libats-logging" % libatsV,
"com.advancedtelematic" %% "libtuf" % libtufV,
"com.advancedtelematic" %% "libtuf-server" % libtufV,
"io.github.uptane" %% "libats" % libatsV,
"io.github.uptane" %% "libats-http" % libatsV,
"io.github.uptane" %% "libats-http-tracing" % libatsV,
"io.github.uptane" %% "libats-messaging" % libatsV,
"io.github.uptane" %% "libats-messaging-datatype" % libatsV,
"io.github.uptane" %% "libats-metrics" % libatsV,
"io.github.uptane" %% "libats-metrics-akka" % libatsV,
"io.github.uptane" %% "libats-metrics-prometheus" % libatsV,
"io.github.uptane" %% "libats-slick" % libatsV,
"io.github.uptane" %% "libats-logging" % libatsV,
"io.github.uptane" %% "libtuf" % libtufV,
"io.github.uptane" %% "libtuf-server" % libtufV,
"org.scalacheck" %% "scalacheck" % "1.14.1" % Test,
"org.scalatest" %% "scalatest" % scalaTestV % Test,
"com.typesafe.akka" %% "akka-testkit" % akkaV % Test
)
}

sonarProperties ++= Map(
"sonar.projectName" -> "OTA Connect Campaigner",
"sonar.projectKey" -> "ota-connect-campaigner",
"sonar.host.url" -> "http://sonar.in.here.com",
"sonar.links.issue" -> "https://saeljira.it.here.com/projects/OTA/issues",
"sonar.links.scm" -> "https://main.gitlab.in.here.com/olp/edge/ota/connect/back-end/campaigner",
"sonar.links.ci" -> "https://main.gitlab.in.here.com/olp/edge/ota/connect/back-end/campaigner/pipelines",
"sonar.projectVersion" -> version.value,
"sonar.language" -> "scala")


enablePlugins(BuildInfoPlugin)

buildInfoOptions += BuildInfoOption.ToMap

buildInfoOptions += BuildInfoOption.BuildTime
buildInfoObject := "AppBuildInfo"
buildInfoPackage := "com.advancedtelematic.campaigner"
buildInfoOptions += BuildInfoOption.Traits("com.advancedtelematic.libats.boot.VersionInfoProvider")

mainClass in Compile := Some("com.advancedtelematic.campaigner.Boot")
Compile / mainClass := Some("com.advancedtelematic.campaigner.Boot")

import com.typesafe.sbt.packager.docker._

dockerRepository := Some("advancedtelematic")

packageName in Docker := packageName.value
Docker / packageName := packageName.value

dockerUpdateLatest := true

Expand All @@ -103,5 +90,5 @@ dockerCommands := Seq(
Cmd("USER", "daemon")
)

enablePlugins(JavaAppPackaging, GitVersioning)
enablePlugins(JavaAppPackaging, GitVersioning, BuildInfoPlugin)

3 changes: 2 additions & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
sbt.version=1.3.8
sbt.version=1.5.5

4 changes: 1 addition & 3 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.7.0")
addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.10.0")
addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "1.4.0")
addSbtPlugin("com.typesafe.sbt" % "sbt-git" % "0.9.3")
addSbtPlugin("com.github.gseitz" % "sbt-release" % "1.0.7")
addSbtPlugin("net.vonbuchholtz" % "sbt-dependency-check" % "1.3.3")
addSbtPlugin("com.typesafe.sbt" % "sbt-license-report" % "1.2.0")
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.6.0")
addSbtPlugin("com.github.mwz" % "sbt-sonar" % "2.1.0")
128 changes: 49 additions & 79 deletions src/main/resources/application.conf
Original file line number Diff line number Diff line change
Expand Up @@ -23,92 +23,62 @@ akka {
}
}

database = {
driver = "org.mariadb.jdbc.Driver"
url = "jdbc:mariadb://localhost:3306/campaigner"
url = ${?DB_URL}
properties {
user = "campaigner"
user = ${?DB_USER}
password = "campaigner"
password = ${?DB_PASSWORD}
}
numThreads = 10
migrate = false
migrate = ${?DB_MIGRATE}
registerMbeans = true
}

server = {
host = "0.0.0.0"
host = ${?BIND_HOST}
port = 8084
port = ${?BIND_PORT}
}
ats.campaigner = {

deviceRegistry = {
host = "localhost"
host = ${?DEVICE_REGISTRY_HOST}
port = 8083
port = ${?DEVICE_REGISTRY_PORT}
uri = "http://"${deviceRegistry.host}":"${deviceRegistry.port}
}

director = {
host = "localhost"
host = ${?DIRECTOR_HOST}
port = 8084
port = ${?DIRECTOR_PORT}
uri = "http://"${director.host}":"${director.port}
}
database = {
driver = "org.mariadb.jdbc.Driver"
url = "jdbc:mariadb://localhost:3306/campaigner"
url = ${?DB_URL}
properties {
user = "campaigner"
user = ${?DB_USER}
password = "campaigner"
password = ${?DB_PASSWORD}
}
numThreads = 10
flyway.schema-table = "schema_version"
flyway.locations = [ "db/migration/campaigner" ]
}

userProfile = {
host = "localhost"
host = ${?USER_PROFILE_HOST}
port = 8085
port = ${?USER_PROFILE_PORT}
uri = "http://"${userProfile.host}":"${userProfile.port}
}
http.server = {
host = "0.0.0.0"
host = ${?BIND_HOST}
port = 8084
port = ${?BIND_PORT}
}

scheduler = {
pollingTimeout = 10 seconds
pollingTimeout = ${?SCHEDULER_POLLING_TIMEOUT}
delay = 10 seconds
delay = ${?SCHEDULER_DELAY}
batchSize = 200
batchSize = ${?SCHEDULER_BATCH_SIZE}
}
http.client = {
deviceRegistry = {
host = "localhost"
host = ${?DEVICE_REGISTRY_HOST}
port = 8083
port = ${?DEVICE_REGISTRY_PORT}
uri = "http://"${ats.campaigner.http.client.deviceRegistry.host}":"${ats.campaigner.http.client.deviceRegistry.port}
}

auth.protocol = "none"
director = {
host = "localhost"
host = ${?DIRECTOR_HOST}
port = 8084
port = ${?DIRECTOR_PORT}
uri = "http://"${ats.campaigner.http.client.director.host}":"${ats.campaigner.http.client.director.port}
}

messaging {
mode = "kafka"
mode = ${?MESSAGING_MODE}
kafka {
groupIdPrefix = "campaigner"
groupIdPrefix = ${?KAFKA_GROUP_ID}
topicSuffix = "dev"
topicSuffix = ${?KAFKA_TOPIC_SUFFIX}
host = "localhost:9092"
host = ${?KAFKA_HOST}
}
listener {
parallelism = 6
parallelism = ${?MESSAGE_LISTENER_PARALLELISM}
batch {
interval = 2 seconds
max = 100
userProfile = {
host = "localhost"
host = ${?USER_PROFILE_HOST}
port = 8085
port = ${?USER_PROFILE_PORT}
uri = "http://"${ats.campaigner.http.client.userProfile.host}":"${ats.campaigner.http.client.userProfile.port}
}
}
}

ats {
metricsReporter {
reportMetrics = true
reportMetrics = ${?REPORT_METRICS}
serviceName=campaigner
serviceName=${?SERVICE_NAME}
instanceId=${ats.metricsReporter.serviceName}
instanceId=${?MESOS_TASK_ID}
scheduler = {
pollingTimeout = 10 seconds
pollingTimeout = ${?SCHEDULER_POLLING_TIMEOUT}
delay = 10 seconds
delay = ${?SCHEDULER_DELAY}
batchSize = 200
batchSize = ${?SCHEDULER_BATCH_SIZE}
}
}
63 changes: 42 additions & 21 deletions src/main/scala/com/advancedtelematic/campaigner/Boot.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.advancedtelematic.campaigner

import akka.actor.ActorSystem
import akka.http.scaladsl.Http
import akka.http.scaladsl.Http.ServerBinding
import akka.http.scaladsl.server.{Directives, Route}
import com.advancedtelematic.campaigner.client.{DeviceRegistryHttpClient, ResolverHttpClient, UserProfileHttpClient}
import com.advancedtelematic.campaigner.db.Campaigns
Expand All @@ -9,11 +11,16 @@ import com.advancedtelematic.libats.http.LogDirectives._
import com.advancedtelematic.libats.http.VersionDirectives._
import com.advancedtelematic.libats.http.tracing.Tracing
import com.advancedtelematic.libats.http.tracing.Tracing.ServerRequestTracing
import com.advancedtelematic.libats.http.{BootApp, ServiceHttpClientSupport}
import com.advancedtelematic.libats.slick.db.{CheckMigrations, DatabaseConfig}
import com.advancedtelematic.libats.http.{BootApp, BootAppDatabaseConfig, BootAppDefaultConfig, ServiceHttpClientSupport}
import com.advancedtelematic.libats.slick.db.{CheckMigrations, DatabaseSupport}
import com.advancedtelematic.libats.slick.monitoring.DatabaseMetrics
import com.advancedtelematic.metrics.{AkkaHttpRequestMetrics, MetricsSupport}
import com.advancedtelematic.metrics.prometheus.PrometheusMetricsSupport
import com.codahale.metrics.MetricRegistry
import com.typesafe.config.Config
import org.slf4j.LoggerFactory

import scala.concurrent.Future

trait Settings {
import java.util.concurrent.TimeUnit
Expand All @@ -22,14 +29,14 @@ trait Settings {

import scala.concurrent.duration._

private lazy val _config = ConfigFactory.load()
private lazy val _config = ConfigFactory.load().getConfig("ats.campaigner")

val host = _config.getString("server.host")
val port = _config.getInt("server.port")
val host = _config.getString("http.server.host")
val port = _config.getInt("http.server.port")

val deviceRegistryUri = _config.getString("deviceRegistry.uri")
val directorUri = _config.getString("director.uri")
val userProfileUri = _config.getString("userProfile.uri")
val deviceRegistryUri = _config.getString("http.client.deviceRegistry.uri")
val directorUri = _config.getString("http.client.director.uri")
val userProfileUri = _config.getString("http.client.userProfile.uri")

val schedulerPollingTimeout =
FiniteDuration(_config.getDuration("scheduler.pollingTimeout").toNanos, TimeUnit.NANOSECONDS)
Expand All @@ -39,37 +46,51 @@ trait Settings {
_config.getInt("scheduler.batchSize")
}

object Boot extends BootApp
class CampaignerBoot(override val globalConfig: Config,
override val dbConfig: Config,
override val metricRegistry: MetricRegistry)
(implicit override val system: ActorSystem) extends BootApp
with Directives
with Settings
with VersionInfo
with DatabaseConfig
with DatabaseSupport
with MetricsSupport
with DatabaseMetrics
with CheckMigrations
with AkkaHttpRequestMetrics
with PrometheusMetricsSupport
with ServiceHttpClientSupport {

implicit val _db = db
private lazy val log = LoggerFactory.getLogger(this.getClass)

log.info(s"Starting $version on http://$host:$port")

import system.dispatcher

def deviceRegistry(implicit tracing: ServerRequestTracing) = new DeviceRegistryHttpClient(deviceRegistryUri, defaultHttpClient)
def userProfile(implicit tracing: ServerRequestTracing) = new UserProfileHttpClient(userProfileUri, defaultHttpClient)
val resolver = new ResolverHttpClient(defaultHttpClient)

val tracing = Tracing.fromConfig(config, projectName)
def bind(): Future[ServerBinding] = {

val campaigns = Campaigns()
val tracing = Tracing.fromConfig(globalConfig, projectName)

val routes: Route =
(versionHeaders(version) & requestMetrics(metricRegistry) & logResponseMetrics(projectName)) {
prometheusMetricsRoutes ~
tracing.traceRequests { implicit serverRequestTracing =>
new Routes(deviceRegistry, resolver, userProfile, campaigns).routes
}
}
val campaigns = Campaigns()

Http().bindAndHandle(routes, host, port)
val routes: Route =
(versionHeaders(version) & requestMetrics(metricRegistry) & logResponseMetrics(projectName)) {
prometheusMetricsRoutes ~
tracing.traceRequests { implicit serverRequestTracing =>
new Routes(deviceRegistry, resolver, userProfile, campaigns).routes
}
}

Http().newServerAt(host, port).bind(routes)
}
}

object Boot extends BootAppDefaultConfig with VersionInfo with BootAppDatabaseConfig {
def main(args: Array[String]): Unit = {
new CampaignerBoot(globalConfig, dbConfig, MetricsSupport.metricRegistry).bind()
}
}
Loading