forked from aws/amazon-ecs-agent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
types.go
155 lines (135 loc) · 5.04 KB
/
types.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
// 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 dockerapi
import (
"fmt"
"time"
apicontainer "github.com/aws/amazon-ecs-agent/agent/api/container"
apicontainerstatus "github.com/aws/amazon-ecs-agent/agent/api/container/status"
apierrors "github.com/aws/amazon-ecs-agent/agent/api/errors"
"github.com/aws/aws-sdk-go/aws"
"github.com/docker/docker/api/types"
)
// ContainerNotFound is a type for a missing container
type ContainerNotFound struct {
// TaskArn is the ARN of the task the container belongs to
TaskArn string
// ContainerName is the name of the container that's missing
ContainerName string
}
// Error returns an error string for the ContainerNotFound error
func (cnferror ContainerNotFound) Error() string {
return fmt.Sprintf("Could not find container '%s' in task '%s'",
cnferror.ContainerName, cnferror.TaskArn)
}
// DockerContainerChangeEvent is a type for container change events
type DockerContainerChangeEvent struct {
// Status represents the container's status in the event
Status apicontainerstatus.ContainerStatus
// DockerContainerMetadata is the metadata of the container in the event
DockerContainerMetadata
// Type is the event type received from docker events
Type apicontainer.DockerEventType
}
// DockerContainerMetadata is a type for metadata about Docker containers
type DockerContainerMetadata struct {
// DockerID is the contianer's id generated by Docker
DockerID string
// ExitCode contains container's exit code if it has stopped
ExitCode *int
// PortBindings is the list of port binding information of the container
PortBindings []apicontainer.PortBinding
// Error wraps various container transition errors and is set if engine
// is unable to perform any of the required container transitions
Error apierrors.NamedError
// Volumes contains volume informaton for the container
Volumes []types.MountPoint
// Labels contains labels set for the container
Labels map[string]string
// CreatedAt is the timestamp of container creation
CreatedAt time.Time
// StartedAt is the timestamp of container start
StartedAt time.Time
// FinishedAt is the timestamp of container stop
FinishedAt time.Time
// Health contains the result of a container health check
Health apicontainer.HealthStatus
// NetworkMode denotes the network mode in which the container is started
NetworkMode string
// NetworksUnsafe denotes the Docker Network Settings in the container
NetworkSettings *types.NetworkSettings
}
// ListContainersResponse encapsulates the response from the docker client for the
// ListContainers call.
type ListContainersResponse struct {
// DockerIDs is the list of container IDs from the ListContainers call
DockerIDs []string
// Error contains any error returned when listing containers
Error error
}
// ListImagesResponse encapsulates the response from the docker client for the
// ListImages call.
type ListImagesResponse struct {
// ImagesIDs is the list of Images IDs from the ListImages call
ImageIDs []string
// RepoTags is the list of Images names from the ListImages call
RepoTags []string
// Error contains any error returned when listing images
Error error
}
// VolumeResponse wrapper for CreateVolume and InspectVolume
// TODO Remove type when migration is complete
type VolumeResponse struct {
DockerVolume *types.Volume
Error error
}
// VolumeResponse wrapper for CreateVolume for SDK Clients
type SDKVolumeResponse struct {
DockerVolume *types.Volume
Error error
}
// ListPluginsResponse is a wrapper for ListPlugins api
type ListPluginsResponse struct {
Plugins []*types.Plugin
Error error
}
// String returns a human readable string of the container change event
func (event *DockerContainerChangeEvent) String() string {
res := fmt.Sprintf("Status: %s, DockerID: %s", event.Status.String(), event.DockerID)
res += ", health: " + event.Health.Status.String()
if event.ExitCode != nil {
res += fmt.Sprintf(", ExitCode: %d", aws.IntValue(event.ExitCode))
}
if len(event.PortBindings) != 0 {
res += fmt.Sprintf(", PortBindings: %v", event.PortBindings)
}
if event.Error != nil {
res += ", Error: " + event.Error.Error()
}
if len(event.Volumes) != 0 {
res += fmt.Sprintf(", Volumes: %v", event.Volumes)
}
if len(event.Labels) != 0 {
res += fmt.Sprintf(", Labels: %v", event.Labels)
}
if !event.CreatedAt.IsZero() {
res += ", CreatedAt: " + event.CreatedAt.String()
}
if !event.StartedAt.IsZero() {
res += ", StartedAt: " + event.StartedAt.String()
}
if !event.FinishedAt.IsZero() {
res += ", FinishedAt: " + event.FinishedAt.String()
}
return res
}