-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#4493]: Functionality to delete backups through platform.
Summary: Adding an endpoint as well as schedulable task to delete old backups after a specified time period. 1) Backup can be deleted through just a stand alone endpoint. 2) For scheduled backups, the user can set an expiry time, and the scheduler will delete the backup after the specified amount of time. The backups now have an assosciated schedule (if created via a schedule) as well as an expiry. The backups only get deleted as long as the universe exists (this is also due to the fact that we don't have a way to see orphaned backups). Test Plan: Created a stand-alone backup and deleted it. Also created a schedule and saw that the old backups got deleted after the set amount of time. Also tested it out on s3, gcp and azure backups. UI mocks: {F14065} {F14066} {F14067} Reviewers: wesley, daniel, sanketh Reviewed By: sanketh Subscribers: andrew, zyu, jenkins-bot, yugaware Differential Revision: https://phabricator.dev.yugabyte.com/D9361
- Loading branch information
Showing
20 changed files
with
475 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
managed/src/main/java/com/yugabyte/yw/commissioner/tasks/DeleteBackup.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* | ||
* Copyright 2019 YugaByte, Inc. and Contributors | ||
* | ||
* Licensed under the Polyform Free Trial License 1.0.0 (the "License"); you | ||
* may not use this file except in compliance with the License. You | ||
* may obtain a copy of the License at | ||
* | ||
* https://github.com/YugaByte/yugabyte-db/blob/master/licenses/POLYFORM-FREE-TRIAL-LICENSE-1.0.0.txt | ||
*/ | ||
|
||
package com.yugabyte.yw.commissioner.tasks; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.yugabyte.yw.commissioner.AbstractTaskBase; | ||
import com.yugabyte.yw.common.ShellProcessHandler; | ||
import com.yugabyte.yw.common.TableManager; | ||
import com.yugabyte.yw.forms.AbstractTaskParams; | ||
import com.yugabyte.yw.forms.BackupTableParams; | ||
import com.yugabyte.yw.forms.ITaskParams; | ||
import com.yugabyte.yw.models.Backup; | ||
import com.yugabyte.yw.models.Universe; | ||
import play.api.Play; | ||
import play.libs.Json; | ||
|
||
import java.util.UUID; | ||
|
||
|
||
public class DeleteBackup extends AbstractTaskBase { | ||
|
||
public static class Params extends AbstractTaskParams { | ||
public UUID customerUUID; | ||
public UUID backupUUID; | ||
} | ||
|
||
public Params params() { | ||
return (Params)taskParams; | ||
} | ||
private TableManager tableManager; | ||
|
||
@Override | ||
public void initialize(ITaskParams params) { | ||
super.initialize(params); | ||
tableManager = Play.current().injector().instanceOf(TableManager.class); | ||
} | ||
|
||
@Override | ||
public void run() { | ||
try { | ||
Backup backup = Backup.get(params().customerUUID, params().backupUUID); | ||
if (backup.state != Backup.BackupState.Completed) { | ||
LOG.error("Cannot delete backup in any other state other than completed."); | ||
throw new RuntimeException("Backup cannot be deleted"); | ||
} | ||
backup.transitionState(Backup.BackupState.Deleted); | ||
BackupTableParams backupParams = Json.fromJson(backup.backupInfo, BackupTableParams.class); | ||
backupParams.actionType = BackupTableParams.ActionType.DELETE; | ||
ShellProcessHandler.ShellResponse response = tableManager.deleteBackup(backupParams); | ||
JsonNode jsonNode = Json.parse(response.message); | ||
if (response.code != 0 || jsonNode.has("error")) { | ||
LOG.error("Delete Backup failed. Response code={}, hasError={}.", | ||
response.code, jsonNode.has("error")); | ||
throw new RuntimeException(response.message); | ||
} else { | ||
LOG.info("[" + getName() + "] STDOUT: " + response.message); | ||
} | ||
} catch (Exception e) { | ||
LOG.error("Errored out with: " + e); | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.