diff --git a/pkg/storage/donut/donut.go b/pkg/storage/donut/donut.go index 57098e099..178a23707 100644 --- a/pkg/storage/donut/donut.go +++ b/pkg/storage/donut/donut.go @@ -10,7 +10,7 @@ type Donut interface { ListBuckets() ([]string, error) GetObjectWriter(bucket, object string) (ObjectWriter, 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) // ListObjects(bucket string) ([]string, error) } diff --git a/pkg/storage/donut/donutdriver.go b/pkg/storage/donut/donutdriver.go index 7ee88925a..14ec2082c 100644 --- a/pkg/storage/donut/donutdriver.go +++ b/pkg/storage/donut/donutdriver.go @@ -113,6 +113,21 @@ func (driver donutDriver) GetObject(bucketName, objectName string) (io.ReadClose 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) { totalChunks, _ := strconv.Atoi(donutMetadata["chunkCount"]) totalLeft, _ := strconv.Atoi(donutMetadata["totalLength"]) diff --git a/pkg/storage/donut/donutdriver_test.go b/pkg/storage/donut/donutdriver_test.go index 680dab10b..8988e147e 100644 --- a/pkg/storage/donut/donutdriver_test.go +++ b/pkg/storage/donut/donutdriver_test.go @@ -7,6 +7,7 @@ import ( . "gopkg.in/check.v1" "io" "io/ioutil" + "log" "os" ) @@ -159,6 +160,11 @@ func (s *MySuite) TestNewObjectCanBeWritten(c *C) { _, err = io.Copy(&actualData, reader) c.Assert(err, IsNil) 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) {