-
Notifications
You must be signed in to change notification settings - Fork 75
Feature/port scheduling and magic entity resolution #398
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
Conversation
- Add get_port(identifier, identifier_type) for retrieving ports by ID or name - Add schedule_port(port, scheduled) following schedule_processor pattern - Register PortEntity in config.py for filter_obj support - Add comprehensive tests for both functions
Previously create_controller() set the name in a separate update call after creation, but returned the stale object from the initial call. This caused component.name to show the type name instead of the custom name. Now sets name directly in the ControllerServiceDTO during creation, matching the pattern used by create_processor(). Also defaults to short type name if no name provided (e.g., 'JsonTreeReader').
Utilities implemented in nipyapi/utils.py:
- resolve_schedule_state(): Standardized bool/string to state normalization
- resolve_entity(): Entity resolution accepting ID, name, or object
(to be used in next phase)
Scheduling functions consolidated in canvas.py:
- schedule_processor: Uses resolve_schedule_state()
- schedule_port: Uses resolve_schedule_state()
- schedule_controller: Uses resolve_schedule_state(), now accepts string
states ('ENABLED', 'DISABLED') in addition to bool
- schedule_all_controllers: Same extension
- schedule_components: Now accepts string states ('RUNNING', 'STOPPED')
Breaking change: Invalid scheduled values now raise ValueError instead
of AssertionError. This is a more appropriate exception type.
Tests expanded for new string state acceptance in controller scheduling.
All 660 tests pass.
…oss modules - Add resolve_entity() and resolve_schedule_state() utilities in utils.py - Refactor 17 canvas.py functions to accept object, ID, or name - Refactor 9 versioning.py functions with consistent entity resolution - Refactor 5 parameters.py functions with consistent entity resolution - Add schedule_port() and get_port() functions to canvas.py - Add greedy parameter to get_controller() - Remove deprecated get_variable_registry/update_variable_registry - Consolidate verification request pattern with _run_verification_request helper - Make location optional in create_process_group and create_funnel - Add PortEntity to registered_filters in config.py - Optimize fix_state_flow fixture to module scope - Update tests for new ValueError exceptions and expanded functionality Closes #396
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR implements consistent entity resolution across nipyapi, addressing issue #396. The main improvement is that functions now accept objects, IDs, or names with automatic type detection, eliminating the inconsistency where some functions only accepted specific object types or ID strings.
Key Changes
- New utility functions (
nipyapi/utils.py):resolve_entity()for automatic entity resolution andresolve_schedule_state()for normalizing bool/string scheduling states - Refactored 31 functions across canvas.py, versioning.py, and parameters.py to use consistent entity resolution patterns with new
greedyandidentifier_typeparameters - Breaking changes: Scheduling functions now raise
ValueErrorinstead ofAssertionErrorfor invalid inputs; removed deprecated Variable Registry functions (get_variable_registry,update_variable_registry)
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| nipyapi/utils.py | Added resolve_entity() and resolve_schedule_state() utilities with helper functions for consistent entity resolution and state normalization |
| nipyapi/canvas.py | Refactored 17 functions (scheduling, CRUD operations, state management, verification) to accept flexible inputs; added schedule_port() and get_port(); removed deprecated Variable Registry functions; added _run_verification_request() helper |
| nipyapi/versioning.py | Refactored 9 functions (registry client, git flow, version control) to accept flexible inputs with consistent parameter patterns |
| nipyapi/parameters.py | Refactored 5 functions (parameter context management) to accept flexible inputs |
| nipyapi/config.py | Added PortEntity to registered_filters to support name-based port lookups |
| tests/test_utils.py | Added 311 lines of comprehensive unit and integration tests for new utility functions |
| tests/test_canvas.py | Updated tests to verify new flexible input patterns and ValueError exception changes; added tests for schedule_port() and get_port() |
| tests/test_versioning_registry.py | Updated exception assertions from AssertionError to ValueError; added tests for string ID/name inputs |
| tests/test_parameters.py | Added tests for flexible input patterns (ID and name string inputs) |
| tests/conftest.py | Changed fix_state_flow fixture from function to module scope for performance (saves ~20s per test run); removed unused Variable Registry test data |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #398 +/- ##
==========================================
+ Coverage 75.91% 76.47% +0.56%
==========================================
Files 41 41
Lines 4738 4732 -6
==========================================
+ Hits 3597 3619 +22
+ Misses 1141 1113 -28 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
@Chaffelson I've opened a new pull request, #399, to work on those changes. Once the pull request is ready, I'll request review from you. |
ottobackwards
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All the entity resolutions now possibly raise exceptions, but the exceptions are not in the docstring.
It should be, so they know to handle exceptions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.
…ation (#399) * Initial plan * docs: Clarify test comment about ValueError from resolve_entity validation Co-authored-by: Chaffelson <[email protected]> --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: Chaffelson <[email protected]>
Good spot, should be fixed now |
ottobackwards
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ship it
Description
This PR implements consistent entity resolution patterns across nipyapi, addressing #396. Functions that previously required specific object types or only accepted ID strings now accept objects, IDs, or names with automatic type detection.
Motivation
Agents and users frequently trip over inconsistent function signatures:
schedule_controller)schedule_process_group)This PR standardizes all action functions to accept flexible input while maintaining backward compatibility.
Changes
New Utilities (
nipyapi/utils.py)resolve_entity()resolve_schedule_state()Refactored Functions
canvas.py (17 functions):
schedule_processor,schedule_port,schedule_controller,schedule_all_controllers,schedule_components,schedule_process_groupdelete_controller,update_controller,verify_controller,get_controller(addedgreedy)verify_processor,create_processordelete_process_group,update_process_group,purge_process_group,create_process_groupget_controller_state,clear_controller_state,get_processor_state,clear_processor_stateversioning.py (9 functions):
delete_registry_client,update_registry_client,get_version_infoupdate_git_flow_ver,get_local_modifications,stop_flow_ver,revert_flow_versave_git_flow_ver,import_process_group_definitionparameters.py (5 functions):
delete_parameter_context,delete_parameter_from_context,upsert_parameter_to_contextassign_context_to_process_group,remove_context_from_process_groupAdditional Changes During Refactoring
The following changes were discovered necessary or beneficial during the refactoring review:
New Functions
nipyapi.canvas.schedule_port()- Start/stop/disable ports (gap identified during review)nipyapi.canvas.get_port()- Retrieve port by ID or name (required for schedule_port)Dead Code Removed
get_variable_registry()- Variable Registries removed in NiFi 2.x, function was brokenupdate_variable_registry()- Use Parameter Contexts insteadConsistency Fixes
get_controller()- Added missinggreedyparameter for consistency with other getterscreate_process_group()- Madelocationoptional, useslayout.suggest_pg_position()create_funnel()- Madepositionoptional, useslayout.new_flow()Code Consolidation
_run_verification_request()- Extracted common async pattern fromverify_controllerandverify_processor_check_processor_state()- Consolidated multiple state-checking helpers into parameterized function_check_port_state()- Same consolidation for port schedulingConfiguration
PortEntityadded toregistered_filtersin config.py (required forget_portname lookup)Test Optimization
fix_state_flowfixture changed to module scope (saves ~20s per test run)New Parameters
All refactored functions gain:
greedy(bool, default=True) - Partial vs exact name matchingidentifier_type(str, default="auto") - Force "id" or "name" lookupBreaking Changes
ValueErrorinstead ofAssertionErrorfor invalid scheduling inputsWhat changed: Scheduling functions (
schedule_controller,schedule_all_controllers,schedule_components) now raiseValueErrorinstead ofAssertionErrorwhen given invalidscheduledparameter values.Why:
AssertionErroris intended for internal invariant violations, not user input validation.ValueErroris the standard Python exception for invalid arguments and provides clearer error messages.Impact: Low. Code catching
AssertionErrorfrom these functions is rare, and the newValueErrormessages are more descriptive. Users who weren't catching exceptions see improved error messages.Removed Variable Registry functions
What changed:
get_variable_registry()andupdate_variable_registry()removed fromnipyapi.canvas.Why: Variable Registries were deprecated in NiFi 1.10 (2019) and removed entirely in NiFi 2.x. The underlying API endpoints no longer exist, so these functions would fail with cryptic errors if called.
Impact: None for NiFi 2.x users (functions were already broken). Users on older NiFi versions should use Parameter Contexts (
nipyapi.parameters) which have been the replacement since NiFi 1.10.Testing
All tests pass across authentication profiles:
Examples
Checklist