You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@nifi.apache.org by "emiliosetiadarma (via GitHub)" <gi...@apache.org> on 2023/04/25 21:53:13 UTC

[GitHub] [nifi] emiliosetiadarma opened a new pull request, #7196: NIFI-11230: Log Warnings on Startup for OS Best Practices

emiliosetiadarma opened a new pull request, #7196:
URL: https://github.com/apache/nifi/pull/7196

   <!-- Licensed to the Apache Software Foundation (ASF) under one or more -->
   <!-- contributor license agreements.  See the NOTICE file distributed with -->
   <!-- this work for additional information regarding copyright ownership. -->
   <!-- The ASF licenses this file to You under the Apache License, Version 2.0 -->
   <!-- (the "License"); you may not use this file except in compliance with -->
   <!-- the License.  You may obtain a copy of the License at -->
   <!--     http://www.apache.org/licenses/LICENSE-2.0 -->
   <!-- Unless required by applicable law or agreed to in writing, software -->
   <!-- distributed under the License is distributed on an "AS IS" BASIS, -->
   <!-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -->
   <!-- See the License for the specific language governing permissions and -->
   <!-- limitations under the License. -->
   
   # Summary
   
   [NIFI-11230](https://issues.apache.org/jira/browse/NIFI-11230)
   
   # Tracking
   
   Please complete the following tracking steps prior to pull request creation.
   
   ### Issue Tracking
   
   - [x] [Apache NiFi Jira](https://issues.apache.org/jira/browse/NIFI) issue created
   
   ### Pull Request Tracking
   
   - [x] Pull Request title starts with Apache NiFi Jira issue number, such as `NIFI-00000`
   - [x] Pull Request commit message starts with Apache NiFi Jira issue number, as such `NIFI-00000`
   
   ### Pull Request Formatting
   
   - [x] Pull Request based on current revision of the `main` branch
   - [x] Pull Request refers to a feature branch with one commit containing changes
   
   # Verification
   
   Please indicate the verification steps performed prior to pull request creation.
   
   ### Build
   
   - [x] Build completed using `mvn clean install -P contrib-check`
     - [x] JDK 11
     - [ ] JDK 17
   
   ### Licensing
   
   - [ ] New dependencies are compatible with the [Apache License 2.0](https://apache.org/licenses/LICENSE-2.0) according to the [License Policy](https://www.apache.org/legal/resolved.html)
   - [ ] New dependencies are documented in applicable `LICENSE` and `NOTICE` files
   
   ### Documentation
   
   - [ ] Documentation formatting appears as expected in rendered files
   


-- 
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: issues-unsubscribe@nifi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nifi] exceptionfactory closed pull request #7196: NIFI-11230: Log Warnings on Startup for OS Best Practices

Posted by "exceptionfactory (via GitHub)" <gi...@apache.org>.
exceptionfactory closed pull request #7196: NIFI-11230: Log Warnings on Startup for OS Best Practices
URL: https://github.com/apache/nifi/pull/7196


-- 
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: issues-unsubscribe@nifi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nifi] exceptionfactory commented on a diff in pull request #7196: NIFI-11230: Log Warnings on Startup for OS Best Practices

Posted by "exceptionfactory (via GitHub)" <gi...@apache.org>.
exceptionfactory commented on code in PR #7196:
URL: https://github.com/apache/nifi/pull/7196#discussion_r1179395677


##########
nifi-bootstrap/src/main/java/org/apache/nifi/bootstrap/RunNiFi.java:
##########
@@ -1113,6 +1114,9 @@ public void start(final boolean monitor) throws IOException {
             cmdLogger.warn("Failed to delete previous lock file {}; this file should be cleaned up manually", prevLockFile);
         }
 
+        final RuntimeValidatorChecker configChecker = new RuntimeValidatorChecker();
+        configChecker.check();

Review Comment:
   This works, but it looks like the `RuntimeValidatorChecker` could be declared once as a static variable and reused.



##########
nifi-bootstrap/src/main/java/org/apache/nifi/bootstrap/process/AvailablePorts.java:
##########
@@ -0,0 +1,112 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.bootstrap.process;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Scanner;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+public class AvailablePorts implements RuntimeValidator {
+    private static final String DIRECTORY = "/proc/sys/net/ipv4/ip_local_port_range";
+    private static final String DIGITS_REGEX = "(\\d+)\\s+(\\d+)";
+    private static final Pattern PATTERN = Pattern.compile(DIGITS_REGEX);

Review Comment:
   The pattern value could be collapsed into a single `Pattern` declaration.
   ```suggestion
       private static final Pattern PATTERN = Pattern.compile("(\\d+)\\s+(\\d+)");
   ```



##########
nifi-bootstrap/src/main/java/org/apache/nifi/bootstrap/process/RuntimeValidatorChecker.java:
##########
@@ -0,0 +1,69 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.bootstrap.process;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.stream.Collectors;
+
+public class RuntimeValidatorChecker {
+    private final List<RuntimeValidator> configurationClasses;
+    private static final Logger logger = LoggerFactory.getLogger(RuntimeValidatorChecker.class);
+
+    public RuntimeValidatorChecker() {
+        this.configurationClasses = Arrays.asList(
+                new AvailablePorts(),
+                new FileHandles(),
+                new ForkedProcesses(),
+                new Swappiness(),
+                new TimedWaitDuration()
+        );
+    }
+
+    RuntimeValidatorChecker(final List<RuntimeValidator> configurationClasses) {
+        this.configurationClasses = configurationClasses;
+    }
+
+    /**
+     * Checks all the system configuration settings that are supported to be checked
+     */
+    public List<RuntimeValidatorResult> check() {

Review Comment:
   Following the class name suggestion, this could be changed to `execute()`.
   ```suggestion
       public List<RuntimeValidatorResult> execute() {
   ```



##########
nifi-bootstrap/src/main/java/org/apache/nifi/bootstrap/process/AvailablePorts.java:
##########
@@ -0,0 +1,112 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.bootstrap.process;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Scanner;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+public class AvailablePorts implements RuntimeValidator {
+    private static final String DIRECTORY = "/proc/sys/net/ipv4/ip_local_port_range";

Review Comment:
   Recommend renaming these variables to something like `FILE_PATH` or `CONFIGURATION_PATH` instead of `DIRECTORY`.



##########
nifi-bootstrap/src/main/java/org/apache/nifi/bootstrap/process/AvailablePorts.java:
##########
@@ -0,0 +1,112 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.bootstrap.process;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Scanner;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+public class AvailablePorts implements RuntimeValidator {
+    private static final String DIRECTORY = "/proc/sys/net/ipv4/ip_local_port_range";
+    private static final String DIGITS_REGEX = "(\\d+)\\s+(\\d+)";
+    private static final Pattern PATTERN = Pattern.compile(DIGITS_REGEX);
+    private static final int DESIRED_AVAILABLE_PORTS = 55000;

Review Comment:
   What do you think about naming this `RECOMMENDED` instead of `DESIRED`?
   ```suggestion
       private static final int RECOMMENDED_AVAILABLE_PORTS = 55000;
   ```



##########
nifi-bootstrap/src/main/java/org/apache/nifi/bootstrap/process/AvailablePorts.java:
##########
@@ -0,0 +1,112 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.bootstrap.process;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Scanner;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+public class AvailablePorts implements RuntimeValidator {
+    private static final String DIRECTORY = "/proc/sys/net/ipv4/ip_local_port_range";
+    private static final String DIGITS_REGEX = "(\\d+)\\s+(\\d+)";
+    private static final Pattern PATTERN = Pattern.compile(DIGITS_REGEX);
+    private static final int DESIRED_AVAILABLE_PORTS = 55000;
+
+    private final File configurationFile;
+
+    public AvailablePorts() {
+        configurationFile = new File(DIRECTORY);
+    }
+
+    AvailablePorts(final File configurationFile) {
+        this.configurationFile = configurationFile;
+    }
+
+    @Override
+    public List<RuntimeValidatorResult> check() {
+        final List<RuntimeValidatorResult> results = new ArrayList<>();
+        if (configurationFile == null) {
+            final RuntimeValidatorResult result = new RuntimeValidatorResult.Builder()
+                    .subject(this.getClass().getName())
+                    .outcome(RuntimeValidatorResult.Outcome.SKIPPED)
+                    .explanation("Configuration file is null")
+                    .build();
+            results.add(result);
+            return results;
+        }
+        if (!configurationFile.canRead()) {
+            final RuntimeValidatorResult result = new RuntimeValidatorResult.Builder()
+                    .subject(this.getClass().getName())
+                    .outcome(RuntimeValidatorResult.Outcome.SKIPPED)
+                    .explanation(String.format("Configuration file [%s] cannot be read", configurationFile.getAbsolutePath()))
+                    .build();
+            results.add(result);
+            return results;
+        }

Review Comment:
   This file existence checking looks similar across implementations, so it would be helpful to pull it out to a shared abstract class.



##########
nifi-bootstrap/src/main/java/org/apache/nifi/bootstrap/process/RuntimeValidator.java:
##########
@@ -0,0 +1,28 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.bootstrap.process;
+
+import java.util.List;
+
+public interface RuntimeValidator {
+    /**
+     * Checks if the given runtime configuration is within NiFi's best practices
+     *
+     * @return a List of {@code RuntimeValidatorResult}
+     */
+    public List<RuntimeValidatorResult> check();

Review Comment:
   Recommend naming this `validate` instead of `check`.
   ```suggestion
       public List<RuntimeValidatorResult> validate();
   ```



##########
nifi-bootstrap/src/main/java/org/apache/nifi/bootstrap/process/AvailablePorts.java:
##########
@@ -0,0 +1,112 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.bootstrap.process;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Scanner;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+public class AvailablePorts implements RuntimeValidator {
+    private static final String DIRECTORY = "/proc/sys/net/ipv4/ip_local_port_range";
+    private static final String DIGITS_REGEX = "(\\d+)\\s+(\\d+)";
+    private static final Pattern PATTERN = Pattern.compile(DIGITS_REGEX);
+    private static final int DESIRED_AVAILABLE_PORTS = 55000;
+
+    private final File configurationFile;
+
+    public AvailablePorts() {
+        configurationFile = new File(DIRECTORY);
+    }
+
+    AvailablePorts(final File configurationFile) {
+        this.configurationFile = configurationFile;
+    }
+
+    @Override
+    public List<RuntimeValidatorResult> check() {
+        final List<RuntimeValidatorResult> results = new ArrayList<>();
+        if (configurationFile == null) {
+            final RuntimeValidatorResult result = new RuntimeValidatorResult.Builder()
+                    .subject(this.getClass().getName())
+                    .outcome(RuntimeValidatorResult.Outcome.SKIPPED)
+                    .explanation("Configuration file is null")
+                    .build();
+            results.add(result);
+            return results;
+        }
+        if (!configurationFile.canRead()) {
+            final RuntimeValidatorResult result = new RuntimeValidatorResult.Builder()
+                    .subject(this.getClass().getName())
+                    .outcome(RuntimeValidatorResult.Outcome.SKIPPED)
+                    .explanation(String.format("Configuration file [%s] cannot be read", configurationFile.getAbsolutePath()))
+                    .build();
+            results.add(result);
+            return results;
+        }
+
+        try {
+            final Scanner scanner = new Scanner(configurationFile);
+            final StringBuilder sb = new StringBuilder();
+            while (scanner.hasNextLine()) {
+                sb.append(scanner.nextLine());
+            }
+            scanner.close();

Review Comment:
   Recommend pulling this out to a separate method that uses try-with-resources along the following lines. The method could also be pulled out to an abstract class and reused.
   ```suggestion
               private String getFileContents() throws IOException {
                   try (Scanner scanner = new Scanner(configurationFile)) {
                       final StringBuilder builder = new StringBuilder();
                       while (scanner.hasNextLine()) {
                           builder.append(scanner.nextLine());
                       }
                       return builder.toString();
                   }
               }
   ```



##########
nifi-bootstrap/src/main/java/org/apache/nifi/bootstrap/process/ForkedProcesses.java:
##########
@@ -0,0 +1,113 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.bootstrap.process;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+public class ForkedProcesses implements RuntimeValidator {
+    private static final String DIRECTORY = String.format("/proc/%s/limits", ProcessHandle.current().pid());
+    private static final String MAX_PROCESSES_REGEX = "Max processes\\s+(\\d+)\\s+(\\d+)\\s+processes\\s+";
+    private static final Pattern PATTERN = Pattern.compile(MAX_PROCESSES_REGEX);
+    private static final int DESIRED_SOFT_LIMIT = 10000;
+    private static final int DESIRED_HARD_LIMIT = 10000;
+    private final File configurationFile;
+
+    public ForkedProcesses() {
+        configurationFile = new File(DIRECTORY);
+    }
+
+    ForkedProcesses(final File configurationFile) {
+        this.configurationFile = configurationFile;
+    }
+
+    @Override
+    public List<RuntimeValidatorResult> check() {
+        final List<RuntimeValidatorResult> results = new ArrayList<>();
+        if (configurationFile == null) {
+            final RuntimeValidatorResult result = new RuntimeValidatorResult.Builder()
+                    .subject(this.getClass().getName())
+                    .outcome(RuntimeValidatorResult.Outcome.SKIPPED)
+                    .explanation("Configuration file is null")
+                    .build();
+            results.add(result);
+            return results;
+        }
+        if (!configurationFile.canRead()) {
+            final RuntimeValidatorResult result = new RuntimeValidatorResult.Builder()
+                    .subject(this.getClass().getName())
+                    .outcome(RuntimeValidatorResult.Outcome.SKIPPED)
+                    .explanation(String.format("Configuration file [%s] cannot be read", configurationFile.getAbsolutePath()))
+                    .build();
+            results.add(result);
+            return results;
+        }
+
+        try {
+            final String forkedProcessesString = new String(Files.readAllBytes(configurationFile.toPath()));
+            final Matcher matcher = PATTERN.matcher(forkedProcessesString);
+            if (matcher.find()) {
+                final int softLimit = Integer.valueOf(matcher.group(1));
+                final int hardLimit = Integer.valueOf(matcher.group(2));
+                if (softLimit < DESIRED_SOFT_LIMIT) {
+                    final RuntimeValidatorResult result =  new RuntimeValidatorResult.Builder()
+                            .subject(this.getClass().getName())
+                            .outcome(RuntimeValidatorResult.Outcome.FAILED)
+                            .explanation(String.format("Soft limit for forked processes [%d] is less than desired soft limit [%d]", softLimit, DESIRED_SOFT_LIMIT))
+                            .build();
+                    results.add(result);
+                }
+                if (hardLimit < DESIRED_HARD_LIMIT) {
+                    final RuntimeValidatorResult result =  new RuntimeValidatorResult.Builder()
+                            .subject(this.getClass().getName())
+                            .outcome(RuntimeValidatorResult.Outcome.FAILED)
+                            .explanation(String.format("Hard limit for forked processes [%d] is less than desired hard limit [%d]", hardLimit, DESIRED_HARD_LIMIT))
+                            .build();
+                    results.add(result);
+                }

Review Comment:
   It might be possible to abstract successful regular expression matching evaluating using an abstract method along the following lines:
   ```
   protected abstract void checkMatchedPattern(Matcher matcher, List<RuntimeValidatorResult> results);
   ```



##########
nifi-bootstrap/src/main/java/org/apache/nifi/bootstrap/process/RuntimeValidatorChecker.java:
##########
@@ -0,0 +1,69 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.bootstrap.process;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.stream.Collectors;
+
+public class RuntimeValidatorChecker {

Review Comment:
   What do you think of naming this something like `RuntimeValidatorExecutor`?



##########
nifi-bootstrap/src/main/java/org/apache/nifi/bootstrap/process/TimedWaitDuration.java:
##########
@@ -0,0 +1,132 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.bootstrap.process;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Scanner;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+public class TimedWaitDuration implements RuntimeValidator {
+    private static final String[] POSSIBLE_DIRECTORIES = new String[] {

Review Comment:
   It might be helpful to add a comment on this property indicating that different Linux Kernel versions have different locations.



##########
nifi-bootstrap/src/test/java/org/apache/nifi/bootstrap/process/RuntimeValidatorCheckerTest.java:
##########
@@ -0,0 +1,207 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.bootstrap.process;
+
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URL;
+import java.nio.file.Files;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.stream.Collectors;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+public class RuntimeValidatorCheckerTest {
+    @TempDir
+    private File tempDir;
+
+    private RuntimeValidatorChecker checker;
+
+    @Test
+    public void testAllSatisfactory() throws IOException {
+        final List<RuntimeValidator> configurationClasses = getAllTestConfigurationClasses();
+        checker = new RuntimeValidatorChecker(configurationClasses);
+
+        final List<RuntimeValidatorResult> results = checker.check();
+        assertEquals(5, results.size());
+        final List<RuntimeValidatorResult> failures = getFailures(results);
+        assertEquals(0, failures.size());
+    }
+
+    @Test
+    public void testAllFailuresEmptyFiles() throws IOException {
+        final List<RuntimeValidator> configurationClasses = new ArrayList<>();
+        final File emptyFile = getTempFile("empty_file", "");
+        configurationClasses.add(new AvailablePorts(emptyFile));
+        configurationClasses.add(new FileHandles(emptyFile));
+        configurationClasses.add(new ForkedProcesses(emptyFile));
+        configurationClasses.add(new Swappiness(emptyFile));
+        configurationClasses.add(new TimedWaitDuration(emptyFile));
+        checker = new RuntimeValidatorChecker(configurationClasses);
+
+        final List<RuntimeValidatorResult> results = checker.check();
+        assertEquals(5, results.size());
+        final List<RuntimeValidatorResult> failures = getFailures(results);
+        assertEquals(5, failures.size());
+        for (final RuntimeValidatorResult failure : failures) {
+            assertTrue(failure.getExplanation().contains("parse"));
+        }
+    }
+
+    @Test
+    public void testAllFailuresUnparsable() throws IOException {
+        final List<RuntimeValidator> configurationClasses = new ArrayList<>();
+        final File unparsableFile = getTempFile("unparsable", "abcdefghijklmnopqrstuvwxyz");
+        configurationClasses.add(new AvailablePorts(unparsableFile));
+        configurationClasses.add(new FileHandles(unparsableFile));
+        configurationClasses.add(new ForkedProcesses(unparsableFile));
+        configurationClasses.add(new Swappiness(unparsableFile));
+        configurationClasses.add(new TimedWaitDuration(unparsableFile));
+        checker = new RuntimeValidatorChecker(configurationClasses);
+
+        final List<RuntimeValidatorResult> results = checker.check();
+        assertEquals(5, results.size());
+        final List<RuntimeValidatorResult> failures = getFailures(results);
+        assertEquals(5, failures.size());
+        for (final RuntimeValidatorResult failure : failures) {
+            assertTrue(failure.getExplanation().contains("parse"));
+        }
+    }
+
+    @Test
+    public void testCannotFindFilesForConfiguration() {
+        final List<RuntimeValidator> configurationClasses = new ArrayList<>();
+        final File missingFile = new File("missing_file");
+        configurationClasses.add(new AvailablePorts(missingFile));
+        configurationClasses.add(new FileHandles(missingFile));
+        configurationClasses.add(new ForkedProcesses(missingFile));
+        configurationClasses.add(new Swappiness(missingFile));
+        configurationClasses.add(new TimedWaitDuration(missingFile));

Review Comment:
   It looks like the configuration of configuration classes could be pulled out to a private method and reused, passing the test file reference and returning the List.



-- 
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: issues-unsubscribe@nifi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org