Documentation
¶
Overview ¶
Package importer provides functionality for importing job data into the ClusterCockpit database.
The package supports two primary use cases:
- Bulk database initialization from archived jobs via InitDB()
- Individual job import from file pairs via HandleImportFlag()
Both operations enrich job metadata by calculating footprints and energy metrics before persisting to the database.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func HandleImportFlag ¶
HandleImportFlag imports jobs from file pairs specified in a comma-separated flag string.
The flag format is: "<path-to-meta.json>:<path-to-data.json>[,<path-to-meta2.json>:<path-to-data2.json>,...]"
For each job pair, this function:
- Reads and validates the metadata JSON file (schema.Job)
- Reads and validates the job data JSON file (schema.JobData)
- Enriches the job with calculated footprints and energy metrics
- Validates the job using SanityChecks()
- Imports the job into the archive
- Inserts the job into the database with associated tags
Schema validation is performed if config.Keys.Validate is true.
Returns an error if file reading, validation, enrichment, or database operations fail. The function stops processing on the first error encountered.
func InitDB ¶
func InitDB() error
InitDB reinitializes the job database from archived job data.
This function performs the following operations:
- Flushes existing job, tag, and jobtag tables
- Iterates through all jobs in the archive
- Enriches each job with calculated footprints and energy metrics
- Inserts jobs and tags into the database in batched transactions
Jobs are processed in batches of 100 for optimal performance. The function continues processing even if individual jobs fail, logging errors and returning a summary at the end.
Returns an error if database initialization, transaction management, or critical operations fail. Individual job failures are logged but do not stop the overall import process.
func Normalize ¶
Normalize adjusts a metric value and its SI unit prefix to a more readable range.
This function is useful for automatically scaling metrics to appropriate units. For example, normalizing 2048 MiB might result in ~2.0 GiB.
The function analyzes the average value and determines if a different SI prefix would make the number more human-readable (typically keeping values between 1 and 1000).
Parameters:
- avg: The metric value to normalize
- p: The current SI prefix as a string (e.g., "K", "M", "G")
Returns:
- factor: The multiplicative factor to apply to convert the value
- newPrefix: The new SI prefix string to use
Example:
factor, newPrefix := Normalize(2048.0, "M") // returns factor for MB->GB conversion, "G"
func SanityChecks ¶
SanityChecks validates job metadata and ensures cluster/subcluster configuration is valid.
This function performs the following validations:
- Verifies the cluster exists in the archive configuration
- Assigns and validates the subcluster (may modify job.SubCluster)
- Validates job state is a recognized value
- Ensures resources and user fields are populated
- Validates node counts and hardware thread counts are positive
- Verifies the number of resources matches the declared node count
The function may modify the job's SubCluster field if it needs to be assigned.
Returns an error if any validation check fails.
Types ¶
This section is empty.