-
Notifications
You must be signed in to change notification settings - Fork 501
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Weave the new presence code through the apiserver.
- Loading branch information
Showing
32 changed files
with
497 additions
and
125 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Copyright 2018 Canonical Ltd. | ||
// Licensed under the AGPLv3, see LICENCE file for details. | ||
|
||
package common | ||
|
||
import ( | ||
"gopkg.in/juju/names.v2" | ||
|
||
"github.com/juju/juju/core/presence" | ||
) | ||
|
||
// ModelPresence represents the API server connections for a model. | ||
type ModelPresence interface { | ||
// For a given non controller agent, return the Status for that agent. | ||
AgentStatus(agent string) (presence.Status, error) | ||
} | ||
|
||
// ModelPresenceContext represents the known agent presence state for the | ||
// entire model. | ||
type ModelPresenceContext struct { | ||
// Presence represents the API server connections for a model. | ||
// If this is non-nil it is used in preference to the state AgentPresence method. | ||
Presence ModelPresence | ||
} | ||
|
||
func (c *ModelPresenceContext) machinePresence(machine MachineStatusGetter) (bool, error) { | ||
if c.Presence == nil { | ||
return machine.AgentPresence() | ||
} | ||
agent := names.NewMachineTag(machine.Id()) | ||
status, err := c.Presence.AgentStatus(agent.String()) | ||
return status == presence.Alive, err | ||
} | ||
|
||
func (c *ModelPresenceContext) unitPresence(unit UnitStatusGetter) (bool, error) { | ||
if c.Presence == nil { | ||
return unit.AgentPresence() | ||
} | ||
agent := names.NewUnitTag(unit.Name()) | ||
status, err := c.Presence.AgentStatus(agent.String()) | ||
return status == presence.Alive, err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Copyright 2018 Canonical Ltd. | ||
// Licensed under the AGPLv3, see LICENCE file for details. | ||
|
||
package common_test | ||
|
||
import ( | ||
"github.com/juju/errors" | ||
|
||
"github.com/juju/juju/apiserver/common" | ||
"github.com/juju/juju/core/presence" | ||
) | ||
|
||
func allAlive() common.ModelPresence { | ||
return &fakeModelPresence{status: presence.Alive} | ||
} | ||
|
||
func agentsDown() common.ModelPresence { | ||
return &fakeModelPresence{status: presence.Missing} | ||
} | ||
|
||
func presenceError() common.ModelPresence { | ||
return &fakeModelPresence{err: errors.New("boom")} | ||
} | ||
|
||
type fakeModelPresence struct { | ||
status presence.Status | ||
err error | ||
} | ||
|
||
func (f *fakeModelPresence) AgentStatus(agent string) (presence.Status, error) { | ||
return f.status, f.err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.