Skip to content

NIFI-10493 MiNiFi: Add C2 handler for Transfer/Debug operation#6434

Closed
briansolo1985 wants to merge 5 commits intoapache:mainfrom
briansolo1985:NIFI-10458_C2_DEBUG
Closed

NIFI-10493 MiNiFi: Add C2 handler for Transfer/Debug operation#6434
briansolo1985 wants to merge 5 commits intoapache:mainfrom
briansolo1985:NIFI-10458_C2_DEBUG

Conversation

@briansolo1985
Copy link
Contributor

@briansolo1985 briansolo1985 commented Sep 20, 2022

Summary

NIFI-10493

Tracking

Please complete the following tracking steps prior to pull request creation.

Issue Tracking

Pull Request Tracking

  • Pull Request title starts with Apache NiFi Jira issue number, such as NIFI-00000
  • Pull Request commit message starts with Apache NiFi Jira issue number, as such NIFI-00000

Pull Request Formatting

  • Pull Request based on current revision of the main branch
  • 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

  • Build completed using mvn clean install -P contrib-check
    • JDK 8
    • JDK 11
    • JDK 17

Licensing

  • New dependencies are compatible with the Apache License 2.0 according to the License Policy
  • New dependencies are documented in applicable LICENSE and NOTICE files

Documentation

  • Documentation formatting appears as expected in rendered files

@ferencerdei ferencerdei added the minifi Pull requests that updates minifi/c2 codes label Sep 21, 2022
Copy link
Contributor

@ferencerdei ferencerdei left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think lines() needs to be used with try with resource

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for spotting this, I missed that

}

public Optional<byte[]> createDebugBundle(List<Path> filePaths) {
if (filePaths.size() == 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use the isEmpty() method

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed.

}
} catch (Exception e) {
LOG.error("Error during create compressed bundle", e);
closeQuietly(byteOutputStream);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor Author

@briansolo1985 briansolo1985 Sep 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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"),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The filenames depend on the logback configuration. It's not ideal to hardcode this. Can we use it from a property?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for highlighting this. Now these are injected via properties

}

private void cleanup(List<Path> paths) {
paths.forEach(path -> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what do you think about removing the temporary directory as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added logic to remove the temporary directory

}

enum ConfigFile implements DebugBundleFile {
CONFIG_YML_FILE("config.yml"),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These file names are also configurable via environment and bootsrap.conf variables, therefore we shouldn't hardcode.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed this as well

@briansolo1985 briansolo1985 changed the title NIFI-10458 MiNiFi: Add C2 handler for Transfer/Debug operation NIFI-10493 MiNiFi: Add C2 handler for Transfer/Debug operation Sep 21, 2022
Copy link
Contributor

@bejancsaba bejancsaba left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Standardized the log messages

<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-compress</artifactId>
<version>1.21</version>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please externalise the version to the main nifi pom so everything is in one place.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks


@Override
public C2OperationAck handle(C2Operation operation) {
Function<C2OperationState, C2OperationAck> operationAckCreate = operationAck(operation);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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"),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
@briansolo1985 briansolo1985 requested review from bejancsaba and ferencerdei and removed request for ferencerdei September 24, 2022 12:23
Copy link
Contributor

@bejancsaba bejancsaba left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor

@bejancsaba bejancsaba left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 from my side all the changes look good, thanks for applying those

p-kimberley pushed a commit to p-kimberley/nifi that referenced this pull request Oct 15, 2022
This closes apache#6434

Signed-off-by: Ferenc Erdei <erdei.ferenc90@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

minifi Pull requests that updates minifi/c2 codes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants