-
Notifications
You must be signed in to change notification settings - Fork 40
Implemented direct download cmd #162
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
34371ac
add direct download command
reshmifrog 175ad98
refactored direct download cmd
reshmifrog 47112f6
update client-go dependency
reshmifrog 9061eec
refactor new direct command logic
reshmifrog 38a86e0
renamed command name,added comments
reshmifrog e81bbd9
removed unnecessary flags from ddl cmd, renamed cmd
reshmifrog f5b25f2
merge upstream
reshmifrog 56cf4f9
refactor ddl command logic
reshmifrog 9d25243
update dependency, add unit tests
reshmifrog c523850
resolve conflicts
reshmifrog 1a4cf03
fix lints
reshmifrog 7b1cf62
added bundle flag and remove unnecesary logs
reshmifrog 8a9f275
removed extra default from help docs
reshmifrog 5f717e6
upstream
reshmifrog 5e3d6b3
add include-deps and exclude-artifacts as string flags
reshmifrog a0665c1
update deps
reshmifrog a91d029
update dependency
reshmifrog File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,224 @@ | ||
| package generic | ||
reshmifrog marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| import ( | ||
| "errors" | ||
| "os" | ||
| "path/filepath" | ||
| "strconv" | ||
|
|
||
| buildinfo "github.com/jfrog/build-info-go/entities" | ||
| gofrog "github.com/jfrog/gofrog/io" | ||
| "github.com/jfrog/jfrog-cli-core/v2/common/spec" | ||
|
|
||
| "github.com/jfrog/jfrog-cli-core/v2/artifactory/utils" | ||
| "github.com/jfrog/jfrog-cli-core/v2/common/build" | ||
| "github.com/jfrog/jfrog-client-go/artifactory/services" | ||
| serviceutils "github.com/jfrog/jfrog-client-go/artifactory/services/utils" | ||
| "github.com/jfrog/jfrog-client-go/utils/errorutils" | ||
| "github.com/jfrog/jfrog-client-go/utils/io/fileutils" | ||
| "github.com/jfrog/jfrog-client-go/utils/log" | ||
| ) | ||
|
|
||
| type DirectDownloadCommand struct { | ||
| DownloadCommand | ||
| } | ||
|
|
||
| func NewDirectDownloadCommand() *DirectDownloadCommand { | ||
| return &DirectDownloadCommand{DownloadCommand: *NewDownloadCommand()} | ||
| } | ||
|
|
||
| func (ddc *DirectDownloadCommand) CommandName() string { | ||
| return "rt_direct_download" | ||
| } | ||
|
|
||
| func (ddc *DirectDownloadCommand) Run() error { | ||
| return ddc.directDownload() | ||
| } | ||
|
|
||
| func (ddc *DirectDownloadCommand) directDownload() error { | ||
reshmifrog marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| // Init progress bar if needed | ||
| if ddc.progress != nil { | ||
| ddc.progress.SetHeadlineMsg("") | ||
| ddc.progress.InitProgressReaders() | ||
| } | ||
|
|
||
| servicesManager, err := utils.CreateDownloadServiceManager(ddc.serverDetails, ddc.configuration.Threads, ddc.retries, ddc.retryWaitTimeMilliSecs, ddc.DryRun(), ddc.progress) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| // Build Info Collection: | ||
| toCollect, err := ddc.buildConfiguration.IsCollectBuildInfo() | ||
| if err != nil { | ||
| return err | ||
| } | ||
| if toCollect && !ddc.DryRun() { | ||
| var buildName, buildNumber string | ||
| buildName, err = ddc.buildConfiguration.GetBuildName() | ||
| if err != nil { | ||
| return err | ||
| } | ||
| buildNumber, err = ddc.buildConfiguration.GetBuildNumber() | ||
| if err != nil { | ||
| return err | ||
| } | ||
| if err = build.SaveBuildGeneralDetails(buildName, buildNumber, ddc.buildConfiguration.GetProject()); err != nil { | ||
| return err | ||
| } | ||
| } | ||
|
|
||
| // var downloadParamsArray []services.DirectDownloadParams | ||
| var errorOccurred = false | ||
| var downloadParamsArray []services.DirectDownloadParams | ||
| // Create DownloadParams for all File-Spec groups. | ||
| var downParams services.DirectDownloadParams | ||
| for i := 0; i < len(ddc.Spec().Files); i++ { | ||
| downParams, err = getDirectDownloadParams(ddc.Spec().Get(i), ddc.configuration) | ||
| if err != nil { | ||
| errorOccurred = true | ||
| log.Error(err) | ||
| continue | ||
| } | ||
| downloadParamsArray = append(downloadParamsArray, downParams) | ||
| } | ||
| // Perform download. | ||
| // In case of build-info collection/sync-deletes operation/a detailed summary is required, we use the download service which provides results file reader, | ||
| // otherwise we use the download service which provides only general counters. | ||
| var totalDownloaded, totalFailed int | ||
| var summary *serviceutils.OperationSummary | ||
| if toCollect || ddc.SyncDeletesPath() != "" || ddc.DetailedSummary() { | ||
| summary, err = servicesManager.DirectDownloadFilesWithSummary(downloadParamsArray...) | ||
| if err != nil { | ||
| errorOccurred = true | ||
| log.Error(err) | ||
| } | ||
| if summary != nil { | ||
| defer gofrog.Close(summary.ArtifactsDetailsReader, &err) | ||
| // If 'detailed summary' was requested, then the reader should not be closed here. | ||
| // It will be closed after it will be used to generate the summary. | ||
| if ddc.DetailedSummary() { | ||
| ddc.result.SetReader(summary.TransferDetailsReader) | ||
| } else { | ||
| defer gofrog.Close(summary.TransferDetailsReader, &err) | ||
| } | ||
| totalDownloaded = summary.TotalSucceeded | ||
| totalFailed = summary.TotalFailed | ||
| } | ||
| } else { | ||
| totalDownloaded, totalFailed, err = servicesManager.DirectDownloadFiles(downloadParamsArray...) | ||
| if err != nil { | ||
| errorOccurred = true | ||
| log.Error(err) | ||
| } | ||
| } | ||
| ddc.result.SetSuccessCount(totalDownloaded) | ||
| ddc.result.SetFailCount(totalFailed) | ||
| // Check for errors. | ||
| if errorOccurred { | ||
| return errors.New("download finished with errors, please review the logs") | ||
| } | ||
| if ddc.DryRun() { | ||
| ddc.result.SetSuccessCount(totalDownloaded) | ||
| ddc.result.SetFailCount(0) | ||
| return err | ||
| } else if ddc.SyncDeletesPath() != "" { | ||
| var absSyncDeletesPath string | ||
| absSyncDeletesPath, err = filepath.Abs(ddc.SyncDeletesPath()) | ||
| if err != nil { | ||
| return errorutils.CheckError(err) | ||
| } | ||
| if _, err = os.Stat(absSyncDeletesPath); err == nil { | ||
| // Unmarshal the local paths of the downloaded files from the results file reader | ||
| var tmpRoot string | ||
| tmpRoot, err = createDownloadResultEmptyTmpReflection(summary.TransferDetailsReader) | ||
| defer func() { | ||
| err = errors.Join(err, fileutils.RemoveTempDir(tmpRoot)) | ||
| }() | ||
| if err != nil { | ||
| return err | ||
| } | ||
| walkFn := createSyncDeletesWalkFunction(tmpRoot) | ||
| err = gofrog.Walk(ddc.SyncDeletesPath(), walkFn, false) | ||
| if err != nil { | ||
| return errorutils.CheckError(err) | ||
| } | ||
| } else if os.IsNotExist(err) { | ||
| log.Info("Sync-deletes path", absSyncDeletesPath, "does not exists.") | ||
| } | ||
| } | ||
| log.Debug("Downloaded", strconv.Itoa(totalDownloaded), "artifacts.") | ||
|
|
||
| // Build Info | ||
| if toCollect { | ||
| var buildName, buildNumber string | ||
| buildName, err = ddc.buildConfiguration.GetBuildName() | ||
| if err != nil { | ||
| return err | ||
| } | ||
| buildNumber, err = ddc.buildConfiguration.GetBuildNumber() | ||
| if err != nil { | ||
| return err | ||
| } | ||
| var buildDependencies []buildinfo.Dependency | ||
| buildDependencies, err = serviceutils.ConvertArtifactsDetailsToBuildInfoDependencies(summary.ArtifactsDetailsReader) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| populateFunc := func(partial *buildinfo.Partial) { | ||
| partial.Dependencies = buildDependencies | ||
| partial.ModuleId = ddc.buildConfiguration.GetModule() | ||
| partial.ModuleType = buildinfo.Generic | ||
| } | ||
| return build.SavePartialBuildInfo(buildName, buildNumber, ddc.buildConfiguration.GetProject(), populateFunc) | ||
| } | ||
|
|
||
| return err | ||
| } | ||
|
|
||
| func getDirectDownloadParams(f *spec.File, configuration *utils.DownloadConfiguration) (downParams services.DirectDownloadParams, err error) { | ||
| downParams = services.NewDirectDownloadParams() | ||
| downParams.CommonParams, err = f.ToCommonParams() | ||
| if err != nil { | ||
| return | ||
| } | ||
| downParams.MinSplitSize = configuration.MinSplitSize | ||
| downParams.SplitCount = configuration.SplitCount | ||
| downParams.SkipChecksum = configuration.SkipChecksum | ||
|
|
||
| downParams.Recursive, err = f.IsRecursive(true) | ||
| if err != nil { | ||
| return | ||
| } | ||
|
|
||
| downParams.IncludeDirs, err = f.IsIncludeDirs(false) | ||
| if err != nil { | ||
| return | ||
| } | ||
|
|
||
| downParams.Flat, err = f.IsFlat(false) | ||
| if err != nil { | ||
| return | ||
| } | ||
|
|
||
| downParams.Explode, err = f.IsExplode(false) | ||
| if err != nil { | ||
| return | ||
| } | ||
|
|
||
| downParams.ExcludeArtifacts, err = f.IsExcludeArtifacts(false) | ||
| if err != nil { | ||
| return | ||
| } | ||
|
|
||
| downParams.IncludeDeps, err = f.IsIncludeDeps(false) | ||
| if err != nil { | ||
| return | ||
| } | ||
|
|
||
| downParams.Transitive, err = f.IsTransitive(false) | ||
| if err != nil { | ||
| return | ||
| } | ||
|
|
||
| return | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.