本文整理汇总了Golang中github.com/aws/amazon-ecs-agent/agent/api.Container类的典型用法代码示例。如果您正苦于以下问题:Golang Container类的具体用法?Golang Container怎么用?Golang Container使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Container类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: containerNextState
// containerNextState determines the next state a container should go to.
// It returns: The state it should transition to, a bool indicating whether any
// action is required, and a bool indicating whether a known status change is
// possible.
// 'Stopped, false, true' -> "You can move it to known stopped, but you don't have to call a transition function"
// 'Running, true, true' -> "You can move it to running and you need to call the transition function"
// 'None, false, false' -> "This should not be moved; it has unresolved dependencies or is complete; no knownstatus change"
func (mtask *managedTask) containerNextState(container *api.Container) (api.ContainerStatus, bool, bool) {
clog := log.New("task", mtask.Task, "container", container)
if container.KnownStatus == container.DesiredStatus {
clog.Debug("Container at desired status", "desired", container.DesiredStatus)
return api.ContainerStatusNone, false, false
}
if container.KnownStatus > container.DesiredStatus {
clog.Debug("Container past desired status")
return api.ContainerStatusNone, false, false
}
if !dependencygraph.DependenciesAreResolved(container, mtask.Containers) {
clog.Debug("Can't apply state to container yet; dependencies unresolved", "state", container.DesiredStatus)
return api.ContainerStatusNone, false, false
}
var nextState api.ContainerStatus
if container.DesiredTerminal() {
nextState = api.ContainerStopped
if container.KnownStatus != api.ContainerRunning {
// If it's not currently running we do not need to do anything to make it become stopped.
return nextState, false, true
}
} else {
nextState = container.KnownStatus + 1
}
return nextState, true, true
}
开发者ID:xplenty,项目名称:amazon-ecs-agent,代码行数:35,代码来源:task_manager.go
示例2: pullContainer
func (engine *DockerTaskEngine) pullContainer(task *api.Task, container *api.Container) DockerContainerMetadata {
log.Info("Pulling container", "task", task, "container", container)
seelog.Debugf("Attempting to obtain ImagePullDeleteLock to pull image - %s", container.Image)
ImagePullDeleteLock.Lock()
seelog.Debugf("Obtained ImagePullDeleteLock to pull image - %s", container.Image)
defer seelog.Debugf("Released ImagePullDeleteLock after pulling image - %s", container.Image)
defer ImagePullDeleteLock.Unlock()
// If a task is blocked here for some time, and before it starts pulling image,
// the task's desired status is set to stopped, then don't pull the image
if task.GetDesiredStatus() == api.TaskStopped {
seelog.Infof("Task desired status is stopped, skip pull container: %v, task %v", container, task)
container.SetDesiredStatus(api.ContainerStopped)
return DockerContainerMetadata{Error: TaskStoppedBeforePullBeginError{task.Arn}}
}
metadata := engine.client.PullImage(container.Image, container.RegistryAuthentication)
err := engine.imageManager.AddContainerReferenceToImageState(container)
if err != nil {
seelog.Errorf("Error adding container reference to image state: %v", err)
}
imageState := engine.imageManager.GetImageStateFromImageName(container.Image)
engine.state.AddImageState(imageState)
engine.saver.Save()
return metadata
}
开发者ID:umaptechnologies,项目名称:amazon-ecs-agent,代码行数:27,代码来源:docker_task_engine.go
示例3: emitContainerEvent
// emitContainerEvent passes a given event up through the containerEvents channel if necessary.
// It will omit events the backend would not process and will perform best-effort deduplication of events.
func (engine *DockerTaskEngine) emitContainerEvent(task *api.Task, cont *api.Container, reason string) {
contKnownStatus := cont.GetKnownStatus()
if !contKnownStatus.BackendRecognized() {
return
}
if cont.IsInternal {
return
}
if cont.SentStatus >= contKnownStatus {
log.Debug("Already sent container event; no need to re-send", "task", task.Arn, "container", cont.Name, "event", contKnownStatus.String())
return
}
if reason == "" && cont.ApplyingError != nil {
reason = cont.ApplyingError.Error()
}
event := api.ContainerStateChange{
TaskArn: task.Arn,
ContainerName: cont.Name,
Status: contKnownStatus,
ExitCode: cont.KnownExitCode,
PortBindings: cont.KnownPortBindings,
Reason: reason,
SentStatus: &cont.SentStatus,
}
log.Debug("Container change event", "event", event)
engine.containerEvents <- event
log.Debug("Container change event passed on", "event", event)
}
开发者ID:umaptechnologies,项目名称:amazon-ecs-agent,代码行数:31,代码来源:docker_task_engine.go
示例4: linkCanResolve
func linkCanResolve(target *api.Container, link *api.Container) bool {
targetDesiredStatus := target.GetDesiredStatus()
linkDesiredStatus := link.GetDesiredStatus()
if targetDesiredStatus == api.ContainerCreated {
return linkDesiredStatus == api.ContainerCreated || linkDesiredStatus == api.ContainerRunning
} else if targetDesiredStatus == api.ContainerRunning {
return linkDesiredStatus == api.ContainerRunning
}
log.Error("Unexpected desired status", "target", target)
return false
}
开发者ID:umaptechnologies,项目名称:amazon-ecs-agent,代码行数:11,代码来源:graph.go
示例5: volumeIsResolved
func volumeIsResolved(target *api.Container, volume *api.Container) bool {
targetDesiredStatus := target.GetDesiredStatus()
if targetDesiredStatus == api.ContainerCreated || targetDesiredStatus == api.ContainerRunning {
knownStatus := volume.GetKnownStatus()
return knownStatus == api.ContainerCreated ||
knownStatus == api.ContainerRunning ||
knownStatus == api.ContainerStopped
}
log.Error("Unexpected desired status", "target", target)
return false
}
开发者ID:umaptechnologies,项目名称:amazon-ecs-agent,代码行数:12,代码来源:graph.go
示例6: verifyStatusResolveable
// verifyStatusResolveable validates that `target` can be resolved given that
// target depends on `dependencies` (which are container names) and there are
// `existingContainers` (map from name to container). The `resolves` function
// passed should return true if the named container is resolved.
func verifyStatusResolveable(target *api.Container, existingContainers map[string]*api.Container, dependencies []string, resolves func(*api.Container, *api.Container) bool) bool {
targetGoal := target.GetDesiredStatus()
if targetGoal != api.ContainerRunning && targetGoal != api.ContainerCreated {
// A container can always stop, die, or reach whatever other statre it
// wants regardless of what dependencies it has
return true
}
for _, dependency := range dependencies {
maybeResolves, exists := existingContainers[dependency]
if !exists {
return false
}
if !resolves(target, maybeResolves) {
return false
}
}
return true
}
开发者ID:umaptechnologies,项目名称:amazon-ecs-agent,代码行数:23,代码来源:graph.go
示例7: RemoveContainerReference
func (imageState *ImageState) RemoveContainerReference(container *api.Container) error {
// Get the image state write lock for updating container reference
imageState.updateLock.Lock()
defer imageState.updateLock.Unlock()
for i, _ := range imageState.Containers {
if imageState.Containers[i].Name == container.Name {
// Container reference found; hence remove it
seelog.Infof("Removing Container Reference: %v from Image State- %v", container.Name, imageState.Image.ImageID)
imageState.Containers = append(imageState.Containers[:i], imageState.Containers[i+1:]...)
// Update the last used time for the image
imageState.LastUsedAt = time.Now()
return nil
}
}
return fmt.Errorf("Container reference is not found in the image state container: %s", container.String())
}
开发者ID:umaptechnologies,项目名称:amazon-ecs-agent,代码行数:16,代码来源:types.go
示例8: onRunIsResolved
// onRunIsResolved defines a relationship where a target cannot be created until
// 'run' has reached a running state.
func onRunIsResolved(target *api.Container, run *api.Container) bool {
if target.GetDesiredStatus() >= api.ContainerCreated {
return run.GetKnownStatus() >= api.ContainerRunning
}
return false
}
开发者ID:umaptechnologies,项目名称:amazon-ecs-agent,代码行数:8,代码来源:graph.go
注:本文中的github.com/aws/amazon-ecs-agent/agent/api.Container类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论