github.com/mhilton/juju-juju@v0.0.0-20150901100907-a94dd2c73455/apiserver/params/status.go (about)

     1  // Copyright 2015 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package params
     5  
     6  // TODO(ericsnow) Eliminate the juju-related imports.
     7  
     8  import (
     9  	"time"
    10  
    11  	"gopkg.in/juju/charm.v5"
    12  
    13  	"github.com/juju/juju/instance"
    14  	"github.com/juju/juju/network"
    15  	"github.com/juju/juju/state/multiwatcher"
    16  )
    17  
    18  // StatusParams holds parameters for the Status call.
    19  type StatusParams struct {
    20  	Patterns []string
    21  }
    22  
    23  // TODO(ericsnow) Add FullStatusResult.
    24  
    25  // Status holds information about the status of a juju environment.
    26  type FullStatus struct {
    27  	EnvironmentName string
    28  	Machines        map[string]MachineStatus
    29  	Services        map[string]ServiceStatus
    30  	Networks        map[string]NetworkStatus
    31  	Relations       []RelationStatus
    32  }
    33  
    34  // MachineStatus holds status info about a machine.
    35  type MachineStatus struct {
    36  	Agent AgentStatus
    37  
    38  	// The following fields mirror fields in AgentStatus (introduced
    39  	// in 1.19.x). The old fields below are being kept for
    40  	// compatibility with old clients.
    41  	// They can be removed once API versioning lands.
    42  	AgentState     Status
    43  	AgentStateInfo string
    44  	AgentVersion   string
    45  	Life           string
    46  	Err            error
    47  
    48  	DNSName       string
    49  	InstanceId    instance.Id
    50  	InstanceState string
    51  	Series        string
    52  	Id            string
    53  	Containers    map[string]MachineStatus
    54  	Hardware      string
    55  	Jobs          []multiwatcher.MachineJob
    56  	HasVote       bool
    57  	WantsVote     bool
    58  }
    59  
    60  // ServiceStatus holds status info about a service.
    61  type ServiceStatus struct {
    62  	Err           error
    63  	Charm         string
    64  	Exposed       bool
    65  	Life          string
    66  	Relations     map[string][]string
    67  	Networks      NetworksSpecification
    68  	CanUpgradeTo  string
    69  	SubordinateTo []string
    70  	Units         map[string]UnitStatus
    71  	MeterStatuses map[string]MeterStatus
    72  	Status        AgentStatus
    73  }
    74  
    75  // MeterStatus represents the meter status of a unit.
    76  type MeterStatus struct {
    77  	Color   string
    78  	Message string
    79  }
    80  
    81  // UnitStatus holds status info about a unit.
    82  type UnitStatus struct {
    83  	// UnitAgent holds the status for a unit's agent.
    84  	UnitAgent AgentStatus
    85  
    86  	// Workload holds the status for a unit's workload
    87  	Workload AgentStatus
    88  
    89  	// Until Juju 2.0, we need to continue to return legacy agent state values
    90  	// as top level struct attributes when the "FullStatus" API is called.
    91  	AgentState     Status
    92  	AgentStateInfo string
    93  	AgentVersion   string
    94  	Life           string
    95  	Err            error
    96  
    97  	Machine       string
    98  	OpenedPorts   []string
    99  	PublicAddress string
   100  	Charm         string
   101  	Subordinates  map[string]UnitStatus
   102  }
   103  
   104  // TODO(ericsnow) Rename to ServiceNetworksSepcification.
   105  
   106  // NetworksSpecification holds the enabled and disabled networks for a
   107  // service.
   108  type NetworksSpecification struct {
   109  	Enabled  []string
   110  	Disabled []string
   111  }
   112  
   113  // NetworkStatus holds status info about a network.
   114  type NetworkStatus struct {
   115  	Err        error
   116  	ProviderId network.Id
   117  	CIDR       string
   118  	VLANTag    int
   119  }
   120  
   121  // RelationStatus holds status info about a relation.
   122  type RelationStatus struct {
   123  	Id        int
   124  	Key       string
   125  	Interface string
   126  	Scope     charm.RelationScope
   127  	Endpoints []EndpointStatus
   128  }
   129  
   130  // EndpointStatus holds status info about a single endpoint
   131  type EndpointStatus struct {
   132  	ServiceName string
   133  	Name        string
   134  	Role        charm.RelationRole
   135  	Subordinate bool
   136  }
   137  
   138  // TODO(ericsnow) Eliminate the String method.
   139  
   140  func (epStatus *EndpointStatus) String() string {
   141  	return epStatus.ServiceName + ":" + epStatus.Name
   142  }
   143  
   144  // AgentStatus holds status info about a machine or unit agent.
   145  type AgentStatus struct {
   146  	Status  Status
   147  	Info    string
   148  	Data    map[string]interface{}
   149  	Since   *time.Time
   150  	Kind    HistoryKind
   151  	Version string
   152  	Life    string
   153  	Err     error
   154  }
   155  
   156  // LegacyStatus holds minimal information on the status of a juju environment.
   157  type LegacyStatus struct {
   158  	Machines map[string]LegacyMachineStatus
   159  }
   160  
   161  // LegacyMachineStatus holds just the instance-id of a machine.
   162  type LegacyMachineStatus struct {
   163  	InstanceId string // Not type instance.Id just to match original api.
   164  }
   165  
   166  // TODO(ericsnow) Rename to StatusHistoryArgs.
   167  
   168  // StatusHistory holds the parameters to filter a status history query.
   169  type StatusHistory struct {
   170  	Kind HistoryKind
   171  	Size int
   172  	Name string
   173  }
   174  
   175  // TODO(ericsnow) Rename to UnitStatusHistoryResult.
   176  
   177  // UnitStatusHistory holds a slice of statuses.
   178  type UnitStatusHistory struct {
   179  	Statuses []AgentStatus
   180  }
   181  
   182  // StatusResult holds an entity status, extra information, or an
   183  // error.
   184  type StatusResult struct {
   185  	Error  *Error
   186  	Id     string
   187  	Life   Life
   188  	Status Status
   189  	Info   string
   190  	Data   map[string]interface{}
   191  	Since  *time.Time
   192  }
   193  
   194  // StatusResults holds multiple status results.
   195  type StatusResults struct {
   196  	Results []StatusResult
   197  }
   198  
   199  // ServiceStatusResult holds results for a service Full Status
   200  type ServiceStatusResult struct {
   201  	Service StatusResult
   202  	Units   map[string]StatusResult
   203  	Error   *Error
   204  }
   205  
   206  // ServiceStatusResults holds multiple StatusResult.
   207  type ServiceStatusResults struct {
   208  	Results []ServiceStatusResult
   209  }
   210  
   211  type HistoryKind string
   212  
   213  const (
   214  	KindCombined HistoryKind = "combined"
   215  	KindAgent    HistoryKind = "agent"
   216  	KindWorkload HistoryKind = "workload"
   217  )
   218  
   219  // Life describes the lifecycle state of an entity ("alive", "dying" or "dead").
   220  type Life multiwatcher.Life
   221  
   222  const (
   223  	Alive Life = "alive"
   224  	Dying Life = "dying"
   225  	Dead  Life = "dead"
   226  )
   227  
   228  // Status represents the status of an entity.
   229  // It could be a unit, machine or its agent.
   230  type Status multiwatcher.Status
   231  
   232  const (
   233  	// Status values common to machine and unit agents.
   234  
   235  	// The entity requires human intervention in order to operate
   236  	// correctly.
   237  	StatusError Status = "error"
   238  
   239  	// The entity is actively participating in the environment.
   240  	// For unit agents, this is a state we preserve for backwards
   241  	// compatibility with scripts during the life of Juju 1.x.
   242  	// In Juju 2.x, the agent-state will remain “active” and scripts
   243  	// will watch the unit-state instead for signals of service readiness.
   244  	StatusStarted Status = "started"
   245  )
   246  
   247  const (
   248  	// Status values specific to machine agents.
   249  
   250  	// The machine is not yet participating in the environment.
   251  	StatusPending Status = "pending"
   252  
   253  	// The machine's agent will perform no further action, other than
   254  	// to set the unit to Dead at a suitable moment.
   255  	StatusStopped Status = "stopped"
   256  
   257  	// The machine ought to be signalling activity, but it cannot be
   258  	// detected.
   259  	StatusDown Status = "down"
   260  )
   261  
   262  const (
   263  	// Status values specific to unit agents.
   264  
   265  	// The machine on which a unit is to be hosted is still being
   266  	// spun up in the cloud.
   267  	StatusAllocating Status = "allocating"
   268  
   269  	// The machine on which this agent is running is being rebooted.
   270  	// The juju-agent should move from rebooting to idle when the reboot is complete.
   271  	StatusRebooting Status = "rebooting"
   272  
   273  	// The agent is running a hook or action. The human-readable message should reflect
   274  	// which hook or action is being run.
   275  	StatusExecuting Status = "executing"
   276  
   277  	// Once the agent is installed and running it will notify the Juju server and its state
   278  	// becomes "idle". It will stay "idle" until some action (e.g. it needs to run a hook) or
   279  	// error (e.g it loses contact with the Juju server) moves it to a different state.
   280  	StatusIdle Status = "idle"
   281  
   282  	// The unit agent has failed in some way,eg the agent ought to be signalling
   283  	// activity, but it cannot be detected. It might also be that the unit agent
   284  	// detected an unrecoverable condition and managed to tell the Juju server about it.
   285  	StatusFailed Status = "failed"
   286  
   287  	// The juju agent has has not communicated with the juju server for an unexpectedly long time;
   288  	// the unit agent ought to be signalling activity, but none has been detected.
   289  	StatusLost Status = "lost"
   290  
   291  	// ---- Outdated ----
   292  	// The unit agent is downloading the charm and running the install hook.
   293  	StatusInstalling Status = "installing"
   294  
   295  	// The unit is being destroyed; the agent will soon mark the unit as “dead”.
   296  	// In Juju 2.x this will describe the state of the agent rather than a unit.
   297  	StatusStopping Status = "stopping"
   298  )
   299  
   300  const (
   301  	// Status values specific to services and units, reflecting the
   302  	// state of the software itself.
   303  
   304  	// The unit is not yet providing services, but is actively doing stuff
   305  	// in preparation for providing those services.
   306  	// This is a "spinning" state, not an error state.
   307  	// It reflects activity on the unit itself, not on peers or related units.
   308  	StatusMaintenance Status = "maintenance"
   309  
   310  	// This unit used to exist, we have a record of it (perhaps because of storage
   311  	// allocated for it that was flagged to survive it). Nonetheless, it is now gone.
   312  	StatusTerminated Status = "terminated"
   313  
   314  	// A unit-agent has finished calling install, config-changed, and start,
   315  	// but the charm has not called status-set yet.
   316  	StatusUnknown Status = "unknown"
   317  
   318  	// The unit is unable to progress to an active state because a service to
   319  	// which it is related is not running.
   320  	StatusWaiting Status = "waiting"
   321  
   322  	// The unit needs manual intervention to get back to the Running state.
   323  	StatusBlocked Status = "blocked"
   324  
   325  	// The unit believes it is correctly offering all the services it has
   326  	// been asked to offer.
   327  	StatusActive Status = "active"
   328  )
   329  
   330  const (
   331  	// Status values specific to storage.
   332  
   333  	// StatusAttaching indicates that the storage is being attached
   334  	// to a machine.
   335  	StatusAttaching Status = "attaching"
   336  
   337  	// StatusAttached indicates that the storage is attached to a
   338  	// machine.
   339  	StatusAttached Status = "attached"
   340  
   341  	// StatusDetaching indicates that the storage is being detached
   342  	// from a machine.
   343  	StatusDetaching Status = "detaching"
   344  
   345  	// StatusDetached indicates that the storage is not attached to
   346  	// any machine.
   347  	StatusDetached Status = "detached"
   348  
   349  	// StatusDestroying indicates that the storage is being destroyed.
   350  	StatusDestroying Status = "destroying"
   351  )