-
Notifications
You must be signed in to change notification settings - Fork 32
/
InstanceProvision.kt
62 lines (51 loc) · 2.19 KB
/
InstanceProvision.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package com.cognifide.gradle.aem.instance.tasks
import com.cognifide.gradle.aem.common.instance.action.AwaitUpAction
import com.cognifide.gradle.aem.common.instance.provision.Provisioner
import com.cognifide.gradle.aem.common.instance.provision.Status
import com.cognifide.gradle.aem.common.tasks.Instance
import com.cognifide.gradle.common.utils.Formats
import org.gradle.api.tasks.TaskAction
open class InstanceProvision : Instance() {
private val provisioner by lazy {
val urls = aem.prop.list("instance.provision.deployPackage.urls")
when {
urls != null -> Provisioner(instanceManager).apply { urls.forEach { deployPackage(it) } }
else -> instanceManager.provisioner
}
}
private var awaitUpOptions: AwaitUpAction.() -> Unit = {
unchanged { enabled.set(false) }
}
fun awaitUp(options: AwaitUpAction.() -> Unit) {
this.awaitUpOptions = options
}
@TaskAction
fun provision() {
instanceManager.examinePrerequisites(anyInstances)
instanceManager.awaitUp(anyInstances, awaitUpOptions)
val allActions = provisioner.provision(anyInstances)
val performedActions = allActions.filter { it.status != Status.SKIPPED }
val skippedActions = allActions - performedActions
val instances = performedActions.map { it.step.instance }.toSet()
val performed = performedActions.count()
val ended = performedActions.count { it.status == Status.ENDED }
val failed = performedActions.count { it.status == Status.FAILED }
if (performed > 0) {
val succedded = Formats.percentExplained(ended - failed, ended)
common.notifier.notify(
"Instances provisioned",
listOf(
"Steps: $succedded succeeded on ${instances.size} instance(s)",
"${skippedActions.size} skipped",
"${allActions.size} in total"
).joinToString(", ")
)
}
}
init {
description = "Configures instances only in concrete circumstances (only once, after some time etc)"
}
companion object {
const val NAME = "instanceProvision"
}
}