Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
4 changes: 2 additions & 2 deletions api/specs/web-server/_projects_states.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from pydantic import ValidationError
from servicelib.aiohttp import status
from simcore_service_webserver._meta import API_VTAG
from simcore_service_webserver.director_v2.exceptions import DirectorServiceError
from simcore_service_webserver.director_v2.exceptions import DirectorV2ServiceError
from simcore_service_webserver.projects._controller.projects_states_rest import (
ProjectPathParams,
_OpenProjectQuery,
Expand Down Expand Up @@ -62,7 +62,7 @@ def to_desc(exceptions: list[type[Exception]] | type[Exception]):
"description": to_desc([ValidationError])
},
status.HTTP_503_SERVICE_UNAVAILABLE: {
"description": to_desc([DirectorServiceError])
"description": to_desc([DirectorV2ServiceError])
},
},
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from tenacity.wait import wait_random
from yarl import URL

from .exceptions import DirectorServiceError
from .exceptions import DirectorV2ServiceError
from .settings import get_client_session

log = logging.getLogger(__name__)
Expand All @@ -30,7 +30,9 @@
DataBody: TypeAlias = DataType | list[DataType] | None


_StatusToExceptionMapping = dict[int, tuple[type[DirectorServiceError], dict[str, Any]]]
_StatusToExceptionMapping = dict[
int, tuple[type[DirectorV2ServiceError], dict[str, Any]]
]


def _get_exception_from(
Expand All @@ -40,7 +42,7 @@ def _get_exception_from(
exc, exc_ctx = on_error[status_code]
return exc(**exc_ctx, status=status_code, reason=reason)
# default
return DirectorServiceError(status=status_code, reason=reason, url=url)
return DirectorV2ServiceError(status=status_code, reason=reason, url=url)


@retry(**DEFAULT_RETRY_POLICY)
Expand Down Expand Up @@ -95,14 +97,14 @@ async def request_director_v2(
return payload

except TimeoutError as err:
raise DirectorServiceError(
raise DirectorV2ServiceError(
status=status.HTTP_503_SERVICE_UNAVAILABLE,
reason=f"request to director-v2 timed-out: {err}",
url=url,
) from err

except aiohttp.ClientError as err:
raise DirectorServiceError(
raise DirectorV2ServiceError(
status=status.HTTP_503_SERVICE_UNAVAILABLE,
reason=f"request to director-v2 service unexpected error {err}",
url=url,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
from aiohttp import web
from servicelib.aiohttp import status
from servicelib.aiohttp.rest_responses import create_http_error
from servicelib.aiohttp.web_exceptions_extension import get_http_error_class_or_none
from simcore_service_webserver.director_v2.exceptions import DirectorServiceError
from simcore_service_webserver.constants import MSG_TRY_AGAIN_OR_SUPPORT
from simcore_service_webserver.director_v2.exceptions import DirectorV2ServiceError

from ...exception_handling import (
ExceptionHandlersMap,
Expand All @@ -17,23 +15,6 @@
_exceptions_handlers_map: ExceptionHandlersMap = {}


async def _handler_director_service_error(
request: web.Request, exception: Exception
) -> web.Response:
assert request # nosec

assert isinstance(exception, DirectorServiceError) # nosec
return create_http_error(
exception,
reason=exception.reason,
http_error_cls=get_http_error_class_or_none(exception.status)
or web.HTTPServiceUnavailable,
)


_exceptions_handlers_map[DirectorServiceError] = _handler_director_service_error


_TO_HTTP_ERROR_MAP: ExceptionToHttpErrorMap = {
UserDefaultWalletNotFoundError: HttpErrorInfo(
status.HTTP_404_NOT_FOUND,
Expand All @@ -43,6 +24,13 @@ async def _handler_director_service_error(
status.HTTP_402_PAYMENT_REQUIRED,
"Wallet does not have enough credits for computations. {reason}",
),
DirectorV2ServiceError: HttpErrorInfo(
status.HTTP_503_SERVICE_UNAVAILABLE,
# This error is raised when the director service raises an unhandled exception.
# Most likely the director service is down or misconfigured so the user is asked to try again later.
"This service is temporarily unavailable. The incident was logged and will be investigated. "
+ MSG_TRY_AGAIN_OR_SUPPORT,
),
}

_exceptions_handlers_map.update(to_exceptions_handlers_map(_TO_HTTP_ERROR_MAP))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
from ..users.exceptions import UserDefaultWalletNotFoundError
from ..wallets import api as wallets_service
from ._client_base import DataType, request_director_v2
from .exceptions import ComputationNotFoundError, DirectorServiceError
from .exceptions import ComputationNotFoundError, DirectorV2ServiceError
from .settings import DirectorV2Settings, get_plugin_settings

_logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -75,7 +75,7 @@ async def create_or_update_pipeline(
assert isinstance(computation_task_out, dict) # nosec
return computation_task_out

except DirectorServiceError as exc:
except DirectorV2ServiceError as exc:
_logger.error( # noqa: TRY400
"could not create pipeline from project %s: %s",
project_id,
Expand Down Expand Up @@ -117,7 +117,7 @@ async def get_computation_task(
_logger.debug("found computation task: %s", f"{task_out=}")

return task_out
except DirectorServiceError as exc:
except DirectorV2ServiceError as exc:
if exc.status == status.HTTP_404_NOT_FOUND:
# the pipeline might not exist and that is ok
return None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
is_pipeline_running,
stop_pipeline,
)
from .exceptions import DirectorServiceError
from .exceptions import DirectorV2ServiceError

# director-v2 module internal API
__all__: tuple[str, ...] = (
"AbstractProjectRunPolicy",
"DirectorServiceError",
"DirectorV2ServiceError",
"create_or_update_pipeline",
"delete_pipeline",
"get_batch_tasks_outputs",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from ..errors import WebServerBaseError


class DirectorServiceError(WebServerBaseError, RuntimeError):
class DirectorV2ServiceError(WebServerBaseError, RuntimeError):
"""Basic exception for errors raised by director-v2"""

msg_template = "Unexpected error: director-v2 returned '{status}', reason '{reason}' after calling '{url}'"
Expand All @@ -16,5 +16,5 @@ def __init__(self, *, status: int, reason: str, **ctx: Any) -> None:
self.reason = reason


class ComputationNotFoundError(DirectorServiceError):
class ComputationNotFoundError(DirectorV2ServiceError):
msg_template = "Computation '{project_id}' not found"
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from simcore_postgres_database.webserver_models import ProjectType

from ..._meta import API_VTAG as VTAG
from ...director_v2.exceptions import DirectorServiceError
from ...director_v2.exceptions import DirectorV2ServiceError
from ...login.decorators import login_required
from ...notifications import project_logs
from ...products import products_web
Expand Down Expand Up @@ -141,7 +141,7 @@ async def open_project(request: web.Request) -> web.Response:

return envelope_json_response(ProjectGet.from_domain_model(project))

except DirectorServiceError as exc:
except DirectorV2ServiceError as exc:
# there was an issue while accessing the director-v2/director-v0
# ensure the project is closed again
await _projects_service.try_close_project_for_user(
Expand Down
Loading