github.com/hernad/nomad@v1.6.112/nomad/structs/event.go (about)

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