NIFI-12160: Kafka Connect: Check if all the necessary nars have been …#7832
NIFI-12160: Kafka Connect: Check if all the necessary nars have been …#7832pgyori wants to merge 4 commits intoapache:mainfrom
Conversation
…fully unpacked before starting a connector
|
The integration test ITStatelessKafkaConnectorUtil.testCreateDataflowThenCorruptWorkingDirectoryAndRedeployDataflow() currently can only be executed on NiFi 1.x branch because it needs to fetch the most recent version of the Stateless NiFi Kafka Connector Plugin from the repository https://repository.apache.org/content/repositories/releases/org/apache/nifi/nifi-kafka-connector-assembly/ and the most recent build of the plugin in the repo (v.1.23.2) is not compatible with the changes in NiFi 2.x. |
exceptionfactory
left a comment
There was a problem hiding this comment.
Thanks for working on improving the behavior @pgyori. As noted in the detailed comments, I am concerned about introducing a new integration test for this specific issue. It looks like the purge logic could be abstracted out, which would make it much easier to unit test quickly. What do you think of that approach?
| <dependency> | ||
| <groupId>commons-io</groupId> | ||
| <artifactId>commons-io</artifactId> | ||
| <version>2.13.0</version> |
There was a problem hiding this comment.
This version number should be removed because it is set in the root Maven configuration.
There was a problem hiding this comment.
Although this exercise the issue, we should avoid adding new integration tests unless they provide significant value. Integration tests outside of nifi-system-test-suite are not executed in automated workflows and canmore stale when refactoring.
| } | ||
|
|
||
| private static void checkWorkingDirectoryIntegrity(final File workingDirectory) { | ||
| purgeIncompleteUnpackedNars(new File(new File(workingDirectory, "nar"), "extensions")); |
There was a problem hiding this comment.
It looks like purge method could be abstracted to a separate utility, which would make it much easier to unit test.
|
Thank you @exceptionfactory for your feedback! |
…ve been fully unpacked before starting a connector" This reverts commit 4337982.
…fully unpacked before starting a connector
exceptionfactory
left a comment
There was a problem hiding this comment.
Thanks for making the adjustments and refactoring the testing approach @pgyori, the updated version appears more straightforward. I noted several naming adjustment recommendations, but this looks closer to completion.
| final File[] unpackedDirs = directory.listFiles(file -> file.isDirectory() && file.getName().endsWith(NAR_UNPACKED_SUFFIX)); | ||
| if (unpackedDirs == null || unpackedDirs.length == 0) { | ||
| logger.debug("Found no unpacked NARs in {}", directory); | ||
| logger.debug("Directory contains: {}", Arrays.deepToString(directory.listFiles())); |
There was a problem hiding this comment.
The Arrays.deepToString() could be somewhat expensive, recommend wrapping this log in a conditional of isDebugEnabled().
| if (!narHashFile.exists()) { | ||
| purgeDirectory(unpackedDir); | ||
| } else { | ||
| logger.debug("Already successfully unpacked {}", unpackedDir); | ||
| } |
There was a problem hiding this comment.
Recommend reversing the logic to make it more straightforward:
| if (!narHashFile.exists()) { | |
| purgeDirectory(unpackedDir); | |
| } else { | |
| logger.debug("Already successfully unpacked {}", unpackedDir); | |
| } | |
| if (narHashFile.exists()) { | |
| logger.debug("Already successfully unpacked {}", unpackedDir); | |
| } else { | |
| purgeDirectory(unpackedDir); | |
| } |
| deleteOrDebug(fileOrDirectory); | ||
| } | ||
|
|
||
| private static void deleteOrDebug(final File file) { |
There was a problem hiding this comment.
Recommend renaming to deleteQuietly.
| private static void deleteOrDebug(final File file) { | |
| private static void deleteQuietly(final File file) { |
| * "nar-digest" file in it. | ||
| * @param workingDirectory File object pointing to the working directory. | ||
| */ | ||
| public static void checkWorkingDirectoryIntegrity(final File workingDirectory) { |
There was a problem hiding this comment.
The documentation comment is helpful, but the name of signature of the method are not very clear. What do you think of naming this something like reconcileWorkingDirectory?
| public static final String NAR_UNPACKED_SUFFIX = "nar-unpacked"; | ||
| public static final String HASH_FILENAME = "nar-digest"; |
There was a problem hiding this comment.
Can these be marked as protected since the only outside reference appears to be the test class?
| import java.io.File; | ||
| import java.util.Arrays; | ||
|
|
||
| public class StatelessKafkaConnectorWorkingDirectoryUtil { |
There was a problem hiding this comment.
Given that this class is already in the kafka.connect package, the name can be simplified. The general convention for utilities is ending with Utils. What do you think about WorkingDirectoryUtils?
|
Thank you @exceptionfactory ! I made the changes you recommended. Can you please recheck when your time permits? |
exceptionfactory
left a comment
There was a problem hiding this comment.
Thanks for making the adjustments @pgyori! +1 merging
…fully unpacked before starting a connector
Summary
NIFI-12160
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