Skip to content

Commit 7494359

Browse files
committed
renamed exceptions
1 parent c6c637d commit 7494359

File tree

2 files changed

+23
-11
lines changed

2 files changed

+23
-11
lines changed

services/autoscaling/src/simcore_service_autoscaling/core/errors.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,18 @@ class ConfigurationError(AutoscalingRuntimeError):
1414
msg_template: str = "Application misconfiguration: {msg}"
1515

1616

17-
class Ec2InstanceInvalidError(AutoscalingRuntimeError):
18-
msg_template: str = "Invalid EC2 defined: {msg}"
17+
class TaskRequiresUnauthorizedEC2InstanceTypeError(AutoscalingRuntimeError):
18+
msg_template: str = (
19+
"Task {task} requires unauthorized {instance_type}. "
20+
"TIP: check task required instance type or allow the instance type in autoscaling service settings"
21+
)
22+
23+
24+
class TaskRequirementsAboveRequiredEC2InstanceTypeError(AutoscalingRuntimeError):
25+
msg_template: str = (
26+
"Task {task} requires {instance_type} but requires {resources}. "
27+
"TIP: Ensure task resources requirements fit required instance type available resources."
28+
)
1929

2030

2131
class Ec2InvalidDnsNameError(AutoscalingRuntimeError):

services/autoscaling/src/simcore_service_autoscaling/utils/auto_scaling_core.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@
77
from models_library.generated_models.docker_rest_api import Node
88
from types_aiobotocore_ec2.literals import InstanceTypeType
99

10-
from ..core.errors import Ec2InstanceInvalidError, Ec2InvalidDnsNameError
10+
from ..core.errors import (
11+
Ec2InvalidDnsNameError,
12+
TaskRequirementsAboveRequiredEC2InstanceTypeError,
13+
TaskRequiresUnauthorizedEC2InstanceTypeError,
14+
)
1115
from ..core.settings import ApplicationSettings
1216
from ..models import AssociatedInstance
1317
from ..modules.auto_scaling_mode_base import BaseAutoscaling
@@ -142,11 +146,9 @@ def find_selected_instance_type_for_task(
142146
)
143147
)
144148
if not filtered_instances:
145-
msg = (
146-
f"Task {task} requires an unauthorized EC2 instance type."
147-
f"Asked for {instance_type_name}, authorized are {available_ec2_types}. Please check!"
149+
raise TaskRequiresUnauthorizedEC2InstanceTypeError(
150+
task=task, instance_type=instance_type_name
148151
)
149-
raise Ec2InstanceInvalidError(msg=msg)
150152

151153
assert len(filtered_instances) == 1 # nosec
152154
selected_instance = filtered_instances[0]
@@ -156,11 +158,11 @@ def find_selected_instance_type_for_task(
156158
auto_scaling_mode.get_task_required_resources(task)
157159
> selected_instance.resources
158160
):
159-
msg = (
160-
f"Task {task} requires more resources than the selected instance provides."
161-
f" Asked for {selected_instance}, but task needs {auto_scaling_mode.get_task_required_resources(task)}. Please check!"
161+
raise TaskRequirementsAboveRequiredEC2InstanceTypeError(
162+
task=task,
163+
instance_type=selected_instance,
164+
resources=auto_scaling_mode.get_task_required_resources(task),
162165
)
163-
raise Ec2InstanceInvalidError(msg=msg)
164166

165167
return selected_instance
166168

0 commit comments

Comments
 (0)