|
13 | 13 | import arrow |
14 | 14 | import httpx |
15 | 15 | import tenacity |
| 16 | +from common_library.json_serialization import json_loads |
16 | 17 | from fastapi import FastAPI, status |
17 | 18 | from packaging.version import Version |
18 | 19 | from servicelib.async_utils import run_sequentially_in_context |
@@ -135,7 +136,7 @@ async def _read_service_settings( |
135 | 136 | ) -> dict[str, Any] | list[Any] | None: |
136 | 137 | image_labels, _ = await registry_proxy.get_image_labels(app, key, tag) |
137 | 138 | settings: dict[str, Any] | list[Any] | None = ( |
138 | | - json.loads(image_labels[settings_name]) |
| 139 | + json_loads(image_labels[settings_name]) |
139 | 140 | if settings_name in image_labels |
140 | 141 | else None |
141 | 142 | ) |
@@ -306,28 +307,28 @@ async def _create_docker_service_params( |
306 | 307 | ] += f", {service_name}_stripprefixregex" |
307 | 308 |
|
308 | 309 | placement_constraints_to_substitute: list[str] = [] |
309 | | - placement_substitutions: dict[ |
310 | | - str, str |
311 | | - ] = app_settings.DIRECTOR_GENERIC_RESOURCE_PLACEMENT_CONSTRAINTS_SUBSTITUTIONS |
| 310 | + placement_substitutions: dict[str, str] = ( |
| 311 | + app_settings.DIRECTOR_GENERIC_RESOURCE_PLACEMENT_CONSTRAINTS_SUBSTITUTIONS |
| 312 | + ) |
312 | 313 | assert isinstance(service_parameters_labels, list) # nosec |
313 | 314 | for param in service_parameters_labels: |
314 | 315 | _check_setting_correctness(param) |
315 | 316 | # replace %service_uuid% by the given uuid |
316 | 317 | if str(param["value"]).find("%service_uuid%") != -1: |
317 | 318 | dummy_string = json.dumps(param["value"]) |
318 | 319 | dummy_string = dummy_string.replace("%service_uuid%", node_uuid) |
319 | | - param["value"] = json.loads(dummy_string) |
| 320 | + param["value"] = json_loads(dummy_string) |
320 | 321 |
|
321 | 322 | if param["type"] == "Resources": |
322 | 323 | # python-API compatible for backward compatibility |
323 | 324 | if "mem_limit" in param["value"]: |
324 | | - docker_params["task_template"]["Resources"]["Limits"][ |
325 | | - "MemoryBytes" |
326 | | - ] = param["value"]["mem_limit"] |
| 325 | + docker_params["task_template"]["Resources"]["Limits"]["MemoryBytes"] = ( |
| 326 | + param["value"]["mem_limit"] |
| 327 | + ) |
327 | 328 | if "cpu_limit" in param["value"]: |
328 | | - docker_params["task_template"]["Resources"]["Limits"][ |
329 | | - "NanoCPUs" |
330 | | - ] = param["value"]["cpu_limit"] |
| 329 | + docker_params["task_template"]["Resources"]["Limits"]["NanoCPUs"] = ( |
| 330 | + param["value"]["cpu_limit"] |
| 331 | + ) |
331 | 332 | if "mem_reservation" in param["value"]: |
332 | 333 | docker_params["task_template"]["Resources"]["Reservations"][ |
333 | 334 | "MemoryBytes" |
@@ -379,11 +380,11 @@ async def _create_docker_service_params( |
379 | 380 |
|
380 | 381 | # publishing port on the ingress network. |
381 | 382 | elif param["name"] == "ports" and param["type"] == "int": # backward comp |
382 | | - docker_params["labels"][ |
383 | | - _to_simcore_runtime_docker_label_key("port") |
384 | | - ] = docker_params["labels"][ |
385 | | - f"traefik.http.services.{service_name}.loadbalancer.server.port" |
386 | | - ] = str( |
| 383 | + docker_params["labels"][_to_simcore_runtime_docker_label_key("port")] = ( |
| 384 | + docker_params["labels"][ |
| 385 | + f"traefik.http.services.{service_name}.loadbalancer.server.port" |
| 386 | + ] |
| 387 | + ) = str( |
387 | 388 | param["value"] |
388 | 389 | ) |
389 | 390 | # REST-API compatible |
@@ -445,11 +446,9 @@ async def _create_docker_service_params( |
445 | 446 | ] = container_spec["Labels"][ |
446 | 447 | _to_simcore_runtime_docker_label_key("cpu_limit") |
447 | 448 | ] = f"{float(nano_cpus_limit) / 1e9}" |
448 | | - docker_params["labels"][ |
449 | | - _to_simcore_runtime_docker_label_key("memory_limit") |
450 | | - ] = container_spec["Labels"][ |
451 | | - _to_simcore_runtime_docker_label_key("memory_limit") |
452 | | - ] = mem_limit |
| 449 | + docker_params["labels"][_to_simcore_runtime_docker_label_key("memory_limit")] = ( |
| 450 | + container_spec["Labels"][_to_simcore_runtime_docker_label_key("memory_limit")] |
| 451 | + ) = mem_limit |
453 | 452 |
|
454 | 453 | # and make the container aware of them via env variables |
455 | 454 | resource_limits = { |
|
0 commit comments