exceptionfactory commented on code in PR #8648:
URL: https://github.com/apache/nifi/pull/8648#discussion_r1567371606


##########
minifi/minifi-bootstrap/src/main/java/org/apache/nifi/minifi/bootstrap/command/StartRunner.java:
##########
@@ -279,15 +280,33 @@ private void regenerateFlowConfiguration(String 
flowConfigFileLocation) throws C
         }
     }
 
-    private Process startMiNiFi() throws IOException {
+    private Process startMiNiFi(BootstrapProperties bootstrapProperties) 
throws IOException {
+        int bootstrapListenPort = 
parseBootstrapListenPort(bootstrapProperties);
+
         MiNiFiListener listener = new MiNiFiListener();
-        listenPort = listener.start(runMiNiFi, bootstrapFileProvider, 
configurationChangeListener);
+        listenPort = listener.start(runMiNiFi, bootstrapListenPort, 
bootstrapFileProvider, configurationChangeListener);
 
         CMD_LOGGER.info("Starting Apache MiNiFi...");
 
         return startMiNiFiProcess(getProcessBuilder());
     }
 
+    private int parseBootstrapListenPort(BootstrapProperties 
bootstrapProperties) {
+        String bootstrapListenPort = 
bootstrapProperties.getProperty(NIFI_BOOTSTRAP_LISTEN_PORT);
+        if (bootstrapListenPort != null) {
+            try {
+                int port = Integer.parseInt(bootstrapListenPort.trim());
+                CMD_LOGGER.info("Using boostrap listen port {}", port);
+                return port;
+            } catch (Exception e) {
+                CMD_LOGGER.warn("Unable to parse bootstrap listen port, 
falling back to default (random) port");
+                return 0;

Review Comment:
   Instead of logging a warning, it seems like this should throw an 
`IllegalArgumentException`. The configuration attempted to specify a port 
number, so starting on a random port is contrary to the configured behavior.



##########
minifi/minifi-bootstrap/src/main/java/org/apache/nifi/minifi/bootstrap/command/StartRunner.java:
##########
@@ -279,15 +280,33 @@ private void regenerateFlowConfiguration(String 
flowConfigFileLocation) throws C
         }
     }
 
-    private Process startMiNiFi() throws IOException {
+    private Process startMiNiFi(BootstrapProperties bootstrapProperties) 
throws IOException {
+        int bootstrapListenPort = 
parseBootstrapListenPort(bootstrapProperties);
+
         MiNiFiListener listener = new MiNiFiListener();
-        listenPort = listener.start(runMiNiFi, bootstrapFileProvider, 
configurationChangeListener);
+        listenPort = listener.start(runMiNiFi, bootstrapListenPort, 
bootstrapFileProvider, configurationChangeListener);
 
         CMD_LOGGER.info("Starting Apache MiNiFi...");
 
         return startMiNiFiProcess(getProcessBuilder());
     }
 
+    private int parseBootstrapListenPort(BootstrapProperties 
bootstrapProperties) {
+        String bootstrapListenPort = 
bootstrapProperties.getProperty(NIFI_BOOTSTRAP_LISTEN_PORT);
+        if (bootstrapListenPort != null) {
+            try {
+                int port = Integer.parseInt(bootstrapListenPort.trim());
+                CMD_LOGGER.info("Using boostrap listen port {}", port);
+                return port;
+            } catch (Exception e) {
+                CMD_LOGGER.warn("Unable to parse bootstrap listen port, 
falling back to default (random) port");
+                return 0;
+            }
+        }
+        CMD_LOGGER.info("Bootstrap listen port is not provided, falling back 
to default (random) port");
+        return 0;

Review Comment:
   I recommend refactoring this method to have a single return statement.



##########
minifi/minifi-bootstrap/src/main/java/org/apache/nifi/minifi/bootstrap/command/StartRunner.java:
##########
@@ -279,15 +280,33 @@ private void regenerateFlowConfiguration(String 
flowConfigFileLocation) throws C
         }
     }
 
-    private Process startMiNiFi() throws IOException {
+    private Process startMiNiFi(BootstrapProperties bootstrapProperties) 
throws IOException {
+        int bootstrapListenPort = 
parseBootstrapListenPort(bootstrapProperties);
+
         MiNiFiListener listener = new MiNiFiListener();
-        listenPort = listener.start(runMiNiFi, bootstrapFileProvider, 
configurationChangeListener);
+        listenPort = listener.start(runMiNiFi, bootstrapListenPort, 
bootstrapFileProvider, configurationChangeListener);
 
         CMD_LOGGER.info("Starting Apache MiNiFi...");
 
         return startMiNiFiProcess(getProcessBuilder());
     }
 
+    private int parseBootstrapListenPort(BootstrapProperties 
bootstrapProperties) {
+        String bootstrapListenPort = 
bootstrapProperties.getProperty(NIFI_BOOTSTRAP_LISTEN_PORT);
+        if (bootstrapListenPort != null) {
+            try {
+                int port = Integer.parseInt(bootstrapListenPort.trim());
+                CMD_LOGGER.info("Using boostrap listen port {}", port);
+                return port;
+            } catch (Exception e) {
+                CMD_LOGGER.warn("Unable to parse bootstrap listen port, 
falling back to default (random) port");
+                return 0;
+            }
+        }
+        CMD_LOGGER.info("Bootstrap listen port is not provided, falling back 
to default (random) port");

Review Comment:
   This log seems unnecessary. Perhaps a debug message is useful in some 
scenarios.



-- 
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]

Reply via email to