Skip to content

Commit

Permalink
Merge pull request #1882 from ubhattacharjya/Naming
Browse files Browse the repository at this point in the history
Dependency Condition Naming change:
  • Loading branch information
ubhattacharjya authored Feb 24, 2019
2 parents c698919 + 4ac84e4 commit 7ba5947
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 53 deletions.
8 changes: 4 additions & 4 deletions agent/api/task/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ const (
NvidiaVisibleDevicesEnvVar = "NVIDIA_VISIBLE_DEVICES"
GPUAssociationType = "gpu"

ContainerOrderingStartCondition = "START"
ContainerOrderingRunningCondition = "RUNNING"
ContainerOrderingCreateCondition = "CREATE"
ContainerOrderingStartCondition = "START"

arnResourceSections = 2
arnResourceDelimiter = "/"
Expand Down Expand Up @@ -1272,7 +1272,7 @@ func (task *Task) initializeContainerOrderingForVolumes() error {
if _, ok := task.ContainerByName(volume.SourceContainer); !ok {
return fmt.Errorf("could not find container with name %s", volume.SourceContainer)
}
dependOn := apicontainer.DependsOn{Container: volume.SourceContainer, Condition: ContainerOrderingStartCondition}
dependOn := apicontainer.DependsOn{Container: volume.SourceContainer, Condition: ContainerOrderingCreateCondition}
container.DependsOn = append(container.DependsOn, dependOn)
}
}
Expand All @@ -1292,7 +1292,7 @@ func (task *Task) initializeContainerOrderingForLinks() error {
if _, ok := task.ContainerByName(linkName); !ok {
return fmt.Errorf("could not find container with name %s", linkName)
}
dependOn := apicontainer.DependsOn{Container: linkName, Condition: ContainerOrderingRunningCondition}
dependOn := apicontainer.DependsOn{Container: linkName, Condition: ContainerOrderingStartCondition}
container.DependsOn = append(container.DependsOn, dependOn)
}
}
Expand Down
8 changes: 4 additions & 4 deletions agent/api/task/task_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2887,17 +2887,17 @@ func TestInitializeContainerOrderingWithLinksAndVolumesFrom(t *testing.T) {

containerResultWithVolume := task.Containers[0]
assert.Equal(t, "myName1", containerResultWithVolume.DependsOn[0].Container)
assert.Equal(t, ContainerOrderingStartCondition, containerResultWithVolume.DependsOn[0].Condition)
assert.Equal(t, ContainerOrderingCreateCondition, containerResultWithVolume.DependsOn[0].Condition)

containerResultWithLink := task.Containers[1]
assert.Equal(t, "myName", containerResultWithLink.DependsOn[0].Container)
assert.Equal(t, ContainerOrderingRunningCondition, containerResultWithLink.DependsOn[0].Condition)
assert.Equal(t, ContainerOrderingStartCondition, containerResultWithLink.DependsOn[0].Condition)

containerResultWithBothVolumeAndLink := task.Containers[2]
assert.Equal(t, "myName", containerResultWithBothVolumeAndLink.DependsOn[0].Container)
assert.Equal(t, ContainerOrderingStartCondition, containerResultWithBothVolumeAndLink.DependsOn[0].Condition)
assert.Equal(t, ContainerOrderingCreateCondition, containerResultWithBothVolumeAndLink.DependsOn[0].Condition)
assert.Equal(t, "myName1", containerResultWithBothVolumeAndLink.DependsOn[1].Container)
assert.Equal(t, ContainerOrderingRunningCondition, containerResultWithBothVolumeAndLink.DependsOn[1].Condition)
assert.Equal(t, ContainerOrderingStartCondition, containerResultWithBothVolumeAndLink.DependsOn[1].Condition)

containerResultWithNoVolumeOrLink := task.Containers[3]
assert.Equal(t, 0, len(containerResultWithNoVolumeOrLink.DependsOn))
Expand Down
16 changes: 8 additions & 8 deletions agent/engine/dependencygraph/graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,16 @@ import (
)

const (
// StartCondition ensures that a container progresses to next state only when dependency container has started
// CreateCondition ensures that a container progresses to next state only when dependency container has started
createCondition = "CREATE"
// StartCondition ensures that a container progresses to next state only when dependency container is running
startCondition = "START"
// RunningCondition ensures that a container progresses to next state only when dependency container is running
runningCondition = "RUNNING"
// SuccessCondition ensures that a container progresses to next state only when
// dependency container has successfully completed with exit code 0
successCondition = "SUCCESS"
// CompleteCondition ensures that a container progresses to next state only when dependency container has completed
completeCondition = "COMPLETE"
// StartCondition ensures that a container progresses to next state only when dependency container is healthy
// HealthyCondition ensures that a container progresses to next state only when dependency container is healthy
healthyCondition = "HEALTHY"
// 0 is the standard exit code for success.
successExitCode = 0
Expand Down Expand Up @@ -298,10 +298,10 @@ func containerOrderingDependenciesCanResolve(target *apicontainer.Container,
dependsOnContainerDesiredStatus := dependsOnContainer.GetDesiredStatus()

switch dependsOnStatus {
case startCondition:
case createCondition:
return verifyContainerOrderingStatus(dependsOnContainer)

case runningCondition:
case startCondition:
if targetDesiredStatus == apicontainerstatus.ContainerCreated {
// The 'target' container desires to be moved to 'Created' state.
// Allow this only if the desired status of the dependency container is
Expand Down Expand Up @@ -344,13 +344,13 @@ func containerOrderingDependenciesIsResolved(target *apicontainer.Container,
dependsOnContainerKnownStatus := dependsOnContainer.GetKnownStatus()

switch dependsOnStatus {
case startCondition:
case createCondition:
// The 'target' container desires to be moved to 'Created' or the 'steady' state.
// Allow this only if the known status of the dependency container state is already started
// i.e it's state is any of 'Created', 'steady state' or 'Stopped'
return dependsOnContainerKnownStatus >= apicontainerstatus.ContainerCreated

case runningCondition:
case startCondition:
if targetDesiredStatus == apicontainerstatus.ContainerCreated {
// The 'target' container desires to be moved to 'Created' state.
// Allow this only if the known status of the linked container is
Expand Down
74 changes: 37 additions & 37 deletions agent/engine/dependencygraph/graph_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,11 @@ func TestValidDependencies(t *testing.T) {
assert.True(t, resolveable, "One container should resolve trivially")

// Webserver stack
php := steadyStateContainer("php", []apicontainer.DependsOn{{Container: "db", Condition: "RUNNING"}}, apicontainerstatus.ContainerRunning, apicontainerstatus.ContainerRunning)
db := steadyStateContainer("db", []apicontainer.DependsOn{{Container: "dbdatavolume", Condition: "START"}}, apicontainerstatus.ContainerRunning, apicontainerstatus.ContainerRunning)
php := steadyStateContainer("php", []apicontainer.DependsOn{{Container: "db", Condition: startCondition}}, apicontainerstatus.ContainerRunning, apicontainerstatus.ContainerRunning)
db := steadyStateContainer("db", []apicontainer.DependsOn{{Container: "dbdatavolume", Condition: createCondition}}, apicontainerstatus.ContainerRunning, apicontainerstatus.ContainerRunning)
dbdata := createdContainer("dbdatavolume", []apicontainer.DependsOn{}, apicontainerstatus.ContainerRunning)
webserver := steadyStateContainer("webserver", []apicontainer.DependsOn{{Container: "php", Condition: "RUNNING"}, {Container: "htmldata", Condition: "START"}}, apicontainerstatus.ContainerRunning, apicontainerstatus.ContainerRunning)
htmldata := steadyStateContainer("htmldata", []apicontainer.DependsOn{{Container: "sharedcssfiles", Condition: "START"}}, apicontainerstatus.ContainerRunning, apicontainerstatus.ContainerRunning)
webserver := steadyStateContainer("webserver", []apicontainer.DependsOn{{Container: "php", Condition: startCondition}, {Container: "htmldata", Condition: createCondition}}, apicontainerstatus.ContainerRunning, apicontainerstatus.ContainerRunning)
htmldata := steadyStateContainer("htmldata", []apicontainer.DependsOn{{Container: "sharedcssfiles", Condition: createCondition}}, apicontainerstatus.ContainerRunning, apicontainerstatus.ContainerRunning)
sharedcssfiles := createdContainer("sharedcssfiles", []apicontainer.DependsOn{}, apicontainerstatus.ContainerRunning)

task = &apitask.Task{
Expand All @@ -94,8 +94,8 @@ func TestValidDependenciesWithCycles(t *testing.T) {
// Unresolveable: cycle
task := &apitask.Task{
Containers: []*apicontainer.Container{
steadyStateContainer("a", []apicontainer.DependsOn{{Container: "b", Condition: "START"}}, apicontainerstatus.ContainerRunning, apicontainerstatus.ContainerRunning),
steadyStateContainer("b", []apicontainer.DependsOn{{Container: "a", Condition: "START"}}, apicontainerstatus.ContainerRunning, apicontainerstatus.ContainerRunning),
steadyStateContainer("a", []apicontainer.DependsOn{{Container: "b", Condition: createCondition}}, apicontainerstatus.ContainerRunning, apicontainerstatus.ContainerRunning),
steadyStateContainer("b", []apicontainer.DependsOn{{Container: "a", Condition: createCondition}}, apicontainerstatus.ContainerRunning, apicontainerstatus.ContainerRunning),
},
}
resolveable := ValidDependencies(task)
Expand All @@ -106,7 +106,7 @@ func TestValidDependenciesWithUnresolvedReference(t *testing.T) {
// Unresolveable, reference doesn't exist
task := &apitask.Task{
Containers: []*apicontainer.Container{
steadyStateContainer("php", []apicontainer.DependsOn{{Container: "db", Condition: "START"}}, apicontainerstatus.ContainerRunning, apicontainerstatus.ContainerRunning),
steadyStateContainer("php", []apicontainer.DependsOn{{Container: "db", Condition: createCondition}}, apicontainerstatus.ContainerRunning, apicontainerstatus.ContainerRunning),
},
}
resolveable := ValidDependencies(task)
Expand All @@ -126,11 +126,11 @@ func TestDependenciesAreResolvedWhenSteadyStateIsRunning(t *testing.T) {
assert.NoError(t, err, "One container should resolve trivially")

// Webserver stack
php := steadyStateContainer("php", []apicontainer.DependsOn{{Container: "db", Condition: "RUNNING"}}, apicontainerstatus.ContainerRunning, apicontainerstatus.ContainerRunning)
db := steadyStateContainer("db", []apicontainer.DependsOn{{Container: "dbdatavolume", Condition: "START"}}, apicontainerstatus.ContainerRunning, apicontainerstatus.ContainerRunning)
php := steadyStateContainer("php", []apicontainer.DependsOn{{Container: "db", Condition: startCondition}}, apicontainerstatus.ContainerRunning, apicontainerstatus.ContainerRunning)
db := steadyStateContainer("db", []apicontainer.DependsOn{{Container: "dbdatavolume", Condition: createCondition}}, apicontainerstatus.ContainerRunning, apicontainerstatus.ContainerRunning)
dbdata := createdContainer("dbdatavolume", []apicontainer.DependsOn{}, apicontainerstatus.ContainerRunning)
webserver := steadyStateContainer("webserver", []apicontainer.DependsOn{{Container: "php", Condition: "RUNNING"}, {Container: "htmldata", Condition: "START"}}, apicontainerstatus.ContainerRunning, apicontainerstatus.ContainerRunning)
htmldata := steadyStateContainer("htmldata", []apicontainer.DependsOn{{Container: "sharedcssfiles", Condition: "START"}}, apicontainerstatus.ContainerRunning, apicontainerstatus.ContainerRunning)
webserver := steadyStateContainer("webserver", []apicontainer.DependsOn{{Container: "php", Condition: startCondition}, {Container: "htmldata", Condition: createCondition}}, apicontainerstatus.ContainerRunning, apicontainerstatus.ContainerRunning)
htmldata := steadyStateContainer("htmldata", []apicontainer.DependsOn{{Container: "sharedcssfiles", Condition: createCondition}}, apicontainerstatus.ContainerRunning, apicontainerstatus.ContainerRunning)
sharedcssfiles := createdContainer("sharedcssfiles", []apicontainer.DependsOn{}, apicontainerstatus.ContainerRunning)

task = &apitask.Task{
Expand Down Expand Up @@ -194,11 +194,11 @@ func TestRunDependencies(t *testing.T) {

func TestRunDependenciesWhenSteadyStateIsResourcesProvisionedForOneContainer(t *testing.T) {
// Webserver stack
php := steadyStateContainer("php", []apicontainer.DependsOn{{Container: "db", Condition: "START"}}, apicontainerstatus.ContainerRunning, apicontainerstatus.ContainerRunning)
db := steadyStateContainer("db", []apicontainer.DependsOn{{Container: "dbdatavolume", Condition: "START"}}, apicontainerstatus.ContainerRunning, apicontainerstatus.ContainerRunning)
php := steadyStateContainer("php", []apicontainer.DependsOn{{Container: "db", Condition: createCondition}}, apicontainerstatus.ContainerRunning, apicontainerstatus.ContainerRunning)
db := steadyStateContainer("db", []apicontainer.DependsOn{{Container: "dbdatavolume", Condition: createCondition}}, apicontainerstatus.ContainerRunning, apicontainerstatus.ContainerRunning)
dbdata := createdContainer("dbdatavolume", []apicontainer.DependsOn{}, apicontainerstatus.ContainerRunning)
webserver := steadyStateContainer("webserver", []apicontainer.DependsOn{{Container: "php", Condition: "START"}, {Container: "htmldata", Condition: "START"}}, apicontainerstatus.ContainerRunning, apicontainerstatus.ContainerRunning)
htmldata := steadyStateContainer("htmldata", []apicontainer.DependsOn{{Container: "sharedcssfiles", Condition: "START"}}, apicontainerstatus.ContainerRunning, apicontainerstatus.ContainerRunning)
webserver := steadyStateContainer("webserver", []apicontainer.DependsOn{{Container: "php", Condition: createCondition}, {Container: "htmldata", Condition: createCondition}}, apicontainerstatus.ContainerRunning, apicontainerstatus.ContainerRunning)
htmldata := steadyStateContainer("htmldata", []apicontainer.DependsOn{{Container: "sharedcssfiles", Condition: createCondition}}, apicontainerstatus.ContainerRunning, apicontainerstatus.ContainerRunning)
sharedcssfiles := createdContainer("sharedcssfiles", []apicontainer.DependsOn{}, apicontainerstatus.ContainerRunning)
// The Pause container, being added to the webserver stack
pause := steadyStateContainer("pause", []apicontainer.DependsOn{}, apicontainerstatus.ContainerResourcesProvisioned, apicontainerstatus.ContainerResourcesProvisioned)
Expand Down Expand Up @@ -581,67 +581,67 @@ func TestContainerOrderingCanResolve(t *testing.T) {
{
TargetDesired: apicontainerstatus.ContainerCreated,
DependencyDesired: apicontainerstatus.ContainerStatusNone,
DependencyCondition: startCondition,
DependencyCondition: createCondition,
Resolvable: false,
},
{
TargetDesired: apicontainerstatus.ContainerCreated,
DependencyDesired: apicontainerstatus.ContainerStopped,
DependencyCondition: startCondition,
DependencyCondition: createCondition,
Resolvable: true,
},
{
TargetDesired: apicontainerstatus.ContainerCreated,
DependencyDesired: apicontainerstatus.ContainerZombie,
DependencyCondition: startCondition,
DependencyCondition: createCondition,
Resolvable: false,
},
{
TargetDesired: apicontainerstatus.ContainerRunning,
DependencyDesired: apicontainerstatus.ContainerStatusNone,
DependencyCondition: startCondition,
DependencyCondition: createCondition,
Resolvable: false,
},
{
TargetDesired: apicontainerstatus.ContainerRunning,
DependencyDesired: apicontainerstatus.ContainerCreated,
DependencyCondition: startCondition,
DependencyCondition: createCondition,
Resolvable: true,
},
{
TargetDesired: apicontainerstatus.ContainerRunning,
DependencyDesired: apicontainerstatus.ContainerRunning,
DependencyCondition: startCondition,
DependencyCondition: createCondition,
Resolvable: true,
},
{
TargetDesired: apicontainerstatus.ContainerRunning,
DependencyDesired: apicontainerstatus.ContainerStopped,
DependencyCondition: startCondition,
DependencyCondition: createCondition,
Resolvable: true,
},
{
TargetDesired: apicontainerstatus.ContainerCreated,
DependencyDesired: apicontainerstatus.ContainerCreated,
DependencyCondition: runningCondition,
DependencyCondition: startCondition,
Resolvable: true,
},
{
TargetDesired: apicontainerstatus.ContainerRunning,
DependencyDesired: apicontainerstatus.ContainerRunning,
DependencyCondition: runningCondition,
DependencyCondition: startCondition,
Resolvable: true,
},
{
TargetDesired: apicontainerstatus.ContainerCreated,
DependencyDesired: apicontainerstatus.ContainerRunning,
DependencyCondition: runningCondition,
DependencyCondition: startCondition,
Resolvable: true,
},
{
TargetDesired: apicontainerstatus.ContainerRunning,
DependencyDesired: apicontainerstatus.ContainerZombie,
DependencyCondition: runningCondition,
DependencyCondition: startCondition,
Resolvable: false,
},
{
Expand Down Expand Up @@ -700,67 +700,67 @@ func TestContainerOrderingIsResolved(t *testing.T) {
{
TargetDesired: apicontainerstatus.ContainerCreated,
DependencyKnown: apicontainerstatus.ContainerStatusNone,
DependencyCondition: startCondition,
DependencyCondition: createCondition,
Resolved: false,
},
{
TargetDesired: apicontainerstatus.ContainerCreated,
DependencyKnown: apicontainerstatus.ContainerCreated,
DependencyCondition: startCondition,
DependencyCondition: createCondition,
Resolved: true,
},
{
TargetDesired: apicontainerstatus.ContainerRunning,
DependencyKnown: apicontainerstatus.ContainerStopped,
DependencyCondition: startCondition,
DependencyCondition: createCondition,
Resolved: true,
},
{
TargetDesired: apicontainerstatus.ContainerCreated,
DependencyKnown: apicontainerstatus.ContainerStopped,
DependencyCondition: startCondition,
DependencyCondition: createCondition,
Resolved: true,
},
{
TargetDesired: apicontainerstatus.ContainerRunning,
DependencyKnown: apicontainerstatus.ContainerStatusNone,
DependencyCondition: startCondition,
DependencyCondition: createCondition,
Resolved: false,
},
{
TargetDesired: apicontainerstatus.ContainerRunning,
DependencyKnown: apicontainerstatus.ContainerCreated,
DependencyCondition: startCondition,
DependencyCondition: createCondition,
Resolved: true,
},
{
TargetDesired: apicontainerstatus.ContainerCreated,
DependencyKnown: apicontainerstatus.ContainerCreated,
DependencyCondition: runningCondition,
DependencyCondition: startCondition,
Resolved: true,
},
{
TargetDesired: apicontainerstatus.ContainerCreated,
DependencyKnown: apicontainerstatus.ContainerRunning,
DependencyCondition: runningCondition,
DependencyCondition: startCondition,
Resolved: true,
},
{
TargetDesired: apicontainerstatus.ContainerCreated,
DependencyKnown: apicontainerstatus.ContainerZombie,
DependencyCondition: runningCondition,
DependencyCondition: startCondition,
Resolved: false,
},
{
TargetDesired: apicontainerstatus.ContainerRunning,
DependencyKnown: apicontainerstatus.ContainerRunning,
DependencyCondition: runningCondition,
DependencyCondition: startCondition,
Resolved: true,
},
{
TargetDesired: apicontainerstatus.ContainerRunning,
DependencyKnown: apicontainerstatus.ContainerZombie,
DependencyCondition: runningCondition,
DependencyCondition: startCondition,
Resolved: false,
},
{
Expand Down

0 comments on commit 7ba5947

Please sign in to comment.