@@ -75,6 +75,16 @@ public abstract class SpoolDirSourceConnectorConfig extends AbstractConfig {
75
75
public static final String SCHEMA_GENERATION_VALUE_NAME_CONF = "schema.generation.value.name" ;
76
76
public static final String SCHEMA_GENERATION_ENABLED_CONF = "schema.generation.enabled" ;
77
77
public static final String METADATA_SCHEMA_NAME = "com.github.jcustenborder.kafka.connect.spooldir.Metadata" ;
78
+ public static final String CLEANUP_POLICY_CONF = "cleanup.policy" ;
79
+ public static final String CLEANUP_POLICY_DOC = "Determines how the connector should cleanup the " +
80
+ "files that have been successfully processed. NONE leaves the files in place which could " +
81
+ "cause them to be reprocessed if the connector is restarted. DELETE removes the file from the " +
82
+ "filesystem. MOVE will move the file to a finished directory." ;
83
+ public static final String GROUP_FILESYSTEM = "File System" ;
84
+ public static final String GROUP_SCHEMA_GENERATION = "Schema Generation" ;
85
+ public static final String GROUP_SCHEMA = "Schema" ;
86
+ public static final String GROUP_GENERAL = "General" ;
87
+ public static final String GROUP_TIMESTAMP = "Timestamps" ;
78
88
static final String TIMESTAMP_FIELD_DOC = "The field in the value schema that will contain the parsed timestamp for the record. " +
79
89
"This field cannot be marked as optional and must be a " +
80
90
"[Timestamp](https://kafka.apache.org/0102/javadoc/org/apache/kafka/connect/data/Schema.html)" ;
@@ -137,11 +147,18 @@ public abstract class SpoolDirSourceConnectorConfig extends AbstractConfig {
137
147
public final String schemaGenerationValueName ;
138
148
public boolean hasKeyMetadataField ;
139
149
public boolean hasvalueMetadataField ;
140
-
150
+ public CleanupPolicy cleanupPolicy ;
141
151
public SpoolDirSourceConnectorConfig (final boolean isTask , ConfigDef configDef , Map <String , ?> settings ) {
142
152
super (configDef , settings );
143
153
this .inputPath = ConfigUtils .getAbsoluteFile (this , INPUT_PATH_CONFIG );
144
- this .finishedPath = ConfigUtils .getAbsoluteFile (this , FINISHED_PATH_CONFIG );
154
+ this .cleanupPolicy = ConfigUtils .getEnum (CleanupPolicy .class , this , CLEANUP_POLICY_CONF );
155
+
156
+ if (CleanupPolicy .MOVE == this .cleanupPolicy ) {
157
+ this .finishedPath = ConfigUtils .getAbsoluteFile (this , FINISHED_PATH_CONFIG );
158
+ } else {
159
+ this .finishedPath = null ;
160
+ }
161
+
145
162
this .errorPath = ConfigUtils .getAbsoluteFile (this , ERROR_PATH_CONFIG );
146
163
this .haltOnError = this .getBoolean (HALT_ON_ERROR_CONF );
147
164
this .minimumFileAgeMS = this .getLong (FILE_MINIMUM_AGE_MS_CONF );
@@ -271,9 +288,6 @@ public SpoolDirSourceConnectorConfig(final boolean isTask, ConfigDef configDef,
271
288
this .inputFilenameFilter = new PatternFilenameFilter (inputPattern );
272
289
}
273
290
274
- public abstract boolean schemasRequired ();
275
-
276
-
277
291
private static final Field findMetadataField (Schema schema ) {
278
292
Field result = null ;
279
293
for (Field field : schema .fields ()) {
@@ -287,12 +301,6 @@ private static final Field findMetadataField(Schema schema) {
287
301
return result ;
288
302
}
289
303
290
- public static final String GROUP_FILESYSTEM = "File System" ;
291
- public static final String GROUP_SCHEMA_GENERATION = "Schema Generation" ;
292
- public static final String GROUP_SCHEMA = "Schema" ;
293
- public static final String GROUP_GENERAL = "General" ;
294
- public static final String GROUP_TIMESTAMP = "Timestamps" ;
295
-
296
304
public static ConfigDef config () {
297
305
298
306
ConfigDef .Recommender schemaRecommender = new ConfigDef .Recommender () {
@@ -325,6 +333,23 @@ public boolean visible(String key, Map<String, Object> settings) {
325
333
}
326
334
};
327
335
336
+ ConfigDef .Recommender finishedPath = new ConfigDef .Recommender () {
337
+ @ Override
338
+ public List <Object > validValues (String s , Map <String , Object > map ) {
339
+ return null ;
340
+ }
341
+
342
+ @ Override
343
+ public boolean visible (String s , Map <String , Object > map ) {
344
+ if (!FINISHED_PATH_CONFIG .equals (s )) {
345
+ return true ;
346
+ }
347
+
348
+ final String cleanupPolicy = (String ) map .get (CLEANUP_POLICY_CONF );
349
+ return CleanupPolicy .MOVE .toString ().equals (cleanupPolicy );
350
+ }
351
+ };
352
+
328
353
329
354
return new ConfigDef ()
330
355
@@ -351,7 +376,15 @@ public boolean visible(String key, Map<String, Object> settings) {
351
376
.group (GROUP_GENERAL )
352
377
.build ()
353
378
)
354
-
379
+ .define (
380
+ ConfigKeyBuilder .of (CLEANUP_POLICY_CONF , ConfigDef .Type .STRING )
381
+ .documentation (CLEANUP_POLICY_DOC )
382
+ .importance (ConfigDef .Importance .MEDIUM )
383
+ .validator (ValidEnum .of (CleanupPolicy .class ))
384
+ .defaultValue (CleanupPolicy .MOVE .toString ())
385
+ .group (GROUP_FILESYSTEM )
386
+ .build ()
387
+ )
355
388
// Filesystem
356
389
.define (
357
390
ConfigKeyBuilder .of (INPUT_PATH_CONFIG , ConfigDef .Type .STRING )
@@ -364,7 +397,8 @@ public boolean visible(String key, Map<String, Object> settings) {
364
397
ConfigKeyBuilder .of (FINISHED_PATH_CONFIG , ConfigDef .Type .STRING )
365
398
.documentation (FINISHED_PATH_DOC )
366
399
.importance (ConfigDef .Importance .HIGH )
367
- .validator (ValidDirectoryWritable .of ())
400
+ .defaultValue ("" )
401
+ .recommender (finishedPath )
368
402
.group (GROUP_FILESYSTEM )
369
403
.build ()
370
404
).define (
@@ -503,6 +537,8 @@ public boolean visible(String key, Map<String, Object> settings) {
503
537
);
504
538
}
505
539
540
+ public abstract boolean schemasRequired ();
541
+
506
542
Schema readSchema (final String key ) {
507
543
String schema = this .getString (key );
508
544
Schema result ;
@@ -525,4 +561,10 @@ public enum TimestampMode {
525
561
FILE_TIME ,
526
562
PROCESS_TIME
527
563
}
564
+
565
+ public enum CleanupPolicy {
566
+ NONE ,
567
+ DELETE ,
568
+ MOVE
569
+ }
528
570
}
0 commit comments