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
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
---
setup:
- do:
cluster.health:
wait_for_status: yellow

---
"Test Basic Policy CRUD":
- do:
catch: missing
slm.get_lifecycle:
policy_id: "daily-snapshots"

- do:
catch: missing
slm.delete_lifecycle:
policy_id: "daily-snapshots"

- do:
snapshot.create_repository:
repository: repo
body:
type: fs
settings:
location: "my-snaps"

- do:
slm.put_lifecycle:
policy_id: "daily-snapshots"
body: |
{
"schedule": "0 1 2 3 4 ?",
"name": "<production-snap-{now/d}>",
"repository": "repo",
"config": {
"indices": ["foo-*", "important"],
"ignore_unavailable": false,
"include_global_state": false
},
"retention": {
"expire_after": "30d",
"min_count": 1,
"max_count": 50
}
}

- do:
slm.get_lifecycle:
policy_id: "daily-snapshots"
- match: { daily-snapshots.version: 1 }
- match: { daily-snapshots.policy.name: "<production-snap-{now/d}>" }
- is_true: daily-snapshots.next_execution_millis
- is_true: daily-snapshots.stats
- match: { daily-snapshots.policy.schedule: "0 1 2 3 4 ?" }

- do:
slm.put_lifecycle:
policy_id: "daily-snapshots"
body: |
{
"schedule": "1 1 1 1 1 ?",
"name": "<production-snap-{now/d}>",
"repository": "repo",
"config": {
"indices": ["foo-*", "important"],
"ignore_unavailable": false,
"include_global_state": false
},
"retention": {
"expire_after": "30d",
"min_count": 1,
"max_count": 50
}
}

- do:
catch: missing
slm.get_lifecycle:
policy_id: "doesnt-exist"

- do:
slm.get_lifecycle:
policy_id: "daily-snapshots"
- match: { daily-snapshots.version: 2 }
- match: { daily-snapshots.policy.schedule: "1 1 1 1 1 ?" }
- is_true: daily-snapshots.next_execution_millis
- is_true: daily-snapshots.stats
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.elasticsearch.ResourceNotFoundException;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.support.ActionFilters;
import org.elasticsearch.action.support.master.TransportMasterNodeAction;
Expand Down Expand Up @@ -65,7 +66,13 @@ protected void masterOperation(final Task task, final GetSnapshotLifecycleAction
final ActionListener<GetSnapshotLifecycleAction.Response> listener) {
SnapshotLifecycleMetadata snapMeta = state.metaData().custom(SnapshotLifecycleMetadata.TYPE);
if (snapMeta == null) {
listener.onResponse(new GetSnapshotLifecycleAction.Response(Collections.emptyList()));
if (request.getLifecycleIds().length == 0) {
listener.onResponse(new GetSnapshotLifecycleAction.Response(Collections.emptyList()));
} else {
listener.onFailure(new ResourceNotFoundException(
"snapshot lifecycle policy or policies {} not found, no policies are configured",
Arrays.toString(request.getLifecycleIds())));
}
} else {
final Map<String, SnapshotLifecyclePolicyItem.SnapshotInProgress> inProgress;
SnapshotsInProgress sip = state.custom(SnapshotsInProgress.TYPE);
Expand Down Expand Up @@ -100,7 +107,16 @@ protected void masterOperation(final Task task, final GetSnapshotLifecycleAction
new SnapshotLifecyclePolicyItem(policyMeta, inProgress.get(policyMeta.getPolicy().getId()),
slmStats.getMetrics().get(policyMeta.getPolicy().getId())))
.collect(Collectors.toList());
listener.onResponse(new GetSnapshotLifecycleAction.Response(lifecycles));
if (lifecycles.size() == 0) {
if (request.getLifecycleIds().length == 0) {
listener.onResponse(new GetSnapshotLifecycleAction.Response(Collections.emptyList()));
} else {
listener.onFailure(new ResourceNotFoundException("snapshot lifecycle policy or policies {} not found",
Arrays.toString(request.getLifecycleIds())));
}
} else {
listener.onResponse(new GetSnapshotLifecycleAction.Response(lifecycles));
}
}
}

Expand Down