mirror of
https://github.com/goharbor/harbor.git
synced 2024-10-08 10:18:03 +02:00
commit
71a60fca74
@ -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
|
|
||||||
}
|
|
@ -74,6 +74,17 @@ func (d *Deleter) Exit() error {
|
|||||||
|
|
||||||
// Enter deletes repository or tags
|
// Enter deletes repository or tags
|
||||||
func (d *Deleter) Enter() (string, error) {
|
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 {
|
if len(d.tags) == 0 {
|
||||||
tags, err := d.dstClient.ListTag()
|
tags, err := d.dstClient.ListTag()
|
||||||
|
@ -19,12 +19,10 @@ import (
|
|||||||
"net"
|
"net"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ReplicaRetryChecker determines whether a job should be retried when an error occurred
|
func retry(err error) bool {
|
||||||
type ReplicaRetryChecker struct {
|
if err == nil {
|
||||||
}
|
return false
|
||||||
|
}
|
||||||
// Retry ...
|
|
||||||
func (r *ReplicaRetryChecker) Retry(err error) bool {
|
|
||||||
return isTemporary(err)
|
return isTemporary(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -152,6 +152,17 @@ type Checker struct {
|
|||||||
// Enter check existence of project, if it does not exist, create it,
|
// Enter check existence of project, if it does not exist, create it,
|
||||||
// if it exists, check whether the user has write privilege to it.
|
// if it exists, check whether the user has write privilege to it.
|
||||||
func (c *Checker) Enter() (string, error) {
|
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:
|
enter:
|
||||||
exist, canWrite, err := c.projectExist()
|
exist, canWrite, err := c.projectExist()
|
||||||
if err != nil {
|
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
|
// Enter pulls manifest of a tag and checks if all blobs exist in the destination registry
|
||||||
func (m *ManifestPuller) Enter() (string, error) {
|
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 {
|
if len(m.tags) == 0 {
|
||||||
m.logger.Infof("no tag needs to be replicated, next state is \"finished\"")
|
m.logger.Infof("no tag needs to be replicated, next state is \"finished\"")
|
||||||
return models.JobFinished, nil
|
return models.JobFinished, nil
|
||||||
@ -389,6 +411,17 @@ type BlobTransfer struct {
|
|||||||
|
|
||||||
// Enter pulls blobs and then pushs them to destination registry.
|
// Enter pulls blobs and then pushs them to destination registry.
|
||||||
func (b *BlobTransfer) Enter() (string, error) {
|
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
|
name := b.repository
|
||||||
tag := b.tags[0]
|
tag := b.tags[0]
|
||||||
for _, blob := range b.blobs {
|
for _, blob := range b.blobs {
|
||||||
@ -417,6 +450,17 @@ type ManifestPusher struct {
|
|||||||
// exists, pushs it to destination registry. The checking operation is to avoid
|
// exists, pushs it to destination registry. The checking operation is to avoid
|
||||||
// the situation that the tag is deleted during the blobs transfering
|
// the situation that the tag is deleted during the blobs transfering
|
||||||
func (m *ManifestPusher) Enter() (string, error) {
|
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
|
name := m.repository
|
||||||
tag := m.tags[0]
|
tag := m.tags[0]
|
||||||
_, exist, err := m.srcClient.ManifestExist(tag)
|
_, exist, err := m.srcClient.ManifestExist(tag)
|
||||||
|
Loading…
Reference in New Issue
Block a user