func launchUnits(f scheduler.Scheduler, units scheduler.UnitDataList, ui *stateUI) error { ui.Verbosef("Starting %#v\n", units) ui.MessageSink <- fmt.Sprintf("Starting %d unit(s)", units.Len()) if err := f.Start(ui.EventSink, units); err != nil { return maskAny(err) } return nil }
// isFailedPredicate creates a predicate that returns true when the given unit file is in the failed status. func (d *Deployment) isFailedPredicate(sg scalingGroupUnits, f scheduler.Scheduler, ui *stateUI) func(string) bool { return func(unitName string) bool { ui.MessageSink <- fmt.Sprintf("Checking state of %s", unitName) unitState, err := f.GetState(unitName) if scheduler.IsNotFound(err) { ui.Verbosef("Unit '%s' is not found\n", unitName) return true } else if err != nil { ui.Warningf("GetState(%s) failed: %#v", unitName, err) } if unitState.Failed { ui.Verbosef("Unit '%s' is in failed state\n", unitName) return true } return false } }
func (d *Deployment) destroyUnits(f scheduler.Scheduler, units []string, ui *stateUI) error { if len(units) == 0 { return maskAny(fmt.Errorf("No units on cluster: %s", d.cluster.Stack)) } ui.MessageSink <- fmt.Sprintf("Stopping %d unit(s)", len(units)) stats, err := f.Stop(ui.EventSink, units...) if err != nil { ui.Warningf("Warning: stop failed.\n%s\n", err.Error()) } if stats.StoppedGlobalUnits > 0 { InterruptibleSleep(ui.MessageSink, d.StopDelay, "Waiting for %s...") } ui.MessageSink <- fmt.Sprintf("Destroying %d unit(s)", len(units)) if err := f.Destroy(ui.EventSink, units...); err != nil { return maskAny(err) } return nil }
// isModifiedPredicate creates a predicate that returns true when the given unit file is modified func (d *Deployment) isModifiedPredicate(sg scalingGroupUnits, f scheduler.Scheduler, ui *stateUI) func(string) bool { return func(unitName string) bool { if d.force { return true } ui.MessageSink <- fmt.Sprintf("Checking %s for modifications", unitName) cat, err := f.Cat(unitName) if err != nil { ui.Verbosef("Failed to cat '%s': %#v\n", unitName, err) return true // Assume it is modified } newUnit, err := sg.get(unitName) if err != nil { ui.Verbosef("Failed to read new '%s' unit: %#v\n", unitName, err) return true // Assume it is modified } if !compareUnitContent(unitName, cat, newUnit.Content(), ui) { return true } ui.Verbosef("Unit '%s' has not changed\n", unitName) return false } }