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