tpalfy commented on a change in pull request #5195:
URL: https://github.com/apache/nifi/pull/5195#discussion_r689653604
##########
File path:
nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-runtime/src/main/java/org/apache/nifi/NiFi.java
##########
@@ -201,40 +206,70 @@ 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()) {
Review comment:
```suggestion
if (properties.isDiagnosticsOnShutdownEnabled()) {
final String diagnosticDirectoryPath =
properties.getDiagnosticsOnShutdownDirectory();
```
##########
File path:
nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-runtime/src/main/java/org/apache/nifi/NiFi.java
##########
@@ -54,33 +60,38 @@
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;
+import java.util.stream.Stream;
public class NiFi implements NiFiEntryPoint {
- private static final Logger LOGGER = LoggerFactory.getLogger(NiFi.class);
+ public static final String BOOTSTRAP_PORT_PROPERTY =
"nifi.bootstrap.listen.port";
+ public static final DateTimeFormatter DATE_TIME_FORMATTER =
DateTimeFormatter.ofPattern("yyyy-MM-dd_HH-mm-ss");
+
+ private static final Logger logger = LoggerFactory.getLogger(NiFi.class);
Review comment:
Any reason to change the logger into lowercase, even though it's a
constant?
##########
File path:
nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-runtime/src/main/java/org/apache/nifi/NiFi.java
##########
@@ -201,40 +206,70 @@ 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 {
Review comment:
```suggestion
private void runDiagnostics() throws IOException {
```
##########
File path:
nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-runtime/src/main/java/org/apache/nifi/NiFi.java
##########
@@ -201,40 +206,70 @@ 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())) {
Review comment:
Wouldn't it be a bit nicer to merge the file count and directory size
check into a single block?
--
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]