github.com/anth0d/nomad@v0.0.0-20221214183521-ae3a0a2cad06/nomad/structs/event.go (about)

     1  package structs
     2  
     3  // EventStreamRequest is used to stream events from a servers EventBroker
     4  type EventStreamRequest struct {
     5  	Topics map[Topic][]string
     6  	Index  int
     7  
     8  	QueryOptions
     9  }
    10  
    11  type EventStreamWrapper struct {
    12  	Error *RpcError
    13  	Event *EventJson
    14  }
    15  
    16  type Topic string
    17  
    18  const (
    19  	TopicDeployment     Topic = "Deployment"
    20  	TopicEvaluation     Topic = "Evaluation"
    21  	TopicAllocation     Topic = "Allocation"
    22  	TopicJob            Topic = "Job"
    23  	TopicNode           Topic = "Node"
    24  	TopicACLPolicy      Topic = "ACLPolicy"
    25  	TopicACLToken       Topic = "ACLToken"
    26  	TopicACLRole        Topic = "ACLRole"
    27  	TopicACLAuthMethod  Topic = "ACLAuthMethod"
    28  	TopicACLBindingRule Topic = "ACLBindingRule"
    29  	TopicService        Topic = "Service"
    30  	TopicAll            Topic = "*"
    31  
    32  	TypeNodeRegistration              = "NodeRegistration"
    33  	TypeNodeDeregistration            = "NodeDeregistration"
    34  	TypeNodeEligibilityUpdate         = "NodeEligibility"
    35  	TypeNodeDrain                     = "NodeDrain"
    36  	TypeNodeEvent                     = "NodeStreamEvent"
    37  	TypeDeploymentUpdate              = "DeploymentStatusUpdate"
    38  	TypeDeploymentPromotion           = "DeploymentPromotion"
    39  	TypeDeploymentAllocHealth         = "DeploymentAllocHealth"
    40  	TypeAllocationCreated             = "AllocationCreated"
    41  	TypeAllocationUpdated             = "AllocationUpdated"
    42  	TypeAllocationUpdateDesiredStatus = "AllocationUpdateDesiredStatus"
    43  	TypeEvalUpdated                   = "EvaluationUpdated"
    44  	TypeJobRegistered                 = "JobRegistered"
    45  	TypeJobDeregistered               = "JobDeregistered"
    46  	TypeJobBatchDeregistered          = "JobBatchDeregistered"
    47  	TypePlanResult                    = "PlanResult"
    48  	TypeACLTokenDeleted               = "ACLTokenDeleted"
    49  	TypeACLTokenUpserted              = "ACLTokenUpserted"
    50  	TypeACLPolicyDeleted              = "ACLPolicyDeleted"
    51  	TypeACLPolicyUpserted             = "ACLPolicyUpserted"
    52  	TypeACLRoleDeleted                = "ACLRoleDeleted"
    53  	TypeACLRoleUpserted               = "ACLRoleUpserted"
    54  	TypeACLAuthMethodUpserted         = "ACLAuthMethodUpserted"
    55  	TypeACLAuthMethodDeleted          = "ACLAuthMethodDeleted"
    56  	TypeACLBindingRuleUpserted        = "ACLBindingRuleUpserted"
    57  	TypeACLBindingRuleDeleted         = "ACLBindingRuleDeleted"
    58  	TypeServiceRegistration           = "ServiceRegistration"
    59  	TypeServiceDeregistration         = "ServiceDeregistration"
    60  )
    61  
    62  // Event represents a change in Nomads state.
    63  type Event struct {
    64  	// Topic represents the primary object for the event
    65  	Topic Topic
    66  
    67  	// Type is a short string representing the reason for the event
    68  	Type string
    69  
    70  	// Key is the primary identifier of the Event, The involved objects ID
    71  	Key string
    72  
    73  	// Namespace is the namespace of the object, If the object is not namespace
    74  	// aware (Node) it is left blank
    75  	Namespace string
    76  
    77  	// FilterKeys are a set of additional related keys that are used to include
    78  	// events during filtering.
    79  	FilterKeys []string
    80  
    81  	// Index is the raft index that corresponds to the event
    82  	Index uint64
    83  
    84  	// Payload is the Event itself see state/events.go for a list of events
    85  	Payload interface{}
    86  }
    87  
    88  // Events is a wrapper that contains a set of events for a given index.
    89  type Events struct {
    90  	Index  uint64
    91  	Events []Event
    92  }
    93  
    94  // EventJson is a wrapper for a JSON object
    95  type EventJson struct {
    96  	Data []byte
    97  }
    98  
    99  func (j *EventJson) Copy() *EventJson {
   100  	n := new(EventJson)
   101  	*n = *j
   102  	n.Data = make([]byte, len(j.Data))
   103  	copy(n.Data, j.Data)
   104  	return n
   105  }
   106  
   107  // JobEvent holds a newly updated Job.
   108  type JobEvent struct {
   109  	Job *Job
   110  }
   111  
   112  // EvaluationEvent holds a newly updated Eval.
   113  type EvaluationEvent struct {
   114  	Evaluation *Evaluation
   115  }
   116  
   117  // AllocationEvent holds a newly updated Allocation. The
   118  // Allocs embedded Job has been removed to reduce size.
   119  type AllocationEvent struct {
   120  	Allocation *Allocation
   121  }
   122  
   123  // DeploymentEvent holds a newly updated Deployment.
   124  type DeploymentEvent struct {
   125  	Deployment *Deployment
   126  }
   127  
   128  // NodeStreamEvent holds a newly updated Node
   129  type NodeStreamEvent struct {
   130  	Node *Node
   131  }
   132  
   133  type ACLTokenEvent struct {
   134  	ACLToken *ACLToken
   135  	secretID string
   136  }
   137  
   138  // ServiceRegistrationStreamEvent holds a newly updated or deleted service
   139  // registration.
   140  type ServiceRegistrationStreamEvent struct {
   141  	Service *ServiceRegistration
   142  }
   143  
   144  // NewACLTokenEvent takes a token and creates a new ACLTokenEvent.  It creates
   145  // a copy of the passed in ACLToken and empties out the copied tokens SecretID
   146  func NewACLTokenEvent(token *ACLToken) *ACLTokenEvent {
   147  	c := token.Copy()
   148  	c.SecretID = ""
   149  
   150  	return &ACLTokenEvent{
   151  		ACLToken: c,
   152  		secretID: token.SecretID,
   153  	}
   154  }
   155  
   156  func (a *ACLTokenEvent) SecretID() string {
   157  	return a.secretID
   158  }
   159  
   160  type ACLPolicyEvent struct {
   161  	ACLPolicy *ACLPolicy
   162  }
   163  
   164  // ACLRoleStreamEvent holds a newly updated or deleted ACL role to be used as an
   165  // event within the event stream.
   166  type ACLRoleStreamEvent struct {
   167  	ACLRole *ACLRole
   168  }
   169  
   170  // ACLAuthMethodEvent holds a newly updated or deleted ACL auth method to be
   171  // used as an event in the event stream.
   172  type ACLAuthMethodEvent struct {
   173  	AuthMethod *ACLAuthMethod
   174  }
   175  
   176  // ACLBindingRuleEvent holds a newly updated or deleted ACL binding rule to be
   177  // used as an event in the event stream.
   178  type ACLBindingRuleEvent struct {
   179  	ACLBindingRule *ACLBindingRule
   180  }