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

Side by Side Diff: worker/peergrouper/initiate.go

Issue 88790043: HA: upgrade upstart and initiate replset
Patch Set: HA: upgrade upstart and initiate replset Created 10 years, 11 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
« no previous file with comments | « worker/peergrouper/desired_test.go ('k') | worker/peergrouper/initiate_test.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 2014 Canonical Ltd. 1 // Copyright 2014 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 peergrouper 4 package peergrouper
5 5
6 import ( 6 import (
7 "fmt" 7 "fmt"
8 8
9 "labix.org/v2/mgo" 9 "labix.org/v2/mgo"
10 10
(...skipping 21 matching lines...) Expand all
32 // If no existing configuration is found one is created using Initiate. 32 // If no existing configuration is found one is created using Initiate.
33 func MaybeInitiateMongoServer(p InitiateMongoParams) error { 33 func MaybeInitiateMongoServer(p InitiateMongoParams) error {
34 logger.Debugf("Initiating mongo replicaset; dialInfo %#v; memberHostport %q; user %q; password %q", p.DialInfo, p.MemberHostPort, p.User, p.Password) 34 logger.Debugf("Initiating mongo replicaset; dialInfo %#v; memberHostport %q; user %q; password %q", p.DialInfo, p.MemberHostPort, p.User, p.Password)
35 defer logger.Infof("finished MaybeInitiateMongoServer") 35 defer logger.Infof("finished MaybeInitiateMongoServer")
36 36
37 if len(p.DialInfo.Addrs) > 1 { 37 if len(p.DialInfo.Addrs) > 1 {
38 logger.Infof("more than one member; replica set must be already initiated") 38 logger.Infof("more than one member; replica set must be already initiated")
39 return nil 39 return nil
40 } 40 }
41 p.DialInfo.Direct = true 41 p.DialInfo.Direct = true
42
43 // TODO(rog) remove this code when we no longer need to upgrade
44 // from pre-HA-capable environments.
45 if p.User != "" {
46 p.DialInfo.Username = p.User
47 p.DialInfo.Password = p.Password
48 }
49
42 session, err := mgo.DialWithInfo(p.DialInfo) 50 session, err := mgo.DialWithInfo(p.DialInfo)
43 if err != nil { 51 if err != nil {
44 return fmt.Errorf("can't dial mongo to initiate replicaset: %v", err) 52 return fmt.Errorf("can't dial mongo to initiate replicaset: %v", err)
45 } 53 }
46 defer session.Close() 54 defer session.Close()
47 55
48 // TODO(rog) remove this code when we no longer need to upgrade
49 // from pre-HA-capable environments.
50 if p.User != "" {
51 err := session.DB("admin").Login(p.User, p.Password)
52 if err != nil {
53 logger.Errorf("cannot login to admin db as %q, password %q, falling back: %v", p.User, p.Password, err)
54 }
55 }
56 cfg, err := replicaset.CurrentConfig(session) 56 cfg, err := replicaset.CurrentConfig(session)
57 if err == nil && len(cfg.Members) > 0 { 57 if err == nil && len(cfg.Members) > 0 {
58 logger.Infof("replica set configuration already found: %#v", cfg ) 58 logger.Infof("replica set configuration already found: %#v", cfg )
59 return nil 59 return nil
60 } 60 }
61 if err != nil && err != mgo.ErrNotFound { 61 if err != nil && err != mgo.ErrNotFound {
62 return fmt.Errorf("cannot get replica set configuration: %v", er r) 62 return fmt.Errorf("cannot get replica set configuration: %v", er r)
63 } 63 }
64 err = replicaset.Initiate( 64 err = replicaset.Initiate(
65 session, 65 session,
66 p.MemberHostPort, 66 p.MemberHostPort,
67 mongo.ReplicaSetName, 67 mongo.ReplicaSetName,
68 map[string]string{ 68 map[string]string{
69 jujuMachineTag: agent.BootstrapMachineId, 69 jujuMachineTag: agent.BootstrapMachineId,
70 }, 70 },
71 ) 71 )
72 if err != nil { 72 if err != nil {
73 return fmt.Errorf("cannot initiate replica set: %v", err) 73 return fmt.Errorf("cannot initiate replica set: %v", err)
74 } 74 }
75 return nil 75 return nil
76 } 76 }
OLDNEW
« no previous file with comments | « worker/peergrouper/desired_test.go ('k') | worker/peergrouper/initiate_test.go » ('j') | no next file with comments »

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