Skip to content

Commit

Permalink
feat(sql): Flipped over to the mariadb driver and jdbc urls
Browse files Browse the repository at this point in the history
- Enabled SSL
- Support for a writeOnly-mode (`spinnaker.migration.writeOnly: false`)
  • Loading branch information
ajordens committed Jul 8, 2019
1 parent 1ed13dd commit 63cb1f2
Show file tree
Hide file tree
Showing 5 changed files with 457 additions and 5 deletions.
4 changes: 3 additions & 1 deletion front50-sql/front50-sql.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ dependencies {
implementation "io.strikt:strikt-core"
implementation "com.netflix.hystrix:hystrix-core"
implementation "io.github.resilience4j:resilience4j-retry"

implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.2.1"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-slf4j:1.2.1"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core-common:1.2.1"

runtimeOnly "mysql:mysql-connector-java"
implementation "org.mariadb.jdbc:mariadb-java-client:2.2.3"
// runtimeOnly "mysql:mysql-connector-java"

testImplementation "dev.minutest:minutest"
testImplementation "org.testcontainers:mysql"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ class CompositeStorageServiceConfiguration() {
storageServices: List<StorageService>) =
CompositeStorageService(
storageServices.first { it.javaClass.canonicalName.equals(properties.primaryClass) },
storageServices.first { it.javaClass.canonicalName.equals(properties.previousClass) }
storageServices.first { it.javaClass.canonicalName.equals(properties.previousClass) },
properties.writeOnly
)

@Bean
Expand All @@ -55,5 +56,6 @@ class CompositeStorageServiceConfiguration() {
@ConfigurationProperties("spinnaker.migration")
data class StorageServiceMigratorConfigurationProperties(
var primaryClass: String? = null,
var previousClass: String? = null
var previousClass: String? = null,
var writeOnly: Boolean = false
)
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ import org.slf4j.LoggerFactory

class CompositeStorageService(
private val primary: StorageService,
private val previous: StorageService
private val previous: StorageService,
private val writeOnly: Boolean
) : StorageService {

companion object {
Expand All @@ -37,7 +38,7 @@ class CompositeStorageService(
}

override fun <T : Timestamped?> loadObject(objectType: ObjectType?, objectKey: String?): T {
if (objectType == ObjectType.ENTITY_TAGS) {
if (writeOnly || objectType == ObjectType.ENTITY_TAGS) {
return previous.loadObject<T>(objectType, objectKey)
}

Expand Down Expand Up @@ -89,6 +90,10 @@ class CompositeStorageService(
}

override fun listObjectKeys(objectType: ObjectType?): Map<String, Long> {
if (writeOnly) {
return previous.listObjectKeys(objectType)
}

val primaryObjectKeys = primary.listObjectKeys(objectType)
val previousObjectKeys = previous.listObjectKeys(objectType)

Expand All @@ -98,6 +103,10 @@ class CompositeStorageService(
override fun <T : Timestamped?> listObjectVersions(objectType: ObjectType?,
objectKey: String?,
maxResults: Int): MutableCollection<T> {
if (writeOnly) {
return previous.listObjectVersions(objectType, objectKey, maxResults)
}

try {
return primary.listObjectVersions(objectType, objectKey, maxResults)
} catch (e: Exception) {
Expand All @@ -113,6 +122,10 @@ class CompositeStorageService(
}

override fun getLastModified(objectType: ObjectType?): Long {
if (writeOnly) {
return previous.getLastModified(objectType)
}

try {
return primary.getLastModified(objectType)
} catch (e: Exception) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ class SqlStorageService(
override fun <T : Timestamped> storeObject(objectType: ObjectType, objectKey: String, item: T) {
item.lastModifiedBy = AuthenticatedRequest.getSpinnakerUser().orElse("anonymous")

// TODO-AJ handle overriding the `lastModified` during a migration so that not everything is `now()`
item.lastModified = clock.millis()

try {
jooq.transactional(sqlRetryProperties.transactions) { ctx ->
val insert = ctx.insertInto(
Expand Down
Loading

0 comments on commit 63cb1f2

Please sign in to comment.