Skip to content

Commit

Permalink
Common upgrade / lazy props alignment
Browse files Browse the repository at this point in the history
  • Loading branch information
Krystian Panek committed Feb 24, 2020
1 parent 8d7d9f8 commit f76a918
Show file tree
Hide file tree
Showing 15 changed files with 140 additions and 97 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ repositories {
dependencies {
implementation(gradleApi())

implementation("com.cognifide.gradle:common-plugin:0.1.7")
implementation("com.cognifide.gradle:common-plugin:0.1.9")

implementation("com.fasterxml.jackson.module:jackson-module-kotlin:2.10.1")
implementation("com.jayway.jsonpath:json-path:2.4.0")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,33 @@ import org.apache.http.HttpResponse
open class InstanceHttpClient(aem: AemExtension, val instance: Instance) : HttpClient(aem.common) {

init {
baseUrl = instance.httpUrl
basicUser = instance.user
basicPassword = instance.password
authorizationPreemptive = true
baseUrl.set(instance.httpUrl)
basicUser.set(instance.user)
basicPassword.set(instance.password)
authorizationPreemptive.set(true)

connectionTimeout = aem.prop.int("instance.http.connectionTimeout") ?: 30000
connectionRetries = aem.prop.boolean("instance.http.connectionRetries") ?: true
connectionIgnoreSsl = aem.prop.boolean("instance.http.connectionIgnoreSsl") ?: true
connectionTimeout.apply {
convention(30_000)
aem.prop.int("instance.http.connectionTimeout")?.let { set(it) }
}
connectionRetries.apply {
convention(true)
aem.prop.boolean("instance.http.connectionRetries")?.let { set(it) }

proxyHost = aem.prop.string("instance.http.proxyHost")
proxyPort = aem.prop.int("instance.http.proxyPort")
proxyScheme = aem.prop.string("instance.http.proxyScheme")
}
connectionIgnoreSsl.apply {
convention(true)
aem.prop.boolean("instance.http.connectionIgnoreSsl")?.let { set(it) }
}
proxyHost.apply {
aem.prop.string("instance.http.proxyHost")?.let { set(it) }
}
proxyPort.apply {
aem.prop.int("instance.http.proxyPort")?.let { set(it) }
}
proxyScheme.apply {
aem.prop.string("instance.http.proxyScheme")?.let { set(it) }
}
}

override fun throwStatusException(response: HttpResponse) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ open class InstanceManager(val aem: AemExtension) {
" or setting property 'instance.projectDir'!"
)
})
aem.prop.file("instance.projectDir")?.let { set(it) }
aem.prop.string("instance.projectDir")?.let { set(project.rootProject.file(it)) }
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class LocalInstanceManager(private val aem: AemExtension) : Serializable {
" or setting property 'localInstance.projectDir'!"
)
})
aem.prop.file("localInstance.projectDir")?.let { set(it) }
aem.prop.string("localInstance.projectDir")?.let { set(project.rootProject.file(it)) }
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,37 +12,51 @@ import java.util.concurrent.TimeUnit
class AwaitDownAction(aem: AemExtension) : DefaultAction(aem) {

private var timeoutOptions: TimeoutCheck.() -> Unit = {
stateTime = aem.prop.long("instance.awaitDown.timeout.stateTime")
?: TimeUnit.MINUTES.toMillis(2)
constantTime = aem.prop.long("instance.awaitDown.timeout.constantTime")
?: TimeUnit.MINUTES.toMillis(10)
stateTime.apply {
convention(TimeUnit.MINUTES.toMillis(2))
aem.prop.long("instance.awaitDown.timeout.stateTime")?.let { set(it) }
}
constantTime.apply {
convention(TimeUnit.MINUTES.toMillis(10))
aem.prop.long("instance.awaitDown.timeout.constantTime")?.let { set(it) }
}
}

fun timeout(options: TimeoutCheck.() -> Unit) {
timeoutOptions = options
}

private var unavailableOptions: UnavailableCheck.() -> Unit = {
utilisationTime = aem.prop.long("instance.awaitDown.unavailable.utilizationTime")
?: TimeUnit.SECONDS.toMillis(10)
utilisationTime.apply {
convention(TimeUnit.SECONDS.toMillis(10))
aem.prop.long("instance.awaitDown.unavailable.utilizationTime")?.let { set(it) }
}
}

fun unavailable(options: UnavailableCheck.() -> Unit) {
unavailableOptions = options
}

private var unchangedOptions: UnchangedCheck.() -> Unit = {
awaitTime = aem.prop.long("instance.awaitDown.unchanged.awaitTime")
?: TimeUnit.SECONDS.toMillis(3)
awaitTime.apply {
convention(TimeUnit.SECONDS.toMillis(3))
aem.prop.long("instance.awaitDown.unchanged.awaitTime")?.let { set(it) }
}
}

fun unchanged(options: UnchangedCheck.() -> Unit) {
unchangedOptions = options
}

private val runner = CheckRunner(aem).apply {
delay = aem.prop.long("instance.awaitDown.delay") ?: TimeUnit.SECONDS.toMillis(1)
verbose = aem.prop.boolean("instance.awaitDown.verbose") ?: true
delay.apply {
convention(TimeUnit.SECONDS.toMillis(1))
aem.prop.long("instance.awaitDown.delay")?.let { set(it) }
}
verbose.apply {
convention(true)
aem.prop.boolean("instance.awaitDown.verbose")?.let { set(it) }
}

checks {
listOf(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,62 +12,85 @@ import java.util.concurrent.TimeUnit
class AwaitUpAction(aem: AemExtension) : DefaultAction(aem) {

private var timeoutOptions: TimeoutCheck.() -> Unit = {
stateTime = aem.prop.long("instance.awaitUp.timeout.stateTime")
?: TimeUnit.MINUTES.toMillis(10)
constantTime = aem.prop.long("instance.awaitUp.timeout.constantTime")
?: TimeUnit.MINUTES.toMillis(30)
stateTime.apply {
convention(TimeUnit.MINUTES.toMillis(10))
aem.prop.long("instance.awaitUp.timeout.stateTime")?.let { set(it) }
}
constantTime.apply {
convention(TimeUnit.MINUTES.toMillis(30))
aem.prop.long("instance.awaitUp.timeout.constantTime")?.let { set(it) }
}
}

fun timeout(options: TimeoutCheck.() -> Unit) {
timeoutOptions = options
}

private var bundlesOptions: BundlesCheck.() -> Unit = {
symbolicNamesIgnored = aem.prop.list("instance.awaitUp.bundles.symbolicNamesIgnored")
?: listOf()
symbolicNamesIgnored.apply {
convention(listOf())
aem.prop.list("instance.awaitUp.bundles.symbolicNamesIgnored")?.let { set(it) }
}
}

fun bundles(options: BundlesCheck.() -> Unit) {
bundlesOptions = options
}

private var eventsOptions: EventsCheck.() -> Unit = {
unstableTopics = aem.prop.list("instance.awaitUp.event.unstableTopics") ?: listOf(
"org/osgi/framework/ServiceEvent/*",
"org/osgi/framework/FrameworkEvent/*",
"org/osgi/framework/BundleEvent/*"
)
unstableAgeMillis = aem.prop.long("instance.awaitUp.event.unstableAgeMillis")
?: TimeUnit.SECONDS.toMillis(5)
unstableTopics.apply {
convention(listOf(
"org/osgi/framework/ServiceEvent/*",
"org/osgi/framework/FrameworkEvent/*",
"org/osgi/framework/BundleEvent/*"
))
aem.prop.list("instance.awaitUp.event.unstableTopics")?.let { set(it) }
}
unstableAgeMillis.apply {
convention(TimeUnit.SECONDS.toMillis(5))
aem.prop.long("instance.awaitUp.event.unstableAgeMillis")?.let { set(it) }
}
}

fun events(options: EventsCheck.() -> Unit) {
eventsOptions = options
}

private var componentsOptions: ComponentsCheck.() -> Unit = {
platformComponents = aem.prop.list("instance.awaitUp.components.platform")
?: listOf("com.day.crx.packaging.*", "org.apache.sling.installer.*")
specificComponents = aem.prop.list("instance.awaitUp.components.specific")
?: aem.javaPackages.map { "$it.*" }
platformComponents.apply {
convention(listOf("com.day.crx.packaging.*", "org.apache.sling.installer.*"))
aem.prop.list("instance.awaitUp.components.platform")?.let { set(it) }
}
specificComponents.apply {
convention(aem.obj.provider { aem.javaPackages.map { "$it.*" } })
aem.prop.list("instance.awaitUp.components.specific")?.let { set(it) }
}
}

fun components(options: ComponentsCheck.() -> Unit) {
componentsOptions = options
}

private var unchangedOptions: UnchangedCheck.() -> Unit = {
awaitTime = aem.prop.long("instance.awaitUp.unchanged.awaitTime")
?: TimeUnit.SECONDS.toMillis(3)
awaitTime.apply {
convention(TimeUnit.SECONDS.toMillis(3))
aem.prop.long("instance.awaitUp.unchanged.awaitTime")?.let { set(it) }
}
}

fun unchanged(options: UnchangedCheck.() -> Unit) {
unchangedOptions = options
}

private val runner = CheckRunner(aem).apply {
delay = aem.prop.long("instance.awaitUp.delay") ?: TimeUnit.SECONDS.toMillis(1)
verbose = aem.prop.boolean("instance.awaitUp.verbose") ?: true
delay.apply {
convention(TimeUnit.SECONDS.toMillis(1))
aem.prop.long("instance.awaitUp.delay")?.let { set(it) }
}
verbose.apply {
convention(true)
aem.prop.boolean("instance.awaitUp.verbose")?.let { set(it) }
}

checks {
listOf(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ package com.cognifide.gradle.aem.common.instance.check
@Suppress("MagicNumber")
class BundlesCheck(group: CheckGroup) : DefaultCheck(group) {

var symbolicNamesIgnored = listOf<String>()
val symbolicNamesIgnored = aem.obj.strings { convention(listOf()) }

init {
sync.apply {
http.connectionTimeout = 750
http.connectionRetries = false
http.connectionTimeout.convention(750)
http.connectionRetries.convention(false)
}
}

Expand All @@ -25,7 +25,7 @@ class BundlesCheck(group: CheckGroup) : DefaultCheck(group) {
return
}

val unstable = state.bundlesExcept(symbolicNamesIgnored).filter { !it.stable }
val unstable = state.bundlesExcept(symbolicNamesIgnored.get()).filter { !it.stable }
if (unstable.isNotEmpty()) {
statusLogger.error(
when (unstable.size) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class CheckRunner(internal val aem: AemExtension) {
checks = definitions
}

var progresses = listOf<CheckProgress>()
private var progresses = listOf<CheckProgress>()

/**
* Get current checking progress of concrete instance.
Expand All @@ -34,31 +34,29 @@ class CheckRunner(internal val aem: AemExtension) {
/**
* How long to wait after failed checking before checking again.
*/
var delay = 0L
val delay = aem.obj.long { convention(0L) }

/**
* Controls if aborted running should fail build.
*/
var verbose = true
val verbose = aem.obj.boolean { convention(true) }

/**
* Time since running started.
*/
val runningTime: Long
get() = runningWatch.time
val runningTime: Long get() = runningWatch.time

private val runningWatch = StopWatch()

/**
* Error causing running stopped.
*/
var abortCause: Exception? = null
internal var abortCause: Exception? = null

/**
* Verify if running is stopped.
*/
val aborted: Boolean
get() = abortCause != null
val aborted: Boolean get() = abortCause != null

/**
* Controls logging behavior
Expand Down Expand Up @@ -114,7 +112,7 @@ class CheckRunner(internal val aem: AemExtension) {
break
}

Behaviors.waitFor(delay)
Behaviors.waitFor(delay.get())
} while (isActive)
}

Expand All @@ -129,7 +127,7 @@ class CheckRunner(internal val aem: AemExtension) {
progresses.forEach { it.currentCheck?.log() }
}

if (verbose) {
if (verbose.get()) {
abortCause?.let { throw it }
} else {
aem.logger.error("Checking error", abortCause)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import com.cognifide.gradle.common.utils.Formats
@Suppress("MagicNumber")
class ComponentsCheck(group: CheckGroup) : DefaultCheck(group) {

var platformComponents = listOf<String>()
val platformComponents = aem.obj.strings { convention(listOf()) }

var specificComponents = listOf<String>()
val specificComponents = aem.obj.strings { convention(listOf()) }

init {
sync.apply {
http.connectionTimeout = 10000
http.connectionTimeout.convention(10_000)
}
}

Expand All @@ -31,7 +31,7 @@ class ComponentsCheck(group: CheckGroup) : DefaultCheck(group) {

val total = state.components.size

val inactive = state.find(platformComponents, listOf()).filter { !it.active }
val inactive = state.find(platformComponents.get(), listOf()).filter { !it.active }
if (inactive.isNotEmpty()) {
statusLogger.error(
when (inactive.size) {
Expand All @@ -43,7 +43,7 @@ class ComponentsCheck(group: CheckGroup) : DefaultCheck(group) {
)
}

val failed = state.find(specificComponents, listOf()).filter { it.failedActivation }
val failed = state.find(specificComponents.get(), listOf()).filter { it.failedActivation }
if (failed.isNotEmpty()) {
statusLogger.error(
when (failed.size) {
Expand All @@ -55,7 +55,7 @@ class ComponentsCheck(group: CheckGroup) : DefaultCheck(group) {
)
}

val unsatisfied = state.find(specificComponents, listOf()).filter { it.unsatisfied }
val unsatisfied = state.find(specificComponents.get(), listOf()).filter { it.unsatisfied }
if (unsatisfied.isNotEmpty()) {
statusLogger.error(
when (unsatisfied.size) {
Expand Down
Loading

0 comments on commit f76a918

Please sign in to comment.