Skip to content

Commit

Permalink
Merge pull request #275 from NASA-IMPACT/debug_bucket_option
Browse files Browse the repository at this point in the history
Add HLS_DEBUG_BUCKET environment option for intermediate output.
  • Loading branch information
sharkinsspatial authored May 7, 2024
2 parents 40e7b0f + 3fb98f3 commit 1b63b27
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 8 deletions.
37 changes: 37 additions & 0 deletions stack/hlsconstructs/landsat_mgrs_step_function.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json
from typing import Union

from aws_cdk import aws_iam, aws_stepfunctions, core
from hlsconstructs.batch_step_function import BatchStepFunction
Expand All @@ -20,6 +21,7 @@ def __init__(
mgrs_logger: Lambda,
get_random_wait: Lambda,
gibs_outputbucket: str,
debug_bucket: Union[bool, str],
**kwargs,
) -> None:
super().__init__(scope, id, **kwargs)
Expand Down Expand Up @@ -126,6 +128,41 @@ def __init__(
"Done": {"Type": "Succeed"},
},
}
if debug_bucket:
updated_environment = [
{
"Name": "PATHROW_LIST",
"Value.$": "$.mgrs_metadata.pathrows_string",
},
{
"Name": "INPUT_BUCKET",
"Value": debug_bucket,
},
{"Name": "OUTPUT_BUCKET", "Value": debug_bucket},
{
"Name": "GCC_ROLE_ARN",
"Value": outputbucket_role_arn,
},
{"Name": "DATE", "Value.$": "$.date"},
{"Name": "MGRS", "Value.$": "$.MGRS"},
{"Name": "LANDSAT_PATH", "Value.$": "$.path"},
{
"Name": "MGRS_ULX",
"Value.$": "$.mgrs_metadata.mgrs_ulx",
},
{
"Name": "MGRS_ULY",
"Value.$": "$.mgrs_metadata.mgrs_uly",
},
{
"Name": "GIBS_OUTPUT_BUCKET",
"Value": gibs_outputbucket,
},
]

state_definition["States"]["RunLandsatTile"]["Parameters"][
"ContainerOverrides"
]["Environment"] = updated_environment

self.state_machine = aws_stepfunctions.CfnStateMachine(
self,
Expand Down
6 changes: 6 additions & 0 deletions stack/hlsconstructs/landsat_step_function.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json
from typing import Union

from aws_cdk import aws_iam, aws_stepfunctions, core
from hlsconstructs.batch_step_function import BatchStepFunction
Expand All @@ -24,6 +25,7 @@ def __init__(
get_random_wait: Lambda,
replace_existing: bool,
landsat_mgrs_step_function_arn: str,
debug_bucket: Union[bool, str],
**kwargs,
) -> None:
super().__init__(scope, id, **kwargs)
Expand Down Expand Up @@ -238,6 +240,10 @@ def __init__(
},
}

if debug_bucket:
state_definition["States"]["RunLandsatAc"]["Parameters"][
"ContainerOverrides"
]["Environment"].append({"Name": "DEBUG_BUCKET", "Value": debug_bucket})
self.state_machine = aws_stepfunctions.CfnStateMachine(
self,
"LandsatStateMachine",
Expand Down
6 changes: 6 additions & 0 deletions stack/hlsconstructs/sentinel_errors_step_function.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json
from typing import Union

from aws_cdk import aws_iam, aws_stepfunctions, core
from hlsconstructs.batch_step_function import BatchStepFunction
Expand All @@ -19,6 +20,7 @@ def __init__(
update_sentinel_failure: Lambda,
get_random_wait: Lambda,
gibs_outputbucket: str,
debug_bucket: Union[bool, str],
**kwargs,
) -> None:
super().__init__(scope, id, **kwargs)
Expand Down Expand Up @@ -121,6 +123,10 @@ def __init__(
},
}

if debug_bucket:
state_definition["States"]["ProcessSentinel"]["Parameters"][
"ContainerOverrides"
]["Environment"].append({"Name": "DEBUG_BUCKET", "Value": debug_bucket})
self.state_machine = aws_stepfunctions.CfnStateMachine(
self,
"SentineErrorsStateMachine",
Expand Down
7 changes: 7 additions & 0 deletions stack/hlsconstructs/sentinel_step_function.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json
from typing import Union

from aws_cdk import aws_iam, aws_stepfunctions, core
from hlsconstructs.batch_step_function import BatchStepFunction
Expand All @@ -22,6 +23,7 @@ def __init__(
check_exit_code: Lambda,
replace_existing: bool,
gibs_outputbucket: str,
debug_bucket: Union[bool, str],
**kwargs,
) -> None:
super().__init__(scope, id, **kwargs)
Expand Down Expand Up @@ -146,6 +148,11 @@ def __init__(
},
}

if debug_bucket:
sentinel_state_definition["States"]["ProcessSentinel"]["Parameters"][
"ContainerOverrides"
]["Environment"].append({"Name": "DEBUG_BUCKET", "Value": debug_bucket})

self.sentinel_state_machine = aws_stepfunctions.CfnStateMachine(
self,
"SentinelStateMachine",
Expand Down
14 changes: 6 additions & 8 deletions stack/stack.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
import os

from aws_cdk import (
aws_iam,
aws_lambda,
aws_s3,
aws_sns,
aws_ssm,
core,
)
from aws_cdk import aws_iam, aws_lambda, aws_s3, aws_sns, aws_ssm, core
from hlsconstructs.batch import Batch
from hlsconstructs.batch_cron import BatchCron
from hlsconstructs.docker_batchjob import DockerBatchJob
Expand Down Expand Up @@ -64,6 +57,7 @@ def getenv(key, default):
)
RDS_MIN_CAPACITY = int(getenv("HLS_RDS_MIN_CAPACITY", 4))
RDS_MAX_CAPACITY = int(getenv("HLS_RDS_MAX_CAPACITY", 8))
DEBUG_BUCKET = getenv("HLS_DEBUG_BUCKET", False)


# Cron settings
Expand Down Expand Up @@ -570,6 +564,7 @@ def __init__(self, scope: core.Construct, id: str, **kwargs) -> None:
outputbucket_role_arn=OUTPUT_BUCKET_ROLE_ARN,
replace_existing=REPLACE_EXISTING,
gibs_outputbucket=GIBS_OUTPUT_BUCKET,
debug_bucket=DEBUG_BUCKET,
)

self.sentinel_step_function_historic = SentinelStepFunction(
Expand Down Expand Up @@ -628,6 +623,7 @@ def __init__(self, scope: core.Construct, id: str, **kwargs) -> None:
mgrs_logger=self.mgrs_logger,
get_random_wait=self.get_random_wait,
gibs_outputbucket=GIBS_OUTPUT_BUCKET,
debug_bucket=DEBUG_BUCKET,
)

self.landsat_mgrs_partials_step_function = LandsatMGRSPartialsStepFunction(
Expand All @@ -643,6 +639,7 @@ def __init__(self, scope: core.Construct, id: str, **kwargs) -> None:
mgrs_logger=self.mgrs_logger,
get_random_wait=self.get_random_wait,
gibs_outputbucket=GIBS_OUTPUT_BUCKET,
debug_bucket=DEBUG_BUCKET,
)

self.landsat_mgrs_step_function_historic = LandsatMGRSStepFunction(
Expand Down Expand Up @@ -693,6 +690,7 @@ def __init__(self, scope: core.Construct, id: str, **kwargs) -> None:
get_random_wait=self.get_random_wait,
replace_existing=REPLACE_EXISTING,
landsat_mgrs_step_function_arn=self.landsat_mgrs_step_function.state_machine.ref,
debug_bucket=DEBUG_BUCKET,
)

self.landsat_step_function_historic = LandsatStepFunction(
Expand Down

0 comments on commit 1b63b27

Please sign in to comment.