Skip to content

Conversation

@markoceri
Copy link
Collaborator

@markoceri markoceri commented Nov 23, 2025

This branch implements the work needed for issue #32, delivering both the command-line interface and the REST API required to create, inspect, update, enable/disable, and delete Energy Optimization Units. It also introduces the associated validation schemas and integrates the new router into the FastAPI bootstrap so the endpoints are exposed alongside the existing domain APIs.

CLI Interaction

  • Entry point: optimization_unit_menu(configuration_service, logger) adds three options to the interactive console: create, list, and manage units.
  • Creation flow (handle_add_optimization_unit) walks the operator through selecting energy sources, policies, miners (multi-select), and notifiers. It refuses to proceed if any required selection is missing and logs errors via the provided logger.
  • Management flow (manage_single_optimization_unit_menu) lets operators activate/deactivate, update metadata and relationships, and add/remove individual miners or notifiers, delegating to helper functions such as manage_assign_energy_source and manage_add_target_miner.
  • Listing helpers (list_optimization_units, print_optimization_unit_details) format the output with colorized click styles for immediate readability.

REST API Interaction

All routes are mounted under /api/v1/optimization-units thanks to the bootstrap change in edge_mining.adapters.infrastructure.api.main_api.

Method & Path Description
GET /optimization-units Returns every configured unit (EnergyOptimizationUnitSchema).
POST /optimization-units Creates a unit from EnergyOptimizationUnitCreateSchema, validating UUIDs and trimming strings.
GET /optimization-units/{unit_id} Fetches a single unit; returns 404 if it does not exist.
PUT /optimization-units/{unit_id} Updates names, descriptions, and all relationships in one call.
DELETE /optimization-units/{unit_id} Removes a unit and returns the deleted representation.
POST /optimization-units/{unit_id}/enable Activates the unit via ConfigurationService.activate_optimization_unit.
POST /optimization-units/{unit_id}/disable Deactivates the unit.
POST /optimization-units/{unit_id}/energy-source Assigns an energy source.
POST /optimization-units/{unit_id}/policy Assigns an optimization policy.
POST /optimization-units/{unit_id}/miners / POST .../miners/single / DELETE .../miners/{miner_id} Bulk assign, add, or remove miners.
POST /optimization-units/{unit_id}/notifiers / POST .../notifiers/single / DELETE .../notifiers/{notifier_id} Bulk assign, add, or remove notifiers.

How To Interact

CLI

  1. Launch the application entry point (python -m edge_mining cli interactive).
  2. Navigate to the Energy Optimization Unit menu.
  3. Use options 1–3 to add, list, or manage units, following the guided prompts.

REST API

  1. Start the FastAPI app (python -m edge_mining).
  2. Use the swagger to interact with the APIs (using the Fast API Swagger UI at http://localhost:8001/docs)
  3. Use the enable/disable and assignment routes to mirror the CLI operations programmatically.

Additional Notes

  • The CLI and REST layers both rely on the same ConfigurationServiceInterface, ensuring consistent validation and side-effects regardless of the entry point.
  • The new error-handling logic in OptimizationService makes optimization runs resilient when an adapter or external service is misconfigured, surfacing issues via the shared logger and optional notifications.
  • Home forecast providers and performance tracker assignments are scaffolded but still marked for future releases; placeholders are left in both CLI and API flows.

…e tracker IDs, they will be released in the nex release
…h improved selection options for energy sources, miners, policy and notifiers
@markoceri markoceri added this to the 0.1.0 milestone Nov 23, 2025
@markoceri markoceri linked an issue Nov 23, 2025 that may be closed by this pull request
@markoceri markoceri added the enhancement New feature or request label Nov 23, 2025
@markoceri markoceri marked this pull request as ready for review November 23, 2025 22:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add REST API for Energy Optimization Unit (optimization_unit) domain

2 participants