private static InspectContainerResponse.ContainerState buildState(boolean running, boolean paused, String startedAt, String finishedAt) { InspectContainerResponse.ContainerState state = Mockito.mock(InspectContainerResponse.ContainerState.class); when(state.getRunning()).thenReturn(running); when(state.getPaused()).thenReturn(paused); when(state.getStartedAt()).thenReturn(startedAt); when(state.getFinishedAt()).thenReturn(finishedAt); return state; } }
/** * Based on this status, is this container running, and has it been doing so for the specified amount of time? * * @param state the state provided by InspectContainer * @param minimumRunningDuration minimum duration to consider this as "solidly" running, or null * @param now the time to consider as the current time * @return true if we can conclude that the container is running, false otherwise */ public static boolean isContainerRunning(InspectContainerResponse.ContainerState state, Duration minimumRunningDuration, Instant now) { if (state.getRunning()) { if (minimumRunningDuration == null) { return true; } Instant startedAt = DateTimeFormatter.ISO_INSTANT.parse( state.getStartedAt(), Instant::from); if (startedAt.isBefore(now.minus(minimumRunningDuration))) { return true; } } return false; }
try { InspectContainerResponse containerInfo = dockerClient.inspectContainerCmd(containerId).exec(); running = containerInfo.getState().getRunning(); } catch (NotFoundException e) { LOGGER.trace("Was going to stop container but it apparently no longer exists: {}", containerId);
dockerClient.startContainerCmd(exec.getId()).exec(); dockerClient.logContainerCmd(exec.getId()).withFollowStream(true).withStdErr(true).withStdOut(true).exec(callback); while (dockerClient.inspectContainerCmd(exec.getId()).exec().getState().getRunning()) { try { Thread.sleep(300);
try { InspectContainerResponse containerInfo = dockerClient.inspectContainerCmd(containerId).exec(); running = containerInfo.getState().getRunning(); } catch (NotFoundException e) { LOGGER.trace("Was going to stop container but it apparently no longer exists: {}", containerId);
if (!icr.getState().getRunning()) { return;
/** * Based on this status, is this container running, and has it been doing so for the specified amount of time? * * @param state the state provided by InspectContainer * @param minimumRunningDuration minimum duration to consider this as "solidly" running, or null * @param now the time to consider as the current time * @return true if we can conclude that the container is running, false otherwise */ public static boolean isContainerRunning(InspectContainerResponse.ContainerState state, Duration minimumRunningDuration, Instant now) { if (state.getRunning()) { if (minimumRunningDuration == null) { return true; } Instant startedAt = DateTimeFormatter.ISO_INSTANT.parse( state.getStartedAt(), Instant::from); if (startedAt.isBefore(now.minus(minimumRunningDuration))) { return true; } } return false; }
/** * Based on this status, has the container halted? * * @param state the state provided by InspectContainer * @return true if we can conclude that the container has started but is now stopped, false otherwise. */ public static boolean isContainerStopped(InspectContainerResponse.ContainerState state) { // get some preconditions out of the way if (state.getRunning() || state.getPaused()) { return false; } // if the finished timestamp is non-empty, that means the container started and finished. boolean hasStarted = isDockerTimestampNonEmpty(state.getStartedAt()); boolean hasFinished = isDockerTimestampNonEmpty(state.getFinishedAt()); return hasStarted && hasFinished; }
/** * @return is the container currently running? */ default boolean isRunning() { if (getContainerId() == null) { return false; } try { Boolean running = getCurrentContainerInfo().getState().getRunning(); return Boolean.TRUE.equals(running); } catch (DockerException e) { return false; } }
public ContainersAssert areRunning() { for (InspectContainerResponse container : this.actual) { ContainerStateAssert stateAssert = new ContainerStateAssert(container.getState()); stateAssert.isNotNull(); if (!container.getState().getRunning()) { failWithMessage("Container %s is not running", container.getName()); } } return this; } }
public boolean isRunningContainer(String containerName) { boolean isRunning = inspectContainer(containerName).getState().getRunning(); log.trace("Container {} is running: {}", containerName, isRunning); return isRunning; }
public boolean isRunningContainer(String containerName) { boolean isRunning = inspectContainer(containerName).getState().getRunning(); log.trace("Container {} is running: {}", containerName, isRunning); return isRunning; }
@Override public StartupStatus checkStartupState(DockerClient dockerClient, String containerId) { InspectContainerResponse.ContainerState state = getCurrentState(dockerClient, containerId); if (state.getRunning()) { return StartupStatus.SUCCESSFUL; } else if (!DockerStatus.isContainerExitCodeSuccess(state)) { return StartupStatus.FAILED; } else { return StartupStatus.NOT_YET_KNOWN; } } }
private static boolean isRunning(InspectContainerResponse containerInfo) { try { return containerInfo != null && containerInfo.getState().getRunning(); } catch (DockerException e) { return false; } }
public ContainerAssert isRunning() { ContainerStateAssert stateAssert = new ContainerStateAssert(getContainerState()); stateAssert.isNotNull(); if (!getContainerState().getRunning()) { failWithMessage("Expected container's state running to be %s but was %s", true, false); } return this; }
public final ComputerLauncher createLauncher(final DockerAPI api, @Nonnull final String containerId, String workdir, TaskListener listener) throws IOException, InterruptedException { final InspectContainerResponse inspect; try(final DockerClient client = api.getClient()) { inspect = client.inspectContainerCmd(containerId).exec(); } final ComputerLauncher launcher = createLauncher(api, workdir, inspect, listener); final Boolean running = inspect.getState().getRunning(); if (Boolean.FALSE.equals(running)) { listener.error("Container {} is not running. {}", containerId, inspect.getState().getStatus()); throw new IOException("Container is not running."); } return new DockerDelegatingComputerLauncher(launcher, api, containerId); }
/** * Based on this status, has the container halted? * * @param state the state provided by InspectContainer * @return true if we can conclude that the container has started but is now stopped, false otherwise. */ public static boolean isContainerStopped(InspectContainerResponse.ContainerState state) { // get some preconditions out of the way if (state.getRunning() || state.getPaused()) { return false; } // if the finished timestamp is non-empty, that means the container started and finished. boolean hasStarted = isDockerTimestampNonEmpty(state.getStartedAt()); boolean hasFinished = isDockerTimestampNonEmpty(state.getFinishedAt()); return hasStarted && hasFinished; }
/** * @return is the container currently running? */ default boolean isRunning() { if (getContainerId() == null) { return false; } try { Boolean running = getCurrentContainerInfo().getState().getRunning(); return Boolean.TRUE.equals(running); } catch (DockerException e) { return false; } }
@Override public StartupStatus checkStartupState(DockerClient dockerClient, String containerId) { InspectContainerResponse.ContainerState state = getCurrentState(dockerClient, containerId); if (state.getRunning()) { return StartupStatus.SUCCESSFUL; } else if (!DockerStatus.isContainerExitCodeSuccess(state)) { return StartupStatus.FAILED; } else { return StartupStatus.NOT_YET_KNOWN; } } }
private boolean isRunning(InspectContainerResponse containerInfo) { try { return containerInfo != null && containerInfo.getState().getRunning(); } catch (DockerException e) { return false; } } }