Skip to content

Commit

Permalink
Add cloud group backup API
Browse files Browse the repository at this point in the history
  • Loading branch information
ggriffiths committed May 30, 2019
1 parent 3d132c4 commit 180963f
Show file tree
Hide file tree
Showing 10 changed files with 1,614 additions and 1,145 deletions.
4 changes: 4 additions & 0 deletions SDK_CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Releases

### v0.56.0 - Tech Preview (5/29/2019)

* Add cloud group-backup API

### v0.55.0 - Tech Preview (5/7/2019)

* Additions to cloudbackup enumerate filters.
Expand Down
2,420 changes: 1,300 additions & 1,120 deletions api/api.pb.go

Large diffs are not rendered by default.

46 changes: 46 additions & 0 deletions api/api.pb.gw.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 41 additions & 1 deletion api/api.proto
Original file line number Diff line number Diff line change
Expand Up @@ -1750,6 +1750,19 @@ service OpenStorageCloudBackup {
};
}

// Creates a group backup request for a specified group. Use
// OpenStorageCloudBackup.Status() to get the current status of the
// backup request.
//
// This will only backup volumes which the user has read_access to.
rpc GroupCreate(SdkCloudBackupGroupCreateRequest)
returns (SdkCloudBackupGroupCreateResponse) {
option(google.api.http) = {
post: "/v1/cloudbackups/group"
body: "*"
};
}

// Restore creates a new volume from a backup id. The newly created volume
// has an ha_level (number of replicas) of only 1. To increase the number of
// replicas, use OpenStorageVolume.Set() to change the ha_level.
Expand Down Expand Up @@ -2771,6 +2784,33 @@ message SdkCloudBackupCreateResponse {
string task_id = 1;
}

// Defines a request to create a group backup of a group to the cloud
message SdkCloudBackupGroupCreateRequest {
// GroupID of the volume for which cloudbackup is requested
string group_id = 1;
// VolumeIds are a list of volume IDs to use for the backup request.
// If multiple of GroupID, Labels or VolumeIDs are specified, volumes matching
// all of them are backed uup
repeated string volume_ids = 2;
// Credential id refers to the cloud credentials needed to backup
string credential_id = 3;
// Full indicates if full backup is desired even though incremental is possible
bool full = 4;
// Labels are list of key value pairs to tag the cloud backup. These labels
// are stored in the metadata associated with the backup.
map<string, string> labels = 5;
}

// Empty response
message SdkCloudBackupGroupCreateResponse {
// ID for this group of backups
string group_cloud_backup_id = 1;

// TaskIds of the tasks performing the group backup
repeated string task_ids = 2;
}


// Defines a request to restore a volume from an existing backup stored by
// a cloud provider
message SdkCloudBackupRestoreRequest {
Expand Down Expand Up @@ -3285,7 +3325,7 @@ message SdkVersion {
// SDK version major value of this specification
Major = 0;
// SDK version minor value of this specification
Minor = 55;
Minor = 56;
// SDK version patch value of this specification
Patch = 0;
}
Expand Down
33 changes: 28 additions & 5 deletions api/server/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,26 +61,49 @@ func (vd *volAPI) cloudBackupCreate(w http.ResponseWriter, r *http.Request) {

func (vd *volAPI) cloudBackupGroupCreate(w http.ResponseWriter, r *http.Request) {
backupGroupReq := &api.CloudBackupGroupCreateRequest{}
var backupGroupResp api.CloudBackupGroupCreateResponse
method := "cloudBackupGroupCreate"

if err := json.NewDecoder(r.Body).Decode(backupGroupReq); err != nil {
vd.sendError(vd.name, method, w, err.Error(), http.StatusBadRequest)
return
}

d, err := vd.getVolDriver(r)
// Get context with auth token
ctx, err := vd.annotateContext(r)
if err != nil {
notFound(w, r)
vd.sendError(vd.name, method, w, err.Error(), http.StatusBadRequest)
return
}

createResp, err := d.CloudBackupGroupCreate(backupGroupReq)
// Get gRPC connection
conn, err := vd.getConn()
if err != nil {
vd.sendError(method, backupGroupReq.GroupID, w, err.Error(), http.StatusInternalServerError)
vd.sendError(vd.name, method, w, err.Error(), http.StatusInternalServerError)
return
}

json.NewEncoder(w).Encode(createResp)
volumes := api.NewOpenStorageCloudBackupClient(conn)
groupCreateResp, err := volumes.GroupCreate(ctx, &api.SdkCloudBackupGroupCreateRequest{
GroupId: backupGroupReq.GroupID,
VolumeIds: backupGroupReq.VolumeIDs,
CredentialId: backupGroupReq.CredentialUUID,
Full: backupGroupReq.Full,
Labels: backupGroupReq.Labels,
})
if err != nil {
if serverError, ok := status.FromError(err); ok {
if serverError.Code() == codes.AlreadyExists {
w.WriteHeader(http.StatusConflict)
return
}
}
vd.sendError(method, backupGroupReq.GroupID, w, err.Error(), http.StatusInternalServerError)
return
}
backupGroupResp.GroupCloudBackupID = groupCreateResp.GroupCloudBackupId
backupGroupResp.Names = groupCreateResp.TaskIds
json.NewEncoder(w).Encode(&backupGroupResp)
}

func (vd *volAPI) cloudBackupRestore(w http.ResponseWriter, r *http.Request) {
Expand Down
3 changes: 1 addition & 2 deletions api/server/backup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,7 @@ func TestClientBackupCreateFailed(t *testing.T) {
assert.Error(t, err)
}

/*
func TestClientGroupBackup(t *testing.T) {
/*func TestClientGroupBackup(t *testing.T) {
ts, testVolDriver := testRestServer(t)
defer ts.Close()
defer testVolDriver.Stop()
Expand Down
84 changes: 83 additions & 1 deletion api/server/sdk/api/api.swagger.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 180963f

Please sign in to comment.