~ubuntu-branches/ubuntu/saucy/juju-core/saucy

« back to all changes in this revision

Viewing changes to src/launchpad.net/juju-core/environs/ec2/storage.go

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2013-08-20 16:02:16 UTC
  • mfrom: (1.1.5)
  • Revision ID: package-import@ubuntu.com-20130820160216-5yu1llasa2e2youn
Tags: 1.13.1-0ubuntu1
* New upstream release.
  - Build and install juju metadata plugin.
  - d/NEWS: Add some guidance on upgrading environments from 1.11.x
    to 1.13.x.
* d/NEWS: Add details about lack of upgrade path from juju < 1.11
  and how to interact with older juju environments.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
        "launchpad.net/goamz/s3"
18
18
        "launchpad.net/juju-core/environs"
19
19
        "launchpad.net/juju-core/errors"
 
20
        "launchpad.net/juju-core/utils"
20
21
)
21
22
 
22
23
func NewStorage(bucket *s3.Bucket) environs.Storage {
64
65
}
65
66
 
66
67
func (s *storage) Get(file string) (r io.ReadCloser, err error) {
67
 
        for a := shortAttempt.Start(); a.Next(); {
 
68
        for a := s.ConsistencyStrategy().Start(); a.Next(); {
68
69
                r, err = s.bucket.GetReader(file)
69
70
                if s3ErrorStatusCode(err) != 404 {
70
71
                        break
78
79
        return s.bucket.SignedURL(name, time.Now().AddDate(10, 0, 0)), nil
79
80
}
80
81
 
 
82
var storageAttempt = utils.AttemptStrategy{
 
83
        Total: 5 * time.Second,
 
84
        Delay: 200 * time.Millisecond,
 
85
}
 
86
 
 
87
// ConsistencyStrategy is specified in the StorageReader interface.
 
88
func (s *storage) ConsistencyStrategy() utils.AttemptStrategy {
 
89
        return storageAttempt
 
90
}
 
91
 
81
92
// s3ErrorStatusCode returns the HTTP status of the S3 request error,
82
93
// if it is an error from an S3 operation, or 0 if it was not.
83
94
func s3ErrorStatusCode(err error) int {
201
212
                return nil, err
202
213
        }
203
214
        resp, err := http.Get(nameURL)
204
 
        if err != nil && resp.StatusCode == http.StatusNotFound {
 
215
        if err != nil || resp.StatusCode == http.StatusNotFound {
205
216
                return nil, &errors.NotFoundError{err, ""}
206
217
        }
207
218
        return resp.Body, nil
231
242
        return h.url + "/" + name, nil
232
243
}
233
244
 
 
245
// ConsistencyStrategy is specified in the StorageReader interface.
 
246
func (s *httpStorageReader) ConsistencyStrategy() utils.AttemptStrategy {
 
247
        return storageAttempt
 
248
}
 
249
 
234
250
// getListBucketResult retrieves the index of the storage,
235
251
func (h *httpStorageReader) getListBucketResult() (*listBucketResult, error) {
236
252
        resp, err := http.Get(h.url)