Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion docs/cli-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -735,7 +735,7 @@ dw namespace:retention-plan billing --retention=7 --json > plan.json
dw namespace:retention-apply billing --plan-file=plan.json --confirm-retroactive-pruning
```

`namespace:retention-plan` takes the proposed `--retention` days,
`namespace:retention-plan` takes the proposed `--retention` (`-r`) days,
`--retention-mode` (`bounded` or `forever`), or both. A field you leave out
keeps its current value. It shows the current and proposed policy with their
cutoffs and whether the proposal is retroactive, meaning it makes closed runs
Expand Down Expand Up @@ -778,6 +778,10 @@ exits 2:
| `409 retention_plan_revision_mismatch` | The proposal sent is not the one that was planned. | Apply the plan's exact proposal, or plan this one. |
| `422 retention_pruning_confirmation_required` | The proposal is retroactive and `--confirm-retroactive-pruning` was not passed. | Review `newly_eligible`, then repeat with the confirmation. |

After a stale or mismatched apply, the suggested `namespace:retention-plan`
command repeats the proposal you tried to apply: your `--retention` and
`--retention-mode`, or the proposed policy in the `--plan-file`.

With `--json` a refusal keeps the usual error envelope, with `reason`,
`status_code` and the full body in `server_response`.

Expand Down
19 changes: 15 additions & 4 deletions rust/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,21 @@ option definitions and help text), generated from the pinned reference by
read it, so they match 2.x even for commands not ported yet. The harness
also checks `--help` for every catalog command.

Commands with no 2.x equivalent (the `batch:*` commands, cli#60, the task
queue activity dispatch commands, Server #577, and `workflow:update-outcome`,
Server #1131) are added from
`parity/catalog-additions.json` and marked `rust_only`. The harness
Commands with no 2.x equivalent are added from
`parity/catalog-additions.json` and marked `rust_only`:

- `batch:cancel`, `batch:resume`, `batch:show`, `batch:signal` and
`batch:update` (cli#60);
- `namespace:retention-plan` and `namespace:retention-apply` (Server #522);
- `task-queue:activity-dispatch`, `task-queue:pause-activities` and
`task-queue:resume-activities` (Server #577);
- `task-queue:retirement` and `task-queue:retire` (Server #519);
- `workflow:history-archive` and `workflow:history-archive-check`
(Server #520);
- `workflow:update-outcome` (Server #1131);
- `workflow:version-usage` (durable-workflow/.github#220).

`parity/test_parity.py` checks this list against the catalog. The harness
announces them, does not compare their `--help`, and removes only them from
the candidate's listings and completions before comparing, so the rest of
each listing is still checked against 2.x. A namespace header is removed
Expand Down
10 changes: 5 additions & 5 deletions rust/parity/catalog-additions.json
Original file line number Diff line number Diff line change
Expand Up @@ -2564,7 +2564,7 @@
{
"name": "namespace:retention-apply",
"description": "Apply a planned retention policy only while the plan still holds",
"synopsis": "namespace:retention-apply [-s|--server [SERVER]] [--namespace [NAMESPACE]] [--token [TOKEN]] [--tls-verify TLS-VERIFY] [--env ENV] [--output OUTPUT] [--retention RETENTION] [--retention-mode RETENTION-MODE] [--policy-revision POLICY-REVISION] [--plan-revision PLAN-REVISION] [--confirm-retroactive-pruning] [--plan-file PLAN-FILE] [--json] [--] <name>",
"synopsis": "namespace:retention-apply [-s|--server [SERVER]] [--namespace [NAMESPACE]] [--token [TOKEN]] [--tls-verify TLS-VERIFY] [--env ENV] [--output OUTPUT] [-r|--retention RETENTION] [--retention-mode RETENTION-MODE] [--policy-revision POLICY-REVISION] [--plan-revision PLAN-REVISION] [--confirm-retroactive-pruning] [--plan-file PLAN-FILE] [--json] [--] <name>",
"aliases": [],
"hidden": false,
"help": "Apply a retention policy previewed with <info>dw namespace:retention-plan</info>, only\nwhile that plan still holds. Pass the same proposal with the plan's\n<info>--policy-revision</info> and <info>--plan-revision</info>, or pass the plan's saved JSON with\n<info>--plan-file</info>.\n\nA retroactive proposal, one that makes closed runs eligible for pruning\nthat the current policy keeps (fewer days, or bounded replacing forever),\nalso needs <info>--confirm-retroactive-pruning</info>, because pruning is irreversible.\n\nThe request is sent once and never resent. The Server checks the revisions\nand updates the policy in one transaction. A refusal changes nothing, and\ndw prints what to do next and exits 2:\n\n retention_policy_revision_stale (409): the namespace changed after the\n plan. Plan again and apply the new plan's revisions.\n retention_plan_revision_mismatch (409): the proposal is not the one that\n was planned.\n retention_pruning_confirmation_required (422): the proposal is\n retroactive and --confirm-retroactive-pruning was not passed.\n\nThe apply changes only the namespace's policy. Each later retention pass\nprunes the closed, unarchived runs past the cutoff at that pass, which can\ninclude runs that closed or aged after the plan. <info>dw namespace:update</info>\nstill activates a policy at once, without a plan. Needs an admin token and\nnative Server 3.30.0 or later.\n\n<comment>Examples:</comment>\n\n <info>dw namespace:retention-apply billing --retention=7 --policy-revision=sha256:... --plan-revision=sha256:... --confirm-retroactive-pruning</info>\n <info>dw namespace:retention-apply billing --plan-file=plan.json --confirm-retroactive-pruning</info>",
Expand Down Expand Up @@ -2635,7 +2635,7 @@
},
"retention": {
"name": "--retention",
"shortcut": "",
"shortcut": "-r",
"accept_value": true,
"is_value_required": true,
"is_multiple": false,
Expand Down Expand Up @@ -2775,10 +2775,10 @@
{
"name": "namespace:retention-plan",
"description": "Preview a proposed retention policy without applying it",
"synopsis": "namespace:retention-plan [-s|--server [SERVER]] [--namespace [NAMESPACE]] [--token [TOKEN]] [--tls-verify TLS-VERIFY] [--env ENV] [--output OUTPUT] [--retention RETENTION] [--retention-mode RETENTION-MODE] [--scan-limit SCAN-LIMIT] [--hold-scan-limit HOLD-SCAN-LIMIT] [--json] [--] <name>",
"synopsis": "namespace:retention-plan [-s|--server [SERVER]] [--namespace [NAMESPACE]] [--token [TOKEN]] [--tls-verify TLS-VERIFY] [--env ENV] [--output OUTPUT] [-r|--retention RETENTION] [--retention-mode RETENTION-MODE] [--scan-limit SCAN-LIMIT] [--hold-scan-limit HOLD-SCAN-LIMIT] [--json] [--] <name>",
"aliases": [],
"hidden": false,
"help": "Preview what a proposed history-retention policy would do to a namespace,\nwithout applying it. Pass the proposed <info>--retention</info> days, <info>--retention-mode</info>, or\nboth; a field you leave out keeps its current value.\n\nThe plan counts closed, unarchived runs that become eligible for pruning\n(newly_eligible), stop being eligible (no_longer_eligible), stay eligible\nor stay retained, with up to five example runs each, oldest first. It also\ncounts runs a prune would not delete: archived runs past the proposed\ncutoff, runs a forever policy keeps, open runs, and eligible runs held by\nan open abandoned activity, an unsettled external payload reference or an\nactive backup hold. A count that reaches <info>--scan-limit</info> (default 1000, at\nmost 10000) or <info>--hold-scan-limit</info> (default 100, at most 1000) is shown as\n\"at least N\" and makes the plan incomplete.\n\nThe plan writes nothing: it changes no policy, marks no row and prunes\nnothing. It describes one moment. Runs can close, age, be archived or gain\nand lose holds, and the policy can change, before the next retention pass.\n\nApply the plan with <info>dw namespace:retention-apply</info> and its two revisions;\nthe human output prints the exact command. Needs an admin token and native\nServer 3.30.0 or later.\n\n<comment>Examples:</comment>\n\n <info>dw namespace:retention-plan billing --retention=7</info>\n <info>dw namespace:retention-plan archive --retention-mode=forever</info>\n <info>dw namespace:retention-plan billing --retention=7 --json > plan.json</info>",
"help": "Preview what a proposed history-retention policy would do to a namespace,\nwithout applying it. Pass the proposed <info>--retention</info> days, <info>--retention-mode</info>, or\nboth; a field you leave out keeps its current value.\n\nThe plan counts closed, unarchived runs that become eligible for pruning\n(newly_eligible), stop being eligible (no_longer_eligible), stay eligible\nor stay retained, with up to five example runs each, oldest first. It also\ncounts runs a prune would not delete: archived runs past the proposed\ncutoff, runs a forever policy keeps, open runs, and eligible runs held by\nan open abandoned activity, an unsettled external payload reference or an\nactive backup hold. A count that reaches <info>--scan-limit</info> (default 1000, at\nmost 10000) or <info>--hold-scan-limit</info> (default 100, at most 1000) is shown as\n\"at least N\" and makes the plan incomplete.\n\nThe plan writes nothing: it changes no policy, marks no row and prunes\nnothing. It describes one moment. Runs can close, age, be archived or gain\nand lose holds, and the policy can change, before the next retention pass.\n\nApply the plan with <info>dw namespace:retention-apply</info> and its two revisions;\nthe human output prints the exact command. Needs an admin token and native\nServer 3.30.0 or later.\n\n<comment>Examples:</comment>\n\n <info>dw namespace:retention-plan billing --retention=7</info>\n <info>dw namespace:retention-plan billing -r 7 --scan-limit=5000</info>\n <info>dw namespace:retention-plan archive --retention-mode=forever</info>\n <info>dw namespace:retention-plan billing --retention=7 --json > plan.json</info>",
"definition": {
"arguments": {
"name": {
Expand Down Expand Up @@ -2846,7 +2846,7 @@
},
"retention": {
"name": "--retention",
"shortcut": "",
"shortcut": "-r",
"accept_value": true,
"is_value_required": true,
"is_multiple": false,
Expand Down
10 changes: 5 additions & 5 deletions rust/src/catalog.json
Original file line number Diff line number Diff line change
Expand Up @@ -4386,7 +4386,7 @@
{
"name": "namespace:retention-apply",
"description": "Apply a planned retention policy only while the plan still holds",
"synopsis": "namespace:retention-apply [-s|--server [SERVER]] [--namespace [NAMESPACE]] [--token [TOKEN]] [--tls-verify TLS-VERIFY] [--env ENV] [--output OUTPUT] [--retention RETENTION] [--retention-mode RETENTION-MODE] [--policy-revision POLICY-REVISION] [--plan-revision PLAN-REVISION] [--confirm-retroactive-pruning] [--plan-file PLAN-FILE] [--json] [--] <name>",
"synopsis": "namespace:retention-apply [-s|--server [SERVER]] [--namespace [NAMESPACE]] [--token [TOKEN]] [--tls-verify TLS-VERIFY] [--env ENV] [--output OUTPUT] [-r|--retention RETENTION] [--retention-mode RETENTION-MODE] [--policy-revision POLICY-REVISION] [--plan-revision PLAN-REVISION] [--confirm-retroactive-pruning] [--plan-file PLAN-FILE] [--json] [--] <name>",
"aliases": [],
"hidden": false,
"help": "Apply a retention policy previewed with <info>dw namespace:retention-plan</info>, only\nwhile that plan still holds. Pass the same proposal with the plan's\n<info>--policy-revision</info> and <info>--plan-revision</info>, or pass the plan's saved JSON with\n<info>--plan-file</info>.\n\nA retroactive proposal, one that makes closed runs eligible for pruning\nthat the current policy keeps (fewer days, or bounded replacing forever),\nalso needs <info>--confirm-retroactive-pruning</info>, because pruning is irreversible.\n\nThe request is sent once and never resent. The Server checks the revisions\nand updates the policy in one transaction. A refusal changes nothing, and\ndw prints what to do next and exits 2:\n\n retention_policy_revision_stale (409): the namespace changed after the\n plan. Plan again and apply the new plan's revisions.\n retention_plan_revision_mismatch (409): the proposal is not the one that\n was planned.\n retention_pruning_confirmation_required (422): the proposal is\n retroactive and --confirm-retroactive-pruning was not passed.\n\nThe apply changes only the namespace's policy. Each later retention pass\nprunes the closed, unarchived runs past the cutoff at that pass, which can\ninclude runs that closed or aged after the plan. <info>dw namespace:update</info>\nstill activates a policy at once, without a plan. Needs an admin token and\nnative Server 3.30.0 or later.\n\n<comment>Examples:</comment>\n\n <info>dw namespace:retention-apply billing --retention=7 --policy-revision=sha256:... --plan-revision=sha256:... --confirm-retroactive-pruning</info>\n <info>dw namespace:retention-apply billing --plan-file=plan.json --confirm-retroactive-pruning</info>",
Expand Down Expand Up @@ -4457,7 +4457,7 @@
},
"retention": {
"name": "--retention",
"shortcut": "",
"shortcut": "-r",
"accept_value": true,
"is_value_required": true,
"is_multiple": false,
Expand Down Expand Up @@ -4597,10 +4597,10 @@
{
"name": "namespace:retention-plan",
"description": "Preview a proposed retention policy without applying it",
"synopsis": "namespace:retention-plan [-s|--server [SERVER]] [--namespace [NAMESPACE]] [--token [TOKEN]] [--tls-verify TLS-VERIFY] [--env ENV] [--output OUTPUT] [--retention RETENTION] [--retention-mode RETENTION-MODE] [--scan-limit SCAN-LIMIT] [--hold-scan-limit HOLD-SCAN-LIMIT] [--json] [--] <name>",
"synopsis": "namespace:retention-plan [-s|--server [SERVER]] [--namespace [NAMESPACE]] [--token [TOKEN]] [--tls-verify TLS-VERIFY] [--env ENV] [--output OUTPUT] [-r|--retention RETENTION] [--retention-mode RETENTION-MODE] [--scan-limit SCAN-LIMIT] [--hold-scan-limit HOLD-SCAN-LIMIT] [--json] [--] <name>",
"aliases": [],
"hidden": false,
"help": "Preview what a proposed history-retention policy would do to a namespace,\nwithout applying it. Pass the proposed <info>--retention</info> days, <info>--retention-mode</info>, or\nboth; a field you leave out keeps its current value.\n\nThe plan counts closed, unarchived runs that become eligible for pruning\n(newly_eligible), stop being eligible (no_longer_eligible), stay eligible\nor stay retained, with up to five example runs each, oldest first. It also\ncounts runs a prune would not delete: archived runs past the proposed\ncutoff, runs a forever policy keeps, open runs, and eligible runs held by\nan open abandoned activity, an unsettled external payload reference or an\nactive backup hold. A count that reaches <info>--scan-limit</info> (default 1000, at\nmost 10000) or <info>--hold-scan-limit</info> (default 100, at most 1000) is shown as\n\"at least N\" and makes the plan incomplete.\n\nThe plan writes nothing: it changes no policy, marks no row and prunes\nnothing. It describes one moment. Runs can close, age, be archived or gain\nand lose holds, and the policy can change, before the next retention pass.\n\nApply the plan with <info>dw namespace:retention-apply</info> and its two revisions;\nthe human output prints the exact command. Needs an admin token and native\nServer 3.30.0 or later.\n\n<comment>Examples:</comment>\n\n <info>dw namespace:retention-plan billing --retention=7</info>\n <info>dw namespace:retention-plan archive --retention-mode=forever</info>\n <info>dw namespace:retention-plan billing --retention=7 --json > plan.json</info>",
"help": "Preview what a proposed history-retention policy would do to a namespace,\nwithout applying it. Pass the proposed <info>--retention</info> days, <info>--retention-mode</info>, or\nboth; a field you leave out keeps its current value.\n\nThe plan counts closed, unarchived runs that become eligible for pruning\n(newly_eligible), stop being eligible (no_longer_eligible), stay eligible\nor stay retained, with up to five example runs each, oldest first. It also\ncounts runs a prune would not delete: archived runs past the proposed\ncutoff, runs a forever policy keeps, open runs, and eligible runs held by\nan open abandoned activity, an unsettled external payload reference or an\nactive backup hold. A count that reaches <info>--scan-limit</info> (default 1000, at\nmost 10000) or <info>--hold-scan-limit</info> (default 100, at most 1000) is shown as\n\"at least N\" and makes the plan incomplete.\n\nThe plan writes nothing: it changes no policy, marks no row and prunes\nnothing. It describes one moment. Runs can close, age, be archived or gain\nand lose holds, and the policy can change, before the next retention pass.\n\nApply the plan with <info>dw namespace:retention-apply</info> and its two revisions;\nthe human output prints the exact command. Needs an admin token and native\nServer 3.30.0 or later.\n\n<comment>Examples:</comment>\n\n <info>dw namespace:retention-plan billing --retention=7</info>\n <info>dw namespace:retention-plan billing -r 7 --scan-limit=5000</info>\n <info>dw namespace:retention-plan archive --retention-mode=forever</info>\n <info>dw namespace:retention-plan billing --retention=7 --json > plan.json</info>",
"definition": {
"arguments": {
"name": {
Expand Down Expand Up @@ -4668,7 +4668,7 @@
},
"retention": {
"name": "--retention",
"shortcut": "",
"shortcut": "-r",
"accept_value": true,
"is_value_required": true,
"is_multiple": false,
Expand Down
22 changes: 22 additions & 0 deletions rust/src/commands/retention_plan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,28 @@ pub fn apply(context: &Context, input: &Input) -> Result<i32, CliError> {
Ok(0)
}

/// The `dw namespace:retention-plan` command that plans again what a
/// refused apply tried: its `--retention-mode` and `--retention`, or the
/// proposed policy of its `--plan-file`. Planning with no proposal would
/// compare the current policy with itself.
pub fn replan_command(input: &Input) -> String {
let name = input.arg("name").unwrap_or_default();
let mut command = format!("dw namespace:retention-plan {name}");
let attempted = match input.opt_str("plan-file") {
Some(path) => plan_file_body(path, name).ok(),
None => proposal(input).ok(),
};
if let Some(body) = attempted {
if let Some(mode) = body.get("retention_mode").and_then(Value::as_str) {
command.push_str(&format!(" --retention-mode={mode}"));
}
if let Some(days) = body.get("retention_days").and_then(Value::as_i64) {
command.push_str(&format!(" --retention={days}"));
}
}
command
}

/// The proposed `retention_mode` and `retention_days` from the options; a
/// field left out keeps the namespace's current value on the Server.
fn proposal(input: &Input) -> Result<Map<String, Value>, CliError> {
Expand Down
10 changes: 9 additions & 1 deletion rust/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,9 @@ pub struct ErrorContext<'a> {
/// The request a failed `workflow:update` was sending, for its error
/// diagnostics.
pub update: Option<crate::commands::workflow_message::UpdateErrorRequest>,
/// The `namespace:retention-plan` command that plans again what a
/// refused `namespace:retention-apply` tried to apply.
pub retention_replan: Option<String>,
pub server_flag: Option<String>,
pub env_flag: Option<String>,
}
Expand Down Expand Up @@ -299,7 +302,10 @@ fn retention_plan_recommendation(error: &CliError, context: &ErrorContext) -> Op
.as_ref()
.and_then(|body| scalar_text(body.get("namespace")))
.unwrap_or_else(|| "<name>".into());
let plan = format!("dw namespace:retention-plan {namespace}");
let plan = context
.retention_replan
.clone()
.unwrap_or_else(|| format!("dw namespace:retention-plan {namespace}"));
let reason = error.reason();
match (*status, reason) {
(409, Some("retention_policy_revision_stale")) => {
Expand Down Expand Up @@ -779,6 +785,7 @@ mod tests {
request_id: None,
keyed: false,
update: None,
retention_replan: None,
server_flag: None,
env_flag: None,
}
Expand Down Expand Up @@ -867,6 +874,7 @@ mod tests {
request_id: None,
keyed: false,
update: None,
retention_replan: None,
server_flag: Some("http://127.0.0.1:1".into()),
env_flag: None,
};
Expand Down
Loading
Loading