@@ -34,35 +34,47 @@ def __init__(self, storage_cfg: Optional[MinioConfig] = None):
3434 def storage_config (self ) -> Optional [MinioConfig ]:
3535 return self ._storage
3636
37- @property
38- def path (self ) -> str :
39- return self ._path
40-
4137 @property
4238 def allocated_ports (self ) -> set :
4339 return self ._allocated_ports
4440
4541 def serialize (self ) -> dict :
4642 out = {
47- "allocated_ports" : list (self ._allocated_ports )
43+ "allocated_ports" : list (self ._allocated_ports ),
44+ "storage" : self ._storage .serialize ()
4845 }
4946 return out
5047
5148 @staticmethod
52- def initialize (res : Resources , cfg : dict ):
53- pass
49+ def initialize (res : Resources , config : dict ):
5450
55- @staticmethod
56- def deserialize (config : dict , cache : Cache , handlers : LoggingHandlers ) -> Resources :
57- ret = LocalResources ()
58- ret ._path = config ["path" ]
5951 # Check for new config
6052 if "storage" in config :
61- ret ._storage = MinioConfig .deserialize (config ["storage" ])
62- ret .logging .info ("Using user-provided configuration of storage for local containers." )
53+ res ._storage = MinioConfig .deserialize (config ["storage" ])
54+ res .logging .info ("Using user-provided configuration of storage for local containers." )
6355
6456 if "allocated_ports" in config :
65- ret ._allocated_ports = set (config ["allocated_ports" ])
57+ res ._allocated_ports = set (config ["allocated_ports" ])
58+
59+ def update_cache (self , cache : Cache ):
60+ super ().update_cache (cache )
61+ cache .update_config (val = list (self ._allocated_ports ), keys = ["local" , "resources" , "allocated_ports" ])
62+ self ._storage .update_cache (["local" , "resources" , "storage" ], cache )
63+
64+ @staticmethod
65+ def deserialize (config : dict , cache : Cache , handlers : LoggingHandlers ) -> Resources :
66+ ret = LocalResources ()
67+
68+ cached_config = cache .get_config ("local" )
69+ # Load cached values
70+ if cached_config and "resources" in cached_config :
71+ LocalResources .initialize (ret , cached_config ["resources" ])
72+ ret .logging_handlers = handlers
73+ ret .logging .info ("Using cached resources for Local" )
74+ else :
75+ # Check for new config
76+ ret .logging_handlers = handlers
77+ LocalResources .initialize (ret , config )
6678
6779 return ret
6880
@@ -104,13 +116,12 @@ def deserialize(config: dict, cache: Cache, handlers: LoggingHandlers) -> Config
104116 return config_obj
105117
106118 def serialize (self ) -> dict :
107- with open (self .resources .path , "r+" ) as out :
108- config = json .load (out )
109- config ["deployment" ]["local" ].update (self .resources .serialize ())
110- out .seek (0 )
111- out .write (serialize (config ))
112-
113- return {}
119+ out = {
120+ "name" : "local" ,
121+ "region" : self ._region ,
122+ "resources" : self ._resources .serialize ()
123+ }
124+ return out
114125
115126 def update_cache (self , cache : Cache ):
116- pass
127+ self . resources . update_cache ( cache )
0 commit comments