Skip to content

Commit

Permalink
Transfer - Fix phase 3 progressbar
Browse files Browse the repository at this point in the history
  • Loading branch information
yahavi committed Oct 17, 2023
1 parent 720c324 commit 12593e3
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 17 deletions.
12 changes: 8 additions & 4 deletions artifactory/commands/transferfiles/delayedartifactshandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func consumeDelayFilesIfNoErrors(phase phaseBase, addedDelayFiles []string) erro
if len(addedDelayFiles) > 0 && phase.progressBar != nil {
phaseTaskProgressBar := phase.progressBar.phases[phase.phaseId].GetTasksProgressBar()
oldTotal := phaseTaskProgressBar.GetTotal()
delayCount, err := countDelayFilesContent(addedDelayFiles)
delayCount, _, err := countDelayFilesContent(addedDelayFiles)
if err != nil {
return err
}
Expand All @@ -129,16 +129,20 @@ func consumeDelayFilesIfNoErrors(phase phaseBase, addedDelayFiles []string) erro
return nil
}

func countDelayFilesContent(filePaths []string) (int, error) {
func countDelayFilesContent(filePaths []string) (int, int64, error) {
count := 0
var storage int64 = 0
for _, file := range filePaths {
delayFile, err := readDelayFile(file)
if err != nil {
return 0, err
return 0, storage, err
}
count += len(delayFile.DelayedArtifacts)
for _, delay := range delayFile.DelayedArtifacts {
storage += delay.Size
}
}
return count, nil
return count, storage, nil
}

func handleDelayedArtifactsFiles(filesToConsume []string, base phaseBase, delayUploadComparisonFunctions []shouldDelayUpload) error {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@ package transferfiles

import (
"fmt"
"github.com/jfrog/jfrog-cli-core/v2/artifactory/commands/transferfiles/api"
"github.com/jfrog/jfrog-cli-core/v2/artifactory/commands/transferfiles/state"
"github.com/jfrog/jfrog-cli-core/v2/utils/tests"
"github.com/jfrog/jfrog-client-go/utils/io/fileutils"
"github.com/stretchr/testify/assert"
"math"
"os"
"path/filepath"
"sync"
"testing"
"time"

"github.com/jfrog/jfrog-cli-core/v2/artifactory/commands/transferfiles/api"
"github.com/jfrog/jfrog-cli-core/v2/artifactory/commands/transferfiles/state"
"github.com/jfrog/jfrog-cli-core/v2/utils/tests"
"github.com/jfrog/jfrog-client-go/utils/io/fileutils"
"github.com/stretchr/testify/assert"
)

var delayTestRepoKey = "delay-local-repo"
Expand Down Expand Up @@ -52,7 +53,7 @@ func TestDelayedArtifactsMng(t *testing.T) {
go func() {
defer writeWaitGroup.Done()
for i := 0; i < artifactsNumber; i++ {
artifactsChannelMng.channel <- api.FileRepresentation{Repo: testRepoKey, Path: "path", Name: fmt.Sprintf("name%d", i)}
artifactsChannelMng.channel <- api.FileRepresentation{Repo: testRepoKey, Path: "path", Name: fmt.Sprintf("name%d", i), Size: int64(i)}
}
}()

Expand All @@ -71,8 +72,9 @@ func TestDelayedArtifactsMng(t *testing.T) {
expectedNumberOfFiles := int(math.Ceil(float64(artifactsNumber) / float64(maxDelayedArtifactsInFile)))
validateDelayedArtifactsFiles(t, delayFiles, expectedNumberOfFiles, artifactsNumber)

delayCount, err := countDelayFilesContent(delayFiles)
delayCount, storage, err := countDelayFilesContent(delayFiles)
assert.NoError(t, err)
assert.Equal(t, int64(1225), storage)
assert.Equal(t, delayCount, artifactsNumber)
}

Expand Down
20 changes: 17 additions & 3 deletions artifactory/commands/transferfiles/fileserror.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ package transferfiles
import (
"errors"
"fmt"
"os"
"strings"
"time"

"github.com/jfrog/gofrog/parallel"
"github.com/jfrog/jfrog-cli-core/v2/artifactory/commands/transferfiles/api"
"github.com/jfrog/jfrog-client-go/utils/errorutils"
"github.com/jfrog/jfrog-client-go/utils/log"
"os"
"strings"
"time"
)

type errorFileHandlerFunc func() parallel.TaskFunc
Expand Down Expand Up @@ -150,6 +151,19 @@ func (e *errorsRetryPhase) initProgressBar() error {
filesCount += len(failedFiles.Errors)
}
// The progress bar will also be responsible to display the number of delayed items for this repository.
// Those delayed artifacts will be handled at the end of this phase in case they exist.
delayFiles, err := getDelayFiles([]string{e.repoKey})
if err != nil {
return err
}
delayCount, delayStorage, err := countDelayFilesContent(delayFiles)
if err != nil {
return err
}
err = e.stateManager.SetTotalSizeAndFilesPhase3(int64(filesCount)+int64(delayCount), storage+delayStorage)
if err != nil {
return err
}
e.progressBar.AddPhase3()
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion artifactory/commands/transferfiles/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func setRepositoryStatus(stateManager *state.TransferStateManager, output *strin
if stateManager.CurrentRepoPhase == api.Phase1 {
addString(output, "🔢", "Phase", "Transferring all files in the repository (1/3)", 3)
} else {
addString(output, "🔢", "Phase", "Retrying transfer failures (3/3)", 3)
addString(output, "🔢", "Phase", "Retrying transfer failures and deploy delayed files (3/3)", 3)
}
addString(output, "🗄 ", "Storage", sizeToString(currentRepo.Phase1Info.TransferredSizeBytes)+" / "+sizeToString(currentRepo.Phase1Info.TotalSizeBytes)+calcPercentageInt64(currentRepo.Phase1Info.TransferredSizeBytes, currentRepo.Phase1Info.TotalSizeBytes), 3)
addString(output, "📄", "Files", fmt.Sprintf("%d / %d", currentRepo.Phase1Info.TransferredUnits, currentRepo.Phase1Info.TotalUnits)+calcPercentageInt64(currentRepo.Phase1Info.TransferredUnits, currentRepo.Phase1Info.TotalUnits), 3)
Expand Down
2 changes: 1 addition & 1 deletion artifactory/commands/transferfiles/status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ func TestShowBuildInfoRepo(t *testing.T) {
// Check repository status
assert.Contains(t, results, "Current Repository Status")
assert.Contains(t, results, "Name: repo1")
assert.Contains(t, results, "Phase: Retrying transfer failures (3/3)")
assert.Contains(t, results, "Phase: Retrying transfer failures and deploy delayed files (3/3)")
assert.Contains(t, results, "Delayed files: 20 (Files to be transferred last, after all other files)")
assert.Contains(t, results, "Storage: 4.9 KiB / 9.8 KiB (50.0%)")
assert.Contains(t, results, "Files: 500 / 10000 (5.0%)")
Expand Down
2 changes: 1 addition & 1 deletion utils/progressbar/transferprogressbarmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
const (
phase1HeadLine = "Phase 1: Transferring all files in the repository"
phase2HeadLine = "Phase 2: Transferring newly created and modified files"
phase3HeadLine = "Phase 3: Retrying transfer failures"
phase3HeadLine = "Phase 3: Retrying transfer failures and deploy delayed files"
DelayedFilesContentNote = "Files to be transferred last, after all other files"
RetryFailureContentNote = "In Phase 3 and in subsequent executions, we'll retry transferring the failed files"
)
Expand Down

0 comments on commit 12593e3

Please sign in to comment.