|
1 | | -"""AppConfig (merged view) domain adapter |
| 1 | +"""AppConfig (merged view) domain adapter — BEP-1052 §5. |
2 | 2 |
|
3 | 3 | Reads the per-user merged AppConfig view and writes the underlying USER |
4 | 4 | fragments via the same `app_config_fragment` service processors. The |
|
19 | 19 | ) |
20 | 20 | from ai.backend.common.dto.manager.v2.app_config.response import ( |
21 | 21 | AppConfigNode, |
| 22 | + BulkCreateMyAppConfigFragmentsPayload, |
| 23 | + BulkUpdateMyAppConfigFragmentsPayload, |
22 | 24 | GetUserAppConfigPayload, |
23 | | - MyBulkCreateAppConfigFragmentsPayload, |
24 | | - MyBulkUpdateAppConfigFragmentsPayload, |
25 | 25 | SearchAppConfigsPayload, |
26 | 26 | ) |
27 | 27 | from ai.backend.common.dto.manager.v2.app_config.types import AppConfigOrderField, OrderDirection |
28 | 28 | from ai.backend.common.dto.manager.v2.app_config_fragment.request import ( |
29 | | - MyBulkCreateAppConfigFragmentsInput, |
30 | | - MyBulkUpdateAppConfigFragmentsInput, |
| 29 | + BulkCreateMyAppConfigFragmentsInput, |
| 30 | + BulkUpdateMyAppConfigFragmentsInput, |
31 | 31 | ) |
32 | 32 | from ai.backend.common.dto.manager.v2.app_config_fragment.response import ( |
33 | 33 | AppConfigFragmentBulkError, |
|
52 | 52 | from ai.backend.manager.services.app_config_fragment.actions.admin_search_app_configs import ( |
53 | 53 | AdminSearchAppConfigsAction, |
54 | 54 | ) |
55 | | -from ai.backend.manager.services.app_config_fragment.actions.get_user_app_config import ( |
56 | | - GetUserAppConfigAction, |
| 55 | +from ai.backend.manager.services.app_config_fragment.actions.bulk_create_my import ( |
| 56 | + BulkCreateMyAppConfigFragmentsAction, |
57 | 57 | ) |
58 | | -from ai.backend.manager.services.app_config_fragment.actions.my_bulk_create import ( |
59 | | - MyBulkCreateAppConfigFragmentsAction, |
| 58 | +from ai.backend.manager.services.app_config_fragment.actions.bulk_update_my import ( |
| 59 | + BulkUpdateMyAppConfigFragmentsAction, |
60 | 60 | ) |
61 | | -from ai.backend.manager.services.app_config_fragment.actions.my_bulk_update import ( |
62 | | - MyBulkUpdateAppConfigFragmentsAction, |
| 61 | +from ai.backend.manager.services.app_config_fragment.actions.get_user_app_config import ( |
| 62 | + GetUserAppConfigAction, |
63 | 63 | ) |
64 | 64 | from ai.backend.manager.services.app_config_fragment.actions.search_user_app_configs import ( |
65 | 65 | SearchUserAppConfigsAction, |
|
69 | 69 |
|
70 | 70 |
|
71 | 71 | class AppConfigAdapter(BaseAdapter): |
72 | | - """Adapter for the merged AppConfig view. |
| 72 | + """Adapter for the merged AppConfig view (BEP-1052 §5). |
73 | 73 |
|
74 | 74 | Backed by the `app_config_fragment` service processors — the merged |
75 | 75 | view is computed from raw fragments — but exposed as a separate |
@@ -146,41 +146,55 @@ async def admin_search_app_configs( |
146 | 146 | has_previous_page=result.has_previous_page, |
147 | 147 | ) |
148 | 148 |
|
149 | | - # ── Self-service bulk writes ─────────────────────── |
| 149 | + # ── Self-service bulk writes (BEP-1052 §3) ─────────────────────── |
150 | 150 | # |
151 | 151 | # Each bulk processor returns a `BulkProcessResult[T]` whose |
152 | 152 | # `.result` field is the underlying `*ActionResult` produced by the |
153 | 153 | # service. We discard the validator-decision trail here — RBAC |
154 | 154 | # reasons travel back through the per-item `failed` list. |
155 | 155 |
|
156 | 156 | async def my_bulk_create( |
157 | | - self, input: MyBulkCreateAppConfigFragmentsInput |
158 | | - ) -> MyBulkCreateAppConfigFragmentsPayload: |
| 157 | + self, input: BulkCreateMyAppConfigFragmentsInput |
| 158 | + ) -> BulkCreateMyAppConfigFragmentsPayload: |
| 159 | + me = current_user() |
| 160 | + if me is None: |
| 161 | + raise UnreachableError("User context is not available") |
159 | 162 | items = [ |
160 | 163 | MyAppConfigFragmentBulkItem(name=item.name, extra_config=dict(item.extra_config)) |
161 | 164 | for item in input.items |
162 | 165 | ] |
163 | | - wrapper = await self._processors.app_config_fragment.my_bulk_create.wait_for_complete( |
164 | | - MyBulkCreateAppConfigFragmentsAction(entity_ids=[], items=items) |
| 166 | + wrapper = await self._processors.app_config_fragment.bulk_create_my.wait_for_complete( |
| 167 | + BulkCreateMyAppConfigFragmentsAction( |
| 168 | + entity_ids=[], |
| 169 | + user_id=me.user_id, |
| 170 | + items=items, |
| 171 | + ) |
165 | 172 | ) |
166 | 173 | result = wrapper.result |
167 | | - return MyBulkCreateAppConfigFragmentsPayload( |
| 174 | + return BulkCreateMyAppConfigFragmentsPayload( |
168 | 175 | created=[self._data_to_dto(item) for item in result.created], |
169 | 176 | failed=[self._bulk_error_to_dto(err) for err in result.failed], |
170 | 177 | ) |
171 | 178 |
|
172 | 179 | async def my_bulk_update( |
173 | | - self, input: MyBulkUpdateAppConfigFragmentsInput |
174 | | - ) -> MyBulkUpdateAppConfigFragmentsPayload: |
| 180 | + self, input: BulkUpdateMyAppConfigFragmentsInput |
| 181 | + ) -> BulkUpdateMyAppConfigFragmentsPayload: |
| 182 | + me = current_user() |
| 183 | + if me is None: |
| 184 | + raise UnreachableError("User context is not available") |
175 | 185 | items = [ |
176 | 186 | MyAppConfigFragmentBulkItem(name=item.name, extra_config=dict(item.extra_config)) |
177 | 187 | for item in input.items |
178 | 188 | ] |
179 | | - wrapper = await self._processors.app_config_fragment.my_bulk_update.wait_for_complete( |
180 | | - MyBulkUpdateAppConfigFragmentsAction(entity_ids=[], items=items) |
| 189 | + wrapper = await self._processors.app_config_fragment.bulk_update_my.wait_for_complete( |
| 190 | + BulkUpdateMyAppConfigFragmentsAction( |
| 191 | + entity_ids=[], |
| 192 | + user_id=me.user_id, |
| 193 | + items=items, |
| 194 | + ) |
181 | 195 | ) |
182 | 196 | result = wrapper.result |
183 | | - return MyBulkUpdateAppConfigFragmentsPayload( |
| 197 | + return BulkUpdateMyAppConfigFragmentsPayload( |
184 | 198 | updated=[self._data_to_dto(item) for item in result.updated], |
185 | 199 | failed=[self._bulk_error_to_dto(err) for err in result.failed], |
186 | 200 | ) |
|
0 commit comments