Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(478)

Side by Side Diff: environs/emptystorage.go

Issue 13632056: Reduce unnecessary s3 timeouts (Closed)
Patch Set: Reduce unnecessary s3 timeouts Created 11 years, 6 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 Canonical Ltd. 1 // Copyright 2013 Canonical Ltd.
2 // Licensed under the AGPLv3, see LICENCE file for details. 2 // Licensed under the AGPLv3, see LICENCE file for details.
3 3
4 package environs 4 package environs
5 5
6 import ( 6 import (
7 "fmt" 7 "fmt"
8 "io" 8 "io"
9 "strings" 9 "strings"
10 10
11 "launchpad.net/juju-core/environs/storage"
11 "launchpad.net/juju-core/errors" 12 "launchpad.net/juju-core/errors"
12 "launchpad.net/juju-core/log" 13 "launchpad.net/juju-core/log"
13 "launchpad.net/juju-core/utils" 14 "launchpad.net/juju-core/utils"
14 ) 15 )
15 16
16 // EmptyStorage holds a StorageReader object that contains no files and 17 // EmptyStorage holds a StorageReader object that contains no files and
17 // offers no URLs. 18 // offers no URLs.
18 var EmptyStorage StorageReader = emptyStorage{} 19 var EmptyStorage storage.StorageReader = emptyStorage{}
19 20
20 type emptyStorage struct{} 21 type emptyStorage struct{}
21 22
22 // File named `verificationFilename` in the storage will contain 23 // File named `verificationFilename` in the storage will contain
23 // `verificationContent`. This is also used to differentiate between 24 // `verificationContent`. This is also used to differentiate between
24 // Python Juju and juju-core environments, so change the content with 25 // Python Juju and juju-core environments, so change the content with
25 // care (and update CheckEnvironment below when you do that). 26 // care (and update CheckEnvironment below when you do that).
26 const verificationFilename string = "bootstrap-verify" 27 const verificationFilename string = "bootstrap-verify"
27 const verificationContent = "juju-core storage writing verified: ok\n" 28 const verificationContent = "juju-core storage writing verified: ok\n"
28 29
29 var VerifyStorageError error = fmt.Errorf( 30 var VerifyStorageError error = fmt.Errorf(
30 "provider storage is not writable") 31 "provider storage is not writable")
31 32
32 func (s emptyStorage) Get(name string) (io.ReadCloser, error) { 33 func (s emptyStorage) Get(name string) (io.ReadCloser, error) {
33 return nil, errors.NotFoundf("file %q", name) 34 return nil, errors.NotFoundf("file %q", name)
34 } 35 }
35 36
36 func (s emptyStorage) URL(name string) (string, error) { 37 func (s emptyStorage) URL(name string) (string, error) {
37 return "", fmt.Errorf("file %q not found", name) 38 return "", fmt.Errorf("file %q not found", name)
38 } 39 }
39 40
40 // ConsistencyStrategy is specified in the StorageReader interface.
41 func (s emptyStorage) ConsistencyStrategy() utils.AttemptStrategy {
42 return utils.AttemptStrategy{}
43 }
44
45 func (s emptyStorage) List(prefix string) ([]string, error) { 41 func (s emptyStorage) List(prefix string) ([]string, error) {
46 return nil, nil 42 return nil, nil
47 } 43 }
48 44
49 func VerifyStorage(storage Storage) error { 45 // DefaultConsistencyStrategy is specified in the StorageReader interface.
46 func (s emptyStorage) DefaultConsistencyStrategy() utils.AttemptStrategy {
47 » return utils.AttemptStrategy{}
48 }
49
50 // ShouldRetry is specified in the StorageReader interface.
51 func (s emptyStorage) ShouldRetry(err error) bool {
52 » return false
53 }
54
55 func VerifyStorage(stor storage.Storage) error {
50 reader := strings.NewReader(verificationContent) 56 reader := strings.NewReader(verificationContent)
51 » err := storage.Put(verificationFilename, reader, 57 » err := stor.Put(verificationFilename, reader,
52 int64(len(verificationContent))) 58 int64(len(verificationContent)))
53 if err != nil { 59 if err != nil {
54 log.Debugf( 60 log.Debugf(
55 "environs: failed to write bootstrap-verify file: %v", 61 "environs: failed to write bootstrap-verify file: %v",
56 err) 62 err)
57 return VerifyStorageError 63 return VerifyStorageError
58 } 64 }
59 return nil 65 return nil
60 } 66 }
OLDNEW

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b