Package atessera.sensei.util
Class DockerContainer
java.lang.Object
atessera.sensei.util.DockerContainer
- All Implemented Interfaces:
AutoCloseable
Represents a Docker container managed by
DockerRunner.
Implements AutoCloseable to guarantee container cleanup. It provides
non-blocking execution management, container status inspection, truncated log retrieving,
and graceful/forced termination commands.
-
Constructor Summary
ConstructorsConstructorDescriptionDockerContainer(String dockerExecutable, String containerId, ResourceQuota quota) Creates a new Docker container reference. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Guarantees container cleanup.getLogs()Captures current container logs (stdout and stderr), truncated toquota.maxLogBytes.id()Returns the container identifier.booleanChecks whether the container is currently running.voidkill()Forces immediate container termination usingdocker kill.voidremove()Forces removal of the container usingdocker rm -f.voidstop(long timeoutSeconds) Gracefully stops the container with a timeout.intwaitFor(long timeoutSeconds) Waits for the container to finish execution within the specified timeout.
-
Constructor Details
-
DockerContainer
Creates a new Docker container reference.- Parameters:
dockerExecutable- path or name of the Docker CLI executablecontainerId- full or short Docker container IDquota- resource quota containing limits for log size and timeouts
-
-
Method Details
-
id
Returns the container identifier.- Returns:
- container ID string
-
isRunning
public boolean isRunning()Checks whether the container is currently running.- Returns:
trueif running,falseotherwise
-
waitFor
public int waitFor(long timeoutSeconds) Waits for the container to finish execution within the specified timeout. If the execution times out, the container is gracefully stopped and killed.- Parameters:
timeoutSeconds- maximum duration to wait in seconds- Returns:
- exit code of the process inside the container, or -1 on timeout or interruption
-
getLogs
Captures current container logs (stdout and stderr), truncated toquota.maxLogBytes.- Returns:
- accumulated container logs
-
stop
public void stop(long timeoutSeconds) Gracefully stops the container with a timeout. If it does not stop in time, forces termination.- Parameters:
timeoutSeconds- timeout for graceful stop
-
kill
public void kill()Forces immediate container termination usingdocker kill. -
remove
public void remove()Forces removal of the container usingdocker rm -f. -
close
public void close()Guarantees container cleanup. If the container is still running, stops and forcibly removes it.- Specified by:
closein interfaceAutoCloseable
-