From 1decff6d17b55df5a804671164f57b1d70a3ca73 Mon Sep 17 00:00:00 2001 From: Ryan McGinty Date: Tue, 4 Jun 2024 19:31:59 -0700 Subject: [PATCH] addressing PR comments --- .../constructs_/cw/dashboard.py | 6 ++--- .../constructs_/efs/file_system.py | 3 ++- .../constructs_/service/assets.py | 0 src/aibs_informatics_core_app/app.py | 26 +++++++------------ .../stacks/{storage.py => core.py} | 12 ++++++--- .../stacks/network.py | 17 ------------ 6 files changed, 22 insertions(+), 42 deletions(-) delete mode 100644 src/aibs_informatics_cdk_lib/constructs_/service/assets.py rename src/aibs_informatics_core_app/stacks/{storage.py => core.py} (84%) delete mode 100644 src/aibs_informatics_core_app/stacks/network.py diff --git a/src/aibs_informatics_cdk_lib/constructs_/cw/dashboard.py b/src/aibs_informatics_cdk_lib/constructs_/cw/dashboard.py index 41a40eb..f0c1b67 100644 --- a/src/aibs_informatics_cdk_lib/constructs_/cw/dashboard.py +++ b/src/aibs_informatics_cdk_lib/constructs_/cw/dashboard.py @@ -127,10 +127,10 @@ def create_widgets_and_alarms( metric_name = graph_metric.label or metric_config["statistic"] else: metric = metric_config["metric"] - if isinstance(metric, cw.IMetric): - metric_name = cast(str, metric.metric_name) + if isinstance(metric, cw.Metric): + metric_name = metric.metric_name else: - metric_name = metric + metric_name = str(metric) metric_label = metric_config.get( "label", re.sub( diff --git a/src/aibs_informatics_cdk_lib/constructs_/efs/file_system.py b/src/aibs_informatics_cdk_lib/constructs_/efs/file_system.py index 57e2096..4d39dbf 100644 --- a/src/aibs_informatics_cdk_lib/constructs_/efs/file_system.py +++ b/src/aibs_informatics_cdk_lib/constructs_/efs/file_system.py @@ -256,7 +256,7 @@ def access_point_id(self) -> Optional[str]: def to_batch_mount_point(self, name: str, sfn_format: bool = False) -> dict[str, Any]: mount_point: dict[str, Any] = to_mount_point( self.mount_point, self.read_only, source_volume=name - ) # type: ignore + ) # type: ignore[arg-type] # typed dict should be accepted if sfn_format: return convert_to_sfn_api_action_case(mount_point) return mount_point @@ -267,6 +267,7 @@ def to_batch_volume(self, name: str, sfn_format: bool = False) -> dict[str, Any] } if self.access_point: efs_volume_configuration["transitEncryption"] = "ENABLED" + # TODO: Consider adding IAM efs_volume_configuration["authorizationConfig"] = { "accessPointId": self.access_point.access_point_id, "iam": "DISABLED", diff --git a/src/aibs_informatics_cdk_lib/constructs_/service/assets.py b/src/aibs_informatics_cdk_lib/constructs_/service/assets.py deleted file mode 100644 index e69de29..0000000 diff --git a/src/aibs_informatics_core_app/app.py b/src/aibs_informatics_core_app/app.py index a040cd4..2eea2de 100644 --- a/src/aibs_informatics_core_app/app.py +++ b/src/aibs_informatics_core_app/app.py @@ -8,12 +8,11 @@ from aibs_informatics_cdk_lib.project.utils import get_config from aibs_informatics_cdk_lib.stages.base import ConfigBasedStage from aibs_informatics_core_app.stacks.assets import AIBSInformaticsAssetsStack +from aibs_informatics_core_app.stacks.core import CoreStack from aibs_informatics_core_app.stacks.demand_execution import ( DemandExecutionInfrastructureStack, DemandExecutionStack, ) -from aibs_informatics_core_app.stacks.network import NetworkStack -from aibs_informatics_core_app.stacks.storage import StorageStack class InfraStage(ConfigBasedStage): @@ -25,18 +24,11 @@ def __init__(self, scope: Construct, config: StageConfig, **kwargs) -> None: self.env_base, env=self.env, ) - network = NetworkStack( + core = CoreStack( self, - self.get_stack_name("Network"), + self.get_stack_name("Core"), self.env_base, - env=self.env, - ) - storage = StorageStack( - self, - self.get_stack_name("Storage"), - self.env_base, - "core", - vpc=network.vpc, + name="core", env=self.env, ) @@ -44,10 +36,10 @@ def __init__(self, scope: Construct, config: StageConfig, **kwargs) -> None: self, self.get_stack_name("DemandExecutionInfra"), self.env_base, - vpc=network.vpc, - buckets=[storage.bucket], + vpc=core.vpc, + buckets=[core.bucket], mount_point_configs=[ - MountPointConfiguration.from_file_system(storage.file_system, None, "/opt/efs"), + MountPointConfiguration.from_file_system(core.file_system, None, "/opt/efs"), ], env=self.env, ) @@ -57,8 +49,8 @@ def __init__(self, scope: Construct, config: StageConfig, **kwargs) -> None: self.get_stack_name("DemandExecution"), env_base=self.env_base, assets=assets.assets, - scaffolding_bucket=storage.bucket, - efs_ecosystem=storage.efs_ecosystem, + scaffolding_bucket=core.bucket, + efs_ecosystem=core.efs_ecosystem, data_sync_job_queue=demand_execution_infra.infra_compute.lambda_medium_batch_environment.job_queue_name, scaffolding_job_queue=demand_execution_infra.infra_compute.primary_batch_environment.job_queue_name, execution_job_queue=demand_execution_infra.execution_compute.primary_batch_environment.job_queue_name, diff --git a/src/aibs_informatics_core_app/stacks/storage.py b/src/aibs_informatics_core_app/stacks/core.py similarity index 84% rename from src/aibs_informatics_core_app/stacks/storage.py rename to src/aibs_informatics_core_app/stacks/core.py index e310caf..d363f22 100644 --- a/src/aibs_informatics_core_app/stacks/storage.py +++ b/src/aibs_informatics_core_app/stacks/core.py @@ -1,25 +1,25 @@ from typing import Optional from aibs_informatics_core.env import EnvBase -from aws_cdk import aws_ec2 as ec2 from constructs import Construct +from aibs_informatics_cdk_lib.constructs_.ec2.network import EnvBaseVpc from aibs_informatics_cdk_lib.constructs_.efs.file_system import EFSEcosystem, EnvBaseFileSystem from aibs_informatics_cdk_lib.constructs_.s3 import EnvBaseBucket, LifecycleRuleGenerator from aibs_informatics_cdk_lib.stacks.base import EnvBaseStack -class StorageStack(EnvBaseStack): +class CoreStack(EnvBaseStack): def __init__( self, scope: Construct, id: Optional[str], env_base: EnvBase, name: str, - vpc: ec2.Vpc, **kwargs, ) -> None: super().__init__(scope, id, env_base, **kwargs) + self._vpc = EnvBaseVpc(self, "Vpc", self.env_base, max_azs=4) self._bucket = EnvBaseBucket( self, @@ -35,10 +35,14 @@ def __init__( ) self._efs_ecosystem = EFSEcosystem( - self, id="EFS", env_base=self.env_base, file_system_name=name, vpc=vpc + self, id="EFS", env_base=self.env_base, file_system_name=name, vpc=self.vpc ) self._file_system = self._efs_ecosystem.file_system + @property + def vpc(self) -> EnvBaseVpc: + return self._vpc + @property def bucket(self) -> EnvBaseBucket: return self._bucket diff --git a/src/aibs_informatics_core_app/stacks/network.py b/src/aibs_informatics_core_app/stacks/network.py deleted file mode 100644 index ebb97b2..0000000 --- a/src/aibs_informatics_core_app/stacks/network.py +++ /dev/null @@ -1,17 +0,0 @@ -from typing import Optional - -from aibs_informatics_core.env import EnvBase -from constructs import Construct - -from aibs_informatics_cdk_lib.constructs_.ec2 import EnvBaseVpc -from aibs_informatics_cdk_lib.stacks.base import EnvBaseStack - - -class NetworkStack(EnvBaseStack): - def __init__(self, scope: Construct, id: Optional[str], env_base: EnvBase, **kwargs) -> None: - super().__init__(scope, id, env_base, **kwargs) - self._vpc = EnvBaseVpc(self, "Vpc", self.env_base, max_azs=4) - - @property - def vpc(self) -> EnvBaseVpc: - return self._vpc