-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #111 from iamdanfox/shutdown-strategy
add new AggressiveShutdownStrategy
- Loading branch information
Showing
8 changed files
with
130 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
src/main/java/com/palantir/docker/compose/configuration/ShutdownStrategy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* | ||
* Copyright 2016 Palantir Technologies, Inc. All rights reserved. | ||
*/ | ||
|
||
package com.palantir.docker.compose.configuration; | ||
|
||
import com.palantir.docker.compose.execution.AggressiveShutdownStrategy; | ||
import com.palantir.docker.compose.execution.DockerCompose; | ||
import com.palantir.docker.compose.execution.GracefulShutdownStrategy; | ||
import com.palantir.docker.compose.execution.SkipShutdownStrategy; | ||
import java.io.IOException; | ||
|
||
/** | ||
* How should a cluster of containers be shut down by the `after` method of | ||
* DockerComposeRule. | ||
*/ | ||
public interface ShutdownStrategy { | ||
|
||
ShutdownStrategy AGGRESSIVE = new AggressiveShutdownStrategy(); | ||
ShutdownStrategy GRACEFUL = new GracefulShutdownStrategy(); | ||
ShutdownStrategy SKIP = new SkipShutdownStrategy(); | ||
|
||
void shutdown(DockerCompose dockerCompose) throws IOException, InterruptedException; | ||
|
||
} |
21 changes: 21 additions & 0 deletions
21
src/main/java/com/palantir/docker/compose/execution/AggressiveShutdownStrategy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* | ||
* Copyright 2016 Palantir Technologies, Inc. All rights reserved. | ||
*/ | ||
|
||
package com.palantir.docker.compose.execution; | ||
|
||
import com.palantir.docker.compose.configuration.ShutdownStrategy; | ||
import java.io.IOException; | ||
|
||
/** | ||
* Shuts down containers as fast as possible, without giving them time to finish | ||
* IO or clean up any resources. | ||
*/ | ||
public class AggressiveShutdownStrategy implements ShutdownStrategy { | ||
|
||
@Override | ||
public void shutdown(DockerCompose dockerCompose) throws IOException, InterruptedException { | ||
dockerCompose.rm(); | ||
} | ||
|
||
} |
28 changes: 28 additions & 0 deletions
28
src/main/java/com/palantir/docker/compose/execution/GracefulShutdownStrategy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* Copyright 2016 Palantir Technologies, Inc. All rights reserved. | ||
*/ | ||
|
||
package com.palantir.docker.compose.execution; | ||
|
||
import com.palantir.docker.compose.configuration.ShutdownStrategy; | ||
import java.io.IOException; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
/** | ||
* Send SIGTERM to containers first, allowing them up to 10 seconds to | ||
* terminate before killing and rm-ing them. | ||
*/ | ||
public class GracefulShutdownStrategy implements ShutdownStrategy { | ||
|
||
private static final Logger log = LoggerFactory.getLogger(GracefulShutdownStrategy.class); | ||
|
||
@Override | ||
public void shutdown(DockerCompose dockerCompose) throws IOException, InterruptedException { | ||
log.debug("Killing docker-compose cluster"); | ||
dockerCompose.down(); | ||
dockerCompose.kill(); | ||
dockerCompose.rm(); | ||
} | ||
|
||
} |
27 changes: 27 additions & 0 deletions
27
src/main/java/com/palantir/docker/compose/execution/SkipShutdownStrategy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* Copyright 2016 Palantir Technologies, Inc. All rights reserved. | ||
*/ | ||
|
||
package com.palantir.docker.compose.execution; | ||
|
||
import com.palantir.docker.compose.configuration.ShutdownStrategy; | ||
import java.io.IOException; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class SkipShutdownStrategy implements ShutdownStrategy { | ||
|
||
private static final Logger log = LoggerFactory.getLogger(SkipShutdownStrategy.class); | ||
|
||
@Override | ||
public void shutdown(DockerCompose dockerCompose) throws IOException, InterruptedException { | ||
log.warn("******************************************************************************************\n" | ||
+ "* docker-compose-rule has been configured to skip docker-compose shutdown: *\n" | ||
+ "* this means the containers will be left running after tests finish executing. *\n" | ||
+ "* If you see this message when running on CI it means you are potentially abandoning *\n" | ||
+ "* long running processes and leaking resources. *\n" | ||
+ "******************************************************************************************"); | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters