Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Viirs orchestration #282

Merged
merged 23 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
66e96a9
Update laads_available Lambda to use new VIIRS auxiliary file pattern.
sharkinsspatial Feb 6, 2024
f7c04b1
Update Landsat SNS topic
chuckwondo Feb 7, 2024
48e7446
Run the VIIRS climatology job the first 5 days of every month.
sharkinsspatial Feb 7, 2024
665870d
Remove HEAD request failure handling from test_laads_available.
sharkinsspatial Feb 7, 2024
9518ab6
Add UAH development viirs deployment workflow and environment.
sharkinsspatial Feb 7, 2024
ea0ac98
Re-include missing Laads batch cron changes.
sharkinsspatial Feb 7, 2024
9215bce
Make all containerOverrides values a string for submit_job.
sharkinsspatial Feb 7, 2024
d207b62
Lasrc v3.5.1 supports MODIS and VIIRS aux data so needs a force VIIRS…
sharkinsspatial Feb 8, 2024
37d9fbc
Update command path for climatologies.sh in hls-laads container.
sharkinsspatial Feb 8, 2024
5f23d36
Increase memory requirement for LASRC 3.5.1.
sharkinsspatial Feb 8, 2024
bae1ae8
Update name of Laads climatology job.
sharkinsspatial Feb 8, 2024
e1df286
Use wildcard to handle varaible VIIRS product prefixes.
sharkinsspatial Feb 8, 2024
419db14
Temporary commit to enable debug processing for S30. Should revert.
sharkinsspatial Feb 9, 2024
b81d080
Add VIIRS flag to Sentinel errors step function.
sharkinsspatial Feb 11, 2024
1cf468c
Temporary commit to enable debug processing for S30. Should revert.
sharkinsspatial Feb 11, 2024
b4072dd
Add mcp-production-deployment
chuckwondo Feb 12, 2024
d311191
Remove temporary use of DEBUG_BUCKET for AC Batch jobs.
sharkinsspatial Feb 14, 2024
8267c25
Add MCP development VIIRS deployment.
sharkinsspatial Feb 14, 2024
f2c1028
Rename workflow to force console update.
sharkinsspatial Feb 14, 2024
53b12ff
Merge pull request #272 from NASA-IMPACT/issue266/create-mcp-prod
sharkinsspatial Mar 13, 2024
8341637
Fake commit to trigger deployment workflow with new LAADS token.
sharkinsspatial May 6, 2024
6d193a3
Fake commit to trigger uah dev deployment with Landsat SNS disabled.
sharkinsspatial May 6, 2024
4260117
Add mcp production viirs deployment workflow.
sharkinsspatial May 28, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 79 additions & 0 deletions .github/workflows/dev_viirs_deployment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
name: uah dev viirs deployment

on:
push:
branches: [viirs_orchestration]
workflow_dispatch:

env:
AWS_DEFAULT_REGION: us-west-2

jobs:
unit-tests:
runs-on: ubuntu-20.04
strategy:
matrix:
python: [3.8]
steps:
- uses: actions/checkout@v4
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python }}
- name: Install Tox
run: pip install tox
- name: Run Tox test environment
# Run tox using the version of Python in `PATH`
run: tox -e py
dev-viirs-deployment:
strategy:
matrix:
python: [3.8]
runs-on: ubuntu-20.04
needs: [unit-tests]
environment:
name: dev-viirs
steps:
- uses: actions/checkout@v4
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python }}
- name: Install tox
run: pip install tox
- name: Configure awscli
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: us-west-2
- name: Convert secrets to environment variables
env:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
SECRETS_JSON: ${{ toJson(secrets) }}
run: |
while read -rd $'' line; do
echo "$line" >> $GITHUB_ENV
done < <(
jq -r <<<"$SECRETS_JSON" 'to_entries|map("\(.key)=\(.value)\u0000")[]'
)
- name: Convert vars to environment variables
env:
VARS_JSON: ${{ toJson(vars) }}
run: |
while read -rd $'' line; do
echo "$line" >> $GITHUB_ENV
done < <(
jq -r <<<"$VARS_JSON" 'to_entries|map("\(.key)=\(.value)\u0000")[]'
)
- name: Deploy with tox
run: tox -v -e dev -r -- deploy --require-approval never
- name: Run DB setup
run: |
setupdb=$(aws cloudformation describe-stacks \
--stack-name $HLS_STACKNAME \
--query "Stacks[0].Outputs[?OutputKey=='setupdbexport'].OutputValue" \
--output=text
)
aws lambda invoke --function-name=$setupdb response.json
4 changes: 2 additions & 2 deletions .github/workflows/mcp_dev_deployment.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: mcp dev deployment
name: mcp development deployment

on:
push:
Expand Down Expand Up @@ -30,7 +30,7 @@ jobs:
- name: Run Tox test environment
# Run tox using the version of Python in `PATH`
run: tox -e py
mcp-dev-deployment:
mcp-development-deployment:
strategy:
matrix:
python: [3.8]
Expand Down
82 changes: 82 additions & 0 deletions .github/workflows/mcp_dev_viirs_deployment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
name: mcp dev viirs deployment

on:
push:
branches: [viirs_orchestration]
workflow_dispatch:

env:
AWS_DEFAULT_REGION: us-west-2

# See https://docs.github.com/en/actions/deployment/security-hardening-your-deployments/configuring-openid-connect-in-amazon-web-services#updating-your-github-actions-workflow
permissions:
id-token: write # required for requesting the JWT
contents: read # required for actions/checkout

jobs:
unit-tests:
runs-on: ubuntu-20.04
strategy:
matrix:
python: [3.8]
steps:
- uses: actions/checkout@v4
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python }}
- name: Install Tox
run: pip install tox
- name: Run Tox test environment
# Run tox using the version of Python in `PATH`
run: tox -e py
mcp-dev-viirs-deployment:
strategy:
matrix:
python: [3.8]
runs-on: ubuntu-20.04
needs: [unit-tests]
environment:
name: mcp-dev-viirs
steps:
- uses: actions/checkout@v4
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python }}
- name: Install tox
run: pip install tox
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v3
with:
role-to-assume: ${{ vars.AWS_ROLE_TO_ASSUME_ARN }}
role-session-name: ${{ github.actor }}
aws-region: us-west-2
- name: Convert secrets to environment variables
env:
SECRETS_JSON: ${{ toJson(secrets) }}
run: |
while read -rd $'' line; do
echo "$line" >> $GITHUB_ENV
done < <(
jq -r <<<"$SECRETS_JSON" 'to_entries|map("\(.key)=\(.value)\u0000")[]'
)
- name: Convert vars to environment variables
env:
VARS_JSON: ${{ toJson(vars) }}
run: |
while read -rd $'' line; do
echo "$line" >> $GITHUB_ENV
done < <(
jq -r <<<"$VARS_JSON" 'to_entries|map("\(.key)=\(.value)\u0000")[]'
)
- name: Deploy with tox
run: tox -v -e dev -r -- deploy --require-approval never
- name: Run DB setup
run: |
setupdb=$(aws cloudformation describe-stacks \
--stack-name $HLS_STACKNAME \
--query "Stacks[0].Outputs[?OutputKey=='setupdbexport'].OutputValue" \
--output=text
)
aws lambda invoke --function-name=$setupdb response.json
81 changes: 81 additions & 0 deletions .github/workflows/mcp_production_deployment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
name: MCP production deployment

on:
release:
types: [ published ]

env:
AWS_DEFAULT_REGION: us-west-2

# See https://docs.github.com/en/actions/deployment/security-hardening-your-deployments/configuring-openid-connect-in-amazon-web-services#updating-your-github-actions-workflow
permissions:
id-token: write # required for requesting the JWT
contents: read # required for actions/checkout

jobs:
unit-tests:
runs-on: ubuntu-20.04
strategy:
matrix:
python: [3.8]
steps:
- uses: actions/checkout@v4
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python }}
- name: Install Tox
run: pip install tox
- name: Run Tox test environment
# Run tox using the version of Python in `PATH`
run: tox -e py
mcp-production-deployment:
strategy:
matrix:
python: [3.8]
runs-on: ubuntu-20.04
needs: [unit-tests]
environment:
name: mcp-production
steps:
- uses: actions/checkout@v4
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python }}
- name: Install tox
run: pip install tox
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v3
with:
role-to-assume: ${{ vars.AWS_ROLE_TO_ASSUME_ARN }}
role-session-name: ${{ github.actor }}
aws-region: us-west-2
- name: Convert secrets to environment variables
env:
SECRETS_JSON: ${{ toJson(secrets) }}
run: |
while read -rd $'' line; do
echo "$line" >> $GITHUB_ENV
done < <(
jq -r <<<"$SECRETS_JSON" 'to_entries|map("\(.key)=\(.value)\u0000")[]'
)
- name: Convert vars to environment variables
env:
VARS_JSON: ${{ toJson(vars) }}
run: |
while read -rd $'' line; do
echo "$line" >> $GITHUB_ENV
done < <(
jq -r <<<"$VARS_JSON" 'to_entries|map("\(.key)=\(.value)\u0000")[]'
)
- name: Deploy with tox
run: tox -v -e dev -r -- deploy --require-approval never
- name: Run DB setup
run: |
setupdb=$(aws cloudformation describe-stacks \
--stack-name $HLS_STACKNAME \
--query "Stacks[0].Outputs[?OutputKey=='setupdbexport'].OutputValue" \
--output=text
)
aws lambda invoke --function-name=$setupdb response.json
Empty file.
34 changes: 19 additions & 15 deletions lambda_functions/laads_available.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,17 @@
from botocore.errorfactory import ClientError

s3 = boto3.client("s3")
bucket = os.getenv("LAADS_BUCKET", None)
print(bucket)
if bucket is None:
raise Exception("No Bucket set")


def key_exists(bucket: str, key: str):
def key_pattern_exists(bucket: str, key_pattern: str):
try:
s3.head_object(Bucket=bucket, Key=key)
response = s3.list_objects_v2(Bucket=bucket, Prefix=key_pattern)
if "Contents" in response:
return True
else:
return False
except ClientError as e:
print(e)
if e.response["Error"]["Code"] == "404":
return False
else:
raise Exception(e)
return True


def getyyyydoy(date_str: str):
Expand Down Expand Up @@ -65,16 +60,25 @@ def handler(event: Dict, context: Dict):
if date_str is None:
raise Exception("Missing Date Parameter")

bucket = os.getenv("LAADS_BUCKET", None)
if bucket is None:
raise Exception("No Bucket set")
ydoy, year = getyyyydoy(date_str)
key = f"lasrc_aux/LADS/{year}/L8ANC{ydoy}.hdf_fused"
print(f"------{bucket} {key} ------")
exists = key_exists(bucket, key)
vj_pattern = f"lasrc_aux/LADS/{year}/VJ104ANC.A{ydoy}"
print(f"------{bucket} {vj_pattern} ------")
vj_exists = key_pattern_exists(bucket, vj_pattern)
vnp_pattern = f"lasrc_aux/LADS/{year}/VNP04ANC.A{ydoy}"
vnp_exists = key_pattern_exists(bucket, vnp_pattern)
if vj_exists or vnp_exists:
exists = True
else:
exists = False
output = {
"granule": date_str,
"year": year,
"doy": ydoy,
"bucket": bucket,
"key": key,
"pattern": f"{vj_pattern} {vnp_pattern}",
"available": False,
}
if exists:
Expand Down
34 changes: 34 additions & 0 deletions lambda_functions/laads_submit_climatology_job.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import datetime
import json
import os

import boto3

batch_client = boto3.client("batch")


jobQueue = os.getenv("JOB_QUEUE")
jobDefinition = os.getenv("JOB_DEFINITION")
lasrc_aux = os.getenv("LASRC_AUX_DIR")
laads_token = os.getenv("LAADS_TOKEN")
laads_bucket = os.getenv("LAADS_BUCKET")


def handler(event, context):
current_date = datetime.datetime.now()
response = batch_client.submit_job(
jobName="laads_climatology",
jobQueue=jobQueue,
jobDefinition=jobDefinition,
containerOverrides={
"environment": [
{"name": "LASRC_AUX_DIR", "value": lasrc_aux},
{"name": "LAADS_TOKEN", "value": laads_token},
{"name": "LAADS_BUCKET", "value": laads_bucket},
{"name": "CLIM_YEAR", "value": str(current_date.year)},
{"name": "CLIM_MONTH", "value": str(current_date.month)},
],
"command": ["./usr/local/climatologies.sh"],
},
)
return response
Loading
Loading