本文整理汇总了Golang中github.com/aws/amazon-ecs-agent/agent/api.NamedError函数的典型用法代码示例。如果您正苦于以下问题:Golang NamedError函数的具体用法?Golang NamedError怎么用?Golang NamedError使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NamedError函数的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: createContainer
func (engine *DockerTaskEngine) createContainer(task *api.Task, container *api.Container) DockerContainerMetadata {
log.Info("Creating container", "task", task, "container", container)
client := engine.client
if container.DockerConfig.Version != nil {
client = client.WithVersion(dockerclient.DockerVersion(*container.DockerConfig.Version))
}
// Resolve HostConfig
// we have to do this in create, not start, because docker no longer handles
// merging create config with start hostconfig the same; e.g. memory limits
// get lost
containerMap, ok := engine.state.ContainerMapByArn(task.Arn)
if !ok {
containerMap = make(map[string]*api.DockerContainer)
}
hostConfig, hcerr := task.DockerHostConfig(container, containerMap)
hostConfig.NetworkMode = "host"
if hcerr != nil {
return DockerContainerMetadata{Error: api.NamedError(hcerr)}
}
config, err := task.DockerConfig(container)
if err != nil {
return DockerContainerMetadata{Error: api.NamedError(err)}
}
name := ""
for i := 0; i < len(container.Name); i++ {
c := container.Name[i]
if !((c <= '9' && c >= '0') || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c == '-')) {
continue
}
name += string(c)
}
containerName := "ecs-" + task.Family + "-" + task.Version + "-" + name + "-" + utils.RandHex()
// Pre-add the container in case we stop before the next, more useful,
// AddContainer call. This ensures we have a way to get the container if
// we die before 'createContainer' returns because we can inspect by
// name
engine.state.AddContainer(&api.DockerContainer{DockerName: containerName, Container: container}, task)
metadata := client.CreateContainer(config, hostConfig, containerName)
if metadata.Error != nil {
return metadata
}
engine.state.AddContainer(&api.DockerContainer{DockerId: metadata.DockerId, DockerName: containerName, Container: container}, task)
hostConfig.NetworkMode = "host"
log.Info("Created container successfully", "task", task, "container", container)
return metadata
}
示例2: metadataFromContainer
func metadataFromContainer(dockerContainer *docker.Container) DockerContainerMetadata {
var bindings []api.PortBinding
var err api.NamedError
if dockerContainer.NetworkSettings != nil {
// Convert port bindings into the format our container expects
bindings, err = api.PortBindingFromDockerPortBinding(dockerContainer.NetworkSettings.Ports)
if err != nil {
log.Crit("Docker had network bindings we couldn't understand", "err", err)
return DockerContainerMetadata{Error: api.NamedError(err)}
}
}
metadata := DockerContainerMetadata{
DockerId: dockerContainer.ID,
PortBindings: bindings,
Volumes: dockerContainer.Volumes,
}
if !dockerContainer.State.Running && !dockerContainer.State.FinishedAt.IsZero() {
// Only record an exitcode if it has exited
metadata.ExitCode = &dockerContainer.State.ExitCode
}
if dockerContainer.State.Error != "" {
metadata.Error = NewDockerStateError(dockerContainer.State.Error)
}
if dockerContainer.State.OOMKilled {
metadata.Error = OutOfMemoryError{}
}
return metadata
}
示例3: createContainer
func (engine *DockerTaskEngine) createContainer(task *api.Task, container *api.Container) DockerContainerMetadata {
log.Info("Creating container", "task", task, "container", container)
client := engine.client
if container.DockerConfig.Version != nil {
client = client.WithVersion(dockerclient.DockerVersion(*container.DockerConfig.Version))
}
// Resolve HostConfig
// we have to do this in create, not start, because docker no longer handles
// merging create config with start hostconfig the same; e.g. memory limits
// get lost
containerMap, ok := engine.state.ContainerMapByArn(task.Arn)
if !ok {
containerMap = make(map[string]*api.DockerContainer)
}
hostConfig, hcerr := task.DockerHostConfig(container, containerMap)
if hcerr != nil {
return DockerContainerMetadata{Error: api.NamedError(hcerr)}
}
config, err := task.DockerConfig(container)
if err != nil {
return DockerContainerMetadata{Error: api.NamedError(err)}
}
// Augment labels with some metadata from the agent. Explicitly do this last
// such that it will always override duplicates in the provided raw config
// data.
config.Labels[labelPrefix+"task-arn"] = task.Arn
config.Labels[labelPrefix+"container-name"] = container.Name
config.Labels[labelPrefix+"task-definition-family"] = task.Family
config.Labels[labelPrefix+"task-definition-version"] = task.Version
config.Labels[labelPrefix+"cluster"] = engine.cfg.Cluster
name := ""
for i := 0; i < len(container.Name); i++ {
c := container.Name[i]
if !((c <= '9' && c >= '0') || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c == '-')) {
continue
}
name += string(c)
}
containerName := "ecs-" + task.Family + "-" + task.Version + "-" + name + "-" + utils.RandHex()
// Pre-add the container in case we stop before the next, more useful,
// AddContainer call. This ensures we have a way to get the container if
// we die before 'createContainer' returns because we can inspect by
// name
engine.state.AddContainer(&api.DockerContainer{DockerName: containerName, Container: container}, task)
seelog.Infof("Created container name mapping for task %s - %s -> %s", task, container, containerName)
engine.saver.ForceSave()
metadata := client.CreateContainer(config, hostConfig, containerName)
if metadata.DockerId != "" {
engine.state.AddContainer(&api.DockerContainer{DockerId: metadata.DockerId, DockerName: containerName, Container: container}, task)
}
seelog.Infof("Created docker container for task %s: %s -> %s", task, container, metadata.DockerId)
return metadata
}