github.com/makyo/juju@v0.0.0-20160425123129-2608902037e9/apiserver/uniter/status.go (about)

     1  // Copyright 2015 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package uniter
     5  
     6  import (
     7  	"github.com/juju/juju/apiserver/common"
     8  	"github.com/juju/juju/apiserver/params"
     9  	"github.com/juju/juju/state"
    10  )
    11  
    12  // StatusAPI is the uniter part that deals with setting/getting
    13  // status from different entities, this particular separation from
    14  // base is because we have a shim to support unit/agent split.
    15  type StatusAPI struct {
    16  	agentSetter   *common.StatusSetter
    17  	unitSetter    *common.StatusSetter
    18  	unitGetter    *common.StatusGetter
    19  	serviceSetter *common.ServiceStatusSetter
    20  	serviceGetter *common.ServiceStatusGetter
    21  	getCanModify  common.GetAuthFunc
    22  }
    23  
    24  // NewStatusAPI creates a new server-side Status setter API facade.
    25  func NewStatusAPI(st *state.State, getCanModify common.GetAuthFunc) *StatusAPI {
    26  	// TODO(fwereade): so *all* of these have exactly the same auth
    27  	// characteristics? I think not.
    28  	unitSetter := common.NewStatusSetter(st, getCanModify)
    29  	unitGetter := common.NewStatusGetter(st, getCanModify)
    30  	serviceSetter := common.NewServiceStatusSetter(st, getCanModify)
    31  	serviceGetter := common.NewServiceStatusGetter(st, getCanModify)
    32  	agentSetter := common.NewStatusSetter(&common.UnitAgentFinder{st}, getCanModify)
    33  	return &StatusAPI{
    34  		agentSetter:   agentSetter,
    35  		unitSetter:    unitSetter,
    36  		unitGetter:    unitGetter,
    37  		serviceSetter: serviceSetter,
    38  		serviceGetter: serviceGetter,
    39  		getCanModify:  getCanModify,
    40  	}
    41  }
    42  
    43  // SetStatus will set status for a entities passed in args. If the entity is
    44  // a Unit it will instead set status to its agent, to emulate backwards
    45  // compatibility.
    46  func (s *StatusAPI) SetStatus(args params.SetStatus) (params.ErrorResults, error) {
    47  	return s.SetAgentStatus(args)
    48  }
    49  
    50  // SetAgentStatus will set status for agents of Units passed in args, if one
    51  // of the args is not an Unit it will fail.
    52  func (s *StatusAPI) SetAgentStatus(args params.SetStatus) (params.ErrorResults, error) {
    53  	return s.agentSetter.SetStatus(args)
    54  }
    55  
    56  // SetUnitStatus sets status for all elements passed in args, the difference
    57  // with SetStatus is that if an entity is a Unit it will set its status instead
    58  // of its agent.
    59  func (s *StatusAPI) SetUnitStatus(args params.SetStatus) (params.ErrorResults, error) {
    60  	return s.unitSetter.SetStatus(args)
    61  }
    62  
    63  // SetServiceStatus sets the status for all the Services in args if the given Unit is
    64  // the leader.
    65  func (s *StatusAPI) SetServiceStatus(args params.SetStatus) (params.ErrorResults, error) {
    66  	return s.serviceSetter.SetStatus(args)
    67  }
    68  
    69  // UnitStatus returns the workload status information for the unit.
    70  func (s *StatusAPI) UnitStatus(args params.Entities) (params.StatusResults, error) {
    71  	return s.unitGetter.Status(args)
    72  }
    73  
    74  // ServiceStatus returns the status of the Services and its workloads
    75  // if the given unit is the leader.
    76  func (s *StatusAPI) ServiceStatus(args params.Entities) (params.ServiceStatusResults, error) {
    77  	return s.serviceGetter.Status(args)
    78  }