From eeba8477168bc1f1a5647b22e4246336a207a4d0 Mon Sep 17 00:00:00 2001 From: Matt Jia Date: Aug 02 2017 06:12:18 +0000 Subject: WIP: integrating multiple resultsdb instances --- diff --git a/greenwave/api_v1.py b/greenwave/api_v1.py index 466c054..ecb85e4 100644 --- a/greenwave/api_v1.py +++ b/greenwave/api_v1.py @@ -100,12 +100,18 @@ def make_decision(): answers = [] timeout = current_app.config['REQUESTS_TIMEOUT'] for item in subjects: - # XXX make this more efficient than just fetching everything - response = requests_session.get( - current_app.config['RESULTSDB_API_URL'] + '/results', - params={'item': item, 'limit': '1000'}, timeout=timeout) - response.raise_for_status() - results = response.json()['data'] + results = [] + for url in current_app.config['RESULTSDB_API_URLS']: + # XXX make this more efficient than just fetching everything + response = requests_session.get( + url + '/results', + params={'item': item, 'limit': '1000'}, timeout=timeout) + response.raise_for_status() + results = response.json()['data'] + if results: + # If we have found the results, then stop looking up other sources + # as in theory the results should be stored in one ResultsDB instance. + break if results: response = requests_session.get( current_app.config['WAIVERDB_API_URL'] + '/waivers/', diff --git a/greenwave/config.py b/greenwave/config.py index ee38235..866c81b 100644 --- a/greenwave/config.py +++ b/greenwave/config.py @@ -11,7 +11,7 @@ class Config(object): PORT = 5005 PRODUCTION = False SECRET_KEY = 'replace-me-with-something-random' - RESULTSDB_API_URL = 'https://taskotron.fedoraproject.org/resultsdb_api/api/v2.0' + RESULTSDB_API_URLS = ['https://taskotron.fedoraproject.org/resultsdb_api/api/v2.0'] WAIVERDB_API_URL = 'https://waiverdb.fedoraproject.org/api/v1.0' REQUESTS_TIMEOUT = (6.1, 15) POLICIES_DIR = '/etc/greenwave/policies' @@ -23,8 +23,8 @@ class ProductionConfig(Config): class DevelopmentConfig(Config): - #RESULTSDB_API_URL = 'https://taskotron.stg.fedoraproject.org/resultsdb_api/api/v2.0' - RESULTSDB_API_URL = 'http://localhost:5001/api/v2.0' + #RESULTSDB_API_URLS = ['https://taskotron.stg.fedoraproject.org/resultsdb_api/api/v2.0'] + RESULTSDB_API_URLS = ['http://localhost:5001/api/v2.0'] #WAIVERDB_API_URL = 'http://waiverdb-dev.fedorainfracloud.org/api/v1.0' WAIVERDB_API_URL = 'http://localhost:5004/api/v1.0' POLICIES_DIR = os.path.join( @@ -34,7 +34,7 @@ class DevelopmentConfig(Config): class TestingConfig(Config): - RESULTSDB_API_URL = 'http://localhost:5001/api/v2.0' + RESULTSDB_API_URLS = ['http://localhost:5001/api/v2.0'] WAIVERDB_API_URL = 'http://localhost:5004/api/v1.0' POLICIES_DIR = os.path.join( os.path.dirname(os.path.dirname(os.path.abspath(__file__))), 'conf',