示例#1
0
func printReplicasetMembers(session *mgo.Session) error {
	members, err := replicaset.CurrentMembers(session)
	if err != nil {
		return fmt.Errorf("cannot get replica set members: %v", err)
	}
	statusResult, err := replicaset.CurrentStatus(session)
	if err != nil {
		return fmt.Errorf("cannot get replica set status: %v", err)
	}
	statuses := make(map[int]*replicaset.MemberStatus)
	for i, status := range statusResult.Members {
		statuses[status.Id] = &statusResult.Members[i]
	}
	for _, m := range members {
		votes := 1
		if m.Votes != nil {
			votes = *m.Votes
		}
		status := statuses[m.Id]
		if status == nil {
			fmt.Printf("id %3v has no replica set status\n", m.Id)
		}
		fmt.Printf("id %3v; machine id %5q; address %50s; votes %v; healthy %v; state %v\n", m.Id, m.Tags["juju-machine-id"], m.Address, votes, status.Healthy, status.State)
	}
	return nil
}
示例#2
0
文件: shim.go 项目: imoapps/juju
func (s mongoSessionShim) CurrentStatus() (*replicaset.Status, error) {
	return replicaset.CurrentStatus(s.session)
}