Skip to content

Commit

Permalink
Do not fail if a specified locking dependency is missing
Browse files Browse the repository at this point in the history
[#157994374]

Signed-off-by: Chunyi Lyu <[email protected]>
  • Loading branch information
gcapizzi authored and ChunyiLyu committed May 31, 2018
1 parent c36ecd9 commit d2d529f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 24 deletions.
14 changes: 3 additions & 11 deletions orderer/kahn_lock_orderer.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package orderer
import (
"errors"

"fmt"
"github.com/cloudfoundry-incubator/bosh-backup-and-restore/orchestrator"
)

Expand Down Expand Up @@ -50,10 +49,7 @@ func findLockingDependencies(jobs []orchestrator.Job, orderConstraintSpecifier o
jobSpecifiersThatShouldBeLockedAfter := orderConstraintSpecifier.Before(job)

for _, jobSpecifierThatShouldBeLockedAfter := range jobSpecifiersThatShouldBeLockedAfter {
jobsThatShouldBeLockedAfter, err := findJobsBySpecifier(jobs, jobSpecifierThatShouldBeLockedAfter)
if err != nil {
return nil, err
}
jobsThatShouldBeLockedAfter := findJobsBySpecifier(jobs, jobSpecifierThatShouldBeLockedAfter)

for _, afterJob := range jobsThatShouldBeLockedAfter {
lockingDependencies = append(lockingDependencies, lockingDependency{Before: job, After: afterJob})
Expand All @@ -64,19 +60,15 @@ func findLockingDependencies(jobs []orchestrator.Job, orderConstraintSpecifier o
return lockingDependencies, nil
}

func findJobsBySpecifier(jobs []orchestrator.Job, specifier orchestrator.JobSpecifier) ([]orchestrator.Job, error) {
func findJobsBySpecifier(jobs []orchestrator.Job, specifier orchestrator.JobSpecifier) []orchestrator.Job {
var foundJobs []orchestrator.Job
for _, job := range jobs {
if job.Name() == specifier.Name && job.Release() == specifier.Release {
foundJobs = append(foundJobs, job)
}
}

if len(foundJobs) == 0 {
return nil, fmt.Errorf("could not find locking dependency %s/%s", specifier.Release, specifier.Name)
}

return foundJobs, nil
return foundJobs
}

func orderJobsUsingTheKahnAlgorithm(jobs []orchestrator.Job, lockingDependencies []lockingDependency) ([][]orchestrator.Job, error) {
Expand Down
14 changes: 1 addition & 13 deletions orderer/kahn_lock_orderer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,6 @@ var _ = Describe("KahnLockOrderer", func() {
}
}),

Entry("one job, dependency on non-existent job", func() lockingTestCase {
var job = fakeJob("test", "releasetest")

orderConstraintSpecifier := NewFakeOrderConstraintSpecifier()

return lockingTestCase{
inputJobs: []Job{job},
orderedJobs: [][]Job{{job}},
orderConstraintSpecifier: orderConstraintSpecifier,
}
}),

Entry("multiple jobs, no dependencies", func() lockingTestCase {
var a = fakeJob("a", "releasea")
var b = fakeJob("b", "releaseb")
Expand Down Expand Up @@ -103,7 +91,7 @@ var _ = Describe("KahnLockOrderer", func() {

return lockingTestCase{
inputJobs: []Job{a, b, c},
errorMessage: "could not find locking dependency releasee/e",
orderedJobs: [][]Job{{a, b, c}},
orderConstraintSpecifier: orderConstraintSpecifier,
}
}),
Expand Down

0 comments on commit d2d529f

Please sign in to comment.