simonbence commented on a change in pull request #5356:
URL: https://github.com/apache/nifi/pull/5356#discussion_r720386335
##########
File path: nifi-bootstrap/src/main/java/org/apache/nifi/bootstrap/RunNiFi.java
##########
@@ -250,18 +252,13 @@ public static void main(String[] args) throws
IOException, InterruptedException
}
dumpFile = new File(args[2]);
} else {
- try {
- Paths.get(args[1]);
- } catch (InvalidPathException e) {
- System.err.println("Invalid filename. The command
parameters are: status-history <number of days> <dumpFile>");
+ final boolean isValid = DumpFileValidator.validate(args[1]);
Review comment:
Would not it make sense to use this validation at L248 too, instead of
calling `Paths.get(args[2])`?
##########
File path:
nifi-framework-api/src/main/java/org/apache/nifi/controller/status/history/StatusHistoryDumpFactory.java
##########
@@ -17,12 +17,12 @@
package org.apache.nifi.controller.status.history;
/**
- * Container for status history data which is capable to write it in an
implementation dependent format.
+ * Factory class to create StatusHistoryDump instance.
Review comment:
Minor: it worth to annotate this as "code"
##########
File path:
nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/java/org/apache/nifi/controller/status/history/JsonNodeStatusHistoryDumpFactoryTest.java
##########
@@ -55,4 +57,26 @@ public void testJsonNodeStatusDumpFactory() {
assertEquals(startOfDaysBeforeDate, fromArgumentCaptor.getValue());
}
+ @Test
+ public void
testJsonNodeStatusDumpFactoryWithLessThanOneDayThrowsException() {
Review comment:
I believe this should be split into two separate test methods
##########
File path:
nifi-bootstrap/src/main/java/org/apache/nifi/bootstrap/util/DumpFileValidator.java
##########
@@ -0,0 +1,59 @@
+/*
+ * 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.util;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.Closeable;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.InvalidPathException;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+
+public final class DumpFileValidator {
+
+ private static final Logger logger =
LoggerFactory.getLogger(DumpFileValidator.class);
+
+ private DumpFileValidator() {
+ }
+
+ public static boolean validate(final String filePath) {
+ try {
+ final Path path = Paths.get(filePath);
+ return checkFileCanBeCreated(path);
+ } catch (InvalidPathException e) {
+ System.err.println("Invalid filename. The command parameters are:
status-history <number of days> <dumpFile>");
Review comment:
Logging would be good here too
##########
File path: nifi-bootstrap/src/main/java/org/apache/nifi/bootstrap/RunNiFi.java
##########
@@ -813,6 +811,7 @@ private void makeRequest(final String request, final String
arguments, final Fil
final Logger logger = defaultLogger; // dump to bootstrap log file
by default
final Integer port = getCurrentPort(logger);
if (port == null) {
+ cmdLogger.info("Apache NiFi is not currently running");
Review comment:
This (and maybe the one below as well) is more of an error in this case
##########
File path:
nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/status/history/JsonNodeStatusHistoryDumpFactory.java
##########
@@ -27,6 +29,7 @@
@Override
public StatusHistoryDump create(int days) {
+ Preconditions.checkArgument(days > 0, String.format("The number of
days shall be greater than 0. The current value is %s.", days));
Review comment:
The `%s` is for string input primarilty. Format documentation suggests
'%d' for integer values
--
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]