Skip to content
This repository was archived by the owner on Nov 18, 2021. It is now read-only.

added optional undeployment option implementing #4 #6

Merged
merged 1 commit into from
Oct 8, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,9 @@ task("deploy") {
force = false
// [...]
}
```

You can also undeploy an existing deployment with the identical name beforehand
```kotlin
undeployBeforehand = true
```
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ open class DeployWildflyTask : DefaultTask() {
@Input
var awaitReload: Boolean = false

@Input
var undeployBeforehand: Boolean = false

init {
group = "help"
description = "Deploys files to a Wildfly und reloads it afterwards"
Expand All @@ -52,6 +55,23 @@ open class DeployWildflyTask : DefaultTask() {
return
}
println("deployWildfly: going to deploy $file to $host:$port")
FileDeployer(file, host, port, user, password, reload, force, deploymentName, runtimeName, awaitReload).deploy()
try {
FileDeployer(
file,
host,
port,
user,
password,
reload,
force,
deploymentName,
runtimeName,
awaitReload,
undeployBeforehand
).deploy()
} catch (e: Exception) {
println("deployWildfly task failed: ${e.message}")
e.printStackTrace()
}
}
}
30 changes: 26 additions & 4 deletions src/main/kotlin/com/mkring/wildlydeplyplugin/FileDeployer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import java.time.temporal.ChronoUnit

class FileDeployer(
val file: String?, val host: String, val port: Int, val user: String?, val password: String?,
val reload: Boolean, val force: Boolean, val name: String?, val runtimeName: String?, val awaitReload: Boolean
val reload: Boolean, val force: Boolean, val name: String?, val runtimeName: String?, val awaitReload: Boolean,
val undeployBeforehand: Boolean
) {
fun deploy() {
println("deploy(): " + this)
Expand All @@ -37,7 +38,24 @@ class FileDeployer(
""
}
println("connected successfully")
println("given $file existent: ${File(file).isFile}")
val deploymentExists = File(file).isFile
println("given $file existent: $deploymentExists")
if (deploymentExists.not()) throw IllegalStateException("couldn't find given deployment")

if (undeployBeforehand) {
println("\nundeploying existing deployment with same name if preset...")
val shouldUndeploy =
blockingCmd("deployment-info", 2, ChronoUnit.MINUTES).response.get("result").asList()
.any { it.asProperty().name == name.removePrefix("--name=") }
println("shouldUndeploy=$shouldUndeploy")
if (shouldUndeploy) {
blockingCmd("undeploy $name", 2, ChronoUnit.MINUTES).response.also {
println("undeploy response: $it\n")
}
}
}

// deploy
val deploySuccess = cli.cmd("deploy $force $name $runtimeName $file").isSuccess
println("deploy success: $deploySuccess")

Expand All @@ -56,9 +74,10 @@ class FileDeployer(

if (awaitReload) {
println("going to block until the reload finished...\n")
Thread.sleep(1000)
val postReloadDeploymentInfoPrettyPrint =
blockingCmd("deployment-info", 2, ChronoUnit.MINUTES).response.responsePrettyPrint()
println("POST reload deployment info:\n$postReloadDeploymentInfoPrettyPrint")
blockingCmd("deployment-info", 1, ChronoUnit.MINUTES).response.responsePrettyPrint()
println("\n\nPOST reload deployment info:\n$postReloadDeploymentInfoPrettyPrint")
}

}
Expand Down Expand Up @@ -117,12 +136,15 @@ class FileDeployer(
}
return cmd
} catch (e: Exception) {
println("connect + cmd exception: ${e::class.java.simpleName}:${e.message}")
Thread.sleep(500)
continue
} finally {
try {
cli.disconnect()
} catch (e: Exception) {
println("disconnect exception: ${e::class.java.simpleName}:${e.message}")
throw e
}
}
}
Expand Down