本文整理汇总了Golang中launchpad/net/juju-core/state/watcher.MustErr函数的典型用法代码示例。如果您正苦于以下问题:Golang MustErr函数的具体用法?Golang MustErr怎么用?Golang MustErr使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了MustErr函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: loop
func (w *RelationUnitsWatcher) loop() (err error) {
sentInitial := false
changes := RelationUnitsChange{}
out := w.out
out = nil
for {
select {
case <-w.st.watcher.Dead():
return watcher.MustErr(w.st.watcher)
case <-w.tomb.Dying():
return tomb.ErrDying
case c, ok := <-w.sw.Changes():
if !ok {
return watcher.MustErr(w.sw)
}
if err = w.mergeScope(&changes, c); err != nil {
return err
}
if !sentInitial || !changes.empty() {
out = w.out
} else {
out = nil
}
case c := <-w.updates:
if _, err = w.mergeSettings(&changes, c.Id.(string)); err != nil {
return err
}
out = w.out
case out <- changes:
sentInitial = true
changes = RelationUnitsChange{}
out = nil
}
}
}
示例2: loop
func (w *EnvironConfigWatcher) loop() (err error) {
sw := w.st.watchSettings(environGlobalKey)
defer sw.Stop()
out := w.out
out = nil
cfg := &config.Config{}
for {
select {
case <-w.st.watcher.Dead():
return watcher.MustErr(w.st.watcher)
case <-w.tomb.Dying():
return tomb.ErrDying
case settings, ok := <-sw.Changes():
if !ok {
return watcher.MustErr(sw)
}
cfg, err = config.New(settings.Map())
if err == nil {
out = w.out
} else {
out = nil
}
case out <- cfg:
out = nil
}
}
return nil
}
示例3: TestMustErr
func (s *WatcherSuite) TestMustErr(c *C) {
err := watcher.MustErr(&dummyWatcher{errors.New("POW")})
c.Assert(err, ErrorMatches, "POW")
stillAlive := func() { watcher.MustErr(&dummyWatcher{tomb.ErrStillAlive}) }
c.Assert(stillAlive, PanicMatches, "watcher is still running")
noErr := func() { watcher.MustErr(&dummyWatcher{nil}) }
c.Assert(noErr, PanicMatches, "watcher was stopped cleanly")
}
示例4: loop
func (q *AliveHookQueue) loop(initial *State) {
defer q.tomb.Done()
defer watcher.Stop(q.w, &q.tomb)
// Consume initial event, and reconcile with initial state, by inserting
// a new RelationUnitsChange before the initial event, which schedules
// every missing unit for immediate departure before anything else happens
// (apart from a single potential required post-joined changed event).
ch1, ok := <-q.w.Changes()
if !ok {
q.tomb.Kill(watcher.MustErr(q.w))
return
}
if len(ch1.Departed) != 0 {
panic("AliveHookQueue must be started with a fresh RelationUnitsWatcher")
}
q.changedPending = initial.ChangedPending
ch0 := state.RelationUnitsChange{}
for unit, version := range initial.Members {
q.info[unit] = &unitInfo{
unit: unit,
version: version,
joined: true,
}
if _, found := ch1.Changed[unit]; !found {
ch0.Departed = append(ch0.Departed, unit)
}
}
q.update(ch0)
q.update(ch1)
var next hook.Info
var out chan<- hook.Info
for {
if q.empty() {
out = nil
} else {
out = q.out
next = q.next()
}
select {
case <-q.tomb.Dying():
return
case ch, ok := <-q.w.Changes():
if !ok {
q.tomb.Kill(watcher.MustErr(q.w))
return
}
q.update(ch)
case out <- next:
q.pop()
}
}
}
示例5: loop
func (p *Provisioner) loop() error {
environWatcher := p.st.WatchEnvironConfig()
defer watcher.Stop(environWatcher, &p.tomb)
var err error
p.environ, err = worker.WaitForEnviron(environWatcher, p.tomb.Dying())
if err != nil {
return err
}
// Get a new StateInfo from the environment: the one used to
// launch the agent may refer to localhost, which will be
// unhelpful when attempting to run an agent on a new machine.
if p.stateInfo, p.apiInfo, err = p.environ.StateInfo(); err != nil {
return err
}
// Call processMachines to stop any unknown instances before watching machines.
if err := p.processMachines(nil); err != nil {
return err
}
// Start responding to changes in machines, and to any further updates
// to the environment config.
machinesWatcher := p.st.WatchMachines()
defer watcher.Stop(machinesWatcher, &p.tomb)
// START OMIT
// launchpad.net/juju-core/worker/provisioner/provisioner.go
for {
select {
case <-p.tomb.Dying():
return tomb.ErrDying
case cfg, ok := <-environWatcher.Changes():
if !ok {
return watcher.MustErr(environWatcher)
}
if err := p.setConfig(cfg); err != nil {
log.Errorf("worker/provisioner: loaded invalid environment configuration: %v", err)
}
case ids, ok := <-machinesWatcher.Changes():
if !ok {
return watcher.MustErr(machinesWatcher)
}
if err := p.processMachines(ids); err != nil {
return err
}
}
}
// END OMIT
panic("not reached")
}
示例6: loop
func (task *provisionerTask) loop() error {
logger.Infof("Starting up provisioner task %s", task.machineId)
defer watcher.Stop(task.machineWatcher, &task.tomb)
// When the watcher is started, it will have the initial changes be all
// the machines that are relevant. Also, since this is available straight
// away, we know there will be some changes right off the bat.
for {
select {
case <-task.tomb.Dying():
logger.Infof("Shutting down provisioner task %s", task.machineId)
return tomb.ErrDying
case ids, ok := <-task.machineWatcher.Changes():
if !ok {
return watcher.MustErr(task.machineWatcher)
}
// TODO(dfc; lp:1042717) fire process machines periodically to shut down unknown
// instances.
if err := task.processMachines(ids); err != nil {
logger.Errorf("Process machines failed: %v", err)
return err
}
}
}
}
示例7: loop
func (w *minUnitsWatcher) loop() (err error) {
ch := make(chan watcher.Change)
w.st.watcher.WatchCollection(w.st.minUnits.Name, ch)
defer w.st.watcher.UnwatchCollection(w.st.minUnits.Name, ch)
serviceNames, err := w.initial()
if err != nil {
return err
}
out := w.out
for {
select {
case <-w.tomb.Dying():
return tomb.ErrDying
case change, ok := <-ch:
if !ok {
return watcher.MustErr(w.st.watcher)
}
if err = w.merge(serviceNames, change); err != nil {
return err
}
if !serviceNames.IsEmpty() {
out = w.out
}
case out <- serviceNames.Values():
out = nil
serviceNames = new(set.Strings)
}
}
return nil
}
示例8: Watch
// Watch starts an NotifyWatcher for each given machine.
func (m *MachinerAPI) Watch(args params.Entities) (params.NotifyWatchResults, error) {
result := params.NotifyWatchResults{
Results: make([]params.NotifyWatchResult, len(args.Entities)),
}
if len(args.Entities) == 0 {
return result, nil
}
for i, entity := range args.Entities {
err := common.ErrPerm
if m.auth.AuthOwner(entity.Tag) {
var machine *state.Machine
machine, err = m.st.Machine(state.MachineIdFromTag(entity.Tag))
if err == nil {
watch := machine.Watch()
// Consume the initial event. Technically, API
// calls to Watch 'transmit' the initial event
// in the Watch response. But NotifyWatchers
// have no state to transmit.
if _, ok := <-watch.Changes(); ok {
result.Results[i].NotifyWatcherId = m.resources.Register(watch)
} else {
err = watcher.MustErr(watch)
}
}
}
result.Results[i].Error = common.ServerError(err)
}
return result, nil
}
示例9: addRelation
// addRelation causes the unit agent to join the supplied relation, and to
// store persistent state in the supplied dir.
func (u *Uniter) addRelation(rel *state.Relation, dir *relation.StateDir) error {
log.Printf("worker/uniter: joining relation %q", rel)
ru, err := rel.Unit(u.unit)
if err != nil {
return err
}
r := NewRelationer(ru, dir, u.relationHooks)
w := u.unit.Watch()
defer watcher.Stop(w, &u.tomb)
for {
select {
case <-u.tomb.Dying():
return tomb.ErrDying
case _, ok := <-w.Changes():
if !ok {
return watcher.MustErr(w)
}
if err := r.Join(); err == state.ErrCannotEnterScopeYet {
log.Printf("worker/uniter: cannot enter scope for relation %q; waiting for subordinate to be removed", rel)
continue
} else if err != nil {
return err
}
log.Printf("worker/uniter: joined relation %q", rel)
u.relationers[rel.Id()] = r
return nil
}
}
panic("unreachable")
}
示例10: loop
func (d *Deployer) loop(w *state.UnitsWatcher) error {
deployed, err := d.mgr.DeployedUnits()
if err != nil {
return err
}
for _, unitName := range deployed {
d.deployed[unitName] = true
if err := d.changed(unitName); err != nil {
return err
}
}
for {
select {
case <-d.tomb.Dying():
return tomb.ErrDying
case changes, ok := <-w.Changes():
if !ok {
return watcher.MustErr(w)
}
for _, unitName := range changes {
if err := d.changed(unitName); err != nil {
return err
}
}
}
}
panic("unreachable")
}
示例11: loop
func (d *Deployer) loop() error {
machine, err := d.st.Machine(d.machineId)
if err != nil {
return err
}
machineUnitsWatcher := machine.WatchUnits()
defer watcher.Stop(machineUnitsWatcher, &d.tomb)
deployed, err := d.ctx.DeployedUnits()
if err != nil {
return err
}
for _, unitName := range deployed {
d.deployed.Add(unitName)
if err := d.changed(unitName); err != nil {
return err
}
}
for {
select {
case <-d.tomb.Dying():
return tomb.ErrDying
case changes, ok := <-machineUnitsWatcher.Changes():
if !ok {
return watcher.MustErr(machineUnitsWatcher)
}
for _, unitName := range changes {
if err := d.changed(unitName); err != nil {
return err
}
}
}
}
panic("unreachable")
}
示例12: startMachine
// startMachine creates a new data value for tracking details of the
// machine and starts watching the machine for units added or removed.
func (fw *Firewaller) startMachine(id string) error {
machined := &machineData{
fw: fw,
id: id,
unitds: make(map[string]*unitData),
ports: make([]instance.Port, 0),
}
m, err := machined.machine()
if errors.IsNotFoundError(err) {
return nil
} else if err != nil {
return fmt.Errorf("worker/firewaller: cannot watch machine units: %v", err)
}
unitw := m.WatchUnits()
select {
case <-fw.tomb.Dying():
stop("units watcher", unitw)
return tomb.ErrDying
case change, ok := <-unitw.Changes():
if !ok {
stop("units watcher", unitw)
return watcher.MustErr(unitw)
}
fw.machineds[id] = machined
err = fw.unitsChanged(&unitsChange{machined, change})
if err != nil {
stop("units watcher", unitw)
return fmt.Errorf("worker/firewaller: cannot respond to units changes for machine %q: %v", id, err)
}
}
go machined.watchLoop(unitw)
return nil
}
示例13: watchLoop
// watchLoop watches the unit for port changes.
func (ud *unitData) watchLoop(latestPorts []instance.Port) {
defer ud.tomb.Done()
w := ud.unit.Watch()
defer watcher.Stop(w, &ud.tomb)
for {
select {
case <-ud.tomb.Dying():
return
case _, ok := <-w.Changes():
if !ok {
ud.fw.tomb.Kill(watcher.MustErr(w))
return
}
if err := ud.unit.Refresh(); err != nil {
if !errors.IsNotFoundError(err) {
ud.fw.tomb.Kill(err)
}
return
}
change := ud.unit.OpenedPorts()
if samePorts(change, latestPorts) {
continue
}
latestPorts = append(latestPorts[:0], change...)
select {
case ud.fw.portsChange <- &portsChange{ud, change}:
case <-ud.tomb.Dying():
return
}
}
}
}
示例14: ModeTerminating
// ModeTerminating marks the unit dead and returns ErrTerminateAgent.
func ModeTerminating(u *Uniter) (next Mode, err error) {
defer modeContext("ModeTerminating", &err)()
if err = u.unit.SetStatus(params.StatusStopped, ""); err != nil {
return nil, err
}
w := u.unit.Watch()
defer watcher.Stop(w, &u.tomb)
for {
select {
case <-u.tomb.Dying():
return nil, tomb.ErrDying
case _, ok := <-w.Changes():
if !ok {
return nil, watcher.MustErr(w)
}
if err := u.unit.Refresh(); err != nil {
return nil, err
}
if len(u.unit.SubordinateNames()) > 0 {
continue
}
// The unit is known to be Dying; so if it didn't have subordinates
// just above, it can't acquire new ones before this call.
if err := u.unit.EnsureDead(); err != nil {
return nil, err
}
return nil, worker.ErrTerminateAgent
}
}
}
示例15: loop
func (p *Provisioner) loop() error {
environWatcher := p.st.WatchEnvironConfig()
defer watcher.Stop(environWatcher, &p.tomb)
var err error
p.environ, err = worker.WaitForEnviron(environWatcher, p.tomb.Dying())
if err != nil {
return err
}
auth, err := NewSimpleAuthenticator(p.environ)
if err != nil {
return err
}
// Start a new worker for the environment provider.
// Start responding to changes in machines, and to any further updates
// to the environment config.
instanceBroker, err := p.getBroker()
if err != nil {
return err
}
machineWatcher, err := p.getWatcher()
if err != nil {
return err
}
environmentProvisioner := NewProvisionerTask(
p.machineId,
p.st,
machineWatcher,
instanceBroker,
auth)
defer watcher.Stop(environmentProvisioner, &p.tomb)
for {
select {
case <-p.tomb.Dying():
return tomb.ErrDying
case <-environmentProvisioner.Dying():
err := environmentProvisioner.Err()
logger.Errorf("environment provisioner died: %v", err)
return err
case cfg, ok := <-environWatcher.Changes():
if !ok {
return watcher.MustErr(environWatcher)
}
if err := p.setConfig(cfg); err != nil {
logger.Errorf("loaded invalid environment configuration: %v", err)
}
}
}
panic("not reached")
}