~themue/juju-core/053-env-more-script-friendly

« back to all changes in this revision

Viewing changes to environs/mongo.go

Merge trunk and resolve conflicts.

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
        "fmt"
5
5
)
6
6
 
7
 
// MongoURL figures out from where to retrieve a copy of MongoDB compatible with
8
 
// the given version from the given environment. The search locations are (in order):
9
 
// - the environment specific storage
10
 
// - the public storage
11
 
// - a "well known" EC2 bucket
12
 
func MongoURL(env Environ, series, architecture string) string {
13
 
        path := MongoStoragePath(series, architecture)
14
 
        url, err := findMongo(env.Storage(), path)
15
 
        if err == nil {
16
 
                return url
17
 
        }
18
 
        url, err = findMongo(env.PublicStorage(), path)
19
 
        if err == nil {
20
 
                return url
21
 
        }
22
 
        // TODO(thumper): this should at least check that the fallback option
23
 
        // exists before returning it. lp:1164220
24
 
        return fmt.Sprintf("http://juju-dist.s3.amazonaws.com/%s", path)
25
 
}
26
 
 
27
 
// Return the URL of a compatible MongoDB (if it exists) from the storage,
28
 
// for the given series and architecture (in vers).
29
 
func findMongo(store StorageReader, path string) (string, error) {
30
 
        names, err := store.List(path)
31
 
        if err != nil {
32
 
                return "", err
33
 
        }
34
 
        if len(names) != 1 {
35
 
                return "", &NotFoundError{fmt.Errorf("%s not found", path)}
36
 
        }
37
 
        url, err := store.URL(names[0])
38
 
        if err != nil {
39
 
                return "", err
40
 
        }
41
 
        return url, nil
42
 
}
43
 
 
44
7
// MongoStoragePath returns the path that is used to
45
8
// retrieve the given version of mongodb in a Storage.
46
9
func MongoStoragePath(series, architecture string) string {