From 0ec8427d054a2b2e901f35d69fee6ae1953618da Mon Sep 17 00:00:00 2001 From: Marc Bonnici Date: Mon, 18 Mar 2019 15:02:52 +0000 Subject: [PATCH] fw/output: Implement retriving "augmentations" for `JobDatabaseOutput`s Enable retriving augmentations on a per job basis when using a Postgres database backend. --- wa/framework/output.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/wa/framework/output.py b/wa/framework/output.py index 3119e6ce..59f7451c 100644 --- a/wa/framework/output.py +++ b/wa/framework/output.py @@ -1010,6 +1010,7 @@ class RunDatabaseOutput(DatabaseOutput, RunOutputCommon): jobs = self._read_db(columns, tables, conditions) for job in jobs: + job['augmentations'] = self._get_job_augmentations(job['oid']) job['workload_parameters'] = workload_params.pop(job['oid'], {}) job['runtime_parameters'] = runtime_params.pop(job['oid'], {}) job.pop('oid') @@ -1173,6 +1174,15 @@ class RunDatabaseOutput(DatabaseOutput, RunOutputCommon): logger.debug('Failed to deserialize job_oid:{}-"{}":"{}"'.format(job_oid, k, v)) return parm_dict + def _get_job_augmentations(self, job_oid): + columns = ['jobs_augs.augmentation_oid', 'augmentations.name', + 'augmentations.oid', 'jobs_augs.job_oid'] + tables = ['jobs_augs', 'augmentations'] + conditions = ['jobs_augs.job_oid = \'{}\''.format(job_oid), + 'jobs_augs.augmentation_oid = augmentations.oid'] + augmentations = self._read_db(columns, tables, conditions) + return [aug['name'] for aug in augmentations] + def _list_runs(self): columns = ['runs.run_uuid', 'runs.run_name', 'runs.project', 'runs.project_stage', 'runs.status', 'runs.start_time', 'runs.end_time'] @@ -1224,3 +1234,11 @@ class JobDatabaseOutput(DatabaseOutput): def __str__(self): return '{}-{}-{}'.format(self.id, self.label, self.iteration) + + @property + def augmentations(self): + job_augs = set([]) + if self.spec: + for aug in self.spec.augmentations: + job_augs.add(aug) + return list(job_augs)