|
4 | 4 |
|
5 | 5 | from datetime import datetime |
6 | 6 | from typing import Self |
| 7 | +from uuid import UUID |
7 | 8 |
|
8 | 9 | import strawberry |
9 | 10 | from strawberry import ID |
10 | 11 | from strawberry.relay import Node, NodeID |
11 | 12 |
|
12 | 13 | from ai.backend.common.data.model_deployment.types import DeploymentStrategy |
| 14 | +from ai.backend.manager.api.gql.utils import dedent_strip |
13 | 15 | from ai.backend.manager.data.deployment.types import DeploymentPolicyData |
| 16 | +from ai.backend.manager.data.deployment.upserter import DeploymentPolicyUpserter |
| 17 | +from ai.backend.manager.errors.api import InvalidAPIParameters |
14 | 18 | from ai.backend.manager.errors.deployment import InvalidDeploymentStrategySpec |
15 | 19 | from ai.backend.manager.models.deployment_policy import BlueGreenSpec, RollingUpdateSpec |
16 | 20 |
|
@@ -129,3 +133,63 @@ def to_spec(self) -> BlueGreenSpec: |
129 | 133 | auto_promote=self.auto_promote, |
130 | 134 | promote_delay_seconds=self.promote_delay_seconds, |
131 | 135 | ) |
| 136 | + |
| 137 | + |
| 138 | +# ========== Mutation Input/Payload Types ========== |
| 139 | + |
| 140 | + |
| 141 | +@strawberry.input( |
| 142 | + name="UpdateDeploymentPolicyInput", |
| 143 | + description=dedent_strip(""" |
| 144 | + Added in 26.4.0. |
| 145 | + Input for creating or updating a deployment policy (upsert semantics). |
| 146 | + Specify the target deployment_id and the desired strategy type. |
| 147 | + Exactly one of rolling_update or blue_green must be provided, |
| 148 | + matching the chosen strategy type. |
| 149 | + If a policy already exists for the deployment, it is replaced entirely. |
| 150 | + """), |
| 151 | +) |
| 152 | +class UpdateDeploymentPolicyInputGQL: |
| 153 | + deployment_id: ID |
| 154 | + strategy: DeploymentStrategyTypeGQL |
| 155 | + rollback_on_failure: bool = False |
| 156 | + rolling_update: RollingUpdateConfigInputGQL | None = None |
| 157 | + blue_green: BlueGreenConfigInputGQL | None = None |
| 158 | + |
| 159 | + def to_upserter(self) -> DeploymentPolicyUpserter: |
| 160 | + """Convert to DeploymentPolicyUpserter for the service layer.""" |
| 161 | + |
| 162 | + strategy = DeploymentStrategy(self.strategy.value) |
| 163 | + strategy_spec: RollingUpdateSpec | BlueGreenSpec |
| 164 | + match strategy: |
| 165 | + case DeploymentStrategy.ROLLING: |
| 166 | + if self.rolling_update is None: |
| 167 | + raise InvalidAPIParameters( |
| 168 | + "rolling_update config required for ROLLING strategy" |
| 169 | + ) |
| 170 | + strategy_spec = self.rolling_update.to_spec() |
| 171 | + case DeploymentStrategy.BLUE_GREEN: |
| 172 | + if self.blue_green is None: |
| 173 | + raise InvalidAPIParameters("blue_green config required for BLUE_GREEN strategy") |
| 174 | + strategy_spec = self.blue_green.to_spec() |
| 175 | + case _: |
| 176 | + raise InvalidAPIParameters(f"Unsupported deployment strategy: {strategy}") |
| 177 | + |
| 178 | + return DeploymentPolicyUpserter( |
| 179 | + deployment_id=UUID(str(self.deployment_id)), |
| 180 | + strategy=strategy, |
| 181 | + strategy_spec=strategy_spec, |
| 182 | + rollback_on_failure=self.rollback_on_failure, |
| 183 | + ) |
| 184 | + |
| 185 | + |
| 186 | +@strawberry.type( |
| 187 | + name="UpdateDeploymentPolicyPayload", |
| 188 | + description=dedent_strip(""" |
| 189 | + Added in 26.4.0. |
| 190 | + Result payload returned after creating or updating a deployment policy. |
| 191 | + Contains the full deployment_policy object reflecting the applied configuration. |
| 192 | + """), |
| 193 | +) |
| 194 | +class UpdateDeploymentPolicyPayloadGQL: |
| 195 | + deployment_policy: DeploymentPolicyGQL |
0 commit comments