Skip to content

Commit

Permalink
Merge pull request #713 from hubmapconsortium/karlburke/triggerFileRe…
Browse files Browse the repository at this point in the history
…index

Karlburke/trigger file reindex
  • Loading branch information
sunset666 authored Feb 7, 2023
2 parents 48cdbb8 + 96e3be7 commit c53f2ee
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 0 deletions.
79 changes: 79 additions & 0 deletions src/ingest-pipeline/airflow/dags/trigger_file_reindex.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#!/usr/bin/env python3

# Import modules
import http
import datetime

from airflow.operators.python import PythonOperator
from airflow.providers.http.hooks.http import HttpHook
from airflow.configuration import conf as airflow_conf
from airflow.exceptions import AirflowException

import utils
from utils import (
HMDAG,
get_tmp_dir_path,
get_auth_tok,
find_matching_endpoint,
get_queue_resource,
get_preserve_scratch_resource,
)

# Simple call to one files-api endpoint in AWS, cut down from the sample code recommended by Joel at
# https://github.com/hubmapconsortium/ingest-pipeline/blob/devel/src/ingest-pipeline/airflow/dags/generate_usage_report.py

default_args = {
'owner': 'hubmap',
'depends_on_past': False,
'start_date': datetime.datetime(2023, 2, 1),
'email': ['[email protected]'],
'email_on_failure': False,
'email_on_retry': False,
'retries': 1,
'retry_delay': datetime.timedelta(minutes=1),
'xcom_push': True,
'queue': get_queue_resource('trigger_file_reindex')
}

with HMDAG('trigger_file_reindex',
schedule_interval='@weekly',
is_paused_upon_creation=False,
default_args=default_args,
user_defined_macros={
'tmp_dir_path': get_tmp_dir_path,
'preserve_scratch': get_preserve_scratch_resource('trigger_file_reindex'),
}) as dag:

def launch_file_reindex(**kwargs):
auth_token = get_auth_tok(**kwargs)

try:
headers = {
'authorization': 'Bearer ' + auth_token,
'content-type': 'text/plain',
'X-Hubmap-Application': 'files-api'
}
response = HttpHook('PUT', http_conn_id='files_api_connection').run(
endpoint=f'datasets/refresh-indices',
headers=headers,
extra_options=[]
)
response.raise_for_status()
except http.client.HTTPException as he:
print(f'Error {he}')
except AirflowException as ae:
print(f'Error {ae}')
except Exception as e:
print(f'Broad Exception {e}')

t_launch_file_reindex = PythonOperator(
task_id='launch_file_reindex',
python_callable=launch_file_reindex,
provide_context=True,
op_kwargs={
'crypt_auth_tok': utils.encrypt_tok(airflow_conf.as_dict()
['connections']['APP_CLIENT_SECRET']).decode(),
}
)

t_launch_file_reindex
1 change: 1 addition & 0 deletions src/ingest-pipeline/airflow/plugins/hubmap_api/endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
NEEDED_ENV_VARS = [
'AIRFLOW_CONN_INGEST_API_CONNECTION',
'AIRFLOW_CONN_UUID_API_CONNECTION',
'AIRFLOW_CONN_FILES_API_CONNECTION',
'AIRFLOW_CONN_SEARCH_API_CONNECTION',
'AIRFLOW_CONN_ENTITY_API_CONNECTION'
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ HM_AF_HOME=/hive/users/hive/hubmap/hivevm191-dev/ingest-pipeline/src/ingest-pipe

HM_AF_CONN_INGEST_API_CONNECTION=http://hivevm191.psc.edu:7777/
HM_AF_CONN_UUID_API_CONNECTION=http://https%3a%2f%2fuuid-api.dev.hubmapconsortium.org/
HM_AF_CONN_FILES_API_CONNECTION=http://https%3a%2f%2ffiles-api.dev.hubmapconsortium.org/
HM_AF_CONN_CELLS_API_CONNECTION=http://https%3a%2f%2fcells-api.dev.hubmapconsortium.org/
HM_AF_CONN_SEARCH_API_CONNECTION=http://https%3a%2f%2fsearch-api.dev.hubmapconsortium.org%2fv3/
HM_AF_CONN_ENTITY_API_CONNECTION=http://https%3a%2f%2fentity-api.dev.hubmapconsortium.org/
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ HM_AF_HOME=/hive/users/hive/hubmap/hivevm193-prod/ingest-pipeline/src/ingest-pip

HM_AF_CONN_INGEST_API_CONNECTION=http://hivevm193.psc.edu:7777/
HM_AF_CONN_UUID_API_CONNECTION=http://https%3a%2f%2fuuid.api.hubmapconsortium.org/
HM_AF_CONN_FILES_API_CONNECTION=http://https%3a%2f%2ffiles.api.hubmapconsortium.org/
HM_AF_CONN_CELLS_API_CONNECTION=http://https%3a%2f%2fcells.api.hubmapconsortium.org/
HM_AF_CONN_SEARCH_API_CONNECTION=http://https%3a%2f%2fsearch.api.hubmapconsortium.org%2fv3/
HM_AF_CONN_ENTITY_API_CONNECTION=http://https%3a%2f%2fentity.api.hubmapconsortium.org/
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ HM_AF_HOME=/hive/users/hive/hubmap/hivevm195-stage/ingest-pipeline/src/ingest-pi

HM_AF_CONN_INGEST_API_CONNECTION=http://hivevm191.psc.edu:7777/
HM_AF_CONN_UUID_API_CONNECTION=http://https%3a%2f%2fuuid-api.stage.hubmapconsortium.org/
HM_AF_CONN_FILES_API_CONNECTION=http://https%3a%2f%2ffiles-api.stage.hubmapconsortium.org/
HM_AF_CONN_CELLS_API_CONNECTION=http://https%3a%2f%2fcells-api.stage.hubmapconsortium.org/
HM_AF_CONN_SEARCH_API_CONNECTION=http://https%3a%2f%2fsearch-api.stage.hubmapconsortium.org%2fv3/
HM_AF_CONN_ENTITY_API_CONNECTION=http://https%3a%2f%2fentity-api.stage.hubmapconsortium.org/
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ HM_AF_HOME=/hive/users/hive/hubmap/hivevm192-test/ingest-pipeline/src/ingest-pip

HM_AF_CONN_INGEST_API_CONNECTION=http://hivevm192.psc.edu:7777/
HM_AF_CONN_UUID_API_CONNECTION=http://https%3a%2f%2fuuid-api.test.hubmapconsortium.org/
HM_AF_CONN_FILES_API_CONNECTION=http://https%3a%2f%2ffiles-api.test.hubmapconsortium.org/
HM_AF_CONN_CELLS_API_CONNECTION=http://https%3a%2f%2fcells-api.test.hubmapconsortium.org/
HM_AF_CONN_SEARCH_API_CONNECTION=http://https%3a%2f%2fsearch-api.test.hubmapconsortium.org%2fv3/
HM_AF_CONN_ENTITY_API_CONNECTION=http://https%3a%2f%2fentity-api.test.hubmapconsortium.org/
1 change: 1 addition & 0 deletions src/ingest-pipeline/misc/tools/airflow_wrapper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ source source_platform_file.sh
envvars=( CONFIG HOME \
CONN_INGEST_API_CONNECTION \
CONN_UUID_API_CONNECTION \
CONN_FILES_API_CONNECTION \
CONN_CELLS_API_CONNECTION \
CONN_SEARCH_API_CONNECTION \
CONN_ENTITY_API_CONNECTION \
Expand Down

0 comments on commit c53f2ee

Please sign in to comment.