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

Side by Side Diff: provider/common/state.go

Issue 70770043: all: use errgo instead of fmt.Errorf
Patch Set: all: use errgo instead of fmt.Errorf Created 11 years, 1 month 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
« no previous file with comments | « provider/common/polling_test.go ('k') | provider/dummy/environs.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012, 2013 Canonical Ltd. 1 // Copyright 2012, 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 common 4 package common
5 5
6 import ( 6 import (
7 "errors"
8 "fmt" 7 "fmt"
9 8
9 "github.com/juju/errgo/errors"
10
10 "launchpad.net/juju-core/environs" 11 "launchpad.net/juju-core/environs"
11 "launchpad.net/juju-core/environs/bootstrap" 12 "launchpad.net/juju-core/environs/bootstrap"
12 "launchpad.net/juju-core/environs/config" 13 "launchpad.net/juju-core/environs/config"
13 "launchpad.net/juju-core/instance" 14 "launchpad.net/juju-core/instance"
14 "launchpad.net/juju-core/log" 15 "launchpad.net/juju-core/log"
15 "launchpad.net/juju-core/state" 16 "launchpad.net/juju-core/state"
16 "launchpad.net/juju-core/state/api" 17 "launchpad.net/juju-core/state/api"
17 ) 18 )
18 19
19 // getDNSNames queries and returns the DNS names for the given instances, 20 // getDNSNames queries and returns the DNS names for the given instances,
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 62
62 // StateInfo is a reusable implementation of Environ.StateInfo, available to 63 // StateInfo is a reusable implementation of Environ.StateInfo, available to
63 // providers that also use the other functionality from this file. 64 // providers that also use the other functionality from this file.
64 func StateInfo(env environs.Environ) (*state.Info, *api.Info, error) { 65 func StateInfo(env environs.Environ) (*state.Info, *api.Info, error) {
65 st, err := bootstrap.LoadState(env.Storage()) 66 st, err := bootstrap.LoadState(env.Storage())
66 if err != nil { 67 if err != nil {
67 return nil, nil, err 68 return nil, nil, err
68 } 69 }
69 config := env.Config() 70 config := env.Config()
70 if _, hasCert := config.CACert(); !hasCert { 71 if _, hasCert := config.CACert(); !hasCert {
71 » » return nil, nil, fmt.Errorf("no CA certificate in environment co nfiguration") 72 » » return nil, nil, errors.Newf("no CA certificate in environment c onfiguration")
72 } 73 }
73 // Wait for the DNS names of any of the instances 74 // Wait for the DNS names of any of the instances
74 // to become available. 75 // to become available.
75 log.Debugf("waiting for DNS name(s) of state server instances %v", st.St ateInstances) 76 log.Debugf("waiting for DNS name(s) of state server instances %v", st.St ateInstances)
76 var hostnames []string 77 var hostnames []string
77 for a := LongAttempt.Start(); len(hostnames) == 0 && a.Next(); { 78 for a := LongAttempt.Start(); len(hostnames) == 0 && a.Next(); {
78 insts, err := env.Instances(st.StateInstances) 79 insts, err := env.Instances(st.StateInstances)
79 if err != nil && err != environs.ErrPartialInstances { 80 if err != nil && err != environs.ErrPartialInstances {
80 log.Debugf("error getting state instances: %v", err.Erro r()) 81 log.Debugf("error getting state instances: %v", err.Erro r())
81 return nil, nil, err 82 return nil, nil, err
82 } 83 }
83 hostnames = getDNSNames(insts) 84 hostnames = getDNSNames(insts)
84 } 85 }
85 86
86 if len(hostnames) == 0 { 87 if len(hostnames) == 0 {
87 » » return nil, nil, fmt.Errorf("timed out waiting for mgo address f rom %v", st.StateInstances) 88 » » return nil, nil, errors.Newf("timed out waiting for mgo address from %v", st.StateInstances)
88 } 89 }
89 90
90 stateInfo, apiInfo := getStateInfo(config, hostnames) 91 stateInfo, apiInfo := getStateInfo(config, hostnames)
91 return stateInfo, apiInfo, nil 92 return stateInfo, apiInfo, nil
92 } 93 }
OLDNEW
« no previous file with comments | « provider/common/polling_test.go ('k') | provider/dummy/environs.go » ('j') | no next file with comments »

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