Skip to content

Commit

Permalink
Use CONTAINER_TIMEOUT instead of DOCKER_TIMEOUT
Browse files Browse the repository at this point in the history
  • Loading branch information
mattbsox committed Sep 12, 2023
1 parent eae96cb commit 9986468
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public abstract class AbstractContainerSupportUtil {
private static final String CONTAINER_DOCKER_PREFIX = "docker ";
private static final String CONTAINER_PODMAN_PREFIX = "podman ";

private static final int CONTAINER_TIMEOUT = 20; // seconds
protected static final int CONTAINER_TIMEOUT = 20; // seconds

private boolean checkedContainerType = false;
protected boolean isDocker = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ public abstract class DevUtil extends AbstractContainerSupportUtil {
private static final String[] DEFAULT_COMPILER_OPTIONS = new String[] { "-g", "-parameters" };
private static final int LIBERTY_DEFAULT_HTTP_PORT = 9080;
private static final int LIBERTY_DEFAULT_HTTPS_PORT = 9443;
private static final int DOCKER_TIMEOUT = 20; // seconds

/**
* Log debug
Expand Down Expand Up @@ -1349,7 +1348,7 @@ private void startContainer() throws PluginExecutionException {
try {
// remove container in case of an error trying to run the container because the container run --rm will not rm the container
String containerRmCmd = "container rm " + containerName;
execContainerCmdWithPrefix(containerRmCmd, DOCKER_TIMEOUT);
execContainerCmdWithPrefix(containerRmCmd, CONTAINER_TIMEOUT);
} catch (Exception e) {
// do not report the "container rm" error so that we can instead report the startContainer() error
debug("Exception running container command rm:", e);
Expand Down Expand Up @@ -1511,7 +1510,7 @@ private void stopContainer() throws PluginExecutionException {
info("Stopping container...");
String containerStopCmd = "stop " + containerName;
debug("Stopping container " + containerName);
execContainerCmdWithPrefix(containerStopCmd, DOCKER_TIMEOUT + 20); // allow extra time for server shutdown
execContainerCmdWithPrefix(containerStopCmd, CONTAINER_TIMEOUT + 20); // allow extra time for server shutdown
writeDevcMetadata(false);
}
} catch (RuntimeException r) {
Expand Down Expand Up @@ -1674,7 +1673,7 @@ private String getContainerOption(String optionName) {
private String generateNewContainerName() throws PluginExecutionException {
String containerContNamesCmd = "ps -a --format \"{{.Names}}\"";
debug("container names list command: " + containerContNamesCmd);
String result = execContainerCmdWithPrefix(containerContNamesCmd, DOCKER_TIMEOUT);
String result = execContainerCmdWithPrefix(containerContNamesCmd, CONTAINER_TIMEOUT);
if (result == null) {
return DEVMODE_CONTAINER_BASE_NAME;
}
Expand Down Expand Up @@ -1712,7 +1711,7 @@ private String generateNewContainerName() throws PluginExecutionException {
*/
private String[] getContainerNetworks(String contName) throws PluginExecutionException {
String containerNetworkCmd = "inspect -f '{{.NetworkSettings.Networks}}' " + contName;
String cmdResult = execContainerCmdWithPrefix(containerNetworkCmd, DOCKER_TIMEOUT, false);
String cmdResult = execContainerCmdWithPrefix(containerNetworkCmd, CONTAINER_TIMEOUT, false);
if (cmdResult == null || cmdResult.contains(" RC=")) { // RC is added in execContainerCmd if there is an error
warn("Unable to retrieve container networks.");
return null;
Expand Down Expand Up @@ -1744,7 +1743,7 @@ protected static String[] parseNetworks(String containerResult) {

private String getContainerIPAddress(String contName, String network) throws PluginExecutionException {
String containerIPAddressCmd = "inspect -f '{{.NetworkSettings.Networks." + network + ".IPAddress}}' " + contName;
String result = execContainerCmdWithPrefix(containerIPAddressCmd, DOCKER_TIMEOUT, false);
String result = execContainerCmdWithPrefix(containerIPAddressCmd, CONTAINER_TIMEOUT, false);
if (result == null || result.contains(" RC=")) { // RC is added in execContainerCmd if there is an error
warn("Unable to retrieve container IP address for network '" + network + "'.");
return "<no value>"; // this is what Docker/Podman displays when an IP address it not found for a network
Expand Down Expand Up @@ -1992,7 +1991,7 @@ private String getPortFromMessageTokens(String[] messageTokens) throws PluginExe

private String findLocalPort(String internalContainerPort) throws PluginExecutionException {
String containerPortCmd = "port " + containerName + " " + internalContainerPort;
String cmdResult = execContainerCmdWithPrefix(containerPortCmd, DOCKER_TIMEOUT, false);
String cmdResult = execContainerCmdWithPrefix(containerPortCmd, CONTAINER_TIMEOUT, false);
if (cmdResult == null) {
warn("Unable to retrieve locally mapped port.");
return null;
Expand Down

0 comments on commit 9986468

Please sign in to comment.