Skip to content

Commit

Permalink
Merge pull request #440 from ThoughtWorks-SEA/dependabot/gradle/com.d…
Browse files Browse the repository at this point in the history
…iffplug.spotless-6.22.0

Bump com.diffplug.spotless from 6.21.0 to 6.22.0
  • Loading branch information
chadlwilson authored Oct 11, 2023
2 parents 088c8b2 + b1fda4b commit ab65a0c
Show file tree
Hide file tree
Showing 39 changed files with 817 additions and 663 deletions.
62 changes: 33 additions & 29 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ plugins {
id("org.jetbrains.kotlin.plugin.allopen") version kotlinVersion
id("org.jetbrains.kotlin.plugin.jpa") version kotlinVersion
id("io.micronaut.application") version "3.7.10"
id("com.diffplug.spotless") version "6.21.0"
id("com.diffplug.spotless") version "6.22.0"
id("io.gitlab.arturbosch.detekt") version "1.23.1"
id("com.github.spotbugs") version "5.1.4"
jacoco
Expand All @@ -21,14 +21,17 @@ group = "recce.server"
// Workaround to allow dependabot to update versions of libraries together, since dependabot doesn't understand
// the Gradle DSL properly. Here we pick one of the versions where multiple artifacts are released at the same time
// and use this to bump the others consistently.
val depDescriptors = mapOf(
"micronaut" to "io.micronaut:micronaut-core:3.10.1",
"restAssured" to "io.rest-assured:rest-assured:4.5.1"
)
val depVersions = depDescriptors.mapValues { (_, v) -> v.split(':').last() } + mapOf(
"javaMajor" to "17",
"reactorToolsVersionExpected" to "3.5.11"
)
val depDescriptors =
mapOf(
"micronaut" to "io.micronaut:micronaut-core:3.10.1",
"restAssured" to "io.rest-assured:rest-assured:4.5.1"
)
val depVersions =
depDescriptors.mapValues { (_, v) -> v.split(':').last() } +
mapOf(
"javaMajor" to "17",
"reactorToolsVersionExpected" to "3.5.11"
)

repositories {
mavenCentral()
Expand Down Expand Up @@ -56,11 +59,7 @@ micronaut {

kapt {
arguments {
val props = mapOf(
"rapidoc.enabled" to true,
"rapidoc.theme" to "dark",
"rapidoc.render-style" to "view"
)
val props = mapOf("rapidoc.enabled" to true, "rapidoc.theme" to "dark", "rapidoc.render-style" to "view")
arg("micronaut.openapi.views.spec", props.entries.joinToString(",") { "${it.key}=${it.value}" })
}
}
Expand Down Expand Up @@ -265,10 +264,11 @@ jib {
}
to {
val fullVersion = com.github.zafarkhaja.semver.Version.valueOf(project.version.toString())
val tagVersion = com.github.zafarkhaja.semver.Version.Builder()
.setNormalVersion(fullVersion.normalVersion)
.setPreReleaseVersion(fullVersion.preReleaseVersion.split('.')[0])
.build()
val tagVersion =
com.github.zafarkhaja.semver.Version.Builder()
.setNormalVersion(fullVersion.normalVersion)
.setPreReleaseVersion(fullVersion.preReleaseVersion.split('.')[0])
.build()
tags = setOf(tagVersion.toString(), "latest")
}
container {
Expand All @@ -280,19 +280,23 @@ jib {
}
}

val checkJibDependencies = tasks.register("checkJibDependencies") {
doFirst {
val resolvedReactorToolsVersion =
project.configurations.runtimeClasspath.get()
.resolvedConfiguration.resolvedArtifacts.find { it.name == "reactor-tools" }?.moduleVersion?.id?.version
if (depVersions["reactorToolsVersionExpected"] != resolvedReactorToolsVersion) {
throw GradleException(
"Jib docker build expected reactor-tools [${depVersions["reactorToolsVersionExpected"]}] but found " +
"[$resolvedReactorToolsVersion] in dependencies. Update reactorToolsVersionExpected!"
)
val checkJibDependencies =
tasks.register("checkJibDependencies") {
doFirst {
val resolvedReactorToolsVersion =
project.configurations
.runtimeClasspath
.get()
.resolvedConfiguration
.resolvedArtifacts.find { it.name == "reactor-tools" }?.moduleVersion?.id?.version
if (depVersions["reactorToolsVersionExpected"] != resolvedReactorToolsVersion) {
throw GradleException(
"Jib docker build expected reactor-tools [${depVersions["reactorToolsVersionExpected"]}] but " +
"found [$resolvedReactorToolsVersion] in dependencies. Update reactorToolsVersionExpected!"
)
}
}
}
}

// Jib task pushes an image. Only do so after running all checks
tasks.register<com.google.cloud.tools.jib.gradle.BuildImageTask>("jibGitHubContainerRegistry") {
Expand Down
25 changes: 14 additions & 11 deletions src/main/kotlin/recce/server/R2dbcConfiguration.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,24 @@ import jakarta.inject.Inject
import jakarta.inject.Singleton

@Singleton
class R2dbcConfiguration @Inject constructor(sources: List<R2dbcDatasource>) {
private var datasources: Map<String, String>
class R2dbcConfiguration
@Inject
constructor(sources: List<R2dbcDatasource>) {
private var datasources: Map<String, String>

init {
this.datasources = sources.associate { it.name to it.url }
}
init {
this.datasources = sources.associate { it.name to it.url }
}

fun getUrl(datasourceRef: String): String =
datasources[datasourceRef]
?: throw ConfigurationException("Cannot locate datasourceRef [$datasourceRef] in r2dbc configuration!")
}
fun getUrl(datasourceRef: String): String =
datasources[datasourceRef]
?: throw ConfigurationException("Cannot locate datasourceRef [$datasourceRef] in r2dbc configuration!")
}

@Introspected
@EachProperty("r2dbc.datasources")
class R2dbcDatasource
constructor(@param:Parameter val name: String) {
class R2dbcDatasource(
@param:Parameter val name: String
) {
lateinit var url: String
}
66 changes: 34 additions & 32 deletions src/main/kotlin/recce/server/RecConfiguration.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,43 +21,45 @@ interface PostConstructable {
@Context
@ConfigurationProperties("reconciliation")
class RecConfiguration
@ConfigurationInject constructor(
val datasets: Map<String, DatasetConfiguration>,
val defaults: DefaultsProvider = DefaultsProvider()
) : PostConstructable {

@PostConstruct
override fun populate(locator: BeanLocator) {
for ((id, config) in datasets) {
config.id = id
config.populate(locator)
}
logger.info {
"Loaded ${datasets.size} datasets available for triggering: " +
"${datasets.values.groupBy { it.datasourceDescriptor }.toSortedMap()} "
@ConfigurationInject
constructor(
val datasets: Map<String, DatasetConfiguration>,
val defaults: DefaultsProvider = DefaultsProvider()
) : PostConstructable {
@PostConstruct
override fun populate(locator: BeanLocator) {
for ((id, config) in datasets) {
config.id = id
config.populate(locator)
}
logger.info {
"Loaded ${datasets.size} datasets available for triggering: " +
"${datasets.values.groupBy { it.datasourceDescriptor }.toSortedMap()} "
}
}
}
}

@Context
@ConfigurationProperties("reconciliation.defaults")
class DefaultsProvider @ConfigurationInject constructor(
@Bindable(defaultValue = "1000") val batchSize: Int,
@Bindable(defaultValue = "5") val batchConcurrency: Int,
@Bindable(defaultValue = "TypeLenient") val hashingStrategy: HashingStrategy,
@Bindable(defaultValue = "queries") val queryFileBaseDir: Path
) {
constructor() : this(
batchSize = 1000,
batchConcurrency = 5,
hashingStrategy = HashingStrategy.TypeLenient,
queryFileBaseDir = Path("queries")
)
class DefaultsProvider
@ConfigurationInject
constructor(
@Bindable(defaultValue = "1000") val batchSize: Int,
@Bindable(defaultValue = "5") val batchConcurrency: Int,
@Bindable(defaultValue = "TypeLenient") val hashingStrategy: HashingStrategy,
@Bindable(defaultValue = "queries") val queryFileBaseDir: Path
) {
constructor() : this(
batchSize = 1000,
batchConcurrency = 5,
hashingStrategy = HashingStrategy.TypeLenient,
queryFileBaseDir = Path("queries")
)

@PostConstruct
fun log() {
logger.info {
"Reconciliation batch size is $batchSize and concurrency is $batchConcurrency"
@PostConstruct
fun log() {
logger.info {
"Reconciliation batch size is $batchSize and concurrency is $batchConcurrency"
}
}
}
}
12 changes: 6 additions & 6 deletions src/main/kotlin/recce/server/RecceServer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@ private const val GITHUB_PROJECT = "https://github.com/thoughtworks-sea/recce"
private val logger = KotlinLogging.logger {}

@OpenAPIDefinition(
info = Info(
title = "Recce Server",
description = "Server-based database reconciliation tool for developers",
contact = Contact(name = "Recce Community", url = "$GITHUB_PROJECT/issues")
),
info =
Info(
title = "Recce Server",
description = "Server-based database reconciliation tool for developers",
contact = Contact(name = "Recce Community", url = "$GITHUB_PROJECT/issues")
),
externalDocs = ExternalDocumentation(description = "Server Docs", url = "$GITHUB_PROJECT/README.md"),
security = [SecurityRequirement(name = "basicAuth")]
)
Expand All @@ -33,7 +34,6 @@ private val logger = KotlinLogging.logger {}
)
)
object RecceServer {

@JvmStatic
@Suppress("SpreadOperator")
fun main(args: Array<String>) {
Expand Down
10 changes: 3 additions & 7 deletions src/main/kotlin/recce/server/api/DatasetApiModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,10 @@ import java.time.ZonedDateTime
data class DatasetApiModel(
@field:Schema(description = "Identifier for this dataset as specified in server configuration")
val id: String,

@field:Schema(description = "Datasource considered the `source` of this reconciliation dataset")
val source: DatasourceApiModel,

@field:Schema(description = "Datasource considered the `target` of this reconciliation dataset")
val target: DatasourceApiModel,

@field:Schema(description = "Information about the scheduling of this dataset, if configured")
val schedule: ScheduleApiModel? = null
) {
Expand All @@ -29,19 +26,18 @@ data class DatasetApiModel(

@Schema(name = "Datasource")
data class DatasourceApiModel(

@field:Schema(description = "The logical name of the datasource this refers to")
val ref: String
)

@Schema(name = "Schedule", description = "Scheduling information")
data class ScheduleApiModel(
@field:Schema(
description = "Cron Expression valid per " +
"https://docs.micronaut.io/latest/api/io/micronaut/scheduling/cron/CronExpression.html"
description =
"Cron Expression valid per " +
"https://docs.micronaut.io/latest/api/io/micronaut/scheduling/cron/CronExpression.html"
)
val cronExpression: String,

@field:Schema(description = "Time this dataset is scheduled to next be triggered")
val nextTriggerTime: ZonedDateTime
) {
Expand Down
8 changes: 4 additions & 4 deletions src/main/kotlin/recce/server/api/DatasetController.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ import recce.server.dataset.DatasetConfigProvider
class DatasetController(
@Inject private val configProvider: DatasetConfigProvider
) {

@Get
@Operation(
summary = "Retrieve pre-configured datasets",
description = "Retrieves all available datasets that have been pre-configured and loaded by the server",
tags = ["Datasets"],
responses = [ApiResponse(responseCode = "200", description = "Dataset configurations found")]
)
fun getDatasets() = configProvider.availableDataSets
.map { DatasetApiModel(it) }
.sortedBy { it.id }
fun getDatasets() =
configProvider.availableDataSets
.map { DatasetApiModel(it) }
.sortedBy { it.id }
}
31 changes: 16 additions & 15 deletions src/main/kotlin/recce/server/api/DatasetRecRunController.kt
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ class DatasetRecRunController(
@field:Schema(description = "The identifier of the reconciliation run to retrieve")
@field:PathVariable
val runId: Int,

@field:Schema(
description = "How many sample mismatched migration keys of each type (only in source, only in " +
"target, mismatched data) in the results"
description =
"How many sample mismatched migration keys of each type (only in source, only in target, " +
"mismatched data) in the results"
)
@field:QueryValue(defaultValue = "0")
@field:Nullable
Expand All @@ -65,18 +65,19 @@ class DatasetRecRunController(
): Mono<RunApiModel> {
logger.info { "Finding $params" }

val findSampleRows = if (params.includeSampleKeys == 0) {
Mono.just(emptyMap())
} else {
recordRepository.findFirstByRecRunIdSplitByMatchStatus(params.runId, params.includeSampleKeys)
.map { it.matchStatus to it.migrationKey }
.collectList()
.defaultIfEmpty(emptyList())
.map { records ->
records.groupBy { it.first }
.mapValues { entry -> entry.value.map { pair -> pair.second } }
}
}
val findSampleRows =
if (params.includeSampleKeys == 0) {
Mono.just(emptyMap())
} else {
recordRepository.findFirstByRecRunIdSplitByMatchStatus(params.runId, params.includeSampleKeys)
.map { it.matchStatus to it.migrationKey }
.collectList()
.defaultIfEmpty(emptyList())
.map { records ->
records.groupBy { it.first }
.mapValues { entry -> entry.value.map { pair -> pair.second } }
}
}

return runRepository
.findById(params.runId)
Expand Down
Loading

0 comments on commit ab65a0c

Please sign in to comment.