|
5 | 5 | from datetime import datetime, timedelta |
6 | 6 | from distutils.version import StrictVersion |
7 | 7 | from enum import Enum |
| 8 | +from http import HTTPStatus |
8 | 9 | from pprint import pformat |
9 | 10 | from typing import Dict, List, Optional, Tuple |
10 | 11 |
|
@@ -1020,17 +1021,39 @@ async def _save_service_state(service_host_name: str, session: aiohttp.ClientSes |
1020 | 1021 | url=f"http://{service_host_name}/state", |
1021 | 1022 | timeout=ServicesCommonSettings().director_dynamic_service_save_timeout, |
1022 | 1023 | ) as response: |
1023 | | - response.raise_for_status() |
1024 | | - log.info( |
1025 | | - "Service '%s' successfully saved its state: %s", |
1026 | | - service_host_name, |
1027 | | - f"{response}", |
1028 | | - ) |
| 1024 | + try: |
| 1025 | + response.raise_for_status() |
| 1026 | + |
| 1027 | + except ClientResponseError as err: |
| 1028 | + if err.status in (HTTPStatus.METHOD_NOT_ALLOWED, HTTPStatus.NOT_FOUND): |
| 1029 | + # NOTE: Legacy Override. Some old services do not have a state entrypoint defined |
| 1030 | + # therefore we assume there is nothing to be saved and do not raise exception |
| 1031 | + # Responses found so far: |
| 1032 | + # METHOD NOT ALLOWED https://httpstatuses.com/405 |
| 1033 | + # NOT FOUND https://httpstatuses.com/404 |
| 1034 | + # |
| 1035 | + log.warning( |
| 1036 | + "Service '%s' does not seem to implement save state functionality: %s. Skipping save", |
| 1037 | + service_host_name, |
| 1038 | + err, |
| 1039 | + ) |
| 1040 | + else: |
| 1041 | + # re-reaise |
| 1042 | + raise |
| 1043 | + else: |
| 1044 | + log.info( |
| 1045 | + "Service '%s' successfully saved its state: %s", |
| 1046 | + service_host_name, |
| 1047 | + f"{response}", |
| 1048 | + ) |
1029 | 1049 |
|
1030 | 1050 |
|
1031 | 1051 | @run_sequentially_in_context(target_args=["node_uuid"]) |
1032 | 1052 | async def stop_service(app: web.Application, node_uuid: str, save_state: bool) -> None: |
1033 | | - log.debug("stopping service with uuid %s", node_uuid) |
| 1053 | + log.debug( |
| 1054 | + "stopping service with node_uuid=%s, save_state=%s", node_uuid, save_state |
| 1055 | + ) |
| 1056 | + |
1034 | 1057 | # get the docker client |
1035 | 1058 | async with docker_utils.docker_client() as client: # pylint: disable=not-async-context-manager |
1036 | 1059 | try: |
|
0 commit comments