Skip to content

NIFI-10230 added FetchSmb#6279

Closed
kulikg wants to merge 9 commits intoapache:mainfrom
kulikg:NIFI-10230
Closed

NIFI-10230 added FetchSmb#6279
kulikg wants to merge 9 commits intoapache:mainfrom
kulikg:NIFI-10230

Conversation

@kulikg
Copy link
Contributor

@kulikg kulikg commented Aug 9, 2022

Summary

NIFI-00000

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
    • [x ] 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

Copy link
Contributor

@exceptionfactory exceptionfactory 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 introducing this new component @kulikg!

The general implementation looks good, I noted a few questions about property configuration and error handling.

REL_FAILURE,
REL_INPUT_FAILURE
)));
static final PropertyDescriptor RECORD_READER = new PropertyDescriptor.Builder()
Copy link
Contributor

Choose a reason for hiding this comment

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

This property descriptor declaration should be moved up in the file, following after the SMB_CLIENT_PROVIDER_SERVICE.

} catch (Exception e) {
handleInputError(e, session, flowFile);
} finally {
session.remove(flowFile);
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems like the original FlowFile should be routed on failures, instead of cloning and creating a new FlowFile. Following this approach, the input FlowFile would be removed only on a successful fetch.

Comment on lines +168 to +171
final SmbClientProviderService clientProviderService =
context.getProperty(SMB_CLIENT_PROVIDER_SERVICE).asControllerService(SmbClientProviderService.class);

try (SmbClientService client = clientProviderService.getClient()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

The current implementation repeatedly calls getClient() when using record-oriented processing. It would be more efficient to move the retrieval of the SmbClientService out of this method.

Comment on lines +175 to +176
session.putAttribute(outFlowFile, ERROR_CODE_ATTRIBUTE, getErrorCode(e));
session.putAttribute(outFlowFile, ERROR_MESSAGE_ATTRIBUTE, e.getMessage());
Copy link
Contributor

Choose a reason for hiding this comment

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

The return value from putAttribute() needs to be assigned so that the session is working with the most recent FlowFile reference object.

In general, method arguments should be declared as final, but in this case, the outFlowFile variable could be reassigned:

Suggested change
session.putAttribute(outFlowFile, ERROR_CODE_ATTRIBUTE, getErrorCode(e));
session.putAttribute(outFlowFile, ERROR_MESSAGE_ATTRIBUTE, e.getMessage());
outFlowFile = session.putAttribute(outFlowFile, ERROR_CODE_ATTRIBUTE, getErrorCode(e));
outFlowFile = session.putAttribute(outFlowFile, ERROR_MESSAGE_ATTRIBUTE, e.getMessage());

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 think the test framework should complain about this too.

Copy link
Contributor

Choose a reason for hiding this comment

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

It might be difficult to implement this correctly, but it could be a useful addition under a separate issue.


private void handleInputError(Exception exception, ProcessSession session, FlowFile flowFile) {
if (exception instanceof IOException || exception instanceof MalformedRecordException || exception instanceof SchemaNotFoundException) {
getLogger().error("Couldn't read file metadata content as records from incoming flowfile", exception);
Copy link
Contributor

Choose a reason for hiding this comment

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

Recommend adjusting the wording and including the FlowFile in the log for troubleshooting:

Suggested change
getLogger().error("Couldn't read file metadata content as records from incoming flowfile", exception);
getLogger().error("Failed to read input records {}", flowFile, exception);

if (exception instanceof IOException || exception instanceof MalformedRecordException || exception instanceof SchemaNotFoundException) {
getLogger().error("Couldn't read file metadata content as records from incoming flowfile", exception);
} else {
getLogger().error("Unexpected error while processing incoming flowfile", exception);
Copy link
Contributor

Choose a reason for hiding this comment

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

Recommend adjusting the wording and including the FlowFile:

Suggested change
getLogger().error("Unexpected error while processing incoming flowfile", exception);
getLogger().error("Failed to read input {}", flowFile, exception);

return Optional.ofNullable(exception instanceof SmbException ? (SmbException) exception : null)
.map(SmbException::getErrorCode)
.map(String::valueOf)
.orElse("N/A");
Copy link
Contributor

Choose a reason for hiding this comment

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

The use of N/A as a placeholder does not seem like the best option. If -1 does not already have special meaning from the SmbException, that is one option. Otherwise, some other negative number seems best, or perhaps this method should return null instead.

@turcsanyip
Copy link
Contributor

@kulikg There are Checkstyle violations. Please always run mvn clean verify -P contrib-check before adding a commit.

Copy link
Contributor

@turcsanyip turcsanyip left a comment

Choose a reason for hiding this comment

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

@kulikg Thanks for your latest changes! Please find my new comments below.

<version>1.18.0-SNAPSHOT</version>
<scope>test</scope>
</dependency>
<dependency>
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 no longer need this dependency.

import org.apache.nifi.services.smb.SmbException;

@InputRequirement(InputRequirement.Requirement.INPUT_REQUIRED)
@Tags({"samba, smb, cifs, files", "fetch"})
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure if this is an error - searching based on these tags still work on UI:

Suggested change
@Tags({"samba, smb, cifs, files", "fetch"})
@Tags({"samba", "smb", "cifs", "files", "fetch"})

sambaContainer.stop();
}

protected SmbjClientProviderService configureTestRunnerForSambaDockerContainer(TestRunner testRunner)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
protected SmbjClientProviderService configureTestRunnerForSambaDockerContainer(TestRunner testRunner)
protected SmbjClientProviderService configureSmbClient(TestRunner testRunner)

Comment on lines +72 to +73
testRunner.setProperty(smbjClientProviderService, DOMAIN, "domain");
return smbjClientProviderService;
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 it would make sense to enable the controller service here instead of all individual tests.

Suggested change
testRunner.setProperty(smbjClientProviderService, DOMAIN, "domain");
return smbjClientProviderService;
testRunner.setProperty(smbjClientProviderService, DOMAIN, "domain");
testRunner.enableControllerService(smbjClientProviderService);
return smbjClientProviderService;

Comment on lines 164 to 166
allAttributes.forEach(attribute -> assertEquals(
Stream.of(attribute.get("path"), attribute.get("filename")).filter(s -> !s.isEmpty()).collect(
Collectors.joining("/")),
Copy link
Contributor

Choose a reason for hiding this comment

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

absolute.path attribute is no longer available. This test currently fails. Should remove this assertion.

Copy link
Contributor

@turcsanyip turcsanyip left a comment

Choose a reason for hiding this comment

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

@kulikg Thanks for the review changes!

+1 LGTM

@tpalfy
Copy link
Contributor

tpalfy commented Sep 6, 2022

LGTM.

I think it's ready to be merged.
@exceptionfactory, do you have any additional comments?

Copy link
Contributor

@exceptionfactory exceptionfactory 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 checking @tpalfy, and great works on this processor @kulikg!

The latest version looks good, so feel free to merge @tpalfy.

As a minor note, it is best to avoid contractions and trailing periods in log messages, but it is fine to proceed for now.

@asfgit asfgit closed this in 5b56567 Sep 6, 2022
@tpalfy
Copy link
Contributor

tpalfy commented Sep 6, 2022

Thanks for your work @kulikg!
Thanks for you review @turcsanyip and @exceptionfactory!
Merged to main.

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

Signed-off-by: Tamas Palfy <tpalfy@apache.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants