@@ -280,14 +280,17 @@ public int run(final String[] args, final PrintStream stream)
280
280
path = new Path (path , "/" );
281
281
}
282
282
FileSystem fs = path .getFileSystem (getConf ());
283
+ boolean nonAuth = command .getOpt (OPT_NONAUTH );
283
284
ScanResult result = execute (
284
- fs ,
285
- path ,
286
- clean ,
287
- expectedMin ,
288
- expectedMax ,
289
- limit ,
290
- command .getOpt (OPT_NONAUTH ));
285
+ new ScanArgsBuilder ()
286
+ .withSourceFS (fs )
287
+ .withPath (path )
288
+ .withDoPurge (clean )
289
+ .withMinMarkerCount (expectedMin )
290
+ .withMaxMarkerCount (expectedMax )
291
+ .withLimit (limit )
292
+ .withNonAuth (nonAuth )
293
+ .build ());
291
294
if (verbose ) {
292
295
dumpFileSystemStatistics (out );
293
296
}
@@ -329,7 +332,8 @@ private int getOptValue(String option, int defVal) {
329
332
return Integer .parseInt (value );
330
333
} catch (NumberFormatException e ) {
331
334
throw new ExitUtil .ExitException (EXIT_USAGE ,
332
- String .format ("Argument for %s is not a number: %s" , option , value ));
335
+ String .format ("Argument for %s is not a number: %s" ,
336
+ option , value ));
333
337
}
334
338
} else {
335
339
return defVal ;
@@ -338,27 +342,14 @@ private int getOptValue(String option, int defVal) {
338
342
339
343
/**
340
344
* Execute the scan/purge.
341
- * @param sourceFS source FS; must be or wrap an S3A FS.
342
- * @param path path to scan.
343
- * @param doPurge purge?
344
- * @param minMarkerCount min marker count (ignored on purge)
345
- * @param maxMarkerCount max marker count (ignored on purge)
346
- * @param limit limit of files to scan; 0 for 'unlimited'
347
- * @param nonAuth consider only markers in nonauth paths as errors
348
- * @return scan+purge result.
345
+ *
346
+ * @param scanArgs@return scan+purge result.
349
347
* @throws IOException failure
350
348
*/
351
349
@ VisibleForTesting
352
- ScanResult execute (
353
- final FileSystem sourceFS ,
354
- final Path path ,
355
- final boolean doPurge ,
356
- final int minMarkerCount ,
357
- final int maxMarkerCount ,
358
- final int limit ,
359
- final boolean nonAuth )
350
+ ScanResult execute (final ScanArgs scanArgs )
360
351
throws IOException {
361
- S3AFileSystem fs = bindFilesystem (sourceFS );
352
+ S3AFileSystem fs = bindFilesystem (scanArgs . getSourceFS () );
362
353
363
354
// extract the callbacks needed for the rest of the work
364
355
storeContext = fs .createStoreContext ();
@@ -379,6 +370,7 @@ ScanResult execute(
379
370
println (out , "Authoritative path list is \" %s\" " , authPath );
380
371
}
381
372
// qualify the path
373
+ Path path = scanArgs .getPath ();
382
374
Path target = path .makeQualified (fs .getUri (), new Path ("/" ));
383
375
// initial safety check: does the path exist?
384
376
try {
@@ -396,18 +388,18 @@ ScanResult execute(
396
388
397
389
// the default filter policy is that all entries should be deleted
398
390
DirectoryPolicy filterPolicy ;
399
- if (nonAuth ) {
391
+ if (scanArgs . isNonAuth () ) {
400
392
filterPolicy = new DirectoryPolicyImpl (
401
393
DirectoryPolicy .MarkerPolicy .Authoritative ,
402
394
fs ::allowAuthoritative );
403
395
} else {
404
396
filterPolicy = null ;
405
397
}
406
398
ScanResult result = scan (target ,
407
- doPurge ,
408
- maxMarkerCount ,
409
- minMarkerCount ,
410
- limit ,
399
+ scanArgs . isDoPurge () ,
400
+ scanArgs . getMaxMarkerCount () ,
401
+ scanArgs . getMinMarkerCount () ,
402
+ scanArgs . getLimit () ,
411
403
filterPolicy );
412
404
return result ;
413
405
}
@@ -434,7 +426,7 @@ public static final class ScanResult {
434
426
435
427
/**
436
428
* Count of all markers found after excluding
437
- * any from a [-nonauth] qualification;
429
+ * any from a [-nonauth] qualification.
438
430
*/
439
431
private int filteredMarkerCount ;
440
432
@@ -619,7 +611,11 @@ private ScanResult scan(
619
611
* @param args arguments for the error message
620
612
* @return scan result
621
613
*/
622
- private ScanResult failScan (ScanResult result , int code , String message , Object ...args ) {
614
+ private ScanResult failScan (
615
+ ScanResult result ,
616
+ int code ,
617
+ String message ,
618
+ Object ...args ) {
623
619
String text = String .format (message , args );
624
620
result .exitCode = code ;
625
621
result .exitText = text ;
@@ -688,7 +684,7 @@ private boolean scanDirectoryTree(
688
684
* Result of a call of {@link #purgeMarkers(DirMarkerTracker, int)};
689
685
* included in {@link ScanResult} so must share visibility.
690
686
*/
691
- static final class MarkerPurgeSummary {
687
+ public static final class MarkerPurgeSummary {
692
688
693
689
/** Number of markers deleted. */
694
690
private int markersDeleted ;
@@ -714,14 +710,26 @@ public String toString() {
714
710
}
715
711
716
712
713
+ /**
714
+ * Count of markers deleted.
715
+ * @return a number, zero when prune==false.
716
+ */
717
717
int getMarkersDeleted () {
718
718
return markersDeleted ;
719
719
}
720
720
721
+ /**
722
+ * Count of bulk delete requests issued.
723
+ * @return count of calls made to S3.
724
+ */
721
725
int getDeleteRequests () {
722
726
return deleteRequests ;
723
727
}
724
728
729
+ /**
730
+ * Total duration of delete requests.
731
+ * @return a time interval in millis.
732
+ */
725
733
long getTotalDeleteRequestDuration () {
726
734
return totalDeleteRequestDuration ;
727
735
}
@@ -800,28 +808,173 @@ public void setVerbose(final boolean verbose) {
800
808
/**
801
809
* Execute the marker tool, with no checks on return codes.
802
810
*
803
- * @param sourceFS filesystem to use
804
- * @param path path to scan
805
- * @param doPurge should markers be purged
806
- * @param minMarkerCount min marker count (ignored on purge)
807
- * @param maxMarkerCount max marker count (ignored on purge)
808
- * @param limit limit of files to scan; -1 for 'unlimited'
809
- * @param nonAuth only use nonauth path count for failure rules
811
+ * @param scanArgs set of args for the scanner.
810
812
* @return the result
811
813
*/
812
814
@ SuppressWarnings ("IOResourceOpenedButNotSafelyClosed" )
813
815
public static MarkerTool .ScanResult execMarkerTool (
814
- final FileSystem sourceFS ,
815
- final Path path ,
816
- final boolean doPurge ,
817
- final int minMarkerCount ,
818
- final int maxMarkerCount ,
819
- final int limit ,
820
- boolean nonAuth ) throws IOException {
821
- MarkerTool tool = new MarkerTool (sourceFS .getConf ());
816
+ ScanArgs scanArgs ) throws IOException {
817
+ MarkerTool tool = new MarkerTool (scanArgs .getSourceFS ().getConf ());
822
818
tool .setVerbose (LOG .isDebugEnabled ());
823
819
824
- return tool .execute (sourceFS , path , doPurge ,
825
- minMarkerCount , maxMarkerCount , limit , nonAuth );
820
+ return tool .execute (scanArgs );
821
+ }
822
+
823
+ /**
824
+ * Arguments for the scan.
825
+ * <p></p>
826
+ * Uses a builder/argument object because too many arguments were
827
+ * being created and it was making maintenance harder.
828
+ */
829
+ public static final class ScanArgs {
830
+
831
+ /** Source FS; must be or wrap an S3A FS. */
832
+ private final FileSystem sourceFS ;
833
+
834
+ /** Path to scan. */
835
+ private final Path path ;
836
+
837
+ /** Purge? */
838
+ private final boolean doPurge ;
839
+
840
+ /** Min marker count (ignored on purge). */
841
+ private final int minMarkerCount ;
842
+
843
+ /** Max marker count (ignored on purge). */
844
+ private final int maxMarkerCount ;
845
+
846
+ /** Limit of files to scan; 0 for 'unlimited'. */
847
+ private final int limit ;
848
+
849
+ /** Consider only markers in nonauth paths as errors. */
850
+ private final boolean nonAuth ;
851
+
852
+ /**
853
+ * @param sourceFS source FS; must be or wrap an S3A FS.
854
+ * @param path path to scan.
855
+ * @param doPurge purge?
856
+ * @param minMarkerCount min marker count (ignored on purge)
857
+ * @param maxMarkerCount max marker count (ignored on purge)
858
+ * @param limit limit of files to scan; 0 for 'unlimited'
859
+ * @param nonAuth consider only markers in nonauth paths as errors
860
+ */
861
+ private ScanArgs (final FileSystem sourceFS ,
862
+ final Path path ,
863
+ final boolean doPurge ,
864
+ final int minMarkerCount ,
865
+ final int maxMarkerCount ,
866
+ final int limit ,
867
+ final boolean nonAuth ) {
868
+ this .sourceFS = sourceFS ;
869
+ this .path = path ;
870
+ this .doPurge = doPurge ;
871
+ this .minMarkerCount = minMarkerCount ;
872
+ this .maxMarkerCount = maxMarkerCount ;
873
+ this .limit = limit ;
874
+ this .nonAuth = nonAuth ;
875
+ }
876
+
877
+ FileSystem getSourceFS () {
878
+ return sourceFS ;
879
+ }
880
+
881
+ Path getPath () {
882
+ return path ;
883
+ }
884
+
885
+ boolean isDoPurge () {
886
+ return doPurge ;
887
+ }
888
+
889
+ int getMinMarkerCount () {
890
+ return minMarkerCount ;
891
+ }
892
+
893
+ int getMaxMarkerCount () {
894
+ return maxMarkerCount ;
895
+ }
896
+
897
+ int getLimit () {
898
+ return limit ;
899
+ }
900
+
901
+ boolean isNonAuth () {
902
+ return nonAuth ;
903
+ }
904
+ }
905
+
906
+ /**
907
+ * Builder of the scan arguments.
908
+ */
909
+ public static final class ScanArgsBuilder {
910
+
911
+ /** Source FS; must be or wrap an S3A FS. */
912
+ private FileSystem sourceFS ;
913
+
914
+ /** Path to scan. */
915
+ private Path path ;
916
+
917
+ /** Purge? */
918
+ private boolean doPurge = false ;
919
+
920
+ /** Min marker count (ignored on purge). */
921
+ private int minMarkerCount = 0 ;
922
+
923
+ /** Max marker count (ignored on purge). */
924
+ private int maxMarkerCount = 0 ;
925
+
926
+ /** Limit of files to scan; 0 for 'unlimited'. */
927
+ private int limit = UNLIMITED_LISTING ;
928
+
929
+ /** Consider only markers in nonauth paths as errors. */
930
+ private boolean nonAuth = false ;
931
+
932
+ /** Source FS; must be or wrap an S3A FS. */
933
+ public ScanArgsBuilder withSourceFS (final FileSystem sourceFS ) {
934
+ this .sourceFS = sourceFS ;
935
+ return this ;
936
+ }
937
+
938
+ /** Path to scan. */
939
+ public ScanArgsBuilder withPath (final Path path ) {
940
+ this .path = path ;
941
+ return this ;
942
+ }
943
+
944
+ /** Purge? */
945
+ public ScanArgsBuilder withDoPurge (final boolean doPurge ) {
946
+ this .doPurge = doPurge ;
947
+ return this ;
948
+ }
949
+
950
+ /** Min marker count (ignored on purge). */
951
+ public ScanArgsBuilder withMinMarkerCount (final int minMarkerCount ) {
952
+ this .minMarkerCount = minMarkerCount ;
953
+ return this ;
954
+ }
955
+
956
+ /** Max marker count (ignored on purge). */
957
+ public ScanArgsBuilder withMaxMarkerCount (final int maxMarkerCount ) {
958
+ this .maxMarkerCount = maxMarkerCount ;
959
+ return this ;
960
+ }
961
+
962
+ /** Limit of files to scan; 0 for 'unlimited'. */
963
+ public ScanArgsBuilder withLimit (final int limit ) {
964
+ this .limit = limit ;
965
+ return this ;
966
+ }
967
+
968
+ /** Consider only markers in nonauth paths as errors. */
969
+ public ScanArgsBuilder withNonAuth (final boolean nonAuth ) {
970
+ this .nonAuth = nonAuth ;
971
+ return this ;
972
+ }
973
+
974
+ public ScanArgs build () {
975
+ return new ScanArgs (sourceFS , path , doPurge , minMarkerCount ,
976
+ maxMarkerCount ,
977
+ limit , nonAuth );
978
+ }
826
979
}
827
980
}
0 commit comments