private boolean isRunning(InspectContainerResponse containerInfo) { try { return containerInfo != null && containerInfo.getState().getRunning(); } catch (DockerException e) { return false; } } }
protected InspectContainerResponse.ContainerState getCurrentState(DockerClient dockerClient, String containerId) { return dockerClient.inspectContainerCmd(containerId).exec().getState(); }
/** * @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; } }
/** * @return has the container health state 'healthy'? */ default boolean isHealthy() { if (getContainerId() == null) { return false; } try { InspectContainerResponse inspectContainerResponse = getCurrentContainerInfo(); String healthStatus = inspectContainerResponse.getState().getHealth().getStatus(); return healthStatus.equals(STATE_HEALTHY); } catch (DockerException e) { return false; } }
/** * @return is the container created? */ default boolean isCreated() { if (getContainerId() == null) { return false; } try { String status = getCurrentContainerInfo().getState().getStatus(); return "created".equalsIgnoreCase(status) || isRunning(); } catch (DockerException e) { 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);
@Override public void invoke() { super.start(); this.followOutput(new Slf4jLogConsumer(logger())); // wait for the compose container to stop, which should only happen after it has spawned all the service containers logger().info("Docker Compose container is running for command: {}", Joiner.on(" ").join(this.getCommandParts())); while (this.isRunning()) { logger().trace("Compose container is still running"); Uninterruptibles.sleepUninterruptibly(100, TimeUnit.MILLISECONDS); } logger().info("Docker Compose has finished running"); AuditLogger.doComposeLog(this.getCommandParts(), this.getEnv()); final Integer exitCode = this.dockerClient.inspectContainerCmd(containerId) .exec() .getState() .getExitCode(); if (exitCode == null || exitCode != 0) { throw new ContainerLaunchException( "Containerised Docker Compose exited abnormally with code " + exitCode + " whilst running command: " + StringUtils.join(this.getCommandParts(), ' ')); } } }
private static boolean isRunning(InspectContainerResponse containerInfo) { try { return containerInfo != null && containerInfo.getState().getRunning(); } catch (DockerException e) { return false; } }
/** * return container last start epoch time * * @param id container id * @return long epoch time */ public long getContainerStartedAt(String id) { InspectContainerResponse inspectInfo = dockerClient.inspectContainerCmd(id).exec(); String startedAt = inspectInfo.getState().getStartedAt(); return startedAt != null ? DateTimeFormatter.ISO_INSTANT.parse(startedAt, Instant::from).toEpochMilli() : Instant.now().toEpochMilli(); }
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; }
public Optional<String> getContainerStatus(String containerId) { Optional<String> result = Optional.empty(); try { InspectContainerResponse inspectInfo = dockerClient.inspectContainerCmd(containerId).exec(); ContainerState status = inspectInfo.getState(); result = Optional.ofNullable(status.getStatus()); } catch (Exception exp) { logWarning(MODULE_NAME, exp.getMessage()); } return result; }
protected InspectContainerResponse.ContainerState getCurrentState(DockerClient dockerClient, String containerId) { return dockerClient.inspectContainerCmd(containerId).exec().getState(); }
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; } }
/** * @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 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); }
public List<Container> getRunningContainers() { return getContainers().stream() .filter(container -> { InspectContainerResponse inspectInfo = dockerClient.inspectContainerCmd(container.getId()).exec(); ContainerState containerState = inspectInfo.getState(); return containerState != null && containerState.getStatus() != null && MicroserviceState.fromText(containerState.getStatus()) == MicroserviceState.RUNNING; }) .collect(Collectors.toList()); }
/** * @return is the container created? */ default boolean isCreated() { if (getContainerId() == null) { return false; } try { String status = getCurrentContainerInfo().getState().getStatus(); return "created".equalsIgnoreCase(status) || isRunning(); } catch (DockerException e) { return false; } }
private Stream<Container> asContainer(String container) { return inspectContainerCmd(container) .map(response -> new Container( response.getConfig().getHostName(), new DockerImage(response.getConfig().getImage()), containerResourcesFromHostConfig(response.getHostConfig()), new ContainerName(decode(response.getName())), Container.State.valueOf(response.getState().getStatus().toUpperCase()), response.getState().getPid() )) .map(Stream::of) .orElse(Stream.empty()); }
@Override public void invoke() { super.start(); this.followOutput(new Slf4jLogConsumer(logger())); // wait for the compose container to stop, which should only happen after it has spawned all the service containers logger().info("Docker Compose container is running for command: {}", Joiner.on(" ").join(this.getCommandParts())); while (this.isRunning()) { logger().trace("Compose container is still running"); Uninterruptibles.sleepUninterruptibly(100, TimeUnit.MILLISECONDS); } logger().info("Docker Compose has finished running"); AuditLogger.doComposeLog(this.getCommandParts(), this.getEnv()); final Integer exitCode = this.dockerClient.inspectContainerCmd(containerId).exec().getState().getExitCode(); if (exitCode == null || exitCode != 0) { throw new ContainerLaunchException("Containerised Docker Compose exited abnormally with code " + exitCode + " whilst running command: " + StringUtils.join(this.getCommandParts(), ' ')); } } }