@@ -145,13 +145,18 @@ public class FTPConfig extends PluginConfig implements FileSourceProperties {
145
145
"value will only be used if the format is 'csv', 'tsv' or 'delimited'. The default value is false." )
146
146
protected Boolean enableMultilineSupport ;
147
147
148
+ @ Macro
149
+ @ Nullable
150
+ @ Description ("Maximum time in milliseconds to wait for connection initialization before time out." )
151
+ private final Integer connectTimeout ;
152
+
148
153
@ VisibleForTesting
149
154
private FTPConfig (@ Nullable String referenceName , String type , String host , @ Nullable Integer port , String path ,
150
155
String user , String password , @ Nullable String fileSystemProperties ,
151
156
@ Nullable Boolean ignoreNonExistingFolders , @ Nullable String fileRegex ,
152
157
@ Nullable Boolean skipHeader , @ Nullable String format , @ Nullable String schema ,
153
158
@ Nullable String delimiter , @ Nullable Boolean enableQuotedValues ,
154
- @ Nullable Boolean enableMultilineSupport ) {
159
+ @ Nullable Boolean enableMultilineSupport , @ Nullable Integer connectTimeout ) {
155
160
this .referenceName = referenceName ;
156
161
this .type = type ;
157
162
this .host = host ;
@@ -168,6 +173,14 @@ private FTPConfig(@Nullable String referenceName, String type, String host, @Nul
168
173
this .delimiter = delimiter ;
169
174
this .enableQuotedValues = enableQuotedValues ;
170
175
this .enableMultilineSupport = enableMultilineSupport ;
176
+ this .connectTimeout = connectTimeout ;
177
+ }
178
+
179
+ public int getConnectTimeout () {
180
+ if (connectTimeout == null ) {
181
+ return FTPFileSystem .DEFAULT_CONNECTION_TIMEOUT_MS ;
182
+ }
183
+ return connectTimeout ;
171
184
}
172
185
173
186
@ Override
@@ -186,10 +199,9 @@ public void validate(FailureCollector collector) {
186
199
for (Map .Entry <String , String > entry : location .getHadoopProperties ().entrySet ()) {
187
200
conf .set (entry .getKey (), entry .getValue ());
188
201
}
202
+ conf .setInt (FTPFileSystem .FS_CONNECT_TIMEOUT , getConnectTimeout ());
189
203
try (FileSystem fs = JobUtils .applyWithExtraClassLoader (job , getClass ().getClassLoader (),
190
204
f -> FileSystem .get (location .getURI (), conf ))) {
191
- // TODO: Add setTimeout option in the future
192
- // https://cdap.atlassian.net/browse/PLUGIN-1181
193
205
fs .getFileStatus (new Path (location .getURI ()));
194
206
}
195
207
} catch (Exception e ) {
@@ -371,6 +383,7 @@ static class Builder {
371
383
private boolean skipHeader ;
372
384
private boolean enableQuotedValues ;
373
385
private boolean enableMultilineSupport ;
386
+ private Integer connectTimeout ;
374
387
375
388
Builder () {
376
389
this .fileSystemProperties = new HashMap <>();
@@ -379,6 +392,7 @@ static class Builder {
379
392
this .enableMultilineSupport = false ;
380
393
this .skipHeader = false ;
381
394
this .format = "text" ;
395
+ this .connectTimeout = FTPFileSystem .DEFAULT_CONNECTION_TIMEOUT_MS ;
382
396
}
383
397
384
398
Builder setType (FTPLocation .Type type ) {
@@ -462,11 +476,16 @@ Builder setEnableMultilineSupport(boolean enableMultilineSupport) {
462
476
return this ;
463
477
}
464
478
479
+ Builder setConnectTimeout (Integer connectTimeout ) {
480
+ this .connectTimeout = connectTimeout ;
481
+ return this ;
482
+ }
483
+
465
484
FTPConfig build () {
466
485
return new FTPConfig (referenceName , type .name (), host , port , path , user , password ,
467
486
GSON .toJson (fileSystemProperties ), ignoreNonExistingFolders , fileRegex , skipHeader ,
468
487
format , schema == null ? null : schema .toString (), delimiter , enableQuotedValues ,
469
- enableMultilineSupport );
488
+ enableMultilineSupport , connectTimeout );
470
489
}
471
490
}
472
491
}
0 commit comments