This commit is contained in:
Wenkai Yin 2016-07-05 11:06:58 +08:00
parent a2ccb414bd
commit 19ec6177e0
3 changed files with 45 additions and 30 deletions

View File

@ -1,23 +0,0 @@
/*
Copyright (c) 2016 VMware, Inc. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package error
// RetryChecker checks whether a job should retry if encounters an error
type RetryChecker interface {
// Retry : if the error can be disappear after retrying the job, Retry
// returns true
Retry(error) bool
}

View File

@ -19,12 +19,10 @@ import (
"net"
)
// ReplicaRetryChecker determines whether a job should be retried when an error occurred
type ReplicaRetryChecker struct {
}
// Retry ...
func (r *ReplicaRetryChecker) Retry(err error) bool {
func retry(err error) bool {
if err == nil {
return false
}
return isTemporary(err)
}

View File

@ -152,6 +152,16 @@ type Checker struct {
// Enter check existence of project, if it does not exist, create it,
// if it exists, check whether the user has write privilege to it.
func (c *Checker) Enter() (string, error) {
state, err := c.enter()
if err != nil && retry(err) {
return models.JobRetrying, err
}
return state, err
}
func (c *Checker) enter() (string, error) {
enter:
exist, canWrite, err := c.projectExist()
if err != nil {
@ -316,6 +326,16 @@ type ManifestPuller struct {
// Enter pulls manifest of a tag and checks if all blobs exist in the destination registry
func (m *ManifestPuller) Enter() (string, error) {
state, err := m.enter()
if err != nil && retry(err) {
return models.JobRetrying, err
}
return state, err
}
func (m *ManifestPuller) enter() (string, error) {
if len(m.tags) == 0 {
m.logger.Infof("no tag needs to be replicated, next state is \"finished\"")
return models.JobFinished, nil
@ -389,6 +409,16 @@ type BlobTransfer struct {
// Enter pulls blobs and then pushs them to destination registry.
func (b *BlobTransfer) Enter() (string, error) {
state, err := b.enter()
if err != nil && retry(err) {
return models.JobRetrying, err
}
return state, err
}
func (b *BlobTransfer) enter() (string, error) {
name := b.repository
tag := b.tags[0]
for _, blob := range b.blobs {
@ -416,7 +446,17 @@ type ManifestPusher struct {
// Enter checks the existence of manifest in the source registry first, and if it
// exists, pushs it to destination registry. The checking operation is to avoid
// the situation that the tag is deleted during the blobs transfering
func (m *ManifestPusher) Enter() (string, error) {
func (b *ManifestPusher) Enter() (string, error) {
state, err := b.enter()
if err != nil && retry(err) {
return models.JobRetrying, err
}
return state, err
}
func (m *ManifestPusher) enter() (string, error) {
name := m.repository
tag := m.tags[0]
_, exist, err := m.srcClient.ManifestExist(tag)