-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
133 additions
and
56 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import os | ||
import re | ||
import subprocess | ||
from datetime import datetime | ||
from urllib.parse import urlparse | ||
|
||
from kubernetes.client import models as k8s | ||
|
||
from airflow import DAG | ||
from airflow.decorators import task | ||
from airflow.operators.trigger_dagrun import TriggerDagRunOperator | ||
from airflow.utils.trigger_rule import TriggerRule | ||
from airflow.operators.python import PythonOperator, get_current_context, ShortCircuitOperator | ||
from airflow.models.param import Param | ||
from airflow.exceptions import AirflowFailException | ||
from airflow.providers.amazon.aws.hooks.s3 import S3Hook | ||
|
||
|
||
default_args = {"owner": "unity-sps", "start_date": datetime.utcfromtimestamp(0)} | ||
|
||
FNAME_RE = re.compile( | ||
r"^(?P<id>(?P<instrument>SA|SB|FL|FR)(?P<color>[A-GJ-MORTX-Z_])(?P<specFlag>[A-Z_])(?P<primaryTime>\d{4})(?P<spacer0>[A-Z_])(?P<secondaryTime>\d{10})(?P<spacer1>_)(?P<tertiaryTime>\d{3})(?P<prodType>[A-Z_]{3})(?P<geometry>[NT])(?P<seqId>[A-Z]{3}[A-Z_]\d{5})(?P<downsample>[0-3_])(?P<compression>[A-Z0-9]{2})(?P<producer>[A-Z_])(?P<version>[A-Z0-9_]{2}))(?P<extension>\.VIC)$" | ||
) | ||
|
||
|
||
with DAG( | ||
dag_id="eval_srl_vic2png", | ||
default_args=default_args, | ||
schedule=None, | ||
tags=["eval_srl_vic2png"], | ||
params={ | ||
"payload": Param( | ||
"s3://unity-gmanipon-ads-deployment-dev/output/SAM_0000_0734432789_658ECMNAUT_040960LUJ01.VIC", | ||
type="string", | ||
) | ||
}, | ||
) as dag: | ||
|
||
@task | ||
def evaluate_vic2png(params: dict): | ||
context = get_current_context() | ||
dag_run_id = context["dag_run"].run_id | ||
s3_hook = S3Hook() | ||
|
||
# parse triggering payload | ||
payload = params["payload"] | ||
bucket, key = s3_hook.parse_s3_url(payload) | ||
fname = os.path.basename(key) | ||
path = os.path.dirname(key) | ||
|
||
# ensure matches filename convention and parse filename components | ||
match = FNAME_RE.search(fname) | ||
if not match: | ||
raise AirflowFailException("Filename {fname} not recognized.") | ||
|
||
# build expected file prefixes (TODO: fix hardcoding) | ||
keys = {"vic": (bucket, key)} | ||
|
||
# default vic2png DAG parameters | ||
vic2png_args = {"success": True, "vic_url": None, "id": match.groupdict()["id"]} | ||
|
||
# check if all inputs exist | ||
for k, v in keys.items(): | ||
exists = s3_hook.check_for_key(v[1], bucket_name=v[0]) | ||
vic2png_args["success"] &= exists | ||
if exists: | ||
vic2png_args[f"{k}_url"] = f"s3://{v[0]}/{v[1]}" | ||
|
||
# return params and evaluation result | ||
return vic2png_args | ||
|
||
evaluate_vic2png_task = evaluate_vic2png() | ||
|
||
@task.short_circuit() | ||
def vic2png_evaluation_successful(): | ||
context = get_current_context() | ||
print(f"{context['ti'].xcom_pull(task_ids='evaluate_vic2png')}") | ||
return context["ti"].xcom_pull(task_ids="evaluate_vic2png")["success"] | ||
|
||
vic2png_evaluation_successful_task = vic2png_evaluation_successful() | ||
|
||
trigger_vic2png_task = TriggerDagRunOperator( | ||
task_id="trigger_vic2png", | ||
trigger_dag_id="vic2png", | ||
# uncomment the next line if we want to dedup dagRuns for a particular ID | ||
trigger_run_id="{{ ti.xcom_pull(task_ids='evaluate_vic2png')['id'] }}", | ||
trigger_rule=TriggerRule.ALL_SUCCESS, | ||
skip_when_already_exists=True, | ||
conf={ | ||
"vic_url": "{{ ti.xcom_pull(task_ids='evaluate_vic2png')['vic_url'] }}", | ||
"output_url": "s3://gmanipon-dev-sps-isl/STACAM/PNG", | ||
}, | ||
) | ||
|
||
evaluate_vic2png_task >> vic2png_evaluation_successful_task >> trigger_vic2png_task |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
7 changes: 7 additions & 0 deletions
7
terraform-unity/modules/terraform-unity-sps-eks/.terraform.lock.hcl
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.