github.com/niedbalski/juju@v0.0.0-20190215020005-8ff100488e47/pubsub/apiserver/messages.go (about)

     1  // Copyright 2016 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package apiserver
     5  
     6  import "github.com/juju/juju/pubsub/common"
     7  
     8  // DetailsTopic is the topic name for the published message when the details
     9  // of the api servers change. This message is normally published by the
    10  // peergrouper when the set of API servers changes.
    11  const DetailsTopic = "apiserver.details"
    12  
    13  // APIServer contains the machine id and addresses of a single API server machine.
    14  type APIServer struct {
    15  	// ID contains the Juju machine ID for the apiserver.
    16  	ID string `yaml:"id"`
    17  
    18  	// Addresses contains all of the usable addresses of the
    19  	// apiserver machine.
    20  	Addresses []string `yaml:"addresses"`
    21  
    22  	// InternalAddress, if non-empty, is the address that
    23  	// other API servers should use to connect to this API
    24  	// server, in the form addr:port.
    25  	//
    26  	// This may be empty if the API server is not fully
    27  	// initialised.
    28  	InternalAddress string `yaml:"internal-address,omitempty"`
    29  }
    30  
    31  // Details contains the ids and addresses of all the current API server
    32  // machines.
    33  type Details struct {
    34  	// Servers is a map of machine ID to the details for that server.
    35  	Servers   map[string]APIServer `yaml:"servers"`
    36  	LocalOnly bool                 `yaml:"local-only"`
    37  }
    38  
    39  // DetailsRequestTopic is the topic that details requests are
    40  // published on. The peergrouper responds those requests, publishing
    41  // the current details on the DetailsTopic.
    42  const DetailsRequestTopic = "apiserver.details-request"
    43  
    44  // DetailsRequest indicates the worker who is asking for the details
    45  // to be sent. It should always be LocalOnly - we only want to ask our
    46  // local PeerGrouper for details.
    47  type DetailsRequest struct {
    48  	Requester string `yaml:"requester"`
    49  	LocalOnly bool   `yaml:"local-only"`
    50  }
    51  
    52  // ConnectTopic is the topic name for the published message
    53  // whenever an agent conntects to the API server.
    54  // data: `APIConnection`
    55  const ConnectTopic = "apiserver.agent-connect"
    56  
    57  // DisconnectTopic is the topic name for the published message
    58  // whenever an agent disconntects to the API server.
    59  // data: `APIConnection`
    60  const DisconnectTopic = "apiserver.agent-disconnect"
    61  
    62  // APIConnection holds all the salient pieces of information that are
    63  // available when an agent connects to the API server.
    64  type APIConnection struct {
    65  	AgentTag        string `yaml:"agent-tag"`
    66  	ControllerAgent bool   `yaml:"controller-agent,omitempty"`
    67  	ModelUUID       string `yaml:"model-uuid"`
    68  	ConnectionID    uint64 `yaml:"connection-id"`
    69  	Origin          string `yaml:"origin"`
    70  	UserData        string `yaml:"user-data,omitempty"`
    71  }
    72  
    73  // PresenceRequestTopic is used by the presence worker to ask another HA server
    74  // to report its connections.
    75  // data: `OriginTarget`
    76  const PresenceRequestTopic = "presence.request"
    77  
    78  // PresenceResponseTopic is used by the presence worker to respond to the
    79  // request topic above.
    80  // data: `PresenceResponse`
    81  const PresenceResponseTopic = "presence.response"
    82  
    83  // PresenceResponse contains all of the current connections for the server
    84  // identified by Origin.
    85  type PresenceResponse struct {
    86  	Origin      string          `yaml:"origin"`
    87  	Connections []APIConnection `yaml:"connections"`
    88  }
    89  
    90  // OriginTarget represents the data for the connect and disconnect
    91  // topics.
    92  type OriginTarget common.OriginTarget
    93  
    94  // RestartTopic is used by the API server to listen for events that should
    95  // cause the API server to be bounced.
    96  const RestartTopic = "apiserver.restart"
    97  
    98  // Restart message only contains the local-only indicator as the restart
    99  // is only ever for the same agent.
   100  type Restart common.LocalOnly