Skip to content

Commit

Permalink
Merge pull request #153 from davecheney/112-state-life-takes-a-tag
Browse files Browse the repository at this point in the history
api, apiserver: internal life methods now take a names.Tag
  • Loading branch information
jujubot committed Jun 25, 2014
2 parents fa4f610 + 935fbc7 commit e01ac93
Show file tree
Hide file tree
Showing 16 changed files with 36 additions and 40 deletions.
12 changes: 6 additions & 6 deletions state/api/common/life.go
Expand Up @@ -4,25 +4,25 @@
package common

import (
"fmt"
"github.com/juju/errors"
"github.com/juju/names"

"github.com/juju/juju/state/api/base"
"github.com/juju/juju/state/api/params"
)

// Life requests the life cycle of the given entity from the given
// server-side API facade via the given caller.
func Life(caller base.Caller, facadeName, tag string) (params.Life, error) {
func Life(caller base.Caller, facadeName string, tag names.Tag) (params.Life, error) {
var result params.LifeResults
args := params.Entities{
Entities: []params.Entity{{Tag: tag}},
Entities: []params.Entity{{Tag: tag.String()}},
}
err := caller.Call(facadeName, "", "Life", args, &result)
if err != nil {
if err := caller.Call(facadeName, "", "Life", args, &result); err != nil {
return "", err
}
if len(result.Results) != 1 {
return "", fmt.Errorf("expected 1 result, got %d", len(result.Results))
return "", errors.Errorf("expected 1 result, got %d", len(result.Results))
}
if err := result.Results[0].Error; err != nil {
return "", err
Expand Down
6 changes: 3 additions & 3 deletions state/api/deployer/deployer.go
Expand Up @@ -34,17 +34,17 @@ func (st *State) call(method string, params, result interface{}) error {
}

// unitLife returns the lifecycle state of the given unit.
func (st *State) unitLife(tag string) (params.Life, error) {
func (st *State) unitLife(tag names.Tag) (params.Life, error) {
return common.Life(st.caller, deployerFacade, tag)
}

// Unit returns the unit with the given tag.
func (st *State) Unit(unitTag string) (*Unit, error) {
life, err := st.unitLife(unitTag)
tag, err := names.ParseUnitTag(unitTag)
if err != nil {
return nil, err
}
tag, err := names.ParseUnitTag(unitTag)
life, err := st.unitLife(tag)
if err != nil {
return nil, err
}
Expand Down
3 changes: 0 additions & 3 deletions state/api/deployer/deployer_test.go
Expand Up @@ -134,9 +134,6 @@ func (s *deployerSuite) TestUnit(c *gc.C) {
unit, err := s.st.Unit("unit-foo-42")
s.assertUnauthorized(c, err)
c.Assert(unit, gc.IsNil)
unit, err = s.st.Unit("42")
s.assertUnauthorized(c, err)
c.Assert(unit, gc.IsNil)

// Try getting a unit we're not responsible for.
// First create a new machine and deploy another unit there.
Expand Down
2 changes: 1 addition & 1 deletion state/api/deployer/unit.go
Expand Up @@ -33,7 +33,7 @@ func (u *Unit) Life() params.Life {

// Refresh updates the cached local copy of the unit's data.
func (u *Unit) Refresh() error {
life, err := u.st.unitLife(u.tag.String())
life, err := u.st.unitLife(u.tag)
if err != nil {
return err
}
Expand Down
10 changes: 5 additions & 5 deletions state/api/firewaller/firewaller.go
Expand Up @@ -33,17 +33,17 @@ func NewState(caller base.Caller) *State {
}

// life requests the life cycle of the given entity from the server.
func (st *State) life(tag string) (params.Life, error) {
func (st *State) life(tag names.Tag) (params.Life, error) {
return common.Life(st.caller, firewallerFacade, tag)
}

// Unit provides access to methods of a state.Unit through the facade.
func (st *State) Unit(unitTag string) (*Unit, error) {
life, err := st.life(unitTag)
tag, err := names.ParseUnitTag(unitTag)
if err != nil {
return nil, err
}
tag, err := names.ParseUnitTag(unitTag)
life, err := st.life(tag)
if err != nil {
return nil, err
}
Expand All @@ -57,11 +57,11 @@ func (st *State) Unit(unitTag string) (*Unit, error) {
// Machine provides access to methods of a state.Machine through the
// facade.
func (st *State) Machine(machineTag string) (*Machine, error) {
life, err := st.life(machineTag)
tag, err := names.ParseMachineTag(machineTag)
if err != nil {
return nil, err
}
tag, err := names.ParseMachineTag(machineTag)
life, err := st.life(tag)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion state/api/firewaller/service.go
Expand Up @@ -38,7 +38,7 @@ func (s *Service) Life() params.Life {
// Refresh refreshes the contents of the Service from the underlying
// state.
func (s *Service) Refresh() error {
life, err := s.st.life(s.tag.String())
life, err := s.st.life(s.tag)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion state/api/firewaller/unit.go
Expand Up @@ -33,7 +33,7 @@ func (u *Unit) Life() params.Life {

// Refresh updates the cached local copy of the unit's data.
func (u *Unit) Refresh() error {
life, err := u.st.life(u.tag.String())
life, err := u.st.life(u.tag)
if err != nil {
return err
}
Expand Down
3 changes: 1 addition & 2 deletions state/api/machiner/machine.go
Expand Up @@ -31,8 +31,7 @@ func (m *Machine) Life() params.Life {

// Refresh updates the cached local copy of the machine's data.
func (m *Machine) Refresh() error {
// TODO(dfc) machineLife should take a tag.
life, err := m.st.machineLife(m.tag.String())
life, err := m.st.machineLife(m.tag)
if err != nil {
return err
}
Expand Down
6 changes: 3 additions & 3 deletions state/api/machiner/machiner.go
Expand Up @@ -33,17 +33,17 @@ func NewState(caller base.Caller) *State {
}

// machineLife requests the lifecycle of the given machine from the server.
func (st *State) machineLife(tag string) (params.Life, error) {
func (st *State) machineLife(tag names.Tag) (params.Life, error) {
return common.Life(st.caller, machinerFacade, tag)
}

// Machine provides access to methods of a state.Machine through the facade.
func (st *State) Machine(machineTag string) (*Machine, error) {
life, err := st.machineLife(machineTag)
tag, err := names.ParseMachineTag(machineTag)
if err != nil {
return nil, err
}
tag, err := names.ParseMachineTag(machineTag)
life, err := st.machineLife(tag)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion state/api/provisioner/machine.go
Expand Up @@ -42,7 +42,7 @@ func (m *Machine) Life() params.Life {

// Refresh updates the cached local copy of the machine's data.
func (m *Machine) Refresh() error {
life, err := m.st.machineLife(m.tag.String())
life, err := m.st.machineLife(m.tag)
if err != nil {
return err
}
Expand Down
6 changes: 3 additions & 3 deletions state/api/provisioner/provisioner.go
Expand Up @@ -38,17 +38,17 @@ func (st *State) call(method string, params, result interface{}) error {
}

// machineLife requests the lifecycle of the given machine from the server.
func (st *State) machineLife(tag string) (params.Life, error) {
func (st *State) machineLife(tag names.Tag) (params.Life, error) {
return common.Life(st.caller, provisionerFacade, tag)
}

// Machine provides access to methods of a state.Machine through the facade.
func (st *State) Machine(machineTag string) (*Machine, error) {
life, err := st.machineLife(machineTag)
tag, err := names.ParseMachineTag(machineTag)
if err != nil {
return nil, err
}
tag, err := names.ParseMachineTag(machineTag)
life, err := st.machineLife(tag)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion state/api/uniter/service.go
Expand Up @@ -69,7 +69,7 @@ func (s *Service) Life() params.Life {
// Refresh refreshes the contents of the Service from the underlying
// state.
func (s *Service) Refresh() error {
life, err := s.st.life(s.tag.String())
life, err := s.st.life(s.tag)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion state/api/uniter/unit.go
Expand Up @@ -44,7 +44,7 @@ func (u *Unit) Life() params.Life {

// Refresh updates the cached local copy of the unit's data.
func (u *Unit) Refresh() error {
life, err := u.st.life(u.tag.String())
life, err := u.st.life(u.tag)
if err != nil {
return err
}
Expand Down
10 changes: 5 additions & 5 deletions state/api/uniter/uniter.go
Expand Up @@ -41,7 +41,7 @@ func (st *State) call(method string, params, results interface{}) error {
}

// life requests the lifecycle of the given entity from the server.
func (st *State) life(tag string) (params.Life, error) {
func (st *State) life(tag names.Tag) (params.Life, error) {
return common.Life(st.caller, uniterFacade, tag)
}

Expand Down Expand Up @@ -69,11 +69,11 @@ func (st *State) relation(relationTag, unitTag string) (params.RelationResult, e

// Unit provides access to methods of a state.Unit through the facade.
func (st *State) Unit(unitTag string) (*Unit, error) {
life, err := st.life(unitTag)
tag, err := names.ParseUnitTag(unitTag)
if err != nil {
return nil, err
}
tag, err := names.ParseUnitTag(unitTag)
life, err := st.life(tag)
if err != nil {
return nil, err
}
Expand All @@ -86,11 +86,11 @@ func (st *State) Unit(unitTag string) (*Unit, error) {

// Service returns a service state by tag.
func (st *State) Service(serviceTag string) (*Service, error) {
life, err := st.life(serviceTag)
tag, err := names.ParseServiceTag(serviceTag)
if err != nil {
return nil, err
}
tag, err := names.ParseServiceTag(serviceTag)
life, err := st.life(tag)
if err != nil {
return nil, err
}
Expand Down
6 changes: 3 additions & 3 deletions state/apiserver/login_test.go
Expand Up @@ -119,15 +119,15 @@ func (s *loginSuite) TestBadLogin(c *gc.C) {
c.Assert(err, gc.IsNil)
defer st.Close()

_, err = st.Machiner().Machine("0")
_, err = st.Machiner().Machine("machine-0")
c.Assert(err, gc.ErrorMatches, `unknown object type "Machiner"`)

// Since these are user login tests, the nonce is empty.
err = st.Login(t.tag, t.password, "")
c.Assert(err, gc.ErrorMatches, t.err)
c.Assert(params.ErrCode(err), gc.Equals, t.code)

_, err = st.Machiner().Machine("0")
_, err = st.Machiner().Machine("machine-0")
c.Assert(err, gc.ErrorMatches, `unknown object type "Machiner"`)
}()
}
Expand Down Expand Up @@ -524,7 +524,7 @@ func (s *loginSuite) runLoginWithValidator(c *gc.C, validator apiserver.LoginVal
defer st.Close()

// Ensure not already logged in.
_, err = st.Machiner().Machine("0")
_, err = st.Machiner().Machine("machine-0")
c.Assert(err, gc.ErrorMatches, `unknown object type "Machiner"`)

// Since these are user login tests, the nonce is empty.
Expand Down
2 changes: 1 addition & 1 deletion worker/machiner/machiner_test.go
Expand Up @@ -92,7 +92,7 @@ func agentConfig(tag string) agent.Config {
}

func (s *MachinerSuite) TestNotFoundOrUnauthorized(c *gc.C) {
mr := machiner.NewMachiner(s.machinerState, agentConfig("eleventy-one"))
mr := machiner.NewMachiner(s.machinerState, agentConfig("machine-99"))
c.Assert(mr.Wait(), gc.Equals, worker.ErrTerminateAgent)
}

Expand Down

0 comments on commit e01ac93

Please sign in to comment.