2011-10-05 21:34:55 +00:00
|
|
|
/*
|
|
|
|
Copyright 2011 Google Inc.
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package appengine
|
|
|
|
|
|
|
|
import (
|
2011-10-07 00:44:30 +00:00
|
|
|
"http"
|
2011-10-05 21:34:55 +00:00
|
|
|
"io"
|
|
|
|
"os"
|
|
|
|
|
2011-10-07 00:44:30 +00:00
|
|
|
"appengine"
|
|
|
|
|
2011-10-05 21:34:55 +00:00
|
|
|
"camli/blobref"
|
|
|
|
"camli/blobserver"
|
|
|
|
"camli/jsonconfig"
|
|
|
|
)
|
|
|
|
|
|
|
|
type appengineStorage struct {
|
|
|
|
*blobserver.SimpleBlobHubPartitionMap
|
2011-10-07 00:44:30 +00:00
|
|
|
|
|
|
|
ctx appengine.Context
|
2011-10-05 21:34:55 +00:00
|
|
|
}
|
|
|
|
|
2011-10-07 00:44:30 +00:00
|
|
|
var errNoContext = os.NewError("Internal error: no App Engine context is available")
|
|
|
|
|
2011-10-05 21:34:55 +00:00
|
|
|
func newFromConfig(ld blobserver.Loader, config jsonconfig.Obj) (storage blobserver.Storage, err os.Error) {
|
|
|
|
sto := &appengineStorage{
|
|
|
|
SimpleBlobHubPartitionMap: &blobserver.SimpleBlobHubPartitionMap{},
|
|
|
|
}
|
|
|
|
if err := config.Validate(); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return sto, nil
|
|
|
|
}
|
|
|
|
|
2011-10-07 00:44:30 +00:00
|
|
|
var _ blobserver.ContextWrapper = (*appengineStorage)(nil)
|
|
|
|
|
|
|
|
func (sto *appengineStorage) WrapContext(req *http.Request) blobserver.Storage {
|
|
|
|
s2 := new(appengineStorage)
|
|
|
|
*s2 = *sto
|
|
|
|
s2.ctx = appengine.NewContext(req)
|
|
|
|
return s2
|
|
|
|
}
|
|
|
|
|
2011-10-05 21:34:55 +00:00
|
|
|
func (sto *appengineStorage) FetchStreaming(br *blobref.BlobRef) (file io.ReadCloser, size int64, err os.Error) {
|
2011-10-07 00:44:30 +00:00
|
|
|
if sto.ctx == nil {
|
|
|
|
err = errNoContext
|
|
|
|
return
|
|
|
|
}
|
|
|
|
err = os.NewError("TODO-AppEngine-FetchStreaming")
|
2011-10-05 21:34:55 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func (sto *appengineStorage) ReceiveBlob(b *blobref.BlobRef, source io.Reader) (sb blobref.SizedBlobRef, err os.Error) {
|
2011-10-07 00:44:30 +00:00
|
|
|
if sto.ctx == nil {
|
|
|
|
err = errNoContext
|
|
|
|
return
|
|
|
|
}
|
|
|
|
err = os.NewError("TODO-AppEngine-ReceiveBlob")
|
2011-10-05 21:34:55 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func (sto *appengineStorage) RemoveBlobs(blobs []*blobref.BlobRef) os.Error {
|
2011-10-07 00:44:30 +00:00
|
|
|
if sto.ctx == nil {
|
|
|
|
return errNoContext
|
|
|
|
}
|
|
|
|
return os.NewError("TODO-AppEngine-RemoveBlobs")
|
2011-10-05 21:34:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (sto *appengineStorage) StatBlobs(dest chan<- blobref.SizedBlobRef, blobs []*blobref.BlobRef, waitSeconds int) os.Error {
|
2011-10-07 00:44:30 +00:00
|
|
|
if sto.ctx == nil {
|
|
|
|
return errNoContext
|
|
|
|
}
|
|
|
|
return os.NewError("TODO-AppEngine-StatBlobs")
|
2011-10-05 21:34:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (sto *appengineStorage) EnumerateBlobs(dest chan<- blobref.SizedBlobRef, after string, limit uint, waitSeconds int) os.Error {
|
2011-10-07 00:44:30 +00:00
|
|
|
if sto.ctx == nil {
|
|
|
|
return errNoContext
|
|
|
|
}
|
|
|
|
return os.NewError("TODO-AppEngine-EnumerateBlobs")
|
2011-10-05 21:34:55 +00:00
|
|
|
}
|