NIFI-10493 MiNiFi: Add C2 handler for Transfer/Debug operation#6434
NIFI-10493 MiNiFi: Add C2 handler for Transfer/Debug operation#6434briansolo1985 wants to merge 5 commits intoapache:mainfrom
Conversation
0aedc71 to
8bcad1a
Compare
ferencerdei
left a comment
There was a problem hiding this comment.
Thanks for the contribution, I have some recommendations. Please have a look.
| try { | ||
| Path tempDirectory = createTempDirectory(null); | ||
| Path tempFile = Paths.get(tempDirectory.toAbsolutePath().toString(), fileName); | ||
| write(tempFile, (Iterable<String>) lines(path).filter(contentFilter)::iterator); |
There was a problem hiding this comment.
I think lines() needs to be used with try with resource
There was a problem hiding this comment.
Thanks for spotting this, I missed that
| } | ||
|
|
||
| public Optional<byte[]> createDebugBundle(List<Path> filePaths) { | ||
| if (filePaths.size() == 0) { |
There was a problem hiding this comment.
You can use the isEmpty() method
| } | ||
| } catch (Exception e) { | ||
| LOG.error("Error during create compressed bundle", e); | ||
| closeQuietly(byteOutputStream); |
There was a problem hiding this comment.
can't we use try with resources here also?
Also It's not clear why do we need to call the close here and in the finally as well.
There was a problem hiding this comment.
Unfortunately we can't. I need the ByteArrayOutputStream reference to return with byte[] in the end. However if I return with byteOutputStream.toByteArray() from the try-with-resources block, it will return with a malformed result. It seems byteOutputStream needs to be closed before it can be converted to a byte array.
Regarding the two closeQuietly, I had to close the stream in the catch block before nulling the reference out, so it couldn't be closed in the finally clause. I changed this part to be more straightforward.
| } | ||
|
|
||
| enum LogFile implements DebugBundleFile { | ||
| APP_LOG_FILE("minifi-app.log"), |
There was a problem hiding this comment.
The filenames depend on the logback configuration. It's not ideal to hardcode this. Can we use it from a property?
There was a problem hiding this comment.
Thanks for highlighting this. Now these are injected via properties
| } | ||
|
|
||
| private void cleanup(List<Path> paths) { | ||
| paths.forEach(path -> { |
There was a problem hiding this comment.
what do you think about removing the temporary directory as well?
There was a problem hiding this comment.
Added logic to remove the temporary directory
| } | ||
|
|
||
| enum ConfigFile implements DebugBundleFile { | ||
| CONFIG_YML_FILE("config.yml"), |
There was a problem hiding this comment.
These file names are also configurable via environment and bootsrap.conf variables, therefore we shouldn't hardcode.
There was a problem hiding this comment.
Fixed this as well
bejancsaba
left a comment
There was a problem hiding this comment.
Thank you for this new exciting improvement. I agree with the comments from @ferencerdei on top of those I added only a few. The big one would be the one around file names. If these are addressed I think we are good to merge.
| .build()) | ||
| .build(); | ||
|
|
||
| logger.info("Uploading debug bundle to url={} size={}", debugCallbackUrl, debugBundle.length); |
There was a problem hiding this comment.
Super minor just for the sake of consistency sometimes url is logged just as part of the text, sometimes is in brackets [] and sometimes is behind "=". I'm pretty sure it is inconsistent outside this change as well just I saw these 3 patterns in this change. I'm ok with whatever approach so will leave that to you.
There was a problem hiding this comment.
Standardized the log messages
| <dependency> | ||
| <groupId>org.apache.commons</groupId> | ||
| <artifactId>commons-compress</artifactId> | ||
| <version>1.21</version> |
There was a problem hiding this comment.
Please externalise the version to the main nifi pom so everything is in one place.
There was a problem hiding this comment.
I checked the occurrences of this dependency in other modules. Everywhere it is used with version. To not break consistency I would leave this as it is, if you don't mind
|
|
||
| /** | ||
| * Retrive the content of the new flow from the C2 Server | ||
| * Retrieve the content of the new flow from the C2 Server |
|
|
||
| @Override | ||
| public C2OperationAck handle(C2Operation operation) { | ||
| Function<C2OperationState, C2OperationAck> operationAckCreate = operationAck(operation); |
There was a problem hiding this comment.
Is there a specific need for this function based approach? Extending the function to get 2 parameters looks to be sufficient and simpler. What do you think? Or maybe there is something that I'm missing?
There was a problem hiding this comment.
Tried to use a more functional approach, but agree, Java syntax is a bit cluncky for this. Refactored to a 2 parameters accepting method
|
|
||
| enum ConfigFile implements DebugBundleFile { | ||
| CONFIG_YML_FILE("config.yml"), | ||
| CONFIG_NEW_YML_FILE("config-new.yml"), |
There was a problem hiding this comment.
I think we don't need to add the config-new.yml to the debug bundle. It's basically a temporary file that is used to construct the config.yml during config updates.
There was a problem hiding this comment.
Thanks, excluded it from the list of the files
# Conflicts: # c2/c2-client-bundle/c2-client-http/src/main/java/org/apache/nifi/c2/client/http/C2HttpClient.java # nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/c2/C2NifiClientService.java
bejancsaba
left a comment
There was a problem hiding this comment.
Conceptually it looks really good so I had just minor lower level comments regarding structure and naming should be really simple to address. After the NiFi release we should be good to merge.
...-client-bundle/c2-client-http/src/main/java/org/apache/nifi/c2/client/http/C2HttpClient.java
Outdated
Show resolved
Hide resolved
...-client-bundle/c2-client-http/src/main/java/org/apache/nifi/c2/client/http/C2HttpClient.java
Outdated
Show resolved
Hide resolved
...-client-bundle/c2-client-http/src/main/java/org/apache/nifi/c2/client/http/C2HttpClient.java
Outdated
Show resolved
Hide resolved
...service/src/main/java/org/apache/nifi/c2/client/service/operation/DebugOperationHandler.java
Outdated
Show resolved
Hide resolved
...service/src/main/java/org/apache/nifi/c2/client/service/operation/DebugOperationHandler.java
Outdated
Show resolved
Hide resolved
...service/src/main/java/org/apache/nifi/c2/client/service/operation/DebugOperationHandler.java
Outdated
Show resolved
Hide resolved
...service/src/main/java/org/apache/nifi/c2/client/service/operation/DebugOperationHandler.java
Outdated
Show resolved
Hide resolved
...ice/src/test/java/org/apache/nifi/c2/client/service/operation/DebugOperationHandlerTest.java
Show resolved
Hide resolved
...ice/src/test/java/org/apache/nifi/c2/client/service/operation/DebugOperationHandlerTest.java
Outdated
Show resolved
Hide resolved
...ice/src/test/java/org/apache/nifi/c2/client/service/operation/DebugOperationHandlerTest.java
Outdated
Show resolved
Hide resolved
bejancsaba
left a comment
There was a problem hiding this comment.
+1 from my side all the changes look good, thanks for applying those
This closes apache#6434 Signed-off-by: Ferenc Erdei <erdei.ferenc90@gmail.com>
Summary
NIFI-10493
Tracking
Please complete the following tracking steps prior to pull request creation.
Issue Tracking
Pull Request Tracking
NIFI-00000NIFI-00000Pull Request Formatting
mainbranchVerification
Please indicate the verification steps performed prior to pull request creation.
Build
mvn clean install -P contrib-checkLicensing
LICENSEandNOTICEfilesDocumentation