[ARVADOS] created: 241aac492beec3a7480b6e07e4e21d17474455e1
Git user
git at public.curoverse.com
Mon Mar 21 13:18:39 EDT 2016
at 241aac492beec3a7480b6e07e4e21d17474455e1 (commit)
commit 241aac492beec3a7480b6e07e4e21d17474455e1
Author: radhika <radhika at curoverse.com>
Date: Mon Mar 21 13:16:49 2016 -0400
8556: (wip) support GetBlobMetadata in azure stub implementation.
diff --git a/services/keepstore/azure_blob_volume.go b/services/keepstore/azure_blob_volume.go
index 687c2fb..c393cfb 100644
--- a/services/keepstore/azure_blob_volume.go
+++ b/services/keepstore/azure_blob_volume.go
@@ -321,10 +321,6 @@ func (v *AzureBlobVolume) Trash(loc string) error {
return MethodDisabledError
}
- if trashLifetime != 0 {
- return ErrNotImplemented
- }
-
// Ideally we would use If-Unmodified-Since, but that
// particular condition seems to be ignored by Azure. Instead,
// we get the Etag before checking Mtime, and use If-Match to
@@ -339,9 +335,20 @@ func (v *AzureBlobVolume) Trash(loc string) error {
} else if time.Since(t) < blobSignatureTTL {
return nil
}
- return v.bsClient.DeleteBlob(v.containerName, loc, map[string]string{
- "If-Match": props.Etag,
+ if trashLifetime == 0 {
+ return v.bsClient.DeleteBlob(v.containerName, loc, map[string]string{
+ "If-Match": props.Etag,
+ })
+ }
+ // Mark as trash
+ err = v.bsClient.CreateBlockBlobFromReader(v.containerName, loc, 0, bytes.NewReader([]byte("")))
+ if err != nil {
+ return err
+ }
+ err = v.bsClient.SetBlobMetadata(v.containerName, loc, map[string]string{
+ "expires_at": fmt.Sprintf("%d", time.Now().Add(trashLifetime).Unix()),
})
+ return v.bsClient.GetBlobMetadata(v.containerName, loc)
}
// Untrash a Keep block.
diff --git a/services/keepstore/azure_blob_volume_test.go b/services/keepstore/azure_blob_volume_test.go
index 439b402..eb08d81 100644
--- a/services/keepstore/azure_blob_volume_test.go
+++ b/services/keepstore/azure_blob_volume_test.go
@@ -4,6 +4,7 @@ import (
"bytes"
"crypto/md5"
"encoding/base64"
+ "encoding/gob"
"encoding/xml"
"flag"
"fmt"
@@ -74,6 +75,7 @@ func (h *azStubHandler) PutRaw(container, hash string, data []byte) {
h.blobs[container+"|"+hash] = &azBlob{
Data: data,
Mtime: time.Now(),
+ Metadata: make(map[string]string),
Uncommitted: make(map[string][]byte),
}
}
@@ -201,6 +203,22 @@ func (h *azStubHandler) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
}
blob.Mtime = time.Now()
blob.Etag = makeEtag()
+ case r.Method == "GET" && r.Form.Get("comp") == "metadata" && hash != "":
+ // "Get Blob Metadata" API
+ if !blobExists {
+ rw.WriteHeader(http.StatusNotFound)
+ return
+ }
+ buf := new(bytes.Buffer)
+ encoder := gob.NewEncoder(buf)
+ err = encoder.Encode(blob.Metadata)
+ if err != nil {
+ log.Print(err)
+ rw.WriteHeader(http.StatusInternalServerError)
+ return
+ }
+ rw.Write(buf.Bytes())
+ rw.Header().Set("Content-Length", strconv.Itoa(len(buf.Bytes())))
case (r.Method == "GET" || r.Method == "HEAD") && hash != "":
// "Get Blob" API
if !blobExists {
diff --git a/services/keepstore/volume_generic_test.go b/services/keepstore/volume_generic_test.go
index 95166c2..5ac7290 100644
--- a/services/keepstore/volume_generic_test.go
+++ b/services/keepstore/volume_generic_test.go
@@ -730,16 +730,16 @@ func testTrashUntrash(t TB, factory TestableVolumeFactory) {
err = v.Trash(TestHash)
if v.Writable() == false {
if err != MethodDisabledError {
- t.Error(err)
+ t.Fatal(err)
}
} else if err != nil {
if err != ErrNotImplemented {
- t.Error(err)
+ t.Fatal(err)
}
} else {
_, err = v.Get(TestHash)
if err == nil || !os.IsNotExist(err) {
- t.Errorf("os.IsNotExist(%v) should have been true", err)
+ t.Fatalf("os.IsNotExist(%v) should have been true", err)
}
// Untrash
@@ -755,7 +755,7 @@ func testTrashUntrash(t TB, factory TestableVolumeFactory) {
t.Fatal(err)
}
if bytes.Compare(buf, TestBlock) != 0 {
- t.Errorf("Got data %+q, expected %+q", buf, TestBlock)
+ t.Fatalf("Got data %+q, expected %+q", buf, TestBlock)
}
bufs.Put(buf)
}
@@ -859,7 +859,7 @@ func testTrashEmptyTrashUntrash(t TB, factory TestableVolumeFactory) {
err = v.Trash(TestHash)
err = checkGet()
if err == nil || !os.IsNotExist(err) {
- t.Errorf("os.IsNotExist(%v) should have been true", err)
+ t.Fatalf("os.IsNotExist(%v) should have been true", err)
}
v.EmptyTrash()
-----------------------------------------------------------------------
hooks/post-receive
--
More information about the arvados-commits
mailing list