@@ -91,7 +91,7 @@ public class DockerSessionFactory implements SessionFactory {
91
91
private final Capabilities stereotype ;
92
92
private boolean isVideoRecordingAvailable ;
93
93
private Image videoImage ;
94
- private String assetsPath ;
94
+ private DockerSessionAssetsPath assetsPath ;
95
95
96
96
public DockerSessionFactory (
97
97
Tracer tracer ,
@@ -110,8 +110,15 @@ public DockerSessionFactory(
110
110
this .isVideoRecordingAvailable = false ;
111
111
}
112
112
113
- public DockerSessionFactory (Tracer tracer , HttpClient .Factory clientFactory , Docker docker , URI dockerUri ,
114
- Image browserImage , Capabilities stereotype , Image videoImage , String assetsPath ) {
113
+ public DockerSessionFactory (
114
+ Tracer tracer ,
115
+ HttpClient .Factory clientFactory ,
116
+ Docker docker ,
117
+ URI dockerUri ,
118
+ Image browserImage ,
119
+ Capabilities stereotype ,
120
+ Image videoImage ,
121
+ DockerSessionAssetsPath assetsPath ) {
115
122
this (tracer , clientFactory , docker , dockerUri , browserImage , stereotype );
116
123
this .isVideoRecordingAvailable = true ;
117
124
this .videoImage = videoImage ;
@@ -201,16 +208,17 @@ public Optional<ActiveSession> apply(CreateSessionRequest sessionRequest) {
201
208
202
209
SessionId id = new SessionId (response .getSessionId ());
203
210
Capabilities capabilities = new ImmutableCapabilities ((Map <?, ?>) response .getValue ());
204
- Optional <Path > sessionAssetsPath = createSessionAssetsPath ( assetsPath , id );
205
- sessionAssetsPath .ifPresent (path -> saveSessionCapabilities (capabilities , path ));
211
+ Optional <Path > containerAssetsPath = assetsPath . createContainerSessionAssetsPath ( id );
212
+ containerAssetsPath .ifPresent (path -> saveSessionCapabilities (capabilities , path ));
206
213
Container videoContainer = null ;
207
214
if (isVideoRecordingAvailable && recordVideoForSession (capabilities )) {
208
215
Map <String , String > envVars = getVideoContainerEnvVars (
209
216
capabilities ,
210
217
containerInfo .getIp ());
211
- if (sessionAssetsPath .isPresent ()) {
218
+ Optional <Path > hostAssetsPath = assetsPath .createHostSessionAssetsPath (id );
219
+ if (hostAssetsPath .isPresent ()) {
212
220
Map <String , String > volumeBinds =
213
- Collections .singletonMap (sessionAssetsPath .get ().toString (), "/videos" );
221
+ Collections .singletonMap (hostAssetsPath .get ().toString (), "/videos" );
214
222
videoContainer = docker .create (image (videoImage ).env (envVars ).bind (volumeBinds ));
215
223
videoContainer .start ();
216
224
LOG .info (String .format ("Video container started (id: %s)" , videoContainer .getId ()));
@@ -320,16 +328,6 @@ private Object getCapability(Capabilities sessionRequestCapabilities, String cap
320
328
return null ;
321
329
}
322
330
323
- private Optional <Path > createSessionAssetsPath (String assetsPath , SessionId id ) {
324
- try {
325
- return Optional .of (Files .createDirectories (Paths .get (assetsPath , id .toString ())));
326
- } catch (IOException e ) {
327
- LOG .log (Level .WARNING ,
328
- "Failed to create path to store session assets, no assets will be stored" , e );
329
- }
330
- return Optional .empty ();
331
- }
332
-
333
331
private void saveSessionCapabilities (Capabilities sessionRequestCapabilities , Path assetsPath ) {
334
332
String capsToJson = new Json ().toJson (sessionRequestCapabilities );
335
333
try {
0 commit comments