forked from aws/amazon-ecs-agent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
statechange.go
103 lines (91 loc) · 3.37 KB
/
statechange.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
// Copyright 2014-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License"). You may
// not use this file except in compliance with the License. A copy of the
// License is located at
//
// http://aws.amazon.com/apache2.0/
//
// or in the "license" file accompanying this file. This file is distributed
// on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
// express or implied. See the License for the specific language governing
// permissions and limitations under the License.
package api
import (
"fmt"
"strconv"
"github.com/aws/amazon-ecs-agent/agent/statechange"
)
// ContainerStateChange represents a state change that needs to be sent to the
// SubmitContainerStateChange API
type ContainerStateChange struct {
// TaskArn is the unique identifier for the task
TaskArn string
// ContainerName is the name of the container
ContainerName string
// Status is the status to send
Status ContainerStatus
// Reason may contain details of why the container stopped
Reason string
// ExitCode is the exit code of the container, if available
ExitCode *int
// PortBindings are the details of the host ports picked for the specified
// container ports
PortBindings []PortBinding
// Container is a pointer to the container involved in the state change that gives the event handler a hook into
// storing what status was sent. This is used to ensure the same event is handled only once.
Container *Container
}
// TaskStateChange represents a state change that needs to be sent to the
// SubmitTaskStateChange API
type TaskStateChange struct {
// Attachment is the eni attachment object to send
Attachment *ENIAttachment
// TaskArn is the unique identifier for the task
TaskARN string
// Status is the status to send
Status TaskStatus
// Reason may contain details of why the task stopped
Reason string
// Containers holds the events generated by containers owned by this task
Containers []ContainerStateChange
// Task is a pointer to the task involved in the state change that gives the event handler a hook into storing
// what status was sent. This is used to ensure the same event is handled only once.
Task *Task
}
// String returns a human readable string representation of this object
func (c *ContainerStateChange) String() string {
res := fmt.Sprintf("%s %s -> %s", c.TaskArn, c.ContainerName, c.Status.String())
if c.ExitCode != nil {
res += ", Exit " + strconv.Itoa(*c.ExitCode) + ", "
}
if c.Reason != "" {
res += ", Reason " + c.Reason
}
if len(c.PortBindings) != 0 {
res += fmt.Sprintf(", Ports %v", c.PortBindings)
}
if c.Container != nil {
res += ", Known Sent: " + c.Container.GetSentStatus().String()
}
return res
}
// String returns a human readable string representation of this object
func (t *TaskStateChange) String() string {
res := fmt.Sprintf("%s -> %s", t.TaskARN, t.Status.String())
if t.Task != nil {
res += ", Known Sent: " + t.Task.GetSentStatus().String()
}
if t.Attachment != nil {
res += ", " + t.Attachment.String()
}
return res
}
// GetEventType() returns an enum identifying the event type
func (c ContainerStateChange) GetEventType() statechange.EventType {
return statechange.ContainerEvent
}
// GetEventType() returns an enum identifying the event type
func (t TaskStateChange) GetEventType() statechange.EventType {
return statechange.TaskEvent
}