diff --git a/build.sbt b/build.sbt index 8848fb8..91fb176 100644 --- a/build.sbt +++ b/build.sbt @@ -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", @@ -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" @@ -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 @@ -103,5 +90,5 @@ dockerCommands := Seq( Cmd("USER", "daemon") ) -enablePlugins(JavaAppPackaging, GitVersioning) +enablePlugins(JavaAppPackaging, GitVersioning, BuildInfoPlugin) diff --git a/project/build.properties b/project/build.properties index a919a9b..1188d5f 100644 --- a/project/build.properties +++ b/project/build.properties @@ -1 +1,2 @@ -sbt.version=1.3.8 +sbt.version=1.5.5 + diff --git a/project/plugins.sbt b/project/plugins.sbt index 3e16c6c..1b29733 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -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") diff --git a/src/main/resources/application.conf b/src/main/resources/application.conf index 04ae1d0..9df67b0 100644 --- a/src/main/resources/application.conf +++ b/src/main/resources/application.conf @@ -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} } } diff --git a/src/main/resources/db/migration/V10__rename_update_id.sql b/src/main/resources/db/migration/campaigner/V10__rename_update_id.sql similarity index 100% rename from src/main/resources/db/migration/V10__rename_update_id.sql rename to src/main/resources/db/migration/campaigner/V10__rename_update_id.sql diff --git a/src/main/resources/db/migration/V11__add_parent_campaign_column.sql b/src/main/resources/db/migration/campaigner/V11__add_parent_campaign_column.sql similarity index 100% rename from src/main/resources/db/migration/V11__add_parent_campaign_column.sql rename to src/main/resources/db/migration/campaigner/V11__add_parent_campaign_column.sql diff --git a/src/main/resources/db/migration/V12__add_result_code_to_device_updates.sql b/src/main/resources/db/migration/campaigner/V12__add_result_code_to_device_updates.sql similarity index 100% rename from src/main/resources/db/migration/V12__add_result_code_to_device_updates.sql rename to src/main/resources/db/migration/campaigner/V12__add_result_code_to_device_updates.sql diff --git a/src/main/resources/db/migration/V13__add_requested_status_to_device_updates_table.sql b/src/main/resources/db/migration/campaigner/V13__add_requested_status_to_device_updates_table.sql similarity index 100% rename from src/main/resources/db/migration/V13__add_requested_status_to_device_updates_table.sql rename to src/main/resources/db/migration/campaigner/V13__add_requested_status_to_device_updates_table.sql diff --git a/src/main/resources/db/migration/V14__add_timestamp_to_device_update.sql b/src/main/resources/db/migration/campaigner/V14__add_timestamp_to_device_update.sql similarity index 100% rename from src/main/resources/db/migration/V14__add_timestamp_to_device_update.sql rename to src/main/resources/db/migration/campaigner/V14__add_timestamp_to_device_update.sql diff --git a/src/main/resources/db/migration/V15__add_failure_code_to_campaign.sql b/src/main/resources/db/migration/campaigner/V15__add_failure_code_to_campaign.sql similarity index 100% rename from src/main/resources/db/migration/V15__add_failure_code_to_campaign.sql rename to src/main/resources/db/migration/campaigner/V15__add_failure_code_to_campaign.sql diff --git a/src/main/resources/db/migration/V16__add_result_description_to_device_update.sql b/src/main/resources/db/migration/campaigner/V16__add_result_description_to_device_update.sql similarity index 100% rename from src/main/resources/db/migration/V16__add_result_description_to_device_update.sql rename to src/main/resources/db/migration/campaigner/V16__add_result_description_to_device_update.sql diff --git a/src/main/resources/db/migration/V17__increase_result_description_size.sql b/src/main/resources/db/migration/campaigner/V17__increase_result_description_size.sql similarity index 100% rename from src/main/resources/db/migration/V17__increase_result_description_size.sql rename to src/main/resources/db/migration/campaigner/V17__increase_result_description_size.sql diff --git a/src/main/resources/db/migration/V18__device_status_index.sql b/src/main/resources/db/migration/campaigner/V18__device_status_index.sql similarity index 100% rename from src/main/resources/db/migration/V18__device_status_index.sql rename to src/main/resources/db/migration/campaigner/V18__device_status_index.sql diff --git a/src/main/resources/db/migration/V19__update_charset_encoding_for_metadata_value.sql b/src/main/resources/db/migration/campaigner/V19__update_charset_encoding_for_metadata_value.sql similarity index 100% rename from src/main/resources/db/migration/V19__update_charset_encoding_for_metadata_value.sql rename to src/main/resources/db/migration/campaigner/V19__update_charset_encoding_for_metadata_value.sql diff --git a/src/main/resources/db/migration/V1__initial_schema.sql b/src/main/resources/db/migration/campaigner/V1__initial_schema.sql similarity index 100% rename from src/main/resources/db/migration/V1__initial_schema.sql rename to src/main/resources/db/migration/campaigner/V1__initial_schema.sql diff --git a/src/main/resources/db/migration/V2__update_status.sql b/src/main/resources/db/migration/campaigner/V2__update_status.sql similarity index 100% rename from src/main/resources/db/migration/V2__update_status.sql rename to src/main/resources/db/migration/campaigner/V2__update_status.sql diff --git a/src/main/resources/db/migration/V3__cancel_tasks.sql b/src/main/resources/db/migration/campaigner/V3__cancel_tasks.sql similarity index 100% rename from src/main/resources/db/migration/V3__cancel_tasks.sql rename to src/main/resources/db/migration/campaigner/V3__cancel_tasks.sql diff --git a/src/main/resources/db/migration/V4__campaign_metadata.sql b/src/main/resources/db/migration/campaigner/V4__campaign_metadata.sql similarity index 100% rename from src/main/resources/db/migration/V4__campaign_metadata.sql rename to src/main/resources/db/migration/campaigner/V4__campaign_metadata.sql diff --git a/src/main/resources/db/migration/V5__new_table_updates.sql b/src/main/resources/db/migration/campaigner/V5__new_table_updates.sql similarity index 100% rename from src/main/resources/db/migration/V5__new_table_updates.sql rename to src/main/resources/db/migration/campaigner/V5__new_table_updates.sql diff --git a/src/main/resources/db/migration/V6__campaign_metadata_types.sql b/src/main/resources/db/migration/campaigner/V6__campaign_metadata_types.sql similarity index 100% rename from src/main/resources/db/migration/V6__campaign_metadata_types.sql rename to src/main/resources/db/migration/campaigner/V6__campaign_metadata_types.sql diff --git a/src/main/resources/db/migration/V7__auto_accept_campaigns.sql b/src/main/resources/db/migration/campaigner/V7__auto_accept_campaigns.sql similarity index 100% rename from src/main/resources/db/migration/V7__auto_accept_campaigns.sql rename to src/main/resources/db/migration/campaigner/V7__auto_accept_campaigns.sql diff --git a/src/main/resources/db/migration/V8__fk_campaigns_to_updates.sql b/src/main/resources/db/migration/campaigner/V8__fk_campaigns_to_updates.sql similarity index 100% rename from src/main/resources/db/migration/V8__fk_campaigns_to_updates.sql rename to src/main/resources/db/migration/campaigner/V8__fk_campaigns_to_updates.sql diff --git a/src/main/resources/db/migration/V9__add_campaign_status.sql b/src/main/resources/db/migration/campaigner/V9__add_campaign_status.sql similarity index 100% rename from src/main/resources/db/migration/V9__add_campaign_status.sql rename to src/main/resources/db/migration/campaigner/V9__add_campaign_status.sql diff --git a/src/main/scala/com/advancedtelematic/campaigner/Boot.scala b/src/main/scala/com/advancedtelematic/campaigner/Boot.scala index bd1f1fa..ad97b3b 100644 --- a/src/main/scala/com/advancedtelematic/campaigner/Boot.scala +++ b/src/main/scala/com/advancedtelematic/campaigner/Boot.scala @@ -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 @@ -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 @@ -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) @@ -39,11 +46,14 @@ 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 @@ -51,25 +61,36 @@ object Boot extends BootApp 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() + } +} \ No newline at end of file diff --git a/src/main/scala/com/advancedtelematic/campaigner/DaemonBoot.scala b/src/main/scala/com/advancedtelematic/campaigner/DaemonBoot.scala index e25b99e..cf5ceff 100644 --- a/src/main/scala/com/advancedtelematic/campaigner/DaemonBoot.scala +++ b/src/main/scala/com/advancedtelematic/campaigner/DaemonBoot.scala @@ -1,25 +1,36 @@ package com.advancedtelematic.campaigner +import akka.actor.ActorSystem import akka.http.scaladsl.Http +import akka.http.scaladsl.Http.ServerBinding import akka.http.scaladsl.server.Route import com.advancedtelematic.campaigner.actor._ import com.advancedtelematic.campaigner.client._ import com.advancedtelematic.campaigner.daemon._ -import com.advancedtelematic.campaigner.db.{Campaigns, Repositories} +import com.advancedtelematic.campaigner.db.{Campaigns} import com.advancedtelematic.libats.http.tracing.NullServerRequestTracing -import com.advancedtelematic.libats.http.{BootApp, ServiceHttpClientSupport} +import com.advancedtelematic.libats.http.{BootApp, BootAppDatabaseConfig, BootAppDefaultConfig, ServiceHttpClientSupport} import com.advancedtelematic.libats.messaging.MessageListenerSupport +import com.advancedtelematic.libats.messaging.metrics.MonitoredBusListenerSupport import com.advancedtelematic.libats.messaging_datatype.Messages.{DeleteDeviceRequest, DeviceEventMessage, DeviceUpdateEvent} -import com.advancedtelematic.libats.slick.db.{BootMigrations, CheckMigrations, DatabaseConfig} +import com.advancedtelematic.libats.slick.db.{BootMigrations, CheckMigrations, DatabaseSupport} import com.advancedtelematic.libats.slick.monitoring.{DatabaseMetrics, DbHealthResource} import com.advancedtelematic.metrics.prometheus.PrometheusMetricsSupport -import com.advancedtelematic.metrics.{MetricsSupport, MonitoredBusListenerSupport} +import com.advancedtelematic.metrics.MetricsSupport +import com.codahale.metrics.MetricRegistry +import com.typesafe.config.Config +import org.slf4j.LoggerFactory -object DaemonBoot extends BootApp +import scala.concurrent.Future + +class CampaignerDaemonBoot(override val globalConfig: Config, + override val dbConfig: Config, + override val metricRegistry: MetricRegistry) + (implicit override val system: ActorSystem) extends BootApp with Settings with VersionInfo with BootMigrations - with DatabaseConfig + with DatabaseSupport with MetricsSupport with DatabaseMetrics with CheckMigrations @@ -31,8 +42,9 @@ object DaemonBoot extends BootApp import akka.http.scaladsl.server.Directives._ import com.advancedtelematic.libats.http.LogDirectives._ import com.advancedtelematic.libats.http.VersionDirectives._ + import system.dispatcher - implicit val _db = db + private lazy val log = LoggerFactory.getLogger(this.getClass) log.info("Starting campaigner daemon") @@ -42,24 +54,35 @@ object DaemonBoot extends BootApp val director = new DirectorHttpClient(directorUri, defaultHttpClient) - val routes: Route = (versionHeaders(version) & logResponseMetrics(projectName)) { - prometheusMetricsRoutes ~ - DbHealthResource(versionMap).route - } + def bind(): Future[ServerBinding] = { + + val routes: Route = (versionHeaders(version) & logResponseMetrics(projectName)) { + prometheusMetricsRoutes ~ + DbHealthResource(versionMap).route + } + + val campaigns = Campaigns() - val campaigns = Campaigns() + val f = Http().newServerAt(host, port).bindFlow(routes) - Http().bindAndHandle(routes, host, port) + system.actorOf(CampaignSupervisor.props( + director, + campaigns, + schedulerPollingTimeout, + schedulerDelay, + schedulerBatchSize + ), "campaign-supervisor") - system.actorOf(CampaignSupervisor.props( - director, - campaigns, - schedulerPollingTimeout, - schedulerDelay, - schedulerBatchSize - ), "campaign-supervisor") + startMonitoredListener[DeviceUpdateEvent](new DeviceUpdateEventListener(campaigns)) + startMonitoredListener[DeviceEventMessage](new DeviceEventListener(director, campaigns), skipProcessingErrors = true) + startMonitoredListener[DeleteDeviceRequest](new DeleteDeviceRequestListener(director, campaigns)) - startMonitoredListener[DeviceUpdateEvent](new DeviceUpdateEventListener(campaigns)) - startMonitoredListener[DeviceEventMessage](new DeviceEventListener(director, campaigns), skipProcessingErrors = true) - startMonitoredListener[DeleteDeviceRequest](new DeleteDeviceRequestListener(director, campaigns)) + f + } +} + +object DaemonBoot extends BootAppDefaultConfig with BootAppDatabaseConfig with VersionInfo { + def main(args: Array[String]): Unit = { + new CampaignerDaemonBoot(globalConfig, dbConfig, MetricsSupport.metricRegistry).bind() + } } diff --git a/src/main/scala/com/advancedtelematic/campaigner/VersionInfo.scala b/src/main/scala/com/advancedtelematic/campaigner/VersionInfo.scala index 166bdc1..bfb1d7f 100644 --- a/src/main/scala/com/advancedtelematic/campaigner/VersionInfo.scala +++ b/src/main/scala/com/advancedtelematic/campaigner/VersionInfo.scala @@ -1,12 +1,8 @@ package com.advancedtelematic.campaigner -trait VersionInfo { - lazy val projectName: String = buildinfo.BuildInfo.name +import com.advancedtelematic.libats.boot.VersionInfoProvider - lazy val version: String = { - val bi = buildinfo.BuildInfo - s"${bi.name}/${bi.version}" - } - - lazy val versionMap: Map[String, Any] = buildinfo.BuildInfo.toMap +trait VersionInfo extends com.advancedtelematic.libats.boot.VersionInfo { + override protected lazy val provider: VersionInfoProvider = AppBuildInfo } + diff --git a/src/main/scala/com/advancedtelematic/campaigner/client/DeviceRegistryClient.scala b/src/main/scala/com/advancedtelematic/campaigner/client/DeviceRegistryClient.scala index 94f0edc..c55e0ef 100644 --- a/src/main/scala/com/advancedtelematic/campaigner/client/DeviceRegistryClient.scala +++ b/src/main/scala/com/advancedtelematic/campaigner/client/DeviceRegistryClient.scala @@ -3,7 +3,6 @@ package com.advancedtelematic.campaigner.client import akka.actor.ActorSystem import akka.http.scaladsl.model._ import akka.http.scaladsl.util.FastFuture -import akka.stream.Materializer import cats.syntax.show._ import com.advancedtelematic.campaigner.data.DataType._ import com.advancedtelematic.libats.data.DataType.Namespace @@ -48,7 +47,7 @@ trait DeviceRegistryClient { } class DeviceRegistryHttpClient(uri: Uri, httpClient: HttpRequest => Future[HttpResponse]) - (implicit system: ActorSystem, mat: Materializer, tracing: ServerRequestTracing) + (implicit system: ActorSystem, tracing: ServerRequestTracing) extends TracingHttpClient(httpClient, "device-registry") with DeviceRegistryClient { import de.heikoseeberger.akkahttpcirce.FailFastCirceSupport._ diff --git a/src/main/scala/com/advancedtelematic/campaigner/client/DirectorClient.scala b/src/main/scala/com/advancedtelematic/campaigner/client/DirectorClient.scala index 61f471f..9108fa0 100644 --- a/src/main/scala/com/advancedtelematic/campaigner/client/DirectorClient.scala +++ b/src/main/scala/com/advancedtelematic/campaigner/client/DirectorClient.scala @@ -8,13 +8,13 @@ import com.advancedtelematic.campaigner.data.DataType.ExternalUpdateId import com.advancedtelematic.libats.data.DataType.{CorrelationId, MultiTargetUpdateId, Namespace} import com.advancedtelematic.libats.http.HttpOps.HttpRequestOps import com.advancedtelematic.libats.messaging_datatype.DataType.DeviceId -import com.advancedtelematic.libats.codecs.CirceAnyVal._ import java.util.UUID import com.advancedtelematic.libats.http.tracing.Tracing.ServerRequestTracing import com.advancedtelematic.libats.http.tracing.TracingHttpClient import io.circe._ import io.circe.generic.semiauto._ +import com.advancedtelematic.campaigner.data.Codecs._ import scala.concurrent.Future @@ -53,7 +53,7 @@ trait DirectorClient { } class DirectorHttpClient(uri: Uri, httpClient: HttpRequest => Future[HttpResponse]) - (implicit system: ActorSystem, mat: Materializer, tracing: ServerRequestTracing) + (implicit system: ActorSystem, tracing: ServerRequestTracing) extends TracingHttpClient(httpClient, "director") with DirectorClient { import de.heikoseeberger.akkahttpcirce.FailFastCirceSupport._ diff --git a/src/main/scala/com/advancedtelematic/campaigner/client/ResolverClient.scala b/src/main/scala/com/advancedtelematic/campaigner/client/ResolverClient.scala index b6b195e..0c3531e 100644 --- a/src/main/scala/com/advancedtelematic/campaigner/client/ResolverClient.scala +++ b/src/main/scala/com/advancedtelematic/campaigner/client/ResolverClient.scala @@ -2,7 +2,6 @@ package com.advancedtelematic.campaigner.client import akka.actor.ActorSystem import akka.http.scaladsl.model._ -import akka.stream.Materializer import com.advancedtelematic.campaigner.data.DataType.ExternalUpdateId import com.advancedtelematic.libats.codecs.CirceCodecs._ import com.advancedtelematic.libats.data.DataType.Namespace @@ -11,6 +10,7 @@ import com.advancedtelematic.libats.http.ServiceHttpClient import com.advancedtelematic.libats.messaging_datatype.DataType.DeviceId import de.heikoseeberger.akkahttpcirce.FailFastCirceSupport._ import io.circe.Decoder +import com.advancedtelematic.campaigner.data.Codecs._ import scala.concurrent.Future @@ -29,8 +29,7 @@ object ExternalUpdate { } -class ResolverHttpClient(httpClient: HttpRequest => Future[HttpResponse])(implicit system: ActorSystem, - mat: Materializer) +class ResolverHttpClient(httpClient: HttpRequest => Future[HttpResponse])(implicit system: ActorSystem) extends ServiceHttpClient(httpClient) with ResolverClient { diff --git a/src/main/scala/com/advancedtelematic/campaigner/client/UserProfileClient.scala b/src/main/scala/com/advancedtelematic/campaigner/client/UserProfileClient.scala index 600e7fc..db83b85 100644 --- a/src/main/scala/com/advancedtelematic/campaigner/client/UserProfileClient.scala +++ b/src/main/scala/com/advancedtelematic/campaigner/client/UserProfileClient.scala @@ -28,7 +28,7 @@ object UserProfileClient { } class UserProfileHttpClient(uri: Uri, httpClient: HttpRequest => Future[HttpResponse]) - (implicit ec: ExecutionContext, system: ActorSystem, mat: Materializer, tracing: ServerRequestTracing) + (implicit ec: ExecutionContext, system: ActorSystem, tracing: ServerRequestTracing) extends TracingHttpClient(httpClient, "user-profile") with UserProfileClient { import com.advancedtelematic.libats.http.ServiceHttpClient._ diff --git a/src/main/scala/com/advancedtelematic/campaigner/data/Codecs.scala b/src/main/scala/com/advancedtelematic/campaigner/data/Codecs.scala index 78ee0a0..5203492 100644 --- a/src/main/scala/com/advancedtelematic/campaigner/data/Codecs.scala +++ b/src/main/scala/com/advancedtelematic/campaigner/data/Codecs.scala @@ -6,12 +6,17 @@ import com.advancedtelematic.campaigner.data.DataType.MetadataType.MetadataType import com.advancedtelematic.campaigner.data.DataType.UpdateType.UpdateType import com.advancedtelematic.libats.codecs.CirceCodecs._ import io.circe.{Decoder, Encoder, KeyEncoder} +import CampaignId._ +import com.advancedtelematic.libats.messaging_datatype.MessageCodecs._ object Codecs { import DataType.CampaignStatus.CampaignStatus import DataType.RetryStatus.RetryStatus import io.circe.generic.semiauto._ + implicit val externalUpdateIdEncoder: Encoder[ExternalUpdateId] = Encoder.encodeString.contramap(_.value) + implicit val externalUpdateIdDecoder: Decoder[ExternalUpdateId] = Decoder.decodeString.map(ExternalUpdateId.apply) + implicit val createCampaignMetadataEncoder: Encoder[CreateCampaignMetadata] = deriveEncoder implicit val createCampaignMetadataDecoder: Decoder[CreateCampaignMetadata] = deriveDecoder diff --git a/src/main/scala/com/advancedtelematic/campaigner/http/CampaignResource.scala b/src/main/scala/com/advancedtelematic/campaigner/http/CampaignResource.scala index cc2be4f..5343d2e 100644 --- a/src/main/scala/com/advancedtelematic/campaigner/http/CampaignResource.scala +++ b/src/main/scala/com/advancedtelematic/campaigner/http/CampaignResource.scala @@ -16,7 +16,6 @@ import com.advancedtelematic.campaigner.data.DataType.CampaignStatus.CampaignSta import com.advancedtelematic.campaigner.data.DataType.SortBy.SortBy import com.advancedtelematic.campaigner.data.DataType._ import com.advancedtelematic.campaigner.db.Campaigns -import com.advancedtelematic.libats.auth.AuthedNamespaceScope import com.advancedtelematic.libats.data.DataType.{CorrelationId, Namespace, ResultCode, ResultDescription} import com.advancedtelematic.libats.http.UUIDKeyAkka._ import com.advancedtelematic.libats.messaging_datatype.DataType.DeviceId @@ -24,7 +23,7 @@ import de.heikoseeberger.akkahttpcirce.FailFastCirceSupport._ import scala.concurrent.{ExecutionContext, Future} -class CampaignResource(extractAuth: Directive1[AuthedNamespaceScope], +class CampaignResource(extractNs: Directive1[Namespace], deviceRegistry: DeviceRegistryClient, campaigns: Campaigns) (implicit ec: ExecutionContext) extends Settings { @@ -43,13 +42,13 @@ class CampaignResource(extractAuth: Directive1[AuthedNamespaceScope], } def searchCampaigns(ns: Namespace): Route = - parameters(( + parameters( 'status.as[CampaignStatus].?, 'nameContains.as[String].?, 'withErrors.as[Boolean].?, 'sortBy.as[SortBy] ? (SortBy.CreatedAt : SortBy), 'offset.as(nonNegativeLongUnmarshaller) ? 0L, - 'limit.as(nonNegativeLongUnmarshaller) ? 50L)).as(SearchCampaignParams) { params: SearchCampaignParams => + 'limit.as(nonNegativeLongUnmarshaller) ? 50L).as(SearchCampaignParams) { params: SearchCampaignParams => val f = params.withErrors match { case Some(true) => campaigns.findCampaignsWithErrors(ns, params.sortBy, params.offset, params.limit) @@ -112,8 +111,7 @@ class CampaignResource(extractAuth: Directive1[AuthedNamespaceScope], campaigns.cancelDevices(campaign.id, Seq(deviceId)) val route: Route = - extractAuth { auth => - val ns = auth.namespace + extractNs { ns => pathPrefix("campaigns") { path("count") { complete(campaigns.countByStatus) diff --git a/src/main/scala/com/advancedtelematic/campaigner/http/Routes.scala b/src/main/scala/com/advancedtelematic/campaigner/http/Routes.scala index d240048..99f5a80 100644 --- a/src/main/scala/com/advancedtelematic/campaigner/http/Routes.scala +++ b/src/main/scala/com/advancedtelematic/campaigner/http/Routes.scala @@ -4,10 +4,9 @@ import akka.http.scaladsl.server.{Directive1, Directives, Route} import com.advancedtelematic.campaigner.VersionInfo import com.advancedtelematic.campaigner.client.{DeviceRegistryClient, ResolverClient, UserProfileClient} import com.advancedtelematic.campaigner.db.Campaigns -import com.advancedtelematic.libats.auth.NamespaceDirectives -import com.advancedtelematic.libats.data.DataType.Namespace import com.advancedtelematic.libats.http.DefaultRejectionHandler.rejectionHandler -import com.advancedtelematic.libats.http.ErrorHandler +import com.advancedtelematic.libats.http.NamespaceDirectives.defaultNamespaceExtractor +import com.advancedtelematic.libats.http.{ErrorHandler, NamespaceDirectives} import com.advancedtelematic.libats.slick.monitoring.DbHealthResource import slick.jdbc.MySQLProfile.api._ @@ -23,9 +22,6 @@ class Routes(deviceRegistry: DeviceRegistryClient, val extractAuth = NamespaceDirectives.fromConfig() - lazy val defaultNamespaceExtractor: Directive1[Namespace] = - NamespaceDirectives.defaultNamespaceExtractor.map(_.namespace) - val routes: Route = handleRejections(rejectionHandler) { ErrorHandler.handleErrors { diff --git a/src/main/scala/com/advancedtelematic/campaigner/http/UpdateResource.scala b/src/main/scala/com/advancedtelematic/campaigner/http/UpdateResource.scala index 66a2e3f..bfb925c 100644 --- a/src/main/scala/com/advancedtelematic/campaigner/http/UpdateResource.scala +++ b/src/main/scala/com/advancedtelematic/campaigner/http/UpdateResource.scala @@ -105,7 +105,7 @@ class UpdateResource(extractNamespace: Directive1[Namespace], (post & entity(as[CreateUpdate])) { request => createUpdate(ns, request) } ~ - (get & parameters(('groupId.as[GroupId].*, 'nameContains.as[String].?, 'sortBy.as[SortBy].?, 'offset.as(nonNegativeLongUnmarshaller) ? 0L, 'limit.as(nonNegativeLongUnmarshaller) ? 50L))) { + (get & parameters('groupId.as[GroupId].*, 'nameContains.as[String].?, 'sortBy.as[SortBy].?, 'offset.as(nonNegativeLongUnmarshaller) ? 0L, 'limit.as(nonNegativeLongUnmarshaller) ? 50L)) { (groupId, nameContains, sortBy, offset, limit) => (groupId, nameContains) match { case (Nil, _) => complete(getAllUpdates(ns, offset, limit, sortBy, nameContains)) case (groups, None) => availableUpdatesForGroups(ns, groups.toSet) diff --git a/src/test/resources/application.conf b/src/test/resources/application.conf index 07bfc63..33d8790 100644 --- a/src/test/resources/application.conf +++ b/src/test/resources/application.conf @@ -1,12 +1,14 @@ -database = { - catalog = "campaigner_test" -} +ats.campaigner { + database = { + catalog = "campaigner_test" + } -deviceRegistry.uri = "localhost" -director.uri = "localhost" + http.client.deviceRegistry.uri = "localhost" + http.client.director.uri = "localhost" -scheduler = { - pollingTimeout = 1 seconds - delay = 10 milliseconds - batchSize = 10 + scheduler = { + pollingTimeout = 1 seconds + delay = 10 milliseconds + batchSize = 10 + } } diff --git a/src/test/scala/com/advancedtelematic/campaigner/daemon/DeleteDeviceRequestListenerSpec.scala b/src/test/scala/com/advancedtelematic/campaigner/daemon/DeleteDeviceRequestListenerSpec.scala index bc6ffb3..d8551cf 100644 --- a/src/test/scala/com/advancedtelematic/campaigner/daemon/DeleteDeviceRequestListenerSpec.scala +++ b/src/test/scala/com/advancedtelematic/campaigner/daemon/DeleteDeviceRequestListenerSpec.scala @@ -7,7 +7,7 @@ import com.advancedtelematic.campaigner.util.{CampaignerSpec, DatabaseUpdateSpec import com.advancedtelematic.libats.data.DataType.Namespace import com.advancedtelematic.libats.messaging_datatype.DataType.DeviceId import com.advancedtelematic.libats.messaging_datatype.Messages.DeleteDeviceRequest -import com.advancedtelematic.libats.test.DatabaseSpec +import com.advancedtelematic.campaigner.util.DatabaseSpec import org.scalacheck.Arbitrary._ import java.time.Instant diff --git a/src/test/scala/com/advancedtelematic/campaigner/daemon/DeviceEventListenerSpec.scala b/src/test/scala/com/advancedtelematic/campaigner/daemon/DeviceEventListenerSpec.scala index f6f407a..9047c58 100644 --- a/src/test/scala/com/advancedtelematic/campaigner/daemon/DeviceEventListenerSpec.scala +++ b/src/test/scala/com/advancedtelematic/campaigner/daemon/DeviceEventListenerSpec.scala @@ -11,7 +11,7 @@ import com.advancedtelematic.libats.data.DataType.Namespace import com.advancedtelematic.libats.messaging_datatype.DataType.{DeviceId, Event, EventType} import com.advancedtelematic.libats.messaging_datatype.Messages import com.advancedtelematic.libats.messaging_datatype.Messages.DeviceEventMessage -import com.advancedtelematic.libats.test.DatabaseSpec +import com.advancedtelematic.campaigner.util.DatabaseSpec import io.circe.Json import io.circe.syntax._ import org.scalacheck.Arbitrary._ diff --git a/src/test/scala/com/advancedtelematic/campaigner/daemon/DeviceUpdateEventListenerSpec.scala b/src/test/scala/com/advancedtelematic/campaigner/daemon/DeviceUpdateEventListenerSpec.scala index cd9b69e..2bf2c01 100644 --- a/src/test/scala/com/advancedtelematic/campaigner/daemon/DeviceUpdateEventListenerSpec.scala +++ b/src/test/scala/com/advancedtelematic/campaigner/daemon/DeviceUpdateEventListenerSpec.scala @@ -10,7 +10,7 @@ import com.advancedtelematic.campaigner.util.{CampaignerSpec, DatabaseUpdateSpec import com.advancedtelematic.libats.data.DataType.{CorrelationId, ResultCode, ResultDescription, CampaignId => CampaignCorrelationId} import com.advancedtelematic.libats.messaging_datatype.DataType.{DeviceId, InstallationResult} import com.advancedtelematic.libats.messaging_datatype.Messages.{DeviceUpdateCanceled, DeviceUpdateCompleted, DeviceUpdateEvent} -import com.advancedtelematic.libats.test.DatabaseSpec +import com.advancedtelematic.campaigner.util.DatabaseSpec import org.scalacheck.Arbitrary._ import org.scalacheck.Gen diff --git a/src/test/scala/com/advancedtelematic/campaigner/db/CampaignStatusRecalculateSpec.scala b/src/test/scala/com/advancedtelematic/campaigner/db/CampaignStatusRecalculateSpec.scala index 0a47dac..fd90721 100644 --- a/src/test/scala/com/advancedtelematic/campaigner/db/CampaignStatusRecalculateSpec.scala +++ b/src/test/scala/com/advancedtelematic/campaigner/db/CampaignStatusRecalculateSpec.scala @@ -1,20 +1,21 @@ package com.advancedtelematic.campaigner.db import akka.actor.ActorSystem -import akka.stream.ActorMaterializer import akka.testkit.TestKit import cats.data.NonEmptyList import com.advancedtelematic.campaigner.data.DataType._ import com.advancedtelematic.campaigner.data.Generators._ import com.advancedtelematic.campaigner.util.CampaignerSpecUtil import com.advancedtelematic.campaigner.util.DatabaseUpdateSpecUtil -import com.advancedtelematic.libats.test.DatabaseSpec +import com.advancedtelematic.campaigner.util.DatabaseSpec +import com.typesafe.config.{Config, ConfigFactory} import org.scalacheck.Gen import org.scalatest._ import org.scalatest.concurrent.ScalaFutures import org.scalatest.time.Seconds import org.scalatest.time.Span import org.scalatest.time.SpanSugar._ + import scala.concurrent.Future import slick.jdbc.MySQLProfile.api._ @@ -27,8 +28,9 @@ final class CampaignStatusRecalculateSpec with DatabaseUpdateSpecUtil with CampaignerSpecUtil { + lazy val testDbConfig: Config = ConfigFactory.load().getConfig("ats.campaigner.database") + implicit lazy val ec = system.dispatcher - implicit val mat = ActorMaterializer() implicit val defaultPatience = PatienceConfig(timeout = Span(2, Seconds)) it should "set campaign status to `finished` if all devices finished the campaign" in { diff --git a/src/test/scala/com/advancedtelematic/campaigner/db/CampaignsSpec.scala b/src/test/scala/com/advancedtelematic/campaigner/db/CampaignsSpec.scala index fe721b4..04339ac 100644 --- a/src/test/scala/com/advancedtelematic/campaigner/db/CampaignsSpec.scala +++ b/src/test/scala/com/advancedtelematic/campaigner/db/CampaignsSpec.scala @@ -6,7 +6,8 @@ import com.advancedtelematic.campaigner.data.Generators._ import com.advancedtelematic.campaigner.util.{CampaignerSpecUtil, DatabaseUpdateSpecUtil} import com.advancedtelematic.libats.data.DataType.{ResultCode, ResultDescription} import com.advancedtelematic.libats.messaging_datatype.DataType.{DeviceId, UpdateId} -import com.advancedtelematic.libats.test.DatabaseSpec +import com.advancedtelematic.campaigner.util.DatabaseSpec +import com.typesafe.config.{Config, ConfigFactory} import org.scalacheck.{Arbitrary, Gen} import org.scalatest.concurrent.ScalaFutures import org.scalatest.time.SpanSugar._ @@ -22,6 +23,8 @@ class CampaignsSpec extends AsyncFlatSpec with DatabaseUpdateSpecUtil with CampaignerSpecUtil { + lazy val testDbConfig: Config = ConfigFactory.load().getConfig("ats.campaigner.database") + import Arbitrary._ "count campaigns" should "return a list of how many campaigns there are for each status" in { @@ -64,7 +67,9 @@ final class CampaignsFindFailedDevicesSpec extends AsyncFlatSpec with DatabaseUpdateSpecUtil with CampaignerSpecUtil { - implicit val defaultPatience = PatienceConfig(timeout = 2 seconds) + lazy val testDbConfig: Config = ConfigFactory.load().getConfig("ats.campaigner.database") + + implicit val defaultPatience = PatienceConfig(timeout = 2.seconds) "findFailedDeviceUpdates" should "find all failed device update from all the given campaigns and return only the most recent ones" in { val campaignIds = Gen.choose(3, 6).flatMap(Gen.listOfN(_, genCampaignId)).generate diff --git a/src/test/scala/com/advancedtelematic/campaigner/util/ActorSpec.scala b/src/test/scala/com/advancedtelematic/campaigner/util/ActorSpec.scala index 20af929..b3dfdaa 100644 --- a/src/test/scala/com/advancedtelematic/campaigner/util/ActorSpec.scala +++ b/src/test/scala/com/advancedtelematic/campaigner/util/ActorSpec.scala @@ -1,10 +1,9 @@ package com.advancedtelematic.campaigner.util import akka.actor.ActorSystem -import akka.stream.{ActorMaterializer, Materializer} +import akka.stream.Materializer import akka.testkit.TestKit import com.advancedtelematic.campaigner.Settings -import com.advancedtelematic.libats.test.DatabaseSpec import org.scalatest.{BeforeAndAfterAll, FlatSpecLike} import scala.concurrent.ExecutionContext @@ -16,7 +15,6 @@ abstract class ActorSpec[T](implicit m: reflect.Manifest[T]) with DatabaseSpec { implicit lazy val ec: ExecutionContext = system.dispatcher - implicit val mat: Materializer = ActorMaterializer() lazy val deviceRegistry = new FakeDeviceRegistry() lazy val director = new FakeDirectorClient() val batch = schedulerBatchSize.toInt diff --git a/src/test/scala/com/advancedtelematic/campaigner/util/CampaignerSpec.scala b/src/test/scala/com/advancedtelematic/campaigner/util/CampaignerSpec.scala index a4193bb..dff1f7e 100644 --- a/src/test/scala/com/advancedtelematic/campaigner/util/CampaignerSpec.scala +++ b/src/test/scala/com/advancedtelematic/campaigner/util/CampaignerSpec.scala @@ -4,6 +4,7 @@ import com.advancedtelematic.campaigner.data.Generators._ import com.advancedtelematic.campaigner.data.DataType.Campaign import com.advancedtelematic.campaigner.db.UpdateRepository import com.advancedtelematic.libats.test.LongTest +import com.typesafe.config.{Config, ConfigFactory} import slick.jdbc.MySQLProfile.api._ import org.scalacheck.Gen import org.scalacheck.rng.Seed @@ -26,6 +27,8 @@ trait CampaignerSpec extends FlatSpecLike with LongTest with CampaignerSpecUtil { + val testDbConfig: Config = ConfigFactory.load().getConfig("ats.campaigner.database") + def buildCampaignWithUpdate(implicit db: Database, ec: ExecutionContext): Campaign = { val updateRepo = new UpdateRepository() val update = genMultiTargetUpdate.generate diff --git a/src/test/scala/com/advancedtelematic/campaigner/util/DatabaseSpec.scala b/src/test/scala/com/advancedtelematic/campaigner/util/DatabaseSpec.scala new file mode 100644 index 0000000..aeb9802 --- /dev/null +++ b/src/test/scala/com/advancedtelematic/campaigner/util/DatabaseSpec.scala @@ -0,0 +1,8 @@ +package com.advancedtelematic.campaigner.util + +import com.advancedtelematic.libats.test.MysqlDatabaseSpec +import org.scalatest.Suite + +trait DatabaseSpec extends MysqlDatabaseSpec { + self: Suite => +} diff --git a/src/test/scala/com/advancedtelematic/campaigner/util/ResourceSpec.scala b/src/test/scala/com/advancedtelematic/campaigner/util/ResourceSpec.scala index 94e01ba..e9d11d1 100644 --- a/src/test/scala/com/advancedtelematic/campaigner/util/ResourceSpec.scala +++ b/src/test/scala/com/advancedtelematic/campaigner/util/ResourceSpec.scala @@ -11,13 +11,12 @@ import com.advancedtelematic.campaigner.data.Codecs._ import com.advancedtelematic.campaigner.data.DataType.CampaignStatus.CampaignStatus import com.advancedtelematic.campaigner.data.DataType.SortBy.SortBy import com.advancedtelematic.campaigner.data.DataType._ -import com.advancedtelematic.campaigner.db.{Campaigns, Repositories} +import com.advancedtelematic.campaigner.db.Campaigns import com.advancedtelematic.campaigner.http.Routes import com.advancedtelematic.libats.data.DataType.{Namespace, ResultCode} import com.advancedtelematic.libats.data.PaginationResult import com.advancedtelematic.libats.http.HttpOps._ import com.advancedtelematic.libats.http.tracing.NullServerRequestTracing -import com.advancedtelematic.libats.test.DatabaseSpec import de.heikoseeberger.akkahttpcirce.FailFastCirceSupport._ import io.circe.Json import org.scalatest.Suite diff --git a/src/test/scala/com/advancedtelematic/campaigner/util/UpdateResourceSpecUtil.scala b/src/test/scala/com/advancedtelematic/campaigner/util/UpdateResourceSpecUtil.scala index c4a2d62..9fcd0eb 100644 --- a/src/test/scala/com/advancedtelematic/campaigner/util/UpdateResourceSpecUtil.scala +++ b/src/test/scala/com/advancedtelematic/campaigner/util/UpdateResourceSpecUtil.scala @@ -6,7 +6,6 @@ import com.advancedtelematic.campaigner.data.DataType._ import com.advancedtelematic.campaigner.data.Generators._ import com.advancedtelematic.campaigner.db.{Campaigns, Repositories} import com.advancedtelematic.libats.messaging_datatype.DataType.{DeviceId, UpdateId} -import com.advancedtelematic.libats.test.DatabaseSpec import de.heikoseeberger.akkahttpcirce.FailFastCirceSupport._ import org.scalacheck.Arbitrary._ import org.scalacheck.Gen