forked from mozilla-services/socorro
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request mozilla-services#459 from ossreleasefeed/default-t…
…hrottle-level-wrong-731325 Ensure throttle level is always set fixes bug 731325
- Loading branch information
Showing
8 changed files
with
512 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
import logging | ||
import psycopg2 | ||
|
||
from socorro.external.postgresql.base import add_param_to_dict, PostgreSQLBase | ||
from socorro.lib import datetimeutil, external_common | ||
|
||
import socorro.database.database as db | ||
|
||
logger = logging.getLogger("webapi") | ||
|
||
|
||
class MissingOrBadArgumentException(Exception): | ||
pass | ||
|
||
|
||
class Products(PostgreSQLBase): | ||
|
||
def get_versions(self, **kwargs): | ||
""" Return product information for one or more product:version | ||
combinations """ | ||
filters = [ | ||
("versions", None, ["list", "str"]) | ||
] | ||
|
||
params = external_common.parse_arguments(filters, kwargs) | ||
|
||
if not params.versions or params.versions[0] == '': | ||
raise MissingOrBadArgumentException( | ||
"Mandatory parameter 'versions' missing or empty") | ||
|
||
products = [] | ||
(params["products_versions"], | ||
products) = self.parse_versions(params["versions"], []) | ||
|
||
sql_select = """ | ||
SELECT product_name as product, | ||
version_string as version, | ||
start_date, | ||
end_date, | ||
is_featured, | ||
build_type, | ||
throttle::float | ||
FROM product_info WHERE | ||
""" | ||
|
||
sql_where = [] | ||
versions_list = [] | ||
products_list = [] | ||
for x in range(0, len(params["products_versions"]), 2): | ||
products_list.append(params["products_versions"][x]) | ||
versions_list.append(params["products_versions"][x + 1]) | ||
|
||
sql_where = ["(product_name = %(product" + str(x) + | ||
")s AND version_string = %(version" + str(x) + ")s)" | ||
for x in range(len(products_list))] | ||
|
||
sql_params = {} | ||
sql_params = add_param_to_dict(sql_params, "product", products_list) | ||
sql_params = add_param_to_dict(sql_params, "version", versions_list) | ||
|
||
sql_query = " ".join( | ||
("/* socorro.external.postgresql.Products.get_versions */", | ||
sql_select, " OR ".join(sql_where))) | ||
|
||
json_result = { | ||
"total": 0, | ||
"hits": [] | ||
} | ||
|
||
try: | ||
connection = self.database.connection() | ||
cur = connection.cursor() | ||
results = db.execute(cur, sql_query, sql_params) | ||
except psycopg2.Error: | ||
logger.error( | ||
"Failed retrieving products_versions data from PostgreSQL", | ||
exc_info=True) | ||
else: | ||
for product in results: | ||
row = dict(zip(( | ||
"product", | ||
"version", | ||
"start_date", | ||
"end_date", | ||
"is_featured", | ||
"build_type", | ||
"throttle"), product)) | ||
json_result["hits"].append(row) | ||
row["start_date"] = datetimeutil.date_to_string( | ||
row["start_date"]) | ||
row["end_date"] = datetimeutil.date_to_string( | ||
row["end_date"]) | ||
json_result["total"] = len(json_result["hits"]) | ||
|
||
return json_result | ||
finally: | ||
connection.close() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import logging | ||
|
||
from socorro.middleware.service import DataAPIService | ||
|
||
logger = logging.getLogger("webapi") | ||
|
||
|
||
class ProductsVersions(DataAPIService): | ||
|
||
service_name = "products" | ||
uri = "/products/(.*)" | ||
|
||
def __init__(self, config): | ||
super(ProductsVersions, self).__init__(config) | ||
logger.debug('ProductsVersions service __init__') | ||
|
||
def get(self, *args): | ||
params = self.parse_query_string(args[0]) | ||
|
||
module = self.get_module(params) | ||
|
||
impl = module.Products(config=self.context) | ||
|
||
return impl.get_versions(**params) |
Oops, something went wrong.