Skip to content

Refactor CI module to use constants for result field names and API state values #403

@Chaffelson

Description

@Chaffelson

Summary

The CI module uses raw string literals for result dictionary keys and API state comparisons. These should be refactored to use constants (or enums where appropriate) for better maintainability and IDE support.

This was identified during PR review feedback from @ottobackwards.

Background

The CI module functions return dictionaries with standardized field names that are consumed by CI/CD pipelines (GitHub Actions outputs, GitLab CI dotenv). Currently these are raw strings:

# nipyapi/ci/get_status.py
result["queued_flowfiles"] = str(agg.flow_files_queued or 0)
result["queued_bytes"] = str(agg.bytes_queued or 0)
result["active_threads"] = str(agg.active_thread_count or 0)

Similarly, API state values are compared as raw strings:

if c.component.state == "ENABLED":
if vci.state not in ["UP_TO_DATE", "SYNC_FAILURE"]:
if b.level == "WARNING":

Scope

Result field names (~58 instances across 8+ files):

  • get_status.py - ~30 fields (largest)
  • verify_config.py, configure_inherited_params.py, upload_asset.py, list_registry_flows.py, export_parameters.py, etc.

API state values (used in comparisons):

  • Controller states: ENABLED, DISABLED
  • Version control states: UP_TO_DATE, SYNC_FAILURE, LOCALLY_MODIFIED, STALE
  • Bulletin levels: WARNING, ERROR
  • Process group states: RUNNING, STOPPED

Note: Many API values already have allowed_values validation in the generated OpenAPI models (nipyapi/nifi/models/), so these are stable and well-defined by the NiFi API spec.

Proposed Approach

  1. Create nipyapi/ci/constants.py with:

    • Result field name constants (e.g., FIELD_QUEUED_FLOWFILES = "queued_flowfiles")
    • API state constants grouped by category (e.g., STATE_ENABLED = "ENABLED")
  2. Update CI module files to import and use these constants

  3. Update tests to use the same constants

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions