zenml-nightly 0.62.0.dev20240729__py3-none-any.whl → 0.62.0.dev20240730__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. zenml/VERSION +1 -1
  2. zenml/actions/pipeline_run/pipeline_run_action.py +19 -17
  3. zenml/analytics/enums.py +4 -0
  4. zenml/cli/__init__.py +28 -15
  5. zenml/cli/base.py +1 -1
  6. zenml/cli/pipeline.py +54 -61
  7. zenml/cli/stack.py +6 -8
  8. zenml/client.py +232 -99
  9. zenml/config/compiler.py +14 -22
  10. zenml/config/pipeline_run_configuration.py +3 -0
  11. zenml/config/server_config.py +3 -0
  12. zenml/config/source.py +2 -1
  13. zenml/constants.py +2 -0
  14. zenml/enums.py +3 -0
  15. zenml/integrations/aws/orchestrators/sagemaker_orchestrator.py +13 -4
  16. zenml/integrations/databricks/flavors/databricks_orchestrator_flavor.py +11 -2
  17. zenml/integrations/databricks/orchestrators/databricks_orchestrator.py +19 -13
  18. zenml/models/__init__.py +26 -10
  19. zenml/models/v2/base/filter.py +32 -0
  20. zenml/models/v2/core/pipeline.py +73 -89
  21. zenml/models/v2/core/pipeline_build.py +15 -11
  22. zenml/models/v2/core/pipeline_deployment.py +56 -0
  23. zenml/models/v2/core/pipeline_run.py +52 -1
  24. zenml/models/v2/core/run_template.py +393 -0
  25. zenml/models/v2/misc/stack_deployment.py +5 -0
  26. zenml/new/pipelines/build_utils.py +34 -58
  27. zenml/new/pipelines/pipeline.py +17 -76
  28. zenml/new/pipelines/run_utils.py +12 -0
  29. zenml/post_execution/pipeline.py +1 -4
  30. zenml/service_connectors/service_connector_utils.py +4 -2
  31. zenml/stack_deployments/aws_stack_deployment.py +6 -5
  32. zenml/stack_deployments/azure_stack_deployment.py +118 -11
  33. zenml/stack_deployments/gcp_stack_deployment.py +12 -5
  34. zenml/stack_deployments/stack_deployment.py +6 -5
  35. zenml/steps/utils.py +0 -4
  36. zenml/utils/package_utils.py +39 -0
  37. zenml/zen_server/rbac/models.py +1 -0
  38. zenml/zen_server/rbac/utils.py +4 -0
  39. zenml/zen_server/routers/pipeline_builds_endpoints.py +2 -66
  40. zenml/zen_server/routers/pipeline_deployments_endpoints.py +2 -53
  41. zenml/zen_server/routers/pipelines_endpoints.py +1 -74
  42. zenml/zen_server/routers/run_templates_endpoints.py +212 -0
  43. zenml/zen_server/routers/workspaces_endpoints.py +79 -0
  44. zenml/zen_server/{pipeline_deployment → template_execution}/runner_entrypoint_configuration.py +1 -8
  45. zenml/zen_server/{pipeline_deployment → template_execution}/utils.py +214 -92
  46. zenml/zen_server/utils.py +2 -2
  47. zenml/zen_server/zen_server_api.py +2 -1
  48. zenml/zen_stores/migrations/versions/7d1919bb1ef0_add_run_templates.py +100 -0
  49. zenml/zen_stores/migrations/versions/b59aa68fdb1f_simplify_pipelines.py +139 -0
  50. zenml/zen_stores/rest_zen_store.py +107 -36
  51. zenml/zen_stores/schemas/__init__.py +2 -0
  52. zenml/zen_stores/schemas/pipeline_build_schemas.py +3 -3
  53. zenml/zen_stores/schemas/pipeline_deployment_schemas.py +29 -2
  54. zenml/zen_stores/schemas/pipeline_run_schemas.py +26 -3
  55. zenml/zen_stores/schemas/pipeline_schemas.py +29 -30
  56. zenml/zen_stores/schemas/run_template_schemas.py +264 -0
  57. zenml/zen_stores/schemas/step_run_schemas.py +11 -4
  58. zenml/zen_stores/sql_zen_store.py +364 -150
  59. zenml/zen_stores/template_utils.py +261 -0
  60. zenml/zen_stores/zen_store_interface.py +93 -20
  61. {zenml_nightly-0.62.0.dev20240729.dist-info → zenml_nightly-0.62.0.dev20240730.dist-info}/METADATA +1 -1
  62. {zenml_nightly-0.62.0.dev20240729.dist-info → zenml_nightly-0.62.0.dev20240730.dist-info}/RECORD +67 -63
  63. zenml/models/v2/core/pipeline_namespace.py +0 -113
  64. zenml/new/pipelines/deserialization_utils.py +0 -292
  65. /zenml/zen_server/{pipeline_deployment → template_execution}/__init__.py +0 -0
  66. /zenml/zen_server/{pipeline_deployment → template_execution}/workload_manager_interface.py +0 -0
  67. {zenml_nightly-0.62.0.dev20240729.dist-info → zenml_nightly-0.62.0.dev20240730.dist-info}/LICENSE +0 -0
  68. {zenml_nightly-0.62.0.dev20240729.dist-info → zenml_nightly-0.62.0.dev20240730.dist-info}/WHEEL +0 -0
  69. {zenml_nightly-0.62.0.dev20240729.dist-info → zenml_nightly-0.62.0.dev20240730.dist-info}/entry_points.txt +0 -0
zenml/steps/utils.py CHANGED
@@ -413,7 +413,6 @@ def log_step_metadata(
413
413
  metadata: Dict[str, "MetadataType"],
414
414
  step_name: Optional[str] = None,
415
415
  pipeline_name_id_or_prefix: Optional[Union[str, UUID]] = None,
416
- pipeline_version: Optional[str] = None,
417
416
  run_id: Optional[str] = None,
418
417
  ) -> None:
419
418
  """Logs step metadata.
@@ -424,8 +423,6 @@ def log_step_metadata(
424
423
  when being called inside a step.
425
424
  pipeline_name_id_or_prefix: The name of the pipeline to log metadata
426
425
  for. Can be omitted when being called inside a step.
427
- pipeline_version: The version of the pipeline to log metadata for.
428
- Can be omitted when being called inside a step.
429
426
  run_id: The ID of the run to log metadata for. Can be omitted when
430
427
  being called inside a step.
431
428
 
@@ -460,7 +457,6 @@ def log_step_metadata(
460
457
  )
461
458
  pipeline_run = client.get_pipeline(
462
459
  name_id_or_prefix=pipeline_name_id_or_prefix,
463
- version=pipeline_version,
464
460
  ).last_run
465
461
  step_run_id = pipeline_run.steps[step_name].id
466
462
  client.create_run_metadata(
@@ -13,6 +13,8 @@
13
13
  # permissions and limitations under the License.
14
14
  """Utility functions for the package."""
15
15
 
16
+ from typing import List
17
+
16
18
  import requests
17
19
  from packaging import version
18
20
 
@@ -48,3 +50,40 @@ def is_latest_zenml_version() -> bool:
48
50
  return False
49
51
  else:
50
52
  return True
53
+
54
+
55
+ def clean_requirements(requirements: List[str]) -> List[str]:
56
+ """Clean requirements list from redundant requirements.
57
+
58
+ Args:
59
+ requirements: List of requirements.
60
+
61
+ Returns:
62
+ Cleaned list of requirements
63
+
64
+ Raises:
65
+ TypeError: If input is not a list
66
+ ValueError: If any element in the list is not a string
67
+ """
68
+ if not isinstance(requirements, list):
69
+ raise TypeError("Input must be a list")
70
+
71
+ if not all(isinstance(req, str) for req in requirements):
72
+ raise ValueError("All elements in the list must be strings")
73
+
74
+ cleaned = {}
75
+ for req in requirements:
76
+ package = (
77
+ req.split(">=")[0]
78
+ .split("==")[0]
79
+ .split("<")[0]
80
+ .split("~=")[0]
81
+ .split("^=")[0]
82
+ .split("[")[0]
83
+ .strip()
84
+ )
85
+ if package not in cleaned or any(
86
+ op in req for op in ["=", ">", "<", "~", "^"]
87
+ ):
88
+ cleaned[package] = req
89
+ return sorted(cleaned.values())
@@ -58,6 +58,7 @@ class ResourceType(StrEnum):
58
58
  PIPELINE_RUN = "pipeline_run"
59
59
  PIPELINE_DEPLOYMENT = "pipeline_deployment"
60
60
  PIPELINE_BUILD = "pipeline_build"
61
+ RUN_TEMPLATE = "run_template"
61
62
  USER = "user"
62
63
  SERVICE = "service"
63
64
  RUN_METADATA = "run_metadata"
@@ -405,6 +405,7 @@ def get_resource_type_for_model(
405
405
  PipelineResponse,
406
406
  PipelineRunResponse,
407
407
  RunMetadataResponse,
408
+ RunTemplateResponse,
408
409
  SecretResponse,
409
410
  ServiceAccountResponse,
410
411
  ServiceConnectorResponse,
@@ -440,6 +441,7 @@ def get_resource_type_for_model(
440
441
  PipelineDeploymentResponse: ResourceType.PIPELINE_DEPLOYMENT,
441
442
  PipelineBuildResponse: ResourceType.PIPELINE_BUILD,
442
443
  PipelineRunResponse: ResourceType.PIPELINE_RUN,
444
+ RunTemplateResponse: ResourceType.RUN_TEMPLATE,
443
445
  TagResponse: ResourceType.TAG,
444
446
  TriggerResponse: ResourceType.TRIGGER,
445
447
  TriggerExecutionResponse: ResourceType.TRIGGER_EXECUTION,
@@ -556,6 +558,7 @@ def get_schema_for_resource_type(
556
558
  PipelineRunSchema,
557
559
  PipelineSchema,
558
560
  RunMetadataSchema,
561
+ RunTemplateSchema,
559
562
  SecretSchema,
560
563
  ServiceConnectorSchema,
561
564
  ServiceSchema,
@@ -587,6 +590,7 @@ def get_schema_for_resource_type(
587
590
  ResourceType.PIPELINE_RUN: PipelineRunSchema,
588
591
  ResourceType.PIPELINE_DEPLOYMENT: PipelineDeploymentSchema,
589
592
  ResourceType.PIPELINE_BUILD: PipelineBuildSchema,
593
+ ResourceType.RUN_TEMPLATE: RunTemplateSchema,
590
594
  ResourceType.RUN_METADATA: RunMetadataSchema,
591
595
  ResourceType.USER: UserSchema,
592
596
  ResourceType.ACTION: ActionSchema,
@@ -13,18 +13,15 @@
13
13
  # permissions and limitations under the License.
14
14
  """Endpoint definitions for builds."""
15
15
 
16
- from typing import Optional
17
16
  from uuid import UUID
18
17
 
19
- from fastapi import APIRouter, BackgroundTasks, Depends, Security
18
+ from fastapi import APIRouter, Depends, Security
20
19
 
21
- from zenml.config.pipeline_run_configuration import PipelineRunConfiguration
22
20
  from zenml.constants import API, PIPELINE_BUILDS, VERSION_1
23
21
  from zenml.models import (
24
22
  Page,
25
23
  PipelineBuildFilter,
26
24
  PipelineBuildResponse,
27
- PipelineRunResponse,
28
25
  )
29
26
  from zenml.zen_server.auth import AuthContext, authorize
30
27
  from zenml.zen_server.exceptions import error_response
@@ -33,12 +30,10 @@ from zenml.zen_server.rbac.endpoint_utils import (
33
30
  verify_permissions_and_get_entity,
34
31
  verify_permissions_and_list_entities,
35
32
  )
36
- from zenml.zen_server.rbac.models import Action, ResourceType
37
- from zenml.zen_server.rbac.utils import verify_permission
33
+ from zenml.zen_server.rbac.models import ResourceType
38
34
  from zenml.zen_server.utils import (
39
35
  handle_exceptions,
40
36
  make_dependable,
41
- server_config,
42
37
  zen_store,
43
38
  )
44
39
 
@@ -126,62 +121,3 @@ def delete_build(
126
121
  get_method=zen_store().get_build,
127
122
  delete_method=zen_store().delete_build,
128
123
  )
129
-
130
-
131
- if server_config().workload_manager_enabled:
132
-
133
- @router.post(
134
- "/{build_id}/runs",
135
- responses={
136
- 401: error_response,
137
- 404: error_response,
138
- 422: error_response,
139
- },
140
- )
141
- @handle_exceptions
142
- def run_build(
143
- build_id: UUID,
144
- background_tasks: BackgroundTasks,
145
- config: Optional[PipelineRunConfiguration] = None,
146
- auth_context: AuthContext = Security(authorize),
147
- ) -> PipelineRunResponse:
148
- """Run a pipeline from a pipeline build.
149
-
150
- Args:
151
- build_id: The ID of the build.
152
- background_tasks: Background tasks.
153
- config: Configuration for the pipeline run.
154
- auth_context: Authentication context.
155
-
156
- Raises:
157
- ValueError: If the build does not have an associated deployment.
158
-
159
- Returns:
160
- The created run.
161
- """
162
- from zenml.zen_server.pipeline_deployment.utils import (
163
- run_pipeline,
164
- )
165
-
166
- build = verify_permissions_and_get_entity(
167
- id=build_id, get_method=zen_store().get_build, hydrate=True
168
- )
169
-
170
- verify_permission(
171
- resource_type=ResourceType.PIPELINE_RUN, action=Action.CREATE
172
- )
173
-
174
- if not build.template_deployment_id:
175
- raise ValueError("Build does not have template deployment.")
176
-
177
- deployment = zen_store().get_deployment(
178
- deployment_id=build.template_deployment_id, hydrate=True
179
- )
180
- deployment.get_metadata().build = build
181
-
182
- return run_pipeline(
183
- deployment=deployment,
184
- run_config=config,
185
- background_tasks=background_tasks,
186
- auth_context=auth_context,
187
- )
@@ -13,18 +13,15 @@
13
13
  # permissions and limitations under the License.
14
14
  """Endpoint definitions for deployments."""
15
15
 
16
- from typing import Optional
17
16
  from uuid import UUID
18
17
 
19
- from fastapi import APIRouter, BackgroundTasks, Depends, Security
18
+ from fastapi import APIRouter, Depends, Security
20
19
 
21
- from zenml.config.pipeline_run_configuration import PipelineRunConfiguration
22
20
  from zenml.constants import API, PIPELINE_DEPLOYMENTS, VERSION_1
23
21
  from zenml.models import (
24
22
  Page,
25
23
  PipelineDeploymentFilter,
26
24
  PipelineDeploymentResponse,
27
- PipelineRunResponse,
28
25
  )
29
26
  from zenml.zen_server.auth import AuthContext, authorize
30
27
  from zenml.zen_server.exceptions import error_response
@@ -33,8 +30,7 @@ from zenml.zen_server.rbac.endpoint_utils import (
33
30
  verify_permissions_and_get_entity,
34
31
  verify_permissions_and_list_entities,
35
32
  )
36
- from zenml.zen_server.rbac.models import Action, ResourceType
37
- from zenml.zen_server.rbac.utils import verify_permission
33
+ from zenml.zen_server.rbac.models import ResourceType
38
34
  from zenml.zen_server.utils import (
39
35
  handle_exceptions,
40
36
  make_dependable,
@@ -133,53 +129,6 @@ def delete_deployment(
133
129
 
134
130
  if server_config().workload_manager_enabled:
135
131
 
136
- @router.post(
137
- "/{deployment_id}/runs",
138
- responses={
139
- 401: error_response,
140
- 404: error_response,
141
- 422: error_response,
142
- },
143
- )
144
- @handle_exceptions
145
- def create_deployment_run(
146
- deployment_id: UUID,
147
- background_tasks: BackgroundTasks,
148
- config: Optional[PipelineRunConfiguration] = None,
149
- auth_context: AuthContext = Security(authorize),
150
- ) -> PipelineRunResponse:
151
- """Run a pipeline from a pipeline deployment.
152
-
153
- Args:
154
- deployment_id: The ID of the deployment.
155
- background_tasks: Background tasks.
156
- config: Configuration for the pipeline run.
157
- auth_context: Authentication context.
158
-
159
- Returns:
160
- The created run.
161
- """
162
- from zenml.zen_server.pipeline_deployment.utils import (
163
- run_pipeline,
164
- )
165
-
166
- deployment = verify_permissions_and_get_entity(
167
- id=deployment_id,
168
- get_method=zen_store().get_deployment,
169
- hydrate=True,
170
- )
171
-
172
- verify_permission(
173
- resource_type=ResourceType.PIPELINE_RUN, action=Action.CREATE
174
- )
175
-
176
- return run_pipeline(
177
- deployment=deployment,
178
- run_config=config,
179
- background_tasks=background_tasks,
180
- auth_context=auth_context,
181
- )
182
-
183
132
  @router.get(
184
133
  "/{deployment_id}/logs",
185
134
  responses={
@@ -17,10 +17,8 @@ from uuid import UUID
17
17
 
18
18
  from fastapi import APIRouter, Depends, Security
19
19
 
20
- from zenml.config.pipeline_spec import PipelineSpec
21
20
  from zenml.constants import (
22
21
  API,
23
- PIPELINE_SPEC,
24
22
  PIPELINES,
25
23
  REPORTABLE_RESOURCES,
26
24
  RUNS,
@@ -29,8 +27,6 @@ from zenml.constants import (
29
27
  from zenml.models import (
30
28
  Page,
31
29
  PipelineFilter,
32
- PipelineNamespaceFilter,
33
- PipelineNamespaceResponse,
34
30
  PipelineResponse,
35
31
  PipelineRunFilter,
36
32
  PipelineRunResponse,
@@ -46,9 +42,6 @@ from zenml.zen_server.rbac.endpoint_utils import (
46
42
  verify_permissions_and_update_entity,
47
43
  )
48
44
  from zenml.zen_server.rbac.models import ResourceType
49
- from zenml.zen_server.rbac.utils import (
50
- get_allowed_resource_ids,
51
- )
52
45
  from zenml.zen_server.utils import (
53
46
  handle_exceptions,
54
47
  make_dependable,
@@ -64,7 +57,6 @@ router = APIRouter(
64
57
 
65
58
  @router.get(
66
59
  "",
67
- response_model=Page[PipelineResponse],
68
60
  responses={401: error_response, 404: error_response, 422: error_response},
69
61
  )
70
62
  @handle_exceptions
@@ -96,7 +88,6 @@ def list_pipelines(
96
88
 
97
89
  @router.get(
98
90
  "/{pipeline_id}",
99
- response_model=PipelineResponse,
100
91
  responses={401: error_response, 404: error_response, 422: error_response},
101
92
  )
102
93
  @handle_exceptions
@@ -122,7 +113,6 @@ def get_pipeline(
122
113
 
123
114
  @router.put(
124
115
  "/{pipeline_id}",
125
- response_model=PipelineResponse,
126
116
  responses={401: error_response, 404: error_response, 422: error_response},
127
117
  )
128
118
  @handle_exceptions
@@ -179,7 +169,6 @@ def delete_pipeline(
179
169
 
180
170
  @router.get(
181
171
  "/{pipeline_id}" + RUNS,
182
- response_model=Page[PipelineRunResponse],
183
172
  responses={401: error_response, 404: error_response, 422: error_response},
184
173
  )
185
174
  @handle_exceptions
@@ -201,66 +190,4 @@ def list_pipeline_runs(
201
190
  Returns:
202
191
  The pipeline runs according to query filters.
203
192
  """
204
- return zen_store().list_runs(pipeline_run_filter_model)
205
-
206
-
207
- @router.get(
208
- "/{pipeline_id}" + PIPELINE_SPEC,
209
- response_model=PipelineSpec,
210
- responses={401: error_response, 404: error_response, 422: error_response},
211
- )
212
- @handle_exceptions
213
- def get_pipeline_spec(
214
- pipeline_id: UUID,
215
- _: AuthContext = Security(authorize),
216
- ) -> PipelineSpec:
217
- """Gets the spec of a specific pipeline using its unique id.
218
-
219
- Args:
220
- pipeline_id: ID of the pipeline to get.
221
-
222
- Returns:
223
- The spec of the pipeline.
224
- """
225
- pipeline = verify_permissions_and_get_entity(
226
- id=pipeline_id, get_method=zen_store().get_pipeline
227
- )
228
- return pipeline.spec
229
-
230
-
231
- namespace_router = APIRouter(
232
- prefix=API + VERSION_1 + "/pipeline_namespaces",
233
- tags=["pipeline_namespaces"],
234
- responses={401: error_response, 403: error_response},
235
- )
236
-
237
-
238
- @namespace_router.get(
239
- "",
240
- responses={401: error_response, 404: error_response, 422: error_response},
241
- )
242
- @handle_exceptions
243
- def list_pipeline_namespaces(
244
- filter_model: PipelineNamespaceFilter = Depends(
245
- make_dependable(PipelineNamespaceFilter)
246
- ),
247
- hydrate: bool = False,
248
- auth_context: AuthContext = Security(authorize),
249
- ) -> Page[PipelineNamespaceResponse]:
250
- """Gets a list of pipeline namespaces.
251
-
252
- Args:
253
- filter_model: Filter model used for pagination, sorting,
254
- filtering.
255
- hydrate: Flag deciding whether to hydrate the output model(s)
256
- by including metadata fields in the response.
257
- auth_context: Authentication context.
258
-
259
- Returns:
260
- List of pipeline namespace objects.
261
- """
262
- allowed_ids = get_allowed_resource_ids(resource_type=ResourceType.PIPELINE)
263
- filter_model.configure_rbac(
264
- authenticated_user_id=auth_context.user.id, id=allowed_ids
265
- )
266
- return zen_store().list_pipeline_namespaces(filter_model, hydrate=hydrate)
193
+ return zen_store().list_runs(pipeline_run_filter_model, hydrate=hydrate)
@@ -0,0 +1,212 @@
1
+ # Copyright (c) ZenML GmbH 2024. All Rights Reserved.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at:
6
+ #
7
+ # https://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
12
+ # or implied. See the License for the specific language governing
13
+ # permissions and limitations under the License.
14
+ """Endpoint definitions for run templates."""
15
+
16
+ from typing import Optional
17
+ from uuid import UUID
18
+
19
+ from fastapi import APIRouter, BackgroundTasks, Depends, Security
20
+
21
+ from zenml.analytics.enums import AnalyticsEvent
22
+ from zenml.analytics.utils import track_handler
23
+ from zenml.config.pipeline_run_configuration import PipelineRunConfiguration
24
+ from zenml.constants import API, RUN_TEMPLATES, VERSION_1
25
+ from zenml.models import (
26
+ Page,
27
+ PipelineRunResponse,
28
+ RunTemplateFilter,
29
+ RunTemplateResponse,
30
+ RunTemplateUpdate,
31
+ )
32
+ from zenml.zen_server.auth import AuthContext, authorize
33
+ from zenml.zen_server.exceptions import error_response
34
+ from zenml.zen_server.rbac.endpoint_utils import (
35
+ verify_permissions_and_delete_entity,
36
+ verify_permissions_and_get_entity,
37
+ verify_permissions_and_list_entities,
38
+ verify_permissions_and_update_entity,
39
+ )
40
+ from zenml.zen_server.rbac.models import Action, ResourceType
41
+ from zenml.zen_server.rbac.utils import verify_permission
42
+ from zenml.zen_server.utils import (
43
+ handle_exceptions,
44
+ make_dependable,
45
+ server_config,
46
+ zen_store,
47
+ )
48
+
49
+ router = APIRouter(
50
+ prefix=API + VERSION_1 + RUN_TEMPLATES,
51
+ tags=["run_templates"],
52
+ responses={401: error_response, 403: error_response},
53
+ )
54
+
55
+
56
+ @router.get(
57
+ "",
58
+ responses={401: error_response, 404: error_response, 422: error_response},
59
+ )
60
+ @handle_exceptions
61
+ def list_run_templates(
62
+ filter_model: RunTemplateFilter = Depends(
63
+ make_dependable(RunTemplateFilter)
64
+ ),
65
+ hydrate: bool = False,
66
+ _: AuthContext = Security(authorize),
67
+ ) -> Page[RunTemplateResponse]:
68
+ """Get a page of run templates.
69
+
70
+ Args:
71
+ filter_model: Filter model used for pagination, sorting,
72
+ filtering.
73
+ hydrate: Flag deciding whether to hydrate the output model(s)
74
+ by including metadata fields in the response.
75
+
76
+ Returns:
77
+ Page of run templates.
78
+ """
79
+ return verify_permissions_and_list_entities(
80
+ filter_model=filter_model,
81
+ resource_type=ResourceType.RUN_TEMPLATE,
82
+ list_method=zen_store().list_run_templates,
83
+ hydrate=hydrate,
84
+ )
85
+
86
+
87
+ @router.get(
88
+ "/{template_id}",
89
+ responses={401: error_response, 404: error_response, 422: error_response},
90
+ )
91
+ @handle_exceptions
92
+ def get_run_template(
93
+ template_id: UUID,
94
+ hydrate: bool = True,
95
+ _: AuthContext = Security(authorize),
96
+ ) -> RunTemplateResponse:
97
+ """Get a run template.
98
+
99
+ Args:
100
+ template_id: ID of the run template to get.
101
+ hydrate: Flag deciding whether to hydrate the output model(s)
102
+ by including metadata fields in the response.
103
+
104
+ Returns:
105
+ The run template.
106
+ """
107
+ return verify_permissions_and_get_entity(
108
+ id=template_id,
109
+ get_method=zen_store().get_run_template,
110
+ hydrate=hydrate,
111
+ )
112
+
113
+
114
+ @router.put(
115
+ "/{template_id}",
116
+ responses={401: error_response, 404: error_response, 422: error_response},
117
+ )
118
+ @handle_exceptions
119
+ def update_run_template(
120
+ template_id: UUID,
121
+ update: RunTemplateUpdate,
122
+ _: AuthContext = Security(authorize),
123
+ ) -> RunTemplateResponse:
124
+ """Update a run template.
125
+
126
+ Args:
127
+ template_id: ID of the run template to get.
128
+ update: The updates to apply.
129
+
130
+ Returns:
131
+ The updated run template.
132
+ """
133
+ return verify_permissions_and_update_entity(
134
+ id=template_id,
135
+ update_model=update,
136
+ get_method=zen_store().get_run_template,
137
+ update_method=zen_store().update_run_template,
138
+ )
139
+
140
+
141
+ @router.delete(
142
+ "/{template_id}",
143
+ responses={401: error_response, 404: error_response, 422: error_response},
144
+ )
145
+ @handle_exceptions
146
+ def delete_run_template(
147
+ template_id: UUID,
148
+ _: AuthContext = Security(authorize),
149
+ ) -> None:
150
+ """Delete a run template.
151
+
152
+ Args:
153
+ template_id: ID of the run template to delete.
154
+ """
155
+ verify_permissions_and_delete_entity(
156
+ id=template_id,
157
+ get_method=zen_store().get_run_template,
158
+ delete_method=zen_store().delete_run_template,
159
+ )
160
+
161
+
162
+ if server_config().workload_manager_enabled:
163
+
164
+ @router.post(
165
+ "/{template_id}/runs",
166
+ responses={
167
+ 401: error_response,
168
+ 404: error_response,
169
+ 422: error_response,
170
+ },
171
+ )
172
+ @handle_exceptions
173
+ def create_template_run(
174
+ template_id: UUID,
175
+ background_tasks: BackgroundTasks,
176
+ config: Optional[PipelineRunConfiguration] = None,
177
+ auth_context: AuthContext = Security(authorize),
178
+ ) -> PipelineRunResponse:
179
+ """Run a pipeline from a template.
180
+
181
+ Args:
182
+ template_id: The ID of the template.
183
+ background_tasks: Background tasks.
184
+ config: Configuration for the pipeline run.
185
+ auth_context: Authentication context.
186
+
187
+ Returns:
188
+ The created pipeline run.
189
+ """
190
+ from zenml.zen_server.template_execution.utils import run_template
191
+
192
+ with track_handler(event=AnalyticsEvent.EXECUTED_RUN_TEMPLATE):
193
+ template = verify_permissions_and_get_entity(
194
+ id=template_id,
195
+ get_method=zen_store().get_run_template,
196
+ hydrate=True,
197
+ )
198
+
199
+ verify_permission(
200
+ resource_type=ResourceType.PIPELINE_DEPLOYMENT,
201
+ action=Action.CREATE,
202
+ )
203
+ verify_permission(
204
+ resource_type=ResourceType.PIPELINE_RUN, action=Action.CREATE
205
+ )
206
+
207
+ return run_template(
208
+ template=template,
209
+ auth_context=auth_context,
210
+ background_tasks=background_tasks,
211
+ run_config=config,
212
+ )