Skip to content

Commit d213309

Browse files
authored
[Durabletask] Addition of Retention Policy Commands (#8672)
* Adding custom command to list orchestrations Signed-off-by: Ryan Lettieri <ryanLettieri@microsoft.com> * Addition of retention policy commands Signed-off-by: Ryan Lettieri <ryanLettieri@microsoft.com> * Revert "Adding custom command to list orchestrations" This reverts commit bcecfb3. * Reverting earlier commit and enforcing one retention period Signed-off-by: Ryan Lettieri <ryanLettieri@microsoft.com> * Fixing some help text and removing retention-policies from help properties Signed-off-by: Ryan Lettieri <ryanLettieri@microsoft.com> * Linting Signed-off-by: Ryan Lettieri <ryanLettieri@microsoft.com> * Linting again Signed-off-by: Ryan Lettieri <ryanLettieri@microsoft.com> * Removing retention-policies from help Signed-off-by: Ryan Lettieri <ryanLettieri@microsoft.com> * Removing retention-policies from help on parent variable Signed-off-by: Ryan Lettieri <ryanLettieri@microsoft.com> * Removing retention-policies from help on parent variable again Signed-off-by: Ryan Lettieri <ryanLettieri@microsoft.com> --------- Signed-off-by: Ryan Lettieri <ryanLettieri@microsoft.com>
1 parent bf191ed commit d213309

11 files changed

Lines changed: 1465 additions & 6 deletions

File tree

src/durabletask/HISTORY.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
Release History
44
===============
55

6+
1.0.0b4
7+
+++++
8+
* Adding various retention-policy commands.
9+
610
1.0.0b3
711
+++++
812
* Updating the help outputs for various taskhub and scheduler commands
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# --------------------------------------------------------------------------------------------
2+
# Copyright (c) Microsoft Corporation. All rights reserved.
3+
# Licensed under the MIT License. See License.txt in the project root for license information.
4+
#
5+
# Code generated by aaz-dev-tools
6+
# --------------------------------------------------------------------------------------------
7+
8+
# pylint: skip-file
9+
# flake8: noqa
10+
11+
from azure.cli.core.aaz import *
12+
13+
14+
@register_command_group(
15+
"durabletask retention-policy",
16+
)
17+
class __CMDGroup(AAZCommandGroup):
18+
"""Manage Retention Policy
19+
"""
20+
pass
21+
22+
23+
__all__ = ["__CMDGroup"]
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# --------------------------------------------------------------------------------------------
2+
# Copyright (c) Microsoft Corporation. All rights reserved.
3+
# Licensed under the MIT License. See License.txt in the project root for license information.
4+
#
5+
# Code generated by aaz-dev-tools
6+
# --------------------------------------------------------------------------------------------
7+
8+
# pylint: skip-file
9+
# flake8: noqa
10+
11+
from .__cmd_group import *
12+
from ._create import *
13+
from ._delete import *
14+
from ._show import *
15+
from ._update import *
16+
from ._wait import *
Lines changed: 286 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,286 @@
1+
# --------------------------------------------------------------------------------------------
2+
# Copyright (c) Microsoft Corporation. All rights reserved.
3+
# Licensed under the MIT License. See License.txt in the project root for license information.
4+
#
5+
# Code generated by aaz-dev-tools
6+
# --------------------------------------------------------------------------------------------
7+
8+
# pylint: skip-file
9+
# flake8: noqa
10+
11+
from azure.cli.core.aaz import *
12+
13+
14+
@register_command(
15+
"durabletask retention-policy create",
16+
)
17+
class Create(AAZCommand):
18+
"""Create a Retention Policy on a Durabletask Scheduler.
19+
20+
:example: Create a new retention policy for a scheduler with a default retention period of 30 days.
21+
az durabletask retention-policy create -g "example-rg" --scheduler-name "example-scheduler" --retention-days 30
22+
"""
23+
24+
_aaz_info = {
25+
"version": "2025-04-01-preview",
26+
"resources": [
27+
["mgmt-plane", "/subscriptions/{}/resourcegroups/{}/providers/microsoft.durabletask/schedulers/{}/retentionpolicies/default", "2025-04-01-preview"],
28+
]
29+
}
30+
31+
AZ_SUPPORT_NO_WAIT = True
32+
33+
def _handler(self, command_args):
34+
super()._handler(command_args)
35+
return self.build_lro_poller(self._execute_operations, self._output)
36+
37+
_args_schema = None
38+
39+
@classmethod
40+
def _build_arguments_schema(cls, *args, **kwargs):
41+
if cls._args_schema is not None:
42+
return cls._args_schema
43+
cls._args_schema = super()._build_arguments_schema(*args, **kwargs)
44+
45+
# define Arg Group ""
46+
47+
_args_schema = cls._args_schema
48+
_args_schema.resource_group = AAZResourceGroupNameArg(
49+
required=True,
50+
)
51+
_args_schema.scheduler_name = AAZStrArg(
52+
options=["--scheduler-name"],
53+
help="The name of the Scheduler",
54+
required=True,
55+
fmt=AAZStrArgFormat(
56+
pattern="^[a-zA-Z0-9-]{3,64}$",
57+
),
58+
)
59+
60+
# define Arg Group "Properties"
61+
62+
_args_schema = cls._args_schema
63+
_args_schema.retention_policies = AAZListArg()
64+
65+
retention_policies = cls._args_schema.retention_policies
66+
retention_policies.Element = AAZObjectArg()
67+
68+
_element = cls._args_schema.retention_policies.Element
69+
_element.orchestration_state = AAZStrArg(
70+
options=["orchestration-state"],
71+
help="The orchestration state to which this policy applies. If omitted, the policy applies to all purgeable orchestration states.",
72+
enum={"Canceled": "Canceled", "Completed": "Completed", "Failed": "Failed", "Terminated": "Terminated"},
73+
)
74+
_element.retention_period_in_days = AAZIntArg(
75+
options=["retention-period-in-days"],
76+
help="The retention period in days after which the orchestration will be purged automatically",
77+
required=True,
78+
)
79+
80+
return cls._args_schema
81+
82+
def _execute_operations(self):
83+
self.pre_operations()
84+
yield self.RetentionPoliciesCreateOrReplace(ctx=self.ctx)()
85+
self.post_operations()
86+
87+
@register_callback
88+
def pre_operations(self):
89+
pass
90+
91+
@register_callback
92+
def post_operations(self):
93+
pass
94+
95+
def _output(self, *args, **kwargs):
96+
result = self.deserialize_output(self.ctx.vars.instance, client_flatten=True)
97+
return result
98+
99+
class RetentionPoliciesCreateOrReplace(AAZHttpOperation):
100+
CLIENT_TYPE = "MgmtClient"
101+
102+
def __call__(self, *args, **kwargs):
103+
request = self.make_request()
104+
session = self.client.send_request(request=request, stream=False, **kwargs)
105+
if session.http_response.status_code in [202]:
106+
return self.client.build_lro_polling(
107+
self.ctx.args.no_wait,
108+
session,
109+
self.on_200_201,
110+
self.on_error,
111+
lro_options={"final-state-via": "azure-async-operation"},
112+
path_format_arguments=self.url_parameters,
113+
)
114+
if session.http_response.status_code in [200, 201]:
115+
return self.client.build_lro_polling(
116+
self.ctx.args.no_wait,
117+
session,
118+
self.on_200_201,
119+
self.on_error,
120+
lro_options={"final-state-via": "azure-async-operation"},
121+
path_format_arguments=self.url_parameters,
122+
)
123+
124+
return self.on_error(session.http_response)
125+
126+
@property
127+
def url(self):
128+
return self.client.format_url(
129+
"/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DurableTask/schedulers/{schedulerName}/retentionPolicies/default",
130+
**self.url_parameters
131+
)
132+
133+
@property
134+
def method(self):
135+
return "PUT"
136+
137+
@property
138+
def error_format(self):
139+
return "MgmtErrorFormat"
140+
141+
@property
142+
def url_parameters(self):
143+
parameters = {
144+
**self.serialize_url_param(
145+
"resourceGroupName", self.ctx.args.resource_group,
146+
required=True,
147+
),
148+
**self.serialize_url_param(
149+
"schedulerName", self.ctx.args.scheduler_name,
150+
required=True,
151+
),
152+
**self.serialize_url_param(
153+
"subscriptionId", self.ctx.subscription_id,
154+
required=True,
155+
),
156+
}
157+
return parameters
158+
159+
@property
160+
def query_parameters(self):
161+
parameters = {
162+
**self.serialize_query_param(
163+
"api-version", "2025-04-01-preview",
164+
required=True,
165+
),
166+
}
167+
return parameters
168+
169+
@property
170+
def header_parameters(self):
171+
parameters = {
172+
**self.serialize_header_param(
173+
"Content-Type", "application/json",
174+
),
175+
**self.serialize_header_param(
176+
"Accept", "application/json",
177+
),
178+
}
179+
return parameters
180+
181+
@property
182+
def content(self):
183+
_content_value, _builder = self.new_content_builder(
184+
self.ctx.args,
185+
typ=AAZObjectType,
186+
typ_kwargs={"flags": {"required": True, "client_flatten": True}}
187+
)
188+
_builder.set_prop("properties", AAZObjectType)
189+
190+
properties = _builder.get(".properties")
191+
if properties is not None:
192+
properties.set_prop("retentionPolicies", AAZListType, ".retention_policies")
193+
194+
retention_policies = _builder.get(".properties.retentionPolicies")
195+
if retention_policies is not None:
196+
retention_policies.set_elements(AAZObjectType, ".")
197+
198+
_elements = _builder.get(".properties.retentionPolicies[]")
199+
if _elements is not None:
200+
_elements.set_prop("orchestrationState", AAZStrType, ".orchestration_state")
201+
_elements.set_prop("retentionPeriodInDays", AAZIntType, ".retention_period_in_days", typ_kwargs={"flags": {"required": True}})
202+
203+
return self.serialize_content(_content_value)
204+
205+
def on_200_201(self, session):
206+
data = self.deserialize_http_content(session)
207+
self.ctx.set_var(
208+
"instance",
209+
data,
210+
schema_builder=self._build_schema_on_200_201
211+
)
212+
213+
_schema_on_200_201 = None
214+
215+
@classmethod
216+
def _build_schema_on_200_201(cls):
217+
if cls._schema_on_200_201 is not None:
218+
return cls._schema_on_200_201
219+
220+
cls._schema_on_200_201 = AAZObjectType()
221+
222+
_schema_on_200_201 = cls._schema_on_200_201
223+
_schema_on_200_201.id = AAZStrType(
224+
flags={"read_only": True},
225+
)
226+
_schema_on_200_201.name = AAZStrType(
227+
flags={"read_only": True},
228+
)
229+
_schema_on_200_201.properties = AAZObjectType()
230+
_schema_on_200_201.system_data = AAZObjectType(
231+
serialized_name="systemData",
232+
flags={"read_only": True},
233+
)
234+
_schema_on_200_201.type = AAZStrType(
235+
flags={"read_only": True},
236+
)
237+
238+
properties = cls._schema_on_200_201.properties
239+
properties.provisioning_state = AAZStrType(
240+
serialized_name="provisioningState",
241+
flags={"read_only": True},
242+
)
243+
properties.retention_policies = AAZListType(
244+
serialized_name="retentionPolicies",
245+
)
246+
247+
retention_policies = cls._schema_on_200_201.properties.retention_policies
248+
retention_policies.Element = AAZObjectType()
249+
250+
_element = cls._schema_on_200_201.properties.retention_policies.Element
251+
_element.orchestration_state = AAZStrType(
252+
serialized_name="orchestrationState",
253+
)
254+
_element.retention_period_in_days = AAZIntType(
255+
serialized_name="retentionPeriodInDays",
256+
flags={"required": True},
257+
)
258+
259+
system_data = cls._schema_on_200_201.system_data
260+
system_data.created_at = AAZStrType(
261+
serialized_name="createdAt",
262+
)
263+
system_data.created_by = AAZStrType(
264+
serialized_name="createdBy",
265+
)
266+
system_data.created_by_type = AAZStrType(
267+
serialized_name="createdByType",
268+
)
269+
system_data.last_modified_at = AAZStrType(
270+
serialized_name="lastModifiedAt",
271+
)
272+
system_data.last_modified_by = AAZStrType(
273+
serialized_name="lastModifiedBy",
274+
)
275+
system_data.last_modified_by_type = AAZStrType(
276+
serialized_name="lastModifiedByType",
277+
)
278+
279+
return cls._schema_on_200_201
280+
281+
282+
class _CreateHelper:
283+
"""Helper class for Create"""
284+
285+
286+
__all__ = ["Create"]

0 commit comments

Comments
 (0)