@@ -1017,96 +1017,103 @@ public FileVisitResult preVisitDirectory(Path dirPath, BasicFileAttributes dirAt
10171017 * @return TERMINATE if auto ingest is shutting down, CONTINUE if it has
10181018 * not.
10191019 *
1020- * @throws IOException if an I/O error occurs, but this implementation
1021- * does not throw.
10221020 */
10231021 @ Override
1024- public FileVisitResult visitFile (Path filePath , BasicFileAttributes attrs ) throws IOException {
1022+ public FileVisitResult visitFile (Path filePath , BasicFileAttributes attrs ) {
10251023 if (Thread .currentThread ().isInterrupted ()) {
10261024 return TERMINATE ;
10271025 }
10281026
1029- Manifest manifest = null ;
1030- for (ManifestFileParser parser : Lookup .getDefault ().lookupAll (ManifestFileParser .class )) {
1031- if (parser .fileIsManifest (filePath )) {
1032- try {
1033- manifest = parser .parse (filePath );
1034- break ;
1035- } catch (ManifestFileParserException ex ) {
1036- SYS_LOGGER .log (Level .SEVERE , String .format ("Error attempting to parse %s with parser %s" , filePath , parser .getClass ().getCanonicalName ()), ex );
1027+ try {
1028+ Manifest manifest = null ;
1029+ for (ManifestFileParser parser : Lookup .getDefault ().lookupAll (ManifestFileParser .class )) {
1030+ if (parser .fileIsManifest (filePath )) {
1031+ try {
1032+ manifest = parser .parse (filePath );
1033+ break ;
1034+ } catch (ManifestFileParserException ex ) {
1035+ SYS_LOGGER .log (Level .SEVERE , String .format ("Error attempting to parse %s with parser %s" , filePath , parser .getClass ().getCanonicalName ()), ex );
1036+ }
1037+ }
1038+ if (Thread .currentThread ().isInterrupted ()) {
1039+ return TERMINATE ;
10371040 }
10381041 }
1042+
10391043 if (Thread .currentThread ().isInterrupted ()) {
10401044 return TERMINATE ;
10411045 }
1042- }
10431046
1044- if (Thread .currentThread ().isInterrupted ()) {
1045- return TERMINATE ;
1046- }
1047-
1048- if (null != manifest ) {
1049- /*
1047+ if (null != manifest ) {
1048+ /*
10501049 * Update the mapping of case names to manifest paths that is
10511050 * used for case deletion.
1052- */
1053- String caseName = manifest .getCaseName ();
1054- Path manifestPath = manifest .getFilePath ();
1055- if (casesToManifests .containsKey (caseName )) {
1056- Set <Path > manifestPaths = casesToManifests .get (caseName );
1057- manifestPaths .add (manifestPath );
1058- } else {
1059- Set <Path > manifestPaths = new HashSet <>();
1060- manifestPaths .add (manifestPath );
1061- casesToManifests .put (caseName , manifestPaths );
1062- }
1051+ */
1052+ String caseName = manifest .getCaseName ();
1053+ Path manifestPath = manifest .getFilePath ();
1054+ if (casesToManifests .containsKey (caseName )) {
1055+ Set <Path > manifestPaths = casesToManifests .get (caseName );
1056+ manifestPaths .add (manifestPath );
1057+ } else {
1058+ Set <Path > manifestPaths = new HashSet <>();
1059+ manifestPaths .add (manifestPath );
1060+ casesToManifests .put (caseName , manifestPaths );
1061+ }
10631062
1064- /*
1063+ /*
10651064 * Add a job to the pending jobs queue, the completed jobs list,
10661065 * or do crashed job recovery, as required.
1067- */
1068- try {
1069- byte [] rawData = coordinationService .getNodeData (CoordinationService .CategoryNode .MANIFESTS , manifestPath .toString ());
1070- if (null != rawData && rawData .length > 0 ) {
1071- try {
1072- AutoIngestJobNodeData nodeData = new AutoIngestJobNodeData (rawData );
1073- AutoIngestJob .ProcessingStatus processingStatus = nodeData .getProcessingStatus ();
1074- switch (processingStatus ) {
1075- case PENDING :
1076- addPendingJob (manifest , nodeData );
1077- break ;
1078- case PROCESSING :
1079- doRecoveryIfCrashed (manifest , nodeData );
1080- break ;
1081- case COMPLETED :
1082- addCompletedJob (manifest , nodeData );
1083- break ;
1084- case DELETED :
1085- /*
1066+ */
1067+ try {
1068+ byte [] rawData = coordinationService .getNodeData (CoordinationService .CategoryNode .MANIFESTS , manifestPath .toString ());
1069+ if (null != rawData && rawData .length > 0 ) {
1070+ try {
1071+ AutoIngestJobNodeData nodeData = new AutoIngestJobNodeData (rawData );
1072+ AutoIngestJob .ProcessingStatus processingStatus = nodeData .getProcessingStatus ();
1073+ switch (processingStatus ) {
1074+ case PENDING :
1075+ addPendingJob (manifest , nodeData );
1076+ break ;
1077+ case PROCESSING :
1078+ doRecoveryIfCrashed (manifest , nodeData );
1079+ break ;
1080+ case COMPLETED :
1081+ addCompletedJob (manifest , nodeData );
1082+ break ;
1083+ case DELETED :
1084+ /*
10861085 * Ignore jobs marked as "deleted."
1087- */
1088- break ;
1089- default :
1090- SYS_LOGGER .log (Level .SEVERE , "Unknown ManifestNodeData.ProcessingStatus" );
1091- break ;
1086+ */
1087+ break ;
1088+ default :
1089+ SYS_LOGGER .log (Level .SEVERE , "Unknown ManifestNodeData.ProcessingStatus" );
1090+ break ;
1091+ }
1092+ } catch (AutoIngestJobNodeData .InvalidDataException | AutoIngestJobException ex ) {
1093+ SYS_LOGGER .log (Level .SEVERE , String .format ("Invalid auto ingest job node data for %s" , manifestPath ), ex );
1094+ }
1095+ } else {
1096+ try {
1097+ addNewPendingJob (manifest );
1098+ } catch (AutoIngestJobException ex ) {
1099+ SYS_LOGGER .log (Level .SEVERE , String .format ("Invalid manifest data for %s" , manifestPath ), ex );
10921100 }
1093- } catch (AutoIngestJobNodeData .InvalidDataException | AutoIngestJobException ex ) {
1094- SYS_LOGGER .log (Level .SEVERE , String .format ("Invalid auto ingest job node data for %s" , manifestPath ), ex );
1095- }
1096- } else {
1097- try {
1098- addNewPendingJob (manifest );
1099- } catch (AutoIngestJobException ex ) {
1100- SYS_LOGGER .log (Level .SEVERE , String .format ("Invalid manifest data for %s" , manifestPath ), ex );
11011101 }
1102+ } catch (CoordinationServiceException ex ) {
1103+ SYS_LOGGER .log (Level .SEVERE , String .format ("Error transmitting node data for %s" , manifestPath ), ex );
1104+ return CONTINUE ;
1105+ } catch (InterruptedException ex ) {
1106+ Thread .currentThread ().interrupt ();
1107+ return TERMINATE ;
11021108 }
1103- } catch (CoordinationServiceException ex ) {
1104- SYS_LOGGER .log (Level .SEVERE , String .format ("Error transmitting node data for %s" , manifestPath ), ex );
1105- return CONTINUE ;
1106- } catch (InterruptedException ex ) {
1107- Thread .currentThread ().interrupt ();
1108- return TERMINATE ;
11091109 }
1110+
1111+ } catch (Exception ex ) {
1112+ // Catch all unhandled and unexpected exceptions. Otherwise one bad file
1113+ // can stop the entire input folder scanning. Given that the exception is unexpected,
1114+ // I'm hesitant to add logging which requires accessing or de-referencing data.
1115+ SYS_LOGGER .log (Level .SEVERE , "Unexpected exception in file visitor" , ex );
1116+ return CONTINUE ;
11101117 }
11111118
11121119 if (!Thread .currentThread ().isInterrupted ()) {
0 commit comments