From 40677d60e3fc12e5b076231322aa7dac9053bb41 Mon Sep 17 00:00:00 2001 From: Felipe Monteiro Date: Thu, 30 Nov 2017 04:39:48 +0000 Subject: [PATCH] Update DeckhandOperator to do filtering/sorting server-side This PS updates DeckhandOperator to allow Deckhand to do filtering/sorting by way of query parameters passed in from Shipyard, rather than relying on Shipyard to fix up the response from Deckhand to find the revision with the committed tag. This is possible now that Deckhand supports sorting and ordering as query parameters: https://review.gerrithub.io/#/c/389437/ Change-Id: Idf812faacc78af4acbbbaf9ea5168e64f7333a80 --- shipyard_airflow/plugins/deckhand_operator.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/shipyard_airflow/plugins/deckhand_operator.py b/shipyard_airflow/plugins/deckhand_operator.py index 74145477..8cd113cf 100644 --- a/shipyard_airflow/plugins/deckhand_operator.py +++ b/shipyard_airflow/plugins/deckhand_operator.py @@ -119,8 +119,10 @@ class DeckhandOperator(BaseOperator): logging.info("Retrieving revisions information...") try: + query_params = {'tag': 'committed', 'sort': 'id', 'order': 'desc'} revisions = yaml.safe_load(requests.get( - revision_endpoint, headers=x_auth_token).text) + revision_endpoint, headers=x_auth_token, + params=query_params).text) except requests.exceptions.RequestException as e: raise AirflowException(e) @@ -133,14 +135,10 @@ class DeckhandOperator(BaseOperator): # Initialize Committed Version committed_ver = None - # Construct revision_list - revision_list = revisions.get('results', []) - # Search for the last committed version and save it as xcom - for revision in reversed(revision_list): - if 'committed' in revision.get('tags'): - committed_ver = revision.get('id') - break + revision_list = revisions.get('results', []) + if revision_list: + committed_ver = revision_list[-1].get('id') if committed_ver: logging.info("Last committed revision is %d", committed_ver)