diff --git a/job/error/error.go b/job/error/error.go deleted file mode 100644 index 680b1c6c8..000000000 --- a/job/error/error.go +++ /dev/null @@ -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 -} diff --git a/job/replication/delete.go b/job/replication/delete.go index 1bec6378f..ce8ef6a98 100644 --- a/job/replication/delete.go +++ b/job/replication/delete.go @@ -74,6 +74,17 @@ func (d *Deleter) Exit() error { // Enter deletes repository or tags func (d *Deleter) Enter() (string, error) { + state, err := d.enter() + if err != nil && retry(err) { + d.logger.Info("waiting for retrying...") + return models.JobRetrying, nil + } + + return state, err + +} + +func (d *Deleter) enter() (string, error) { if len(d.tags) == 0 { tags, err := d.dstClient.ListTag() diff --git a/job/replication/error.go b/job/replication/error.go index 53c7ca219..197dabbd3 100644 --- a/job/replication/error.go +++ b/job/replication/error.go @@ -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) } diff --git a/job/replication/transfer.go b/job/replication/transfer.go index 28ad5aa41..4eee419f4 100644 --- a/job/replication/transfer.go +++ b/job/replication/transfer.go @@ -152,6 +152,17 @@ 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) { + c.logger.Info("waiting for retrying...") + return models.JobRetrying, nil + } + + return state, err + +} + +func (c *Checker) enter() (string, error) { enter: exist, canWrite, err := c.projectExist() if err != nil { @@ -316,6 +327,17 @@ 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) { + m.logger.Info("waiting for retrying...") + return models.JobRetrying, nil + } + + 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 +411,17 @@ 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) { + b.logger.Info("waiting for retrying...") + return models.JobRetrying, nil + } + + return state, err + +} + +func (b *BlobTransfer) enter() (string, error) { name := b.repository tag := b.tags[0] for _, blob := range b.blobs { @@ -417,6 +450,17 @@ type ManifestPusher struct { // 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) { + state, err := m.enter() + if err != nil && retry(err) { + m.logger.Info("waiting for retrying...") + return models.JobRetrying, nil + } + + return state, err + +} + +func (m *ManifestPusher) enter() (string, error) { name := m.repository tag := m.tags[0] _, exist, err := m.srcClient.ManifestExist(tag)