2011-05-09 13:32:24 +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.
|
|
|
|
*/
|
|
|
|
|
2013-07-08 01:52:14 +00:00
|
|
|
/*
|
|
|
|
Package remote registers the "remote" blobserver storage type, storing
|
|
|
|
and fetching blobs from a remote Camlistore server, speaking the HTTP
|
|
|
|
protocol.
|
|
|
|
|
|
|
|
Example low-level config:
|
|
|
|
|
|
|
|
"/peer/": {
|
|
|
|
"handler": "storage-remote",
|
|
|
|
"handlerArgs": {
|
|
|
|
"url": "http://10.0.0.17/base",
|
2013-12-26 08:48:29 +00:00
|
|
|
"auth": "userpass:user:pass",
|
2013-07-08 01:52:14 +00:00
|
|
|
"skipStartupCheck": false
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
*/
|
2011-05-09 13:32:24 +00:00
|
|
|
package remote
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io"
|
remote: fix crash due to nil logger
This happened in a well-timed HTTP failure:
runtime.panic(0x674580, 0x10e67b9)
/Users/dustin/prog/eprojects/go/src/pkg/runtime/panic.c:266 +0xb6
log.(*Logger).Output(0x0, 0x2, 0xc2104e4870, 0x83, 0x0, ...)
/Users/dustin/prog/eprojects/go/src/pkg/log/log.go:134 +0x46b
log.(*Logger).Print(0x0, 0x13b29b8, 0x1, 0x1)
/Users/dustin/prog/eprojects/go/src/pkg/log/log.go:165 +0x66
camlistore.org/pkg/client.func·011(0x7da390, 0x13, 0xc21075d400, 0x1, 0x1, ...)
$GOPATH/src/camlistore.org/pkg/client/upload.go:363 +0x133
camlistore.org/pkg/client.(*Client).Upload(0xc21014ec00, 0xc2109fa7b0, 0x0, 0x0, 0x0)
Change-Id: I9859bc8f03ef0dd9c9b89b7e22815c5ee5b7fd87
2013-12-26 09:27:56 +00:00
|
|
|
"log"
|
|
|
|
"os"
|
2011-05-09 13:32:24 +00:00
|
|
|
|
2013-08-04 02:54:30 +00:00
|
|
|
"camlistore.org/pkg/blob"
|
Update from r60 to [almost] Go 1.
A lot is still broken, but most stuff at least compiles now.
The directory tree has been rearranged now too. Go libraries are now
under "pkg". Fully qualified, they are e.g. "camlistore.org/pkg/jsonsign".
The go tool cannot yet fetch from arbitrary domains, but discussion is
happening now on which mechanism to use to allow that.
For now, put the camlistore root under $GOPATH/src. Typically $GOPATH
is $HOME, so Camlistore should be at $HOME/src/camlistore.org.
Then you can:
$ go build ./server/camlistored
... etc
The build.pl script is currently disabled. It'll be resurrected at
some point, but with a very different role (helping create a fake
GOPATH and running the go build command, if things are installed at
the wrong place, and/or running fileembed generators).
Many things are certainly broken.
Many things are disabled. (MySQL, all indexing, etc).
Many things need to be moved into
camlistore.org/third_party/{code.google.com,github.com} and updated
from their r60 to Go 1 versions, where applicable.
The GoMySQL stuff should be updated to use database/sql and the ziutek
library implementing database/sql/driver.
Help wanted.
Change-Id: If71217dc5c8f0e70dbe46e9504ca5131c6eeacde
2012-02-19 05:53:06 +00:00
|
|
|
"camlistore.org/pkg/blobserver"
|
|
|
|
"camlistore.org/pkg/client"
|
2013-12-02 21:20:51 +00:00
|
|
|
"camlistore.org/pkg/context"
|
Update from r60 to [almost] Go 1.
A lot is still broken, but most stuff at least compiles now.
The directory tree has been rearranged now too. Go libraries are now
under "pkg". Fully qualified, they are e.g. "camlistore.org/pkg/jsonsign".
The go tool cannot yet fetch from arbitrary domains, but discussion is
happening now on which mechanism to use to allow that.
For now, put the camlistore root under $GOPATH/src. Typically $GOPATH
is $HOME, so Camlistore should be at $HOME/src/camlistore.org.
Then you can:
$ go build ./server/camlistored
... etc
The build.pl script is currently disabled. It'll be resurrected at
some point, but with a very different role (helping create a fake
GOPATH and running the go build command, if things are installed at
the wrong place, and/or running fileembed generators).
Many things are certainly broken.
Many things are disabled. (MySQL, all indexing, etc).
Many things need to be moved into
camlistore.org/third_party/{code.google.com,github.com} and updated
from their r60 to Go 1 versions, where applicable.
The GoMySQL stuff should be updated to use database/sql and the ziutek
library implementing database/sql/driver.
Help wanted.
Change-Id: If71217dc5c8f0e70dbe46e9504ca5131c6eeacde
2012-02-19 05:53:06 +00:00
|
|
|
"camlistore.org/pkg/jsonconfig"
|
2011-05-09 13:32:24 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// remoteStorage is a blobserver.Storage proxy for a remote camlistore
|
|
|
|
// blobserver.
|
|
|
|
type remoteStorage struct {
|
2013-08-21 20:57:28 +00:00
|
|
|
client *client.Client
|
2011-05-09 13:32:24 +00:00
|
|
|
}
|
|
|
|
|
2011-05-10 18:32:47 +00:00
|
|
|
var _ = blobserver.Storage((*remoteStorage)(nil))
|
|
|
|
|
2013-07-08 01:52:14 +00:00
|
|
|
// NewFromClient returns a new Storage implementation using the
|
|
|
|
// provided Camlistore client.
|
2011-09-28 18:05:35 +00:00
|
|
|
func NewFromClient(c *client.Client) blobserver.Storage {
|
|
|
|
return &remoteStorage{client: c}
|
|
|
|
}
|
|
|
|
|
Update from r60 to [almost] Go 1.
A lot is still broken, but most stuff at least compiles now.
The directory tree has been rearranged now too. Go libraries are now
under "pkg". Fully qualified, they are e.g. "camlistore.org/pkg/jsonsign".
The go tool cannot yet fetch from arbitrary domains, but discussion is
happening now on which mechanism to use to allow that.
For now, put the camlistore root under $GOPATH/src. Typically $GOPATH
is $HOME, so Camlistore should be at $HOME/src/camlistore.org.
Then you can:
$ go build ./server/camlistored
... etc
The build.pl script is currently disabled. It'll be resurrected at
some point, but with a very different role (helping create a fake
GOPATH and running the go build command, if things are installed at
the wrong place, and/or running fileembed generators).
Many things are certainly broken.
Many things are disabled. (MySQL, all indexing, etc).
Many things need to be moved into
camlistore.org/third_party/{code.google.com,github.com} and updated
from their r60 to Go 1 versions, where applicable.
The GoMySQL stuff should be updated to use database/sql and the ziutek
library implementing database/sql/driver.
Help wanted.
Change-Id: If71217dc5c8f0e70dbe46e9504ca5131c6eeacde
2012-02-19 05:53:06 +00:00
|
|
|
func newFromConfig(_ blobserver.Loader, config jsonconfig.Obj) (storage blobserver.Storage, err error) {
|
2011-05-09 13:32:24 +00:00
|
|
|
url := config.RequiredString("url")
|
2013-12-26 08:48:29 +00:00
|
|
|
auth := config.RequiredString("auth")
|
2011-05-09 13:32:24 +00:00
|
|
|
skipStartupCheck := config.OptionalBool("skipStartupCheck", false)
|
|
|
|
if err := config.Validate(); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2011-11-16 10:41:38 +00:00
|
|
|
|
|
|
|
client := client.New(url)
|
2013-12-26 08:48:29 +00:00
|
|
|
if err = client.SetupAuthFromString(auth); err != nil {
|
2011-11-16 10:41:38 +00:00
|
|
|
return nil, err
|
|
|
|
}
|
remote: fix crash due to nil logger
This happened in a well-timed HTTP failure:
runtime.panic(0x674580, 0x10e67b9)
/Users/dustin/prog/eprojects/go/src/pkg/runtime/panic.c:266 +0xb6
log.(*Logger).Output(0x0, 0x2, 0xc2104e4870, 0x83, 0x0, ...)
/Users/dustin/prog/eprojects/go/src/pkg/log/log.go:134 +0x46b
log.(*Logger).Print(0x0, 0x13b29b8, 0x1, 0x1)
/Users/dustin/prog/eprojects/go/src/pkg/log/log.go:165 +0x66
camlistore.org/pkg/client.func·011(0x7da390, 0x13, 0xc21075d400, 0x1, 0x1, ...)
$GOPATH/src/camlistore.org/pkg/client/upload.go:363 +0x133
camlistore.org/pkg/client.(*Client).Upload(0xc21014ec00, 0xc2109fa7b0, 0x0, 0x0, 0x0)
Change-Id: I9859bc8f03ef0dd9c9b89b7e22815c5ee5b7fd87
2013-12-26 09:27:56 +00:00
|
|
|
client.SetLogger(log.New(os.Stderr, "remote", log.LstdFlags))
|
2011-05-09 13:32:24 +00:00
|
|
|
sto := &remoteStorage{
|
2011-11-16 10:41:38 +00:00
|
|
|
client: client,
|
2011-05-09 13:32:24 +00:00
|
|
|
}
|
|
|
|
if !skipStartupCheck {
|
2012-07-22 22:03:02 +00:00
|
|
|
// Do a quick dummy operation to check that our credentials are
|
|
|
|
// correct.
|
|
|
|
// TODO(bradfitz,mpl): skip this operation smartly if it turns out this is annoying/slow for whatever reason.
|
2013-08-04 02:54:30 +00:00
|
|
|
c := make(chan blob.SizedRef, 1)
|
2013-12-02 21:20:51 +00:00
|
|
|
err = sto.EnumerateBlobs(context.TODO(), c, "", 1)
|
2012-07-22 22:03:02 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2011-05-09 13:32:24 +00:00
|
|
|
}
|
|
|
|
return sto, nil
|
|
|
|
}
|
|
|
|
|
2013-08-04 02:54:30 +00:00
|
|
|
func (sto *remoteStorage) RemoveBlobs(blobs []blob.Ref) error {
|
2011-05-10 13:25:18 +00:00
|
|
|
return sto.client.RemoveBlobs(blobs)
|
2011-05-09 13:32:24 +00:00
|
|
|
}
|
|
|
|
|
2013-08-21 20:57:28 +00:00
|
|
|
func (sto *remoteStorage) StatBlobs(dest chan<- blob.SizedRef, blobs []blob.Ref) error {
|
2011-05-10 20:04:20 +00:00
|
|
|
// TODO: cache the stat response's uploadUrl to save a future
|
|
|
|
// stat later? otherwise clients will just Stat + Upload, but
|
|
|
|
// Upload will also Stat. should be smart and make sure we
|
|
|
|
// avoid ReceiveBlob's Stat whenever it would be redundant.
|
2013-08-21 20:57:28 +00:00
|
|
|
return sto.client.StatBlobs(dest, blobs)
|
2011-05-09 13:32:24 +00:00
|
|
|
}
|
|
|
|
|
2013-08-04 02:54:30 +00:00
|
|
|
func (sto *remoteStorage) ReceiveBlob(blob blob.Ref, source io.Reader) (outsb blob.SizedRef, outerr error) {
|
2011-05-10 22:51:10 +00:00
|
|
|
h := &client.UploadHandle{
|
|
|
|
BlobRef: blob,
|
|
|
|
Size: -1, // size isn't known; -1 is fine, but TODO: ask source if it knows its size
|
|
|
|
Contents: source,
|
|
|
|
}
|
|
|
|
pr, err := sto.client.Upload(h)
|
|
|
|
if err != nil {
|
2011-05-10 23:13:37 +00:00
|
|
|
outerr = err
|
|
|
|
return
|
2011-05-10 22:51:10 +00:00
|
|
|
}
|
2011-05-10 23:13:37 +00:00
|
|
|
return pr.SizedBlobRef(), nil
|
2011-05-09 13:32:24 +00:00
|
|
|
}
|
|
|
|
|
2013-08-04 02:54:30 +00:00
|
|
|
func (sto *remoteStorage) FetchStreaming(b blob.Ref) (file io.ReadCloser, size int64, err error) {
|
2011-05-10 18:32:47 +00:00
|
|
|
return sto.client.FetchStreaming(b)
|
2011-05-09 13:32:24 +00:00
|
|
|
}
|
|
|
|
|
Update from r60 to [almost] Go 1.
A lot is still broken, but most stuff at least compiles now.
The directory tree has been rearranged now too. Go libraries are now
under "pkg". Fully qualified, they are e.g. "camlistore.org/pkg/jsonsign".
The go tool cannot yet fetch from arbitrary domains, but discussion is
happening now on which mechanism to use to allow that.
For now, put the camlistore root under $GOPATH/src. Typically $GOPATH
is $HOME, so Camlistore should be at $HOME/src/camlistore.org.
Then you can:
$ go build ./server/camlistored
... etc
The build.pl script is currently disabled. It'll be resurrected at
some point, but with a very different role (helping create a fake
GOPATH and running the go build command, if things are installed at
the wrong place, and/or running fileembed generators).
Many things are certainly broken.
Many things are disabled. (MySQL, all indexing, etc).
Many things need to be moved into
camlistore.org/third_party/{code.google.com,github.com} and updated
from their r60 to Go 1 versions, where applicable.
The GoMySQL stuff should be updated to use database/sql and the ziutek
library implementing database/sql/driver.
Help wanted.
Change-Id: If71217dc5c8f0e70dbe46e9504ca5131c6eeacde
2012-02-19 05:53:06 +00:00
|
|
|
func (sto *remoteStorage) MaxEnumerate() int { return 1000 }
|
2011-05-09 13:32:24 +00:00
|
|
|
|
2013-12-02 21:20:51 +00:00
|
|
|
func (sto *remoteStorage) EnumerateBlobs(ctx *context.Context, dest chan<- blob.SizedRef, after string, limit int) error {
|
|
|
|
return sto.client.EnumerateBlobsOpts(ctx, dest, client.EnumerateOpts{
|
2013-08-21 20:57:28 +00:00
|
|
|
After: after,
|
|
|
|
Limit: limit,
|
2011-05-10 18:32:47 +00:00
|
|
|
})
|
2011-05-09 13:32:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
blobserver.RegisterStorageConstructor("remote", blobserver.StorageConstructor(newFromConfig))
|
|
|
|
}
|