Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NIFI-13745 StateManager available via the Python API #9419

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

pgyori
Copy link
Contributor

@pgyori pgyori commented Oct 18, 2024

Summary

NIFI-13745

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 21

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 putting together support for Component State management @pgyori. The package naming and general exception handling approach looks good. The documentation and tests are also very helpful.

I raised a couple questions regarding implementation details.

Comment on lines +125 to +128
if self._java_statemap.getStateVersion().isEmpty():
return None
else:
return self._java_statemap.getStateVersion().get()
Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like this could be set in the constructor.

"""
return self.to_dictionary()

def to_dictionary(self):
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 reason for defining this method separately from toMap?

try:
self._java_state_manager.setState(convert_pydict_to_jmap(state), convert_pyscope_to_jscope(scope))
except Py4JJavaError as exception:
raise StateException(str(exception)) from None
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 it would be better to chain the original exception, as opposed to stringifying it as shown. Is there a particular reason for not chaining the exception?

Suggested change
raise StateException(str(exception)) from None
raise StateException("Set state failed") from exception

Comment on lines +167 to +170
The StateManager Python class propagates the method calls to the underlying Java StateManager object.
When an operation fails on the Java side, a Py4JJavaError is produced on the Python side by the Py4J bridge.
This Py4JJavaError is caught in the Python StateManager and raised as a StateException instead,
indicating that the exception carries information regarding an error when accessing the state.
Copy link
Contributor

Choose a reason for hiding this comment

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

This comment seems more appropriate on the State Manager class, as opposed to the exception itself.

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.

2 participants