Skip to content

Commit

Permalink
[DPE-2345][DPE-2451] Add restore action
Browse files Browse the repository at this point in the history
Extends #135 and
adds restore support.

This PR will override any conflicting index in case of restore. It also updates
list backups action to be shown in table format by default.

It adds 3x extra integration tests:
1) Snapshot / restore in the same cluster
2) Snapshot / remove / readd relation / restore
3) Snapshot / redeploy cluster / restore
  • Loading branch information
phvalguima authored Dec 14, 2023
1 parent f721484 commit a38e774
Show file tree
Hide file tree
Showing 5 changed files with 462 additions and 64 deletions.
18 changes: 18 additions & 0 deletions actions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,21 @@ create-backup:

list-backups:
description: List available backup_ids in the S3 bucket and path provided by the S3 integrator charm.
params:
output:
type: string
default: "table"
description: |
Format which the data should be returned. Possible values: table, json.
The json format will bring more details, such as shard status, indices name, etc.
restore:
description: Restore a database backup.
S3 credentials are retrieved from a relation with the S3 integrator charm.
params:
backup-id:
type: integer
description: |
A backup-id to identify the backup to restore. Format: <backup-id, int>
required:
- backup-id
18 changes: 18 additions & 0 deletions lib/charms/opensearch/v0/helper_cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,24 @@ def shards(
"""Get all shards of all indexes in the cluster."""
return opensearch.request("GET", "/_cat/shards", host=host, alt_hosts=alt_hosts)

@staticmethod
@retry(
stop=stop_after_attempt(3),
wait=wait_exponential(multiplier=1, min=2, max=10),
reraise=True,
)
def indices(
opensearch: OpenSearchDistribution,
host: Optional[str] = None,
alt_hosts: Optional[List[str]] = None,
) -> List[Dict[str, str]]:
"""Get all shards of all indexes in the cluster."""
idx = opensearch.request("GET", "/_cat/indices", host=host, alt_hosts=alt_hosts)
idx = {}
for index in opensearch.request("GET", "/_cat/indices", host=host, alt_hosts=alt_hosts):
idx[index["index"]] = {"health": index["health"], "status": index["status"]}
return idx

@staticmethod
def shards_by_state(
opensearch: OpenSearchDistribution,
Expand Down
Loading

0 comments on commit a38e774

Please sign in to comment.