def get_all(self): LOG.info("Get all %ss.", self.type) jobs = [ resources.Job.from_dict(db_model.to_dict()) for db_model in db_api.get_jobs() ] return resources.Jobs(jobs=jobs)
def delete(self, function_id, version): """Delete a specific function version. - The version should not being used by any job - The version should not being used by any webhook - Admin user can not delete normal user's version """ ctx = context.get_ctx() acl.enforce('function_version:delete', ctx) LOG.info("Deleting version %s of function %s.", version, function_id) with db_api.transaction(): version_db = db_api.get_function_version(function_id, version, insecure=False) latest_version = version_db.function.latest_version version_jobs = db_api.get_jobs( function_id=version_db.function_id, function_version=version_db.version_number, status={'nin': ['done', 'cancelled']}) if len(version_jobs) > 0: raise exc.NotAllowedException( 'The function version is still associated with running ' 'job(s).') version_webhook = db_api.get_webhooks( function_id=version_db.function_id, function_version=version_db.version_number, ) if len(version_webhook) > 0: raise exc.NotAllowedException( 'The function version is still associated with webhook.') filters = rest_utils.get_filters( function_id=version_db.function_id, function_version=version_db.version_number) version_aliases = db_api.get_function_aliases(**filters) if len(version_aliases) > 0: raise exc.NotAllowedException( 'The function version is still associated with alias.') # Delete resources for function version self.engine_client.delete_function(function_id, version=version) etcd_util.delete_function(function_id, version=version) self.storage_provider.delete(ctx.projectid, function_id, None, version=version) db_api.delete_function_version(function_id, version) if latest_version == version: version_db.function.latest_version = latest_version - 1 LOG.info("Version %s of function %s deleted.", version, function_id)
def get_all(self, all_projects=False, project_id=None): project_id, all_projects = rest_utils.get_project_params( project_id, all_projects) if all_projects: acl.enforce('job:get_all:all_projects', context.get_ctx()) filters = rest_utils.get_filters(project_id=project_id, ) LOG.info("Get all %ss. filters=%s", self.type, filters) db_jobs = db_api.get_jobs(insecure=all_projects, **filters) jobs = [resources.Job.from_db_obj(db_model) for db_model in db_jobs] return resources.Jobs(jobs=jobs)