@@ -58,7 +58,7 @@ public DockerService(Config config, StartupScriptsService startupScriptsService)
5858 pullImage ();
5959 }
6060 cleanupLeftovers (WORKER_UNIQUE_ID );
61- executor .submit (() -> initializeCachedContainer (StartupScriptId .EMPTY ));
61+ executor .submit (() -> initializeCachedContainer (StartupScriptId .CUSTOM_DEFAULT ));
6262 }
6363
6464 private void cleanupLeftovers (UUID currentId ) {
@@ -106,6 +106,7 @@ private void pullImage() throws InterruptedException {
106106 * @return The ID of the created container.
107107 */
108108 private String createContainer (String name ) {
109+ LOGGER .debug ("Creating container '{}'" , name );
109110 HostConfig hostConfig = HostConfig .newHostConfig ()
110111 .withAutoRemove (true )
111112 .withInit (true )
@@ -137,10 +138,13 @@ private String createContainer(String name) {
137138 *
138139 * @param name Name of the container.
139140 * @param startupScriptId Script to initialize the container with.
141+ * @throws IOException if an I/O error occurs.
140142 * @return The ContainerState of the newly created container.
141143 */
142144 public ContainerState initializeContainer (String name , StartupScriptId startupScriptId )
143145 throws IOException {
146+ LOGGER .info ("Initializing container '{}' with Startup script ID: {}" , name ,
147+ startupScriptId );
144148 if (startupScriptId == null || cachedContainers .isEmpty ()
145149 || !cachedContainers .containsKey (startupScriptId )) {
146150 String containerId = createContainer (name );
@@ -159,27 +163,34 @@ public ContainerState initializeContainer(String name, StartupScriptId startupSc
159163 * @param startupScriptId Script to initialize the container with.
160164 */
161165 private void initializeCachedContainer (StartupScriptId startupScriptId ) {
162- String containerName = cachedContainerName ();
166+ LOGGER .info ("Initializing cached container with Startup script ID: {}" , startupScriptId );
167+ String containerName = newCachedContainerName ();
163168 String id = createContainer (containerName );
164169 startContainer (id );
165170
166171 try {
167172 ContainerState containerState = setupContainerWithScript (id , startupScriptId );
168173 cachedContainers .put (startupScriptId , containerState );
169174 } catch (IOException e ) {
175+ LOGGER .error ("Could not initialize container '{}'" , id , e );
170176 killContainerByName (containerName );
171177 throw new RuntimeException (e );
172178 }
173179 }
174180
175181 /**
182+ * Setup container with startup script and also initializes input and output streams for the
183+ * container.
184+ *
176185 * @param containerId The id of the container
177186 * @param startupScriptId The startup script id of the session
178187 * @return ContainerState of the spawned container.
179188 * @throws IOException if an I/O error occurs
180189 */
181190 private ContainerState setupContainerWithScript (String containerId ,
182191 StartupScriptId startupScriptId ) throws IOException {
192+ LOGGER .info ("Setting up container with id '{}' with Startup script ID: {}" , containerId ,
193+ startupScriptId );
183194 startContainer (containerId );
184195 PipedInputStream containerInput = new PipedInputStream ();
185196 BufferedWriter writer =
@@ -257,7 +268,7 @@ public boolean isContainerRunning(String containerId) {
257268 return Boolean .TRUE .equals (containerResponse .getState ().getRunning ());
258269 }
259270
260- private String cachedContainerName () {
271+ private String newCachedContainerName () {
261272 return "cached_session_" + UUID .randomUUID ();
262273 }
263274
0 commit comments