Lehel44 commented on a change in pull request #5195:
URL: https://github.com/apache/nifi/pull/5195#discussion_r688597282
##########
File path:
nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-runtime/src/main/java/org/apache/nifi/NiFi.java
##########
@@ -201,40 +204,71 @@ protected void initLogging() {
private static ClassLoader createBootstrapClassLoader() {
//Get list of files in bootstrap folder
final List<URL> urls = new ArrayList<>();
- try {
- Files.list(Paths.get("lib/bootstrap")).forEach(p -> {
+ try (final Stream<Path> files =
Files.list(Paths.get("lib/bootstrap"))) {
+ files.forEach(p -> {
try {
urls.add(p.toUri().toURL());
} catch (final MalformedURLException mef) {
- LOGGER.warn("Unable to load " + p.getFileName() + " due to
" + mef, mef);
+ logger.warn("Unable to load " + p.getFileName() + " due to
" + mef, mef);
}
});
} catch (IOException ioe) {
- LOGGER.warn("Unable to access lib/bootstrap to create bootstrap
classloader", ioe);
+ logger.warn("Unable to access lib/bootstrap to create bootstrap
classloader", ioe);
}
//Create the bootstrap classloader
return new URLClassLoader(urls.toArray(new URL[0]),
Thread.currentThread().getContextClassLoader());
}
- public void shutdownHook(boolean isReload) {
+ public void shutdownHook(final boolean isReload) {
try {
+ runAutomaticDiagnostics();
shutdown();
} catch (final Throwable t) {
- LOGGER.warn("Problem occurred ensuring Jetty web server was
properly terminated due to " + t);
+ logger.warn("Problem occurred ensuring Jetty web server was
properly terminated due to ", t);
+ }
+ }
+
+ private void runAutomaticDiagnostics() throws IOException {
+ final String diagnosticDirectoryPath =
properties.getDiagnosticsOnShutdownDirectory();
+ if (properties.isDiagnosticsOnShutdownEnabled()) {
+ final boolean isCreated =
DiagnosticUtils.createDiagnosticDirectory(diagnosticDirectoryPath);
+ if (isCreated) {
+ logger.debug("Diagnostic directory has successfully been
created.");
+ }
+ if (DiagnosticUtils.isFileCountExceeded(diagnosticDirectoryPath,
properties.getDiagnosticsOnShutdownMaxFileCount())) {
+ final Path oldestFile =
DiagnosticUtils.getOldestFile(diagnosticDirectoryPath);
+ Files.delete(oldestFile);
+ }
+ final DateTimeFormatter formatter =
DateTimeFormatter.ofPattern("yyyy-MM-dd_HH-mm-ss");
Review comment:
Thank you. This was necessary because Windows does not allow colons in
filenames.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]