Uniter solver #3072

Merged
merged 64 commits into from Aug 21, 2015
Commits
Jump to file or symbol
Failed to load files and symbols.
+3,582 −5,421
Split
@@ -165,24 +165,5 @@ func (ru *RelationUnit) ReadSettings(uname string) (params.Settings, error) {
// Watch returns a watcher that notifies of changes to counterpart
// units in the relation.
func (ru *RelationUnit) Watch() (watcher.RelationUnitsWatcher, error) {
- var results params.RelationUnitsWatchResults
- args := params.RelationUnits{
- RelationUnits: []params.RelationUnit{{
- Relation: ru.relation.tag.String(),
- Unit: ru.unit.tag.String(),
- }},
- }
- err := ru.st.facade.FacadeCall("WatchRelationUnits", args, &results)
- if err != nil {
- return nil, err
- }
- if len(results.Results) != 1 {
- return nil, fmt.Errorf("expected 1 result, got %d", len(results.Results))
- }
- result := results.Results[0]
- if result.Error != nil {
- return nil, result.Error
- }
- w := watcher.NewRelationUnitsWatcher(ru.st.facade.RawAPICaller(), result)
- return w, nil
+ return ru.st.WatchRelationUnits(ru.relation.tag, ru.unit.tag)
}
View
@@ -213,3 +213,9 @@ func (s *Service) Status(unitName string) (params.ServiceStatusResult, error) {
}
return result, nil
}
+
+// WatchLeadershipSettings returns a watcher which can be used to wait
+// for leadership settings changes to be made for the service.
+func (s *Service) WatchLeadershipSettings() (watcher.NotifyWatcher, error) {
+ return s.st.LeadershipSettings.WatchLeadershipSettings(s.tag.Id())
+}
View
@@ -359,6 +359,34 @@ func (st *State) AllMachinePorts(machineTag names.MachineTag) (map[network.PortR
return portsMap, nil
}
+// WatchRelationUnits returns a watcher that notifies of changes to the
+// counterpart units in the relation for the given unit.
+func (st *State) WatchRelationUnits(
+ relationTag names.RelationTag,
+ unitTag names.UnitTag,
+) (watcher.RelationUnitsWatcher, error) {
+ var results params.RelationUnitsWatchResults
+ args := params.RelationUnits{
+ RelationUnits: []params.RelationUnit{{
+ Relation: relationTag.String(),
+ Unit: unitTag.String(),
+ }},
+ }
+ err := st.facade.FacadeCall("WatchRelationUnits", args, &results)
+ if err != nil {
+ return nil, err
+ }
+ if len(results.Results) != 1 {
+ return nil, fmt.Errorf("expected 1 result, got %d", len(results.Results))
+ }
+ result := results.Results[0]
+ if result.Error != nil {
+ return nil, result.Error
+ }
+ w := watcher.NewRelationUnitsWatcher(st.facade.RawAPICaller(), result)
+ return w, nil
+}
+
// environment1dot16 requests just the UUID of the current environment, when
// using an older API server that does not support CurrentEnvironment API call.
func (st *State) environment1dot16() (*Environment, error) {
View
@@ -72,6 +72,10 @@ var upgradeOperations = func() []Operation {
version.MustParse("1.25.0"),
stepsFor125(),
},
+ upgradeToVersion{
+ version.MustParse("1.26.0"),
+ stepsFor126(),
+ },
}
return steps
}
View
@@ -0,0 +1,28 @@
+// Copyright 2015 Canonical Ltd.
+// Licensed under the AGPLv3, see LICENCE file for details.
+
+package upgrades
+
+import (
+ "github.com/juju/juju/worker/uniter"
+ "github.com/juju/names"
+)
+
+// stepsFor126 returns upgrade steps for Juju 1.26.
+func stepsFor126() []Step {
+ return []Step{
+ &upgradeStep{
+ description: "installed boolean needs to be set in the uniter local state",
+ targets: []Target{AllMachines},
+ run: func(context Context) error {
+ config := context.AgentConfig()
+ tag, ok := config.Tag().(names.UnitTag)
+ if !ok {
+ // not a Unit; skipping
+ return nil
+ }
+ return uniter.AddInstalledToUniterState(tag, config.DataDir())
+ },
+ },
+ }
+}
@@ -0,0 +1,24 @@
+// Copyright 2015 Canonical Ltd.
+// Licensed under the AGPLv3, see LICENCE file for details.
+
+package upgrades_test
+
+import (
+ gc "gopkg.in/check.v1"
+
+ "github.com/juju/juju/testing"
+ "github.com/juju/juju/version"
+)
+
+type steps126Suite struct {
+ testing.BaseSuite
+}
+
+var _ = gc.Suite(&steps126Suite{})
+
+func (s *steps126Suite) TestStepsFor126(c *gc.C) {
+ expected := []string{
+ "installed boolean needs to be set in the uniter local state",
+ }
+ assertSteps(c, version.MustParse("1.26.0"), expected)
+}
@@ -678,7 +678,7 @@ func (s *upgradeSuite) TestStateUpgradeOperationsVersions(c *gc.C) {
func (s *upgradeSuite) TestUpgradeOperationsVersions(c *gc.C) {
versions := extractUpgradeVersions(c, (*upgrades.UpgradeOperations)())
- c.Assert(versions, gc.DeepEquals, []string{"1.18.0", "1.22.0", "1.23.0", "1.24.0", "1.25.0"})
+ c.Assert(versions, gc.DeepEquals, []string{"1.18.0", "1.22.0", "1.23.0", "1.24.0", "1.25.0", "1.26.0"})
}
func extractUpgradeVersions(c *gc.C, ops []upgrades.Operation) []string {
View
@@ -0,0 +1,34 @@
+// Copyright 2012-2015 Canonical Ltd.
+// Licensed under the AGPLv3, see LICENCE file for details.
+
+package uniter
+
+import (
+ "github.com/juju/juju/apiserver/params"
+)
+
+// setAgentStatus sets the unit's status if it has changed since last time this method was called.
+func setAgentStatus(u *Uniter, status params.Status, info string, data map[string]interface{}) error {
+ u.setStatusMutex.Lock()
+ defer u.setStatusMutex.Unlock()
+ if u.lastReportedStatus == status && u.lastReportedMessage == info {
+ return nil
+ }
+ u.lastReportedStatus = status
+ u.lastReportedMessage = info
+ logger.Debugf("[AGENT-STATUS] %s: %s", status, info)
+ return u.unit.SetAgentStatus(status, info, data)
+}
+
+// reportAgentError reports if there was an error performing an agent operation.
+func reportAgentError(u *Uniter, userMessage string, err error) {
+ // If a non-nil error is reported (e.g. due to an operation failing),
+ // set the agent status to Failed.
+ if err == nil {
+ return
+ }
+ err2 := setAgentStatus(u, params.StatusFailed, userMessage, nil)
+ if err2 != nil {
+ logger.Errorf("updating agent status: %v", err2)
+ }
+}
@@ -1,64 +0,0 @@
-// Copyright 2013, 2014 Canonical Ltd.
-// Licensed under the AGPLv3, see LICENCE file for details.
-
-package uniter
-
-import (
- "fmt"
- "time"
-
- "github.com/juju/juju/testing"
-)
-
-func SetUniterObserver(u *Uniter, observer UniterExecutionObserver) {
- u.observer = observer
-}
-
-var (
- ActiveCollectMetricsTimer = &activeCollectMetricsTimer
- ActiveSendMetricsTimer = &activeSendMetricsTimer
- IdleWaitTime = &idleWaitTime
- LeadershipGuarantee = &leadershipGuarantee
-)
-
-// manualTicker will be used to generate collect-metrics events
-// in a time-independent manner for testing.
-type ManualTicker struct {
- c chan time.Time
-}
-
-// Tick sends a signal on the ticker channel.
-func (t *ManualTicker) Tick() error {
- select {
- case t.c <- time.Now():
- case <-time.After(testing.LongWait):
- return fmt.Errorf("ticker channel blocked")
- }
- return nil
-}
-
-// ReturnTimer can be used to replace the metrics signal generator.
-func (t *ManualTicker) ReturnTimer(now, lastRun time.Time, interval time.Duration) <-chan time.Time {
- return t.c
-}
-
-func NewManualTicker() *ManualTicker {
- return &ManualTicker{
- c: make(chan time.Time),
- }
-}
-
-func NewTestingMetricsTimerChooser(collector TimedSignal) *timerChooser {
- return &timerChooser{
- collector: collector,
- inactive: inactiveMetricsTimer,
- }
-}
-
-func UpdateStatusSignal(now, lastSignal time.Time, interval time.Duration) <-chan time.Time {
- return updateStatusSignal(now, lastSignal, interval)
-}
-
-func ActiveCollectMetricsSignal(now, lastSignal time.Time, interval time.Duration) <-chan time.Time {
- return activeCollectMetricsTimer(now, lastSignal, interval)
-}
@@ -1,10 +0,0 @@
-// Copyright 2015 Canonical Ltd.
-// Licensed under the AGPLv3, see LICENCE file for details.
-
-package filter
-
-func DummyFilter() Filter {
- // This should, obviously, not be used except for type tests that don't
- // try to do anything with it (eg TestOutput*).
- return &filter{}
-}
Oops, something went wrong.