Skip to content

Commit f120dc0

Browse files
authored
Erase volume (#31)
* typos and other minor fixes * Add Erase volume methods .. and deprecate delete volume methods * Fix type in doc * Remove force erase flag 2.x does not support force flag and only 3.x supports this flag. To preserve backward compatibility of the api, use 2.x request against 3.x for now. Once the 2.x is phased out, add force flag. Remove force erase flag 2.x does not support force flag and only 3.x supports this flag. To preserve backward compatibility of the api, use 2.x request against 3.x for now. Once the 2.x is phased out, add force flag. * eraseVolume: Add 3.x and 2.x erase volume methods Adds two different erase volume methods - one for 3.x and other for 2.x. On 2.x, Quobyte decides when to schedule the erase volume task (typically with little delay after api call). On 3.x, user can request immediate erase volume task scheduling or let Quobyte decide.
1 parent 4d1ae5d commit f120dc0

5 files changed

Lines changed: 46 additions & 20 deletions

File tree

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func main() {
3535
Name: "MyVolume",
3636
TenantId: "32edb36d-badc-affe-b44a-4ab749af4d9a",
3737
RootUserId: "root",
38-
RootGroupId: "root",
38+
RootGroupId: "root",
3939
ConfigurationName: "BASE",
4040
Label: []*quobyte_api.Label{
4141
{Name: "label1", Value: "value1"},
@@ -48,8 +48,8 @@ func main() {
4848
log.Fatalf("Error: %v", err)
4949
}
5050

51-
capactiy := int64(1024 * 1024 * 1024)
52-
err = client.SetVolumeQuota(response.VolumeUuid, capactiy)
51+
capacity := int64(1024 * 1024 * 1024)
52+
err = client.SetVolumeQuota(response.VolumeUuid, capacity)
5353
if err != nil {
5454
log.Fatalf("Error: %v", err)
5555
}

docs/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
directory. (It seems go mod ignores .go file that is not placed in declared package directory!!)
1010
* For local testing of edited module,
1111
* Create a standalone project with the `testing or main.go` and `go mod init` inside the project root.
12-
The `go mod init` fetches the depedencies required by code.
12+
The `go mod init` fetches the dependencies required by code.
1313
* Replace Quobyte API with updated API `go mod edit -replace github.com/quobyte/api=</path/to/local/quobyte/api>`
1414
* Publishing change must always have highest minor version of all the published tags (even if the tag is deleted,
1515
the new version must have the higher version than deleted tag).

quobyte/quobyte.go

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ func (client *QuobyteClient) GetVolumeUUID(volume, tenant string) (string, error
7878
return volume, nil
7979
}
8080

81-
// GetTenantUUID resolves the tenatnUUID for the given name
81+
// GetTenantUUID resolves the tenantUUID for the given name
8282
// This method should be used when it is not clear if the given string is Tenant UUID or Name.
8383
func (client *QuobyteClient) GetTenantUUID(tenant string) (string, error) {
8484
if len(tenant) != 0 && !IsValidUUID(tenant) {
@@ -105,6 +105,7 @@ func (client *QuobyteClient) ResolveVolumeNameToUUID(volumeName, tenant string)
105105
return response.VolumeUuid, nil
106106
}
107107

108+
// Deprecated: Use Erase variant of the method instead.
108109
// DeleteVolumeByResolvingNamesToUUID deletes the volume by resolving the volume name and tenant name to
109110
// respective UUID if required.
110111
// This method should be used if the given volume, tenant information is name or UUID.
@@ -118,6 +119,7 @@ func (client *QuobyteClient) DeleteVolumeByResolvingNamesToUUID(volume, tenant s
118119
return err
119120
}
120121

122+
// Deprecated: Use Erase variant of the method instead.
121123
// DeleteVolumeByName deletes a volume by a given name
122124
func (client *QuobyteClient) DeleteVolumeByName(volumeName, tenant string) error {
123125
uuid, err := client.ResolveVolumeNameToUUID(volumeName, tenant)
@@ -129,19 +131,43 @@ func (client *QuobyteClient) DeleteVolumeByName(volumeName, tenant string) error
129131
return err
130132
}
131133

134+
// EraseVolumeByResolvingNamesToUUID Erases the volume by resolving the volume name and tenant name
135+
// to respective UUID if required. (Use only against Quobyte 3.x)
136+
func (client *QuobyteClient) EraseVolumeByResolvingNamesToUUID(volume, tenant string, force bool) error {
137+
volumeUUID, err := client.GetVolumeUUID(volume, tenant)
138+
if err != nil {
139+
return err
140+
}
141+
142+
_, err = client.EraseVolume(&EraseVolumeRequest{VolumeUuid: volumeUUID, Force: force})
143+
return err
144+
}
145+
146+
// EraseVolumeByResolvingNamesToUUID_2X Erases the volume by resolving the volume name and tenant name
147+
// to respective UUID if required. (Use against Quobyte 2.x or 3.x)
148+
func (client *QuobyteClient) EraseVolumeByResolvingNamesToUUID_2X(volume, tenant string) error {
149+
volumeUUID, err := client.GetVolumeUUID(volume, tenant)
150+
if err != nil {
151+
return err
152+
}
153+
154+
_, err = client.EraseVolume(&EraseVolumeRequest{VolumeUuid: volumeUUID})
155+
return err
156+
}
157+
132158
// SetVolumeQuota sets a Quota to the specified Volume
133159
func (client *QuobyteClient) SetVolumeQuota(volumeUUID string, quotaSize int64) error {
134160
request := &SetQuotaRequest{
135161
Quotas: []*Quota{
136-
&Quota{
162+
{
137163
Consumer: []*ConsumingEntity{
138-
&ConsumingEntity{
164+
{
139165
Type: ConsumingEntity_Type_VOLUME,
140166
Identifier: volumeUUID,
141167
},
142168
},
143169
Limits: []*Resource{
144-
&Resource{
170+
{
145171
Type: Resource_Type_LOGICAL_DISK_SPACE,
146172
Value: quotaSize,
147173
},

quobyte/rpc_client.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515
)
1616

1717
const (
18-
emptyResponse string = "Empty result and no error occured"
18+
emptyResponse string = "Empty result and no error occurred"
1919
)
2020

2121
var mux sync.Mutex
@@ -136,7 +136,7 @@ func (client QuobyteClient) sendRequest(method string, request interface{}, resp
136136
if ok {
137137
return errors.New("Unable to authenticate with Quobyte API service")
138138
}
139-
// Session is not valid anymore (service restart, sesssion invalidated etc)!!
139+
// Session is not valid anymore (service restart, session invalidated etc)!!
140140
// resend basic auth and get new cookies
141141
// invalidate session cookies
142142
cookieJar := client.client.Jar

quobyte/rpc_client_test.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"testing"
1010
)
1111

12-
func TestSuccesfullEncodeRequest(t *testing.T) {
12+
func TestSuccessfullEncodeRequest(t *testing.T) {
1313
req := &CreateVolumeRequest{
1414
RootUserId: "root",
1515
RootGroupId: "root",
@@ -49,7 +49,7 @@ func TestSuccesfullEncodeRequest(t *testing.T) {
4949
}
5050
}
5151

52-
func TestSuccesfullDecodeResponse(t *testing.T) {
52+
func TestSuccessfullDecodeResponse(t *testing.T) {
5353
var byt json.RawMessage
5454
byt, _ = json.Marshal(map[string]interface{}{"volume_uuid": "1234"})
5555

@@ -74,7 +74,7 @@ func TestSuccesfullDecodeResponse(t *testing.T) {
7474
}
7575
}
7676

77-
func TestSuccesfullDecodeResponseWithErrorMessage(t *testing.T) {
77+
func TestSuccessfullDecodeResponseWithErrorMessage(t *testing.T) {
7878
errorMessage := "ERROR_CODE_INVALID_REQUEST"
7979
var byt json.RawMessage
8080
byt, _ = json.Marshal(&rpcError{
@@ -93,7 +93,7 @@ func TestSuccesfullDecodeResponseWithErrorMessage(t *testing.T) {
9393
var resp CreateVolumeResponse
9494
err := decodeResponse(bytes.NewReader(res), &resp)
9595
if err == nil {
96-
t.Log("No error occured")
96+
t.Log("No error occurred")
9797
t.Fail()
9898
}
9999

@@ -121,7 +121,7 @@ func TestSuccesfullDecodeResponseWithErrorCode(t *testing.T) {
121121
var resp CreateVolumeResponse
122122
err := decodeResponse(bytes.NewReader(res), &resp)
123123
if err == nil {
124-
t.Log("No error occured")
124+
t.Log("No error occurred")
125125
t.Fail()
126126
}
127127

@@ -142,7 +142,7 @@ func TestBadDecodeResponse(t *testing.T) {
142142
var resp CreateVolumeResponse
143143
err := decodeResponse(bytes.NewReader(res), &resp)
144144
if err == nil {
145-
t.Log("No error occured")
145+
t.Log("No error occurred")
146146
t.Fail()
147147
}
148148

@@ -159,10 +159,10 @@ type decodeErrorCodeTest struct {
159159

160160
func TestDecodeErrorCode(t *testing.T) {
161161
tests := []*decodeErrorCodeTest{
162-
&decodeErrorCodeTest{code: -32600, expected: "ERROR_CODE_INVALID_REQUEST"},
163-
&decodeErrorCodeTest{code: -32603, expected: "ERROR_CODE_JSON_ENCODING_FAILED"},
164-
&decodeErrorCodeTest{code: -32601, expected: "ERROR_CODE_METHOD_NOT_FOUND"},
165-
&decodeErrorCodeTest{code: -32700, expected: "ERROR_CODE_PARSE_ERROR"},
162+
{code: -32600, expected: "ERROR_CODE_INVALID_REQUEST"},
163+
{code: -32603, expected: "ERROR_CODE_JSON_ENCODING_FAILED"},
164+
{code: -32601, expected: "ERROR_CODE_METHOD_NOT_FOUND"},
165+
{code: -32700, expected: "ERROR_CODE_PARSE_ERROR"},
166166
}
167167

168168
_ = tests

0 commit comments

Comments
 (0)