Skip to content

Commit

Permalink
Create RetryExecutor + add retries to client's download and upload op…
Browse files Browse the repository at this point in the history
…erations
  • Loading branch information
barbelity committed Jan 27, 2019
1 parent e3a829e commit 187d4ed
Show file tree
Hide file tree
Showing 13 changed files with 229 additions and 50 deletions.
8 changes: 4 additions & 4 deletions artifactory/httpclient/httpclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,11 @@ func (rtc *ArtifactoryHttpClient) Send(method string, url string, content []byte
return
}

func (rtc *ArtifactoryHttpClient) UploadFile(localPath, url string,
func (rtc *ArtifactoryHttpClient) UploadFile(localPath, url, logMsgPrefix string,
httpClientsDetails *httputils.HttpClientDetails, retries int) (resp *http.Response, body []byte, err error) {
isNewToken := false
for i := 0; i < 2; i++ {
resp, body, err = rtc.httpClient.UploadFile(localPath, url, *httpClientsDetails, retries)
resp, body, err = rtc.httpClient.UploadFile(localPath, url, logMsgPrefix, *httpClientsDetails, retries)
if err != nil {
return
}
Expand All @@ -160,10 +160,10 @@ func (rtc *ArtifactoryHttpClient) UploadFile(localPath, url string,
return
}

func (rtc *ArtifactoryHttpClient) ReadRemoteFile(downloadPath string, httpClientsDetails *httputils.HttpClientDetails, retries int) (ioReaderCloser io.ReadCloser, resp *http.Response, err error) {
func (rtc *ArtifactoryHttpClient) ReadRemoteFile(downloadPath string, httpClientsDetails *httputils.HttpClientDetails) (ioReaderCloser io.ReadCloser, resp *http.Response, err error) {
isNewToken := false
for i := 0; i < 2; i++ {
ioReaderCloser, resp, err = rtc.httpClient.ReadRemoteFile(downloadPath, *httpClientsDetails, retries)
ioReaderCloser, resp, err = rtc.httpClient.ReadRemoteFile(downloadPath, *httpClientsDetails)
if err != nil {
return
}
Expand Down
2 changes: 1 addition & 1 deletion artifactory/services/go/publishwithheaders.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func (pwh *publishWithHeader) PublishPackage(params GoParams, client *rthttpclie
if err != nil {
return err
}
resp, _, err := client.UploadFile(params.GetZipPath(), url, &clientDetails, 0)
resp, _, err := client.UploadFile(params.GetZipPath(), url, "", &clientDetails, 0)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion artifactory/services/go/publishwithmatrixparams.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (pwmp *publishWithMatrixParams) PublishPackage(params GoParams, client *rth
return err
}

resp, _, err := client.UploadFile(params.GetZipPath(), url, &clientDetails, 0)
resp, _, err := client.UploadFile(params.GetZipPath(), url, "", &clientDetails, 0)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions artifactory/services/go/publishzipandmod.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func (pwa *publishZipAndModApi) PublishPackage(params GoParams, client *rthttpcl
clientDetails := ArtDetails.CreateHttpClientDetails()

addGoVersion(params, &zipUrl)
resp, _, err := client.UploadFile(params.GetZipPath(), zipUrl, &clientDetails, 0)
resp, _, err := client.UploadFile(params.GetZipPath(), zipUrl, "", &clientDetails, 0)
if err != nil {
return err
}
Expand All @@ -54,7 +54,7 @@ func (pwa *publishZipAndModApi) PublishPackage(params GoParams, client *rthttpcl
return err
}
addGoVersion(params, &url)
resp, _, err = client.UploadFile(params.GetModPath(), url, &clientDetails, 0)
resp, _, err = client.UploadFile(params.GetModPath(), url, "", &clientDetails, 0)
if err != nil {
return err
}
Expand Down
3 changes: 1 addition & 2 deletions artifactory/services/readfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ type ReadFileService struct {
DryRun bool
MinSplitSize int64
SplitCount int
Retries int
}

func NewReadFileService(client *rthttpclient.ArtifactoryHttpClient) *ReadFileService {
Expand Down Expand Up @@ -56,7 +55,7 @@ func (ds *ReadFileService) ReadRemoteFile(downloadPath string) (io.ReadCloser, e
return nil, err
}
httpClientsDetails := ds.ArtDetails.CreateHttpClientDetails()
ioReadCloser, resp, err := ds.client.ReadRemoteFile(readPath, &httpClientsDetails, ds.Retries)
ioReadCloser, resp, err := ds.client.ReadRemoteFile(readPath, &httpClientsDetails)
if err != nil {
return nil, err
}
Expand Down
8 changes: 4 additions & 4 deletions artifactory/services/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ func (us *UploadService) uploadFile(localPath, targetPath, props string, uploadP
return utils.FileInfo{}, false, err
}
if uploadParams.IsSymlink() && fileutils.IsFileSymlink(fileInfo) {
resp, details, body, err = us.uploadSymlink(targetPathWithProps, httpClientsDetails, uploadParams)
resp, details, body, err = us.uploadSymlink(targetPathWithProps, logMsgPrefix, httpClientsDetails, uploadParams)
} else {
resp, details, body, checksumDeployed, err = us.doUpload(localPath, targetPathWithProps, logMsgPrefix, httpClientsDetails, fileInfo, uploadParams)
}
Expand All @@ -338,12 +338,12 @@ func (us *UploadService) uploadFile(localPath, targetPath, props string, uploadP
return artifact, us.DryRun || checksumDeployed || resp.StatusCode == http.StatusCreated || resp.StatusCode == http.StatusOK, nil
}

func (us *UploadService) uploadSymlink(targetPath string, httpClientsDetails httputils.HttpClientDetails, uploadParams UploadParams) (resp *http.Response, details *fileutils.FileDetails, body []byte, err error) {
func (us *UploadService) uploadSymlink(targetPath, logMsgPrefix string, httpClientsDetails httputils.HttpClientDetails, uploadParams UploadParams) (resp *http.Response, details *fileutils.FileDetails, body []byte, err error) {
details, err = fspatterns.CreateSymlinkFileDetails()
if err != nil {
return
}
resp, body, err = utils.UploadFile("", targetPath, &us.ArtDetails, details, httpClientsDetails, us.client, us.Retries)
resp, body, err = utils.UploadFile("", targetPath, logMsgPrefix, &us.ArtDetails, details, httpClientsDetails, us.client, us.Retries)
return
}

Expand All @@ -363,7 +363,7 @@ func (us *UploadService) doUpload(localPath, targetPath, logMsgPrefix string, ht
}
if !us.DryRun && !checksumDeployed {
var body []byte
resp, body, err = utils.UploadFile(localPath, targetPath, &us.ArtDetails, details, httpClientsDetails, us.client, us.Retries)
resp, body, err = utils.UploadFile(localPath, targetPath, logMsgPrefix, &us.ArtDetails, details, httpClientsDetails, us.client, us.Retries)
if err != nil {
return resp, details, body, checksumDeployed, err
}
Expand Down
4 changes: 2 additions & 2 deletions artifactory/services/utils/artifactoryutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
const ARTIFACTORY_SYMLINK = "symlink.dest"
const SYMLINK_SHA1 = "symlink.destsha1"

func UploadFile(localPath, url string, artifactoryDetails *auth.ArtifactoryDetails, details *fileutils.FileDetails,
func UploadFile(localPath, url, logMsgPrefix string, artifactoryDetails *auth.ArtifactoryDetails, details *fileutils.FileDetails,
httpClientsDetails httputils.HttpClientDetails, client *rthttpclient.ArtifactoryHttpClient, retries int) (*http.Response, []byte, error) {
var err error
if details == nil {
Expand All @@ -34,7 +34,7 @@ func UploadFile(localPath, url string, artifactoryDetails *auth.ArtifactoryDetai
AddChecksumHeaders(requestClientDetails.Headers, details)
AddAuthHeaders(requestClientDetails.Headers, *artifactoryDetails)

return client.UploadFile(localPath, url, requestClientDetails, retries)
return client.UploadFile(localPath, url, logMsgPrefix, requestClientDetails, retries)
}

func AddChecksumHeaders(headers map[string]string, fileDetails *fileutils.FileDetails) {
Expand Down
9 changes: 6 additions & 3 deletions bintray/services/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import (
"sync"
)

const BintrayDownloadRetries = 3

func NewDownloadService(client *httpclient.HttpClient) *DownloadService {
ds := &DownloadService{client: client}
return ds
Expand Down Expand Up @@ -215,7 +217,7 @@ func (ds *DownloadService) downloadBintrayFile(downloadParams *DownloadFileParam
LocalPath: localPath,
LocalFileName: localFileName}

resp, err := client.DownloadFile(downloadDetails, logMsgPrefix, httpClientsDetails, 0, false)
resp, err := client.DownloadFile(downloadDetails, logMsgPrefix, httpClientsDetails, BintrayDownloadRetries, false)
if err != nil {
return err
}
Expand All @@ -229,7 +231,7 @@ func (ds *DownloadService) downloadBintrayFile(downloadParams *DownloadFileParam
var resp *http.Response
var redirectUrl string
resp, redirectUrl, err =
client.DownloadFileNoRedirect(url, localPath, localFileName, httpClientsDetails)
client.DownloadFileNoRedirect(url, localPath, localFileName, httpClientsDetails, BintrayDownloadRetries)
// There are two options now. Either the file has just been downloaded as one block, or
// we got a redirect to DSN download URL. In case of the later, we should download the file
// concurrently from the DSN URL.
Expand All @@ -242,7 +244,8 @@ func (ds *DownloadService) downloadBintrayFile(downloadParams *DownloadFileParam
LocalFileName: localFileName,
LocalPath: localPath,
FileSize: details.Size,
SplitCount: ds.SplitCount}
SplitCount: ds.SplitCount,
Retries: BintrayDownloadRetries}

resp, err = client.DownloadFileConcurrently(concurrentDownloadFlags, "", httpClientsDetails)
if errorutils.CheckError(err) != nil {
Expand Down
3 changes: 2 additions & 1 deletion bintray/services/logs/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package logs
import (
"errors"
"github.com/jfrog/jfrog-client-go/bintray/auth"
"github.com/jfrog/jfrog-client-go/bintray/services"
"github.com/jfrog/jfrog-client-go/bintray/services/versions"
"github.com/jfrog/jfrog-client-go/httpclient"
clientutils "github.com/jfrog/jfrog-client-go/utils"
Expand Down Expand Up @@ -61,7 +62,7 @@ func (ls *LogsService) Download(versionPath *versions.Path, logName string) erro
DownloadPath: downloadUrl,
LocalPath: "",
LocalFileName: logName}
resp, err := client.DownloadFile(details, "", httpClientsDetails, 3, false)
resp, err := client.DownloadFile(details, "", httpClientsDetails, services.BintrayDownloadRetries, false)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion bintray/services/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ func uploadFile(artifact clientutils.Artifact, url, logMsgPrefix string, bintray
if err != nil {
return false, err
}
resp, body, err := client.UploadFile(artifact.LocalPath, url, httpClientsDetails, 0)
resp, body, err := client.UploadFile(artifact.LocalPath, url, logMsgPrefix, httpClientsDetails, 0)
if err != nil {
return false, err
}
Expand Down

0 comments on commit 187d4ed

Please sign in to comment.