Skip to content

Commit

Permalink
Improve behaviour in case of ComposeUp failure (#123)
Browse files Browse the repository at this point in the history
* Fix NullPointerException when ComposeUp task fails

When the ComposeUp task fails, it tries to invoke the ComposeDown task.
This lead to a "java.lang.NullPointerException: Cannot invoke method
down() on null object" error due to an incorrect assignment order.

* Display correct health status when waitForHealthStateTimeout is exceeded

The health state was hard coded as 'starting', but it might also be
'unhealthy'.
  • Loading branch information
HSZemi authored and augi committed Nov 13, 2017
1 parent c1818f0 commit cb0bc53
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ class ComposeSettings {

upTask = project.tasks.create(name ? "${name}ComposeUp" : 'composeUp', ComposeUp)
upTask.settings = this
upTask.downTask = downTask
pullTask = project.tasks.create(name ? "${name}ComposePull" : 'composePull', ComposePull)
pullTask.settings = this
downTask = project.tasks.create(name ? "${name}ComposeDown" : 'composeDown', ComposeDown)
downTask.settings = this
upTask.downTask = downTask

this.dockerExecutor = new DockerExecutor(this)
this.composeExecutor = new ComposeExecutor(this)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,9 @@ class ComposeUp extends DefaultTask {
serviceInfo.containerInfos.each { instanceName, containerInfo ->
while (true) {
Map<String, Object> inspectionState = settings.dockerExecutor.getInspection(containerInfo.containerId).State
String healthStatus = 'undefined'
if (inspectionState.containsKey('Health')) {
String healthStatus = inspectionState.Health.Status
healthStatus = inspectionState.Health.Status
if (!"starting".equalsIgnoreCase(healthStatus) && !"unhealthy".equalsIgnoreCase(healthStatus)) {
logger.lifecycle("${instanceName} health state reported as '$healthStatus' - continuing...")
return
Expand All @@ -114,7 +115,7 @@ class ComposeUp extends DefaultTask {
return
}
if (start.plus(settings.waitForHealthyStateTimeout) < Instant.now()) {
throw new RuntimeException("Container ${containerInfo.containerId} of service ${instanceName} is still reported as 'starting'. Logs:${System.lineSeparator()}${settings.getContainerLogs(containerInfo.containerId)}")
throw new RuntimeException("Container ${containerInfo.containerId} of service ${instanceName} is still reported as '${healthStatus}'. Logs:${System.lineSeparator()}${settings.dockerExecutor.getContainerLogs(containerInfo.containerId)}")
}
}
}
Expand Down

0 comments on commit cb0bc53

Please sign in to comment.