create_restoration_pipeline

Function create_restoration_pipeline 

Source
pub async fn create_restoration_pipeline(
    metadata: &FileHeader,
) -> Result<Pipeline, PipelineError>
Expand description

Creates an ephemeral restoration pipeline from .adapipe file metadata.

This function is the core of the restoration system, responsible for analyzing the processing history stored in .adapipe file headers and creating a corresponding restoration pipeline that can reverse the original processing operations.

§Functionality

The function performs the following operations:

  1. Metadata Analysis: Parses the file header to extract processing steps
  2. Pipeline Generation: Creates a unique restoration pipeline identifier
  3. Stage Reversal: Configures processing stages in reverse order (LIFO)
  4. Validation Setup: Includes checksum validation stages for integrity
  5. Error Handling: Provides comprehensive error reporting and validation

§Architecture

The function follows Domain-Driven Design principles:

  • Domain Entity: Pipeline serves as the aggregate root for restoration
  • Value Objects: Type-safe identifiers (PipelineId, StageId) ensure correctness
  • Immutability: Created pipeline stages are immutable and thread-safe
  • Error Handling: Comprehensive validation with detailed error propagation
  • Business Logic: Encapsulates restoration domain knowledge and rules

§Processing Logic

§Stage Reversal (LIFO)

Processing stages are applied in reverse order to undo the original operations:

  • Last Applied First: The last processing step becomes the first restoration step
  • Parameter Inversion: Stage parameters are configured for reverse operations
  • Checksum Validation: Automatic inclusion of integrity validation stages

§Automatic Stage Management

The pipeline automatically includes:

  • Input Checksum: Validates .adapipe file integrity
  • Output Checksum: Verifies restored file integrity
  • Processing Stages: User-defined stages in reverse order

§Parameters

  • metadata - File header containing processing history and configuration
    • Must contain valid processing steps and pipeline information
    • Used to determine the restoration sequence and parameters
    • Provides checksums for integrity validation

§Returns

Returns a Result<Pipeline> containing:

  • Success: Fully configured restoration pipeline ready for execution
  • Error: Detailed error information if pipeline creation fails

§Errors

This function can return errors for:

  • Invalid Metadata: Corrupted or malformed file headers
  • Unsupported Algorithms: Processing steps with unknown algorithms
  • Configuration Errors: Invalid stage parameters or configurations
  • Pipeline Creation: Errors during pipeline assembly

§Usage Examples

§Basic Restoration Pipeline

§Validation and Error Handling

§Complex Processing History

§Performance Characteristics

  • Lightweight: Pipeline creation is fast and memory-efficient
  • Ephemeral: Pipelines exist only for the duration of restoration
  • Thread-Safe: Created pipelines are immutable and thread-safe
  • Scalable: Can handle complex processing histories efficiently

§Security Considerations

  • Integrity Validation: Automatic checksum verification
  • Algorithm Validation: Only supported algorithms are allowed
  • Parameter Validation: Stage parameters are validated for safety
  • Audit Trail: Pipeline creation is logged for security auditing