diff --git a/sdk/turing/router/config/experiment_config.py b/sdk/turing/router/config/experiment_config.py index 0fe174cff..ffc67e417 100644 --- a/sdk/turing/router/config/experiment_config.py +++ b/sdk/turing/router/config/experiment_config.py @@ -29,9 +29,9 @@ def config(self) -> Dict: @config.setter def config(self, config: Dict): - if config is not None and 'project_id' in config: - config['project_id'] = int(config['project_id']) self._config = config + if self._config is not None and 'project_id' in self._config: + self.config['project_id'] = int(self._config['project_id']) def to_open_api(self) -> OpenApiModel: if self.config is None: diff --git a/sdk/turing/router/config/router_ensembler_config.py b/sdk/turing/router/config/router_ensembler_config.py index 35a487ba0..b19577ebe 100644 --- a/sdk/turing/router/config/router_ensembler_config.py +++ b/sdk/turing/router/config/router_ensembler_config.py @@ -59,11 +59,12 @@ def standard_config(self, standard_config: Union[turing.generated.models.Ensembl if isinstance(standard_config, turing.generated.models.EnsemblerStandardConfig): self._standard_config = standard_config elif isinstance(standard_config, dict): - standard_config['experiment_mappings'] = [ + openapi_standard_config = standard_config.copy() + openapi_standard_config['experiment_mappings'] = [ turing.generated.models.EnsemblerStandardConfigExperimentMappings(**mapping) for mapping in standard_config['experiment_mappings'] ] - self._standard_config = turing.generated.models.EnsemblerStandardConfig(**standard_config) + self._standard_config = turing.generated.models.EnsemblerStandardConfig(**openapi_standard_config) else: self._standard_config = standard_config @@ -76,11 +77,12 @@ def docker_config(self, docker_config: turing.generated.models.EnsemblerDockerCo if isinstance(docker_config, turing.generated.models.EnsemblerDockerConfig): self._docker_config = docker_config elif isinstance(docker_config, dict): - docker_config['resource_request'] = \ - turing.generated.models.ResourceRequest(**docker_config['resource_request']) - docker_config['env'] = [turing.generated.models.EnvVar(**env_var) for env_var in docker_config['env']] + openapi_docker_config = docker_config.copy() + openapi_docker_config['resource_request'] = \ + turing.generated.models.ResourceRequest(**openapi_docker_config['resource_request']) + openapi_docker_config['env'] = [turing.generated.models.EnvVar(**env_var) for env_var in openapi_docker_config['env']] self._docker_config = turing.generated.models.EnsemblerDockerConfig( - **docker_config + **openapi_docker_config ) else: self._docker_config = docker_config diff --git a/sdk/turing/router/router.py b/sdk/turing/router/router.py index eabb4bbbe..16c32f0b3 100644 --- a/sdk/turing/router/router.py +++ b/sdk/turing/router/router.py @@ -44,11 +44,7 @@ def __init__(self, self._endpoint = endpoint self._monitoring_url = monitoring_url self._status = RouterStatus(status) - - if config is not None: - self._config = RouterConfig(name=name, environment_name=environment_name, **config) - else: - self._config = None + self._config = config @property def id(self) -> int: @@ -80,7 +76,11 @@ def status(self) -> RouterStatus: @property def config(self) -> 'RouterConfig': - return self._config + return RouterConfig(name=self.name, environment_name=self.environment_name, **self._config) + + @property + def version(self) -> int: + return self._config.get('version') if self._config else None @classmethod def list(cls) -> List['Router']: @@ -128,7 +128,7 @@ def update(self, config: RouterConfig) -> 'Router': Update the current router with a new set of configs specified in the RouterConfig argument :param config: configuration of router - :return: instance of router updated (self) + :return: instance of router (self); this router contains details of the router and its currently deployed version """ self._config = config updated_router = Router.from_open_api( @@ -201,11 +201,13 @@ def get_events(self) -> List[turing.generated.models.Event]: def wait_for_status(self, status: RouterStatus, max_tries: int = 15, duration: float = 10.0): for i in range(1, max_tries + 1): logger.debug(f"Checking if router {self.id} is {status.value}...") - cur_status = Router.get(self.id).status + current_router = Router.get(self.id) + cur_status = current_router.status if cur_status == status: # Wait for backend components to fully resolve time.sleep(5) logger.debug(f"Router {self.id} is finally {status.value}.") + self.__dict__ = current_router.__dict__ return else: logger.debug(f"Router {self.id} is {cur_status.value}.")