github.com/axw/juju@v0.0.0-20161005053422-4bd6544d08d4/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  	"github.com/juju/juju/instance"
    12  	"github.com/juju/juju/state/multiwatcher"
    13  )
    14  
    15  // StatusParams holds parameters for the Status call.
    16  type StatusParams struct {
    17  	Patterns []string `json:"patterns"`
    18  }
    19  
    20  // TODO(ericsnow) Add FullStatusResult.
    21  
    22  // FullStatus holds information about the status of a juju model.
    23  type FullStatus struct {
    24  	Model        ModelStatusInfo              `json:"model"`
    25  	Machines     map[string]MachineStatus     `json:"machines"`
    26  	Applications map[string]ApplicationStatus `json:"applications"`
    27  	Relations    []RelationStatus             `json:"relations"`
    28  }
    29  
    30  // ModelStatusInfo holds status information about the model itself.
    31  type ModelStatusInfo struct {
    32  	Name             string `json:"name"`
    33  	CloudTag         string `json:"cloud-tag"`
    34  	CloudRegion      string `json:"region,omitempty"`
    35  	Version          string `json:"version"`
    36  	AvailableVersion string `json:"available-version"`
    37  	Migration        string `json:"migration,omitempty"`
    38  }
    39  
    40  // MachineStatus holds status info about a machine.
    41  type MachineStatus struct {
    42  	AgentStatus    DetailedStatus `json:"agent-status"`
    43  	InstanceStatus DetailedStatus `json:"instance-status"`
    44  
    45  	DNSName    string                    `json:"dns-name"`
    46  	InstanceId instance.Id               `json:"instance-id"`
    47  	Series     string                    `json:"series"`
    48  	Id         string                    `json:"id"`
    49  	Containers map[string]MachineStatus  `json:"containers"`
    50  	Hardware   string                    `json:"hardware"`
    51  	Jobs       []multiwatcher.MachineJob `json:"jobs"`
    52  	HasVote    bool                      `json:"has-vote"`
    53  	WantsVote  bool                      `json:"wants-vote"`
    54  }
    55  
    56  // ApplicationStatus holds status info about an application.
    57  type ApplicationStatus struct {
    58  	Err             error                  `json:"err,omitempty"`
    59  	Charm           string                 `json:"charm"`
    60  	Series          string                 `json:"series"`
    61  	Exposed         bool                   `json:"exposed"`
    62  	Life            string                 `json:"life"`
    63  	Relations       map[string][]string    `json:"relations"`
    64  	CanUpgradeTo    string                 `json:"can-upgrade-to"`
    65  	SubordinateTo   []string               `json:"subordinate-to"`
    66  	Units           map[string]UnitStatus  `json:"units"`
    67  	MeterStatuses   map[string]MeterStatus `json:"meter-statuses"`
    68  	Status          DetailedStatus         `json:"status"`
    69  	WorkloadVersion string                 `json:"workload-version"`
    70  }
    71  
    72  // MeterStatus represents the meter status of a unit.
    73  type MeterStatus struct {
    74  	Color   string `json:"color"`
    75  	Message string `json:"message"`
    76  }
    77  
    78  // UnitStatus holds status info about a unit.
    79  type UnitStatus struct {
    80  	// AgentStatus holds the status for a unit's agent.
    81  	AgentStatus DetailedStatus `json:"agent-status"`
    82  
    83  	// WorkloadStatus holds the status for a unit's workload
    84  	WorkloadStatus  DetailedStatus `json:"workload-status"`
    85  	WorkloadVersion string         `json:"workload-version"`
    86  
    87  	Machine       string                `json:"machine"`
    88  	OpenedPorts   []string              `json:"opened-ports"`
    89  	PublicAddress string                `json:"public-address"`
    90  	Charm         string                `json:"charm"`
    91  	Subordinates  map[string]UnitStatus `json:"subordinates"`
    92  	Leader        bool                  `json:"leader,omitempty"`
    93  }
    94  
    95  // RelationStatus holds status info about a relation.
    96  type RelationStatus struct {
    97  	Id        int              `json:"id"`
    98  	Key       string           `json:"key"`
    99  	Interface string           `json:"interface"`
   100  	Scope     string           `json:"scope"`
   101  	Endpoints []EndpointStatus `json:"endpoints"`
   102  }
   103  
   104  // EndpointStatus holds status info about a single endpoint
   105  type EndpointStatus struct {
   106  	ApplicationName string `json:"application"`
   107  	Name            string `json:"name"`
   108  	Role            string `json:"role"`
   109  	Subordinate     bool   `json:"subordinate"`
   110  }
   111  
   112  // TODO(ericsnow) Eliminate the String method.
   113  
   114  func (epStatus *EndpointStatus) String() string {
   115  	return epStatus.ApplicationName + ":" + epStatus.Name
   116  }
   117  
   118  // DetailedStatus holds status info about a machine or unit agent.
   119  type DetailedStatus struct {
   120  	Status  string                 `json:"status"`
   121  	Info    string                 `json:"info"`
   122  	Data    map[string]interface{} `json:"data"`
   123  	Since   *time.Time             `json:"since"`
   124  	Kind    string                 `json:"kind"`
   125  	Version string                 `json:"version"`
   126  	Life    string                 `json:"life"`
   127  	Err     error                  `json:"err,omitempty"`
   128  }
   129  
   130  // History holds many DetailedStatus,
   131  type History struct {
   132  	Statuses []DetailedStatus `json:"statuses"`
   133  	Error    *Error           `json:"error,omitempty"`
   134  }
   135  
   136  // StatusHistoryFilter holds arguments that can be use to filter a status history backlog.
   137  type StatusHistoryFilter struct {
   138  	Size  int            `json:"size"`
   139  	Date  *time.Time     `json:"date"`
   140  	Delta *time.Duration `json:"delta"`
   141  }
   142  
   143  // StatusHistoryRequest holds the parameters to filter a status history query.
   144  type StatusHistoryRequest struct {
   145  	Kind   string              `json:"historyKind"`
   146  	Size   int                 `json:"size"`
   147  	Filter StatusHistoryFilter `json:"filter"`
   148  	Tag    string              `json:"tag"`
   149  }
   150  
   151  // StatusHistoryRequests holds a slice of StatusHistoryArgs
   152  type StatusHistoryRequests struct {
   153  	Requests []StatusHistoryRequest `json:"requests"`
   154  }
   155  
   156  // StatusHistoryResult holds a slice of statuses.
   157  type StatusHistoryResult struct {
   158  	History History `json:"history"`
   159  	Error   *Error  `json:"error,omitempty"`
   160  }
   161  
   162  // StatusHistoryResults holds a slice of StatusHistoryResult.
   163  type StatusHistoryResults struct {
   164  	Results []StatusHistoryResult `json:"results"`
   165  }
   166  
   167  // StatusHistoryPruneArgs holds arguments for status history
   168  // prunning process.
   169  type StatusHistoryPruneArgs struct {
   170  	MaxHistoryTime time.Duration `json:"max-history-time"`
   171  	MaxHistoryMB   int           `json:"max-history-mb"`
   172  }
   173  
   174  // StatusResult holds an entity status, extra information, or an
   175  // error.
   176  type StatusResult struct {
   177  	Error  *Error                 `json:"error,omitempty"`
   178  	Id     string                 `json:"id"`
   179  	Life   Life                   `json:"life"`
   180  	Status string                 `json:"status"`
   181  	Info   string                 `json:"info"`
   182  	Data   map[string]interface{} `json:"data"`
   183  	Since  *time.Time             `json:"since"`
   184  }
   185  
   186  // StatusResults holds multiple status results.
   187  type StatusResults struct {
   188  	Results []StatusResult `json:"results"`
   189  }
   190  
   191  // ApplicationStatusResult holds results for an application Full Status
   192  type ApplicationStatusResult struct {
   193  	Application StatusResult            `json:"application"`
   194  	Units       map[string]StatusResult `json:"units"`
   195  	Error       *Error                  `json:"error,omitempty"`
   196  }
   197  
   198  // ApplicationStatusResults holds multiple StatusResult.
   199  type ApplicationStatusResults struct {
   200  	Results []ApplicationStatusResult `json:"results"`
   201  }
   202  
   203  // Life describes the lifecycle state of an entity ("alive", "dying" or "dead").
   204  type Life multiwatcher.Life
   205  
   206  const (
   207  	Alive Life = "alive"
   208  	Dying Life = "dying"
   209  	Dead  Life = "dead"
   210  )