Adding GetObjectMetadata to donut

master
Frederick F. Kautz IV 10 years ago
parent 703af6c3ce
commit 99cf484488
  1. 2
      pkg/storage/donut/donut.go
  2. 15
      pkg/storage/donut/donutdriver.go
  3. 6
      pkg/storage/donut/donutdriver_test.go

@ -10,7 +10,7 @@ type Donut interface {
ListBuckets() ([]string, error) ListBuckets() ([]string, error)
GetObjectWriter(bucket, object string) (ObjectWriter, error) GetObjectWriter(bucket, object string) (ObjectWriter, error)
GetObject(bucket, object string) (io.ReadCloser, error) GetObject(bucket, object string) (io.ReadCloser, error)
// GetObjectMetadata(bucket, object string) (map[string]string, error) GetObjectMetadata(bucket, object string) (map[string]string, error)
// GetObjectWriter(bucket, object string) (ObjectWriter, error) // GetObjectWriter(bucket, object string) (ObjectWriter, error)
// ListObjects(bucket string) ([]string, error) // ListObjects(bucket string) ([]string, error)
} }

@ -113,6 +113,21 @@ func (driver donutDriver) GetObject(bucketName, objectName string) (io.ReadClose
return nil, errors.New("Bucket not found") return nil, errors.New("Bucket not found")
} }
// GetObjectMetadata returns metadata for a given object in a bucket
func (driver donutDriver) GetObjectMetadata(bucketName, object string) (map[string]string, error) {
if bucket, ok := driver.buckets[bucketName]; ok {
nodes, err := bucket.GetNodes()
if err != nil {
return nil, err
}
if node, ok := driver.nodes[nodes[0]]; ok {
return node.GetMetadata(bucketName+":0:0", object)
}
return nil, errors.New("Cannot connect to node: " + nodes[0])
}
return nil, errors.New("Bucket not found")
}
func erasureReader(readers []io.ReadCloser, donutMetadata map[string]string, writer *io.PipeWriter) { func erasureReader(readers []io.ReadCloser, donutMetadata map[string]string, writer *io.PipeWriter) {
totalChunks, _ := strconv.Atoi(donutMetadata["chunkCount"]) totalChunks, _ := strconv.Atoi(donutMetadata["chunkCount"])
totalLeft, _ := strconv.Atoi(donutMetadata["totalLength"]) totalLeft, _ := strconv.Atoi(donutMetadata["totalLength"])

@ -7,6 +7,7 @@ import (
. "gopkg.in/check.v1" . "gopkg.in/check.v1"
"io" "io"
"io/ioutil" "io/ioutil"
"log"
"os" "os"
) )
@ -159,6 +160,11 @@ func (s *MySuite) TestNewObjectCanBeWritten(c *C) {
_, err = io.Copy(&actualData, reader) _, err = io.Copy(&actualData, reader)
c.Assert(err, IsNil) c.Assert(err, IsNil)
c.Assert(actualData.Bytes(), DeepEquals, []byte(data)) c.Assert(actualData.Bytes(), DeepEquals, []byte(data))
actualMetadata, err := donut.GetObjectMetadata("foo", "obj")
c.Assert(err, IsNil)
log.Println(actualMetadata)
c.Assert(actualMetadata, DeepEquals, expectedMetadata)
} }
func (s *MySuite) TestMultipleNewObjects(c *C) { func (s *MySuite) TestMultipleNewObjects(c *C) {

Loading…
Cancel
Save