Skip to content

Commit

Permalink
Erase volume (#31)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
venkatsc authored Dec 28, 2021
1 parent 4d1ae5d commit f120dc0
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 20 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func main() {
Name: "MyVolume",
TenantId: "32edb36d-badc-affe-b44a-4ab749af4d9a",
RootUserId: "root",
RootGroupId: "root",
RootGroupId: "root",
ConfigurationName: "BASE",
Label: []*quobyte_api.Label{
{Name: "label1", Value: "value1"},
Expand All @@ -48,8 +48,8 @@ func main() {
log.Fatalf("Error: %v", err)
}

capactiy := int64(1024 * 1024 * 1024)
err = client.SetVolumeQuota(response.VolumeUuid, capactiy)
capacity := int64(1024 * 1024 * 1024)
err = client.SetVolumeQuota(response.VolumeUuid, capacity)
if err != nil {
log.Fatalf("Error: %v", err)
}
Expand Down
2 changes: 1 addition & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
directory. (It seems go mod ignores .go file that is not placed in declared package directory!!)
* For local testing of edited module,
* Create a standalone project with the `testing or main.go` and `go mod init` inside the project root.
The `go mod init` fetches the depedencies required by code.
The `go mod init` fetches the dependencies required by code.
* Replace Quobyte API with updated API `go mod edit -replace github.com/quobyte/api=</path/to/local/quobyte/api>`
* Publishing change must always have highest minor version of all the published tags (even if the tag is deleted,
the new version must have the higher version than deleted tag).
Expand Down
34 changes: 30 additions & 4 deletions quobyte/quobyte.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func (client *QuobyteClient) GetVolumeUUID(volume, tenant string) (string, error
return volume, nil
}

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

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

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

// EraseVolumeByResolvingNamesToUUID Erases the volume by resolving the volume name and tenant name
// to respective UUID if required. (Use only against Quobyte 3.x)
func (client *QuobyteClient) EraseVolumeByResolvingNamesToUUID(volume, tenant string, force bool) error {
volumeUUID, err := client.GetVolumeUUID(volume, tenant)
if err != nil {
return err
}

_, err = client.EraseVolume(&EraseVolumeRequest{VolumeUuid: volumeUUID, Force: force})
return err
}

// EraseVolumeByResolvingNamesToUUID_2X Erases the volume by resolving the volume name and tenant name
// to respective UUID if required. (Use against Quobyte 2.x or 3.x)
func (client *QuobyteClient) EraseVolumeByResolvingNamesToUUID_2X(volume, tenant string) error {
volumeUUID, err := client.GetVolumeUUID(volume, tenant)
if err != nil {
return err
}

_, err = client.EraseVolume(&EraseVolumeRequest{VolumeUuid: volumeUUID})
return err
}

// SetVolumeQuota sets a Quota to the specified Volume
func (client *QuobyteClient) SetVolumeQuota(volumeUUID string, quotaSize int64) error {
request := &SetQuotaRequest{
Quotas: []*Quota{
&Quota{
{
Consumer: []*ConsumingEntity{
&ConsumingEntity{
{
Type: ConsumingEntity_Type_VOLUME,
Identifier: volumeUUID,
},
},
Limits: []*Resource{
&Resource{
{
Type: Resource_Type_LOGICAL_DISK_SPACE,
Value: quotaSize,
},
Expand Down
4 changes: 2 additions & 2 deletions quobyte/rpc_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
)

const (
emptyResponse string = "Empty result and no error occured"
emptyResponse string = "Empty result and no error occurred"
)

var mux sync.Mutex
Expand Down Expand Up @@ -136,7 +136,7 @@ func (client QuobyteClient) sendRequest(method string, request interface{}, resp
if ok {
return errors.New("Unable to authenticate with Quobyte API service")
}
// Session is not valid anymore (service restart, sesssion invalidated etc)!!
// Session is not valid anymore (service restart, session invalidated etc)!!
// resend basic auth and get new cookies
// invalidate session cookies
cookieJar := client.client.Jar
Expand Down
20 changes: 10 additions & 10 deletions quobyte/rpc_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"testing"
)

func TestSuccesfullEncodeRequest(t *testing.T) {
func TestSuccessfullEncodeRequest(t *testing.T) {
req := &CreateVolumeRequest{
RootUserId: "root",
RootGroupId: "root",
Expand Down Expand Up @@ -49,7 +49,7 @@ func TestSuccesfullEncodeRequest(t *testing.T) {
}
}

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

Expand All @@ -74,7 +74,7 @@ func TestSuccesfullDecodeResponse(t *testing.T) {
}
}

func TestSuccesfullDecodeResponseWithErrorMessage(t *testing.T) {
func TestSuccessfullDecodeResponseWithErrorMessage(t *testing.T) {
errorMessage := "ERROR_CODE_INVALID_REQUEST"
var byt json.RawMessage
byt, _ = json.Marshal(&rpcError{
Expand All @@ -93,7 +93,7 @@ func TestSuccesfullDecodeResponseWithErrorMessage(t *testing.T) {
var resp CreateVolumeResponse
err := decodeResponse(bytes.NewReader(res), &resp)
if err == nil {
t.Log("No error occured")
t.Log("No error occurred")
t.Fail()
}

Expand Down Expand Up @@ -121,7 +121,7 @@ func TestSuccesfullDecodeResponseWithErrorCode(t *testing.T) {
var resp CreateVolumeResponse
err := decodeResponse(bytes.NewReader(res), &resp)
if err == nil {
t.Log("No error occured")
t.Log("No error occurred")
t.Fail()
}

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

Expand All @@ -159,10 +159,10 @@ type decodeErrorCodeTest struct {

func TestDecodeErrorCode(t *testing.T) {
tests := []*decodeErrorCodeTest{
&decodeErrorCodeTest{code: -32600, expected: "ERROR_CODE_INVALID_REQUEST"},
&decodeErrorCodeTest{code: -32603, expected: "ERROR_CODE_JSON_ENCODING_FAILED"},
&decodeErrorCodeTest{code: -32601, expected: "ERROR_CODE_METHOD_NOT_FOUND"},
&decodeErrorCodeTest{code: -32700, expected: "ERROR_CODE_PARSE_ERROR"},
{code: -32600, expected: "ERROR_CODE_INVALID_REQUEST"},
{code: -32603, expected: "ERROR_CODE_JSON_ENCODING_FAILED"},
{code: -32601, expected: "ERROR_CODE_METHOD_NOT_FOUND"},
{code: -32700, expected: "ERROR_CODE_PARSE_ERROR"},
}

_ = tests
Expand Down

0 comments on commit f120dc0

Please sign in to comment.