8000 add service_name attribute to AssetDirectory by thrau · Pull Request #9125 · localstack/localstack · GitHub
[go: up one dir, main page]

Skip to content

add service_name attribute to AssetDirectory #9125

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

Merged
merged 1 commit into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion localstack/services/dynamodb/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ def on_before_start(self):
def accept_state_visitor(self, visitor: StateVisitor):
visitor.visit(dynamodb_stores)
visitor.visit(dynamodbstreams_stores)
visitor.visit(AssetDirectory(os.path.join(config.dirs.data, self.service)))
visitor.visit(AssetDirectory(self.service, os.path.join(config.dirs.data, self.service)))

def on_before_state_reset(self):
self.server.stop_dynamodb()
Expand Down
2 changes: 1 addition & 1 deletion localstack/services/kinesis/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def __init__(self):

def accept_state_visitor(self, visitor: StateVisitor):
visitor.visit(kinesis_stores)
visitor.visit(AssetDirectory(os.path.join(config.dirs.data, "kinesis")))
visitor.visit(AssetDirectory(self.service, os.path.join(config.dirs.data, "kinesis")))

def on_before_state_load(self):
# no need to restart servers, since that happens lazily in `server_manager.get_server_for_account`.
Expand Down
4 changes: 2 additions & 2 deletions localstack/services/opensearch/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,8 +405,8 @@ def get_store(account_id: str, region_name: str) -> OpenSearchStore:

def accept_state_visitor(self, visitor: StateVisitor):
visitor.visit(opensearch_stores)
visitor.visit(AssetDirectory(os.path.join(config.dirs.data, "opensearch")))
visitor.visit(AssetDirectory(os.path.join(config.dirs.data, "elasticsearch")))
visitor.visit(AssetDirectory(self.service, os.path.join(config.dirs.data, "opensearch")))
visitor.visit(AssetDirectory(self.service, os.path.join(config.dirs.data, "elasticsearch")))

def on_after_state_load(self):
"""Starts clusters whose metadata has been restored."""
Expand Down
2 changes: 1 addition & 1 deletion localstack/services/redshift/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def fix_keys(o, **kwargs):
class RedshiftProvider(RedshiftApi):
def accept_state_visitor(self, visitor: StateVisitor):
visitor.visit(redshift_backends)
visitor.visit(AssetDirectory(os.path.join(config.dirs.data, "redshift")))
visitor.visit(AssetDirectory(self.service, os.path.join(config.dirs.data, "redshift")))

@handler("DescribeClusterSecurityGroups", expand=False)
def describe_cluster_security_groups(
Expand Down
2 changes: 1 addition & 1 deletion localstack/services/s3/v3/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ def on_after_init(self):

def accept_state_visitor(self, visitor: StateVisitor):
visitor.visit(s3_stores)
visitor.visit(AssetDirectory(self._storage_backend.root_directory))
visitor.visit(AssetDirectory(self.service, self._storage_backend.root_directory))

def on_before_state_save(self):
self._storage_backend.flush()
Expand Down
2 changes: 1 addition & 1 deletion localstack/services/stepfunctions/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def get_forward_url(self) -> str:
return f"http://{LOCALHOST}:{config.LOCAL_PORT_STEPFUNCTIONS}"

def accept_state_visitor(self, visitor: StateVisitor):
visitor.visit(AssetDirectory(os.path.join(config.dirs.data, self.service)))
visitor.visit(AssetDirectory(self.service, os.path.join(config.dirs.data, self.service)))

def on_before_start(self):
start_stepfunctions()
Expand Down
24 changes: 16 additions & 8 deletions localstack/state/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@
import io
from typing import IO, Any, Protocol, runtime_checkable

StateContainer = Any
"""While a StateContainer can in principle be anything, localstack currently supports by default the following
containers:

- BackendDict (moto backend state)
- AccountRegionBundle (localstack stores)
- AssetDirectory (folders on disk)
"""
class StateContainer(Protocol):
"""While a StateContainer can in principle be anything, localstack currently supports by default the following
containers:

- BackendDict (moto backend state)
- AccountRegionBundle (localstack stores)
- AssetDirectory (folders on disk)
"""

service_name: str


class StateLifecycleHook:
Expand Down Expand Up @@ -70,12 +73,17 @@ class AssetDirectory:
A state container manifested as a directory on the file system.
"""

service_name: str
path: str

def __init__(self, path: str):
def __init__(self, service_name: str, path: str):
if not service_name:
raise ValueError("service name must be set")

if not path:
raise ValueError("path must be set")

self.service_name = service_name
self.path = path

def __str__(self):
Expand Down
0