Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add cloud group backup API to SDK #1130

Merged
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
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.58.0 - Tech Preview (6/5/2019)

* Add cloud group-backup API

### v0.57.0 - Tech Preview (6/4/2019)

* Added new param credential API to control path style access to s3
Expand Down
2,430 changes: 1,305 additions & 1,125 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 @@ -1761,6 +1761,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 @@ -2786,6 +2799,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 @@ -3300,7 +3340,7 @@ message SdkVersion {
// SDK version major value of this specification
Major = 0;
// SDK version minor value of this specification
Minor = 57;
Minor = 58;
// 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