Skip to content

Commit

Permalink
Make --parallel option specific to the Syncblobs command
Browse files Browse the repository at this point in the history
- parallel option flag value is used when syncing blobs

[#132622945]

Signed-off-by: Zachary Auerbach <[email protected]>
  • Loading branch information
DennisDenuto authored and zaksoup committed Oct 17, 2016
1 parent 0e54267 commit 22aeb1d
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 16 deletions.
2 changes: 1 addition & 1 deletion cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ func (c Cmd) Execute() (cmdErr error) {
return NewUploadBlobsCmd(c.blobsDir(opts.Directory)).Run()

case *SyncBlobsOpts:
return NewSyncBlobsCmd(c.blobsDir(opts.Directory)).Run()
return NewSyncBlobsCmd(c.blobsDir(opts.Directory), opts.ParallelOpt).Run()

case *MessageOpts:
deps.UI.PrintBlock(opts.Message)
Expand Down
2 changes: 1 addition & 1 deletion cmd/opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ type BoshOpts struct {
VersionOpt func() error `long:"version" short:"v" description:"Show CLI version"`

ConfigPathOpt string `long:"config" description:"Config file path" env:"BOSH_CONFIG" default:"~/.bosh/config"`
ParallelOpt string `long:"parallel" description:"Sets the max number of parallel downloads"`

EnvironmentOpt string `long:"environment" short:"e" description:"Director environment name or URL" env:"BOSH_ENVIRONMENT"`
CACertOpt string `long:"ca-cert" description:"Director CA certificate path or value" env:"BOSH_CA_CERT"`
Expand Down Expand Up @@ -740,6 +739,7 @@ type RemoveBlobArgs struct {

type SyncBlobsOpts struct {
Directory DirOrCWDArg `long:"dir" description:"Release directory path if not current working directory" default:"."`
ParallelOpt int `long:"parallel" description:"Sets the max number of parallel downloads" default:"5"`
cmd
}

Expand Down
16 changes: 8 additions & 8 deletions cmd/opts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,6 @@ var _ = Describe("Opts", func() {
})
})

Describe("ParallelOpt", func() {
It("contains desired values", func() {
Expect(getStructTagForName("ParallelOpt", opts)).To(Equal(
`long:"parallel" description:"Sets the max number of parallel downloads"`,
))
})
})

Describe("EnvironmentOpt", func() {
It("contains desired values", func() {
Expect(getStructTagForName("EnvironmentOpt", opts)).To(Equal(
Expand Down Expand Up @@ -2407,6 +2399,14 @@ var _ = Describe("Opts", func() {
))
})
})

Describe("Parallel", func() {
It("contains desired values", func() {
Expect(getStructTagForName("ParallelOpt", opts)).To(Equal(
`long:"parallel" description:"Sets the max number of parallel downloads" default:"5"`,
))
})
})
})

Describe("UploadBlobsOpts", func() {
Expand Down
7 changes: 4 additions & 3 deletions cmd/sync_blobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ import (

type SyncBlobsCmd struct {
blobsDir boshreldir.BlobsDir
numOfParallelWorkers int
}

func NewSyncBlobsCmd(blobsDir boshreldir.BlobsDir) SyncBlobsCmd {
return SyncBlobsCmd{blobsDir: blobsDir}
func NewSyncBlobsCmd(blobsDir boshreldir.BlobsDir, numOfParallelWorkers int) SyncBlobsCmd {
return SyncBlobsCmd{blobsDir: blobsDir, numOfParallelWorkers: numOfParallelWorkers}
}

func (c SyncBlobsCmd) Run() error {
err := c.blobsDir.DownloadBlobs(1)
err := c.blobsDir.DownloadBlobs(c.numOfParallelWorkers)
if err != nil {
return bosherr.WrapErrorf(err, "Downloading blobs")
}
Expand Down
11 changes: 8 additions & 3 deletions cmd/sync_blobs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,27 @@ import (
var _ = Describe("SyncBlobsCmd", func() {
var (
blobsDir *fakereldir.FakeBlobsDir
command SyncBlobsCmd
command SyncBlobsCmd
numOfWorkers int
)

BeforeEach(func() {
numOfWorkers = 5
blobsDir = &fakereldir.FakeBlobsDir{}
command = NewSyncBlobsCmd(blobsDir)
command = NewSyncBlobsCmd(blobsDir, numOfWorkers)
})

Describe("Run", func() {
act := func() error { return command.Run() }
act := func() error {
return command.Run()
}

It("downloads all blobs", func() {
err := act()
Expect(err).ToNot(HaveOccurred())

Expect(blobsDir.DownloadBlobsCallCount()).To(Equal(1))
Expect(blobsDir.DownloadBlobsArgsForCall(0)).To(Equal(5))
})

It("returns error if download fails", func() {
Expand Down

0 comments on commit 22aeb1d

Please sign in to comment.