From 7f6f85aab3eafedeed9ebdea2a4b5dedaa6b8278 Mon Sep 17 00:00:00 2001 From: cd1989 Date: Fri, 12 Apr 2019 19:19:59 +0800 Subject: [PATCH] Remove ValidResource method Signed-off-by: cd1989 --- src/replication/ng/adapter/adapter.go | 3 --- src/replication/ng/adapter/dockerhub/adapter.go | 13 ------------- .../ng/adapter/huawei/huawei_adapter.go | 5 ----- src/replication/ng/adapter/image_registry.go | 5 ----- src/replication/ng/model/resource.go | 2 -- src/replication/ng/operation/controller_test.go | 3 --- src/replication/ng/operation/flow/copy.go | 14 +------------- src/replication/ng/operation/flow/deletion.go | 15 +-------------- src/replication/ng/operation/flow/stage.go | 5 ----- src/replication/ng/operation/flow/stage_test.go | 3 --- 10 files changed, 2 insertions(+), 66 deletions(-) diff --git a/src/replication/ng/adapter/adapter.go b/src/replication/ng/adapter/adapter.go index 3ebc5c65e..7b18d85ac 100644 --- a/src/replication/ng/adapter/adapter.go +++ b/src/replication/ng/adapter/adapter.go @@ -39,9 +39,6 @@ type Adapter interface { // PrepareForPush does the prepare work that needed for pushing/uploading the resource // eg: create the namespace or repository PrepareForPush(*model.Resource) error - // ValidResource checks whether a resource is valid for the registry. For example, DockerHub don't support - // multiple parts repo name like 'a/b/c'. - ValidResource(*model.Resource) bool // Get the namespace specified by the name, the returning value should // contain the metadata about the namespace if it has // TODO remove this method? diff --git a/src/replication/ng/adapter/dockerhub/adapter.go b/src/replication/ng/adapter/dockerhub/adapter.go index 8d3454731..dd7214cf1 100644 --- a/src/replication/ng/adapter/dockerhub/adapter.go +++ b/src/replication/ng/adapter/dockerhub/adapter.go @@ -73,19 +73,6 @@ func (a *adapter) Info() (*model.RegistryInfo, error) { }, nil } -// ValidResource checks whether a resource is valid, in DockerHub, multi-parts repo name like 'a/b/c' is not supported. -func (a *adapter) ValidResource(resource *model.Resource) bool { - if resource == nil || resource.Metadata == nil || resource.Metadata.Repository == nil { - return false - } - - if len(strings.Split(resource.Metadata.Repository.Name, "/")) != 1 { - return false - } - - return true -} - // ConvertResourceMetadata converts the namespace and repository part of the resource metadata // to the one that the adapter can handle func (a *adapter) ConvertResourceMetadata(meta *model.ResourceMetadata, namespace *model.Namespace) (*model.ResourceMetadata, error) { diff --git a/src/replication/ng/adapter/huawei/huawei_adapter.go b/src/replication/ng/adapter/huawei/huawei_adapter.go index 15b01c695..1ab8d829a 100644 --- a/src/replication/ng/adapter/huawei/huawei_adapter.go +++ b/src/replication/ng/adapter/huawei/huawei_adapter.go @@ -118,11 +118,6 @@ func (adapter Adapter) ConvertResourceMetadata(resourceMetadata *model.ResourceM return metadata, nil } -// ValidResource ... -func (adapter Adapter) ValidResource(*model.Resource) bool { - return true -} - // PrepareForPush prepare for push to Huawei SWR func (adapter Adapter) PrepareForPush(resource *model.Resource) error { diff --git a/src/replication/ng/adapter/image_registry.go b/src/replication/ng/adapter/image_registry.go index adbf16680..03b606bb1 100644 --- a/src/replication/ng/adapter/image_registry.go +++ b/src/replication/ng/adapter/image_registry.go @@ -276,11 +276,6 @@ func (d *DefaultImageRegistry) PushBlob(repository, digest string, size int64, b return client.PushBlob(digest, size, blob) } -// ValidResource ... -func (d *DefaultImageRegistry) ValidResource(*model.Resource) bool { - return true -} - func isDigest(str string) bool { return strings.Contains(str, ":") } diff --git a/src/replication/ng/model/resource.go b/src/replication/ng/model/resource.go index 2b7a2d25e..34dd0c911 100644 --- a/src/replication/ng/model/resource.go +++ b/src/replication/ng/model/resource.go @@ -69,6 +69,4 @@ type Resource struct { Deleted bool `json:"deleted"` // indicate whether the resource can be overridden Override bool `json:"override"` - // Invalid indicates the resource is invalid for the registry - Invalid bool `json:"invalid"` } diff --git a/src/replication/ng/operation/controller_test.go b/src/replication/ng/operation/controller_test.go index 66d4375a8..75edb8060 100644 --- a/src/replication/ng/operation/controller_test.go +++ b/src/replication/ng/operation/controller_test.go @@ -149,9 +149,6 @@ func (f *fakedAdapter) PrepareForPush(*model.Resource) error { func (f *fakedAdapter) HealthCheck() (model.HealthStatus, error) { return model.Healthy, nil } -func (f *fakedAdapter) ValidResource(*model.Resource) bool { - return true -} func (f *fakedAdapter) GetNamespace(ns string) (*model.Namespace, error) { var namespace *model.Namespace if ns == "library" { diff --git a/src/replication/ng/operation/flow/copy.go b/src/replication/ng/operation/flow/copy.go index 0d29db069..232956503 100644 --- a/src/replication/ng/operation/flow/copy.go +++ b/src/replication/ng/operation/flow/copy.go @@ -62,12 +62,6 @@ func (c *copyFlow) Run(interface{}) (int, error) { return 0, err } - for i := range dstResources { - if !dstAdapter.ValidResource(dstResources[i]) { - dstResources[i].Invalid = true - } - } - if err = prepareForPush(dstAdapter, dstResources); err != nil { return 0, err } @@ -79,13 +73,7 @@ func (c *copyFlow) Run(interface{}) (int, error) { return 0, err } - var filtered []*scheduler.ScheduleItem - for _, item := range items { - if !item.DstResource.Invalid { - filtered = append(filtered, item) - } - } - return schedule(c.scheduler, c.executionMgr, filtered) + return schedule(c.scheduler, c.executionMgr, items) } // mark the execution as success in database diff --git a/src/replication/ng/operation/flow/deletion.go b/src/replication/ng/operation/flow/deletion.go index 2e000e962..27828e5ea 100644 --- a/src/replication/ng/operation/flow/deletion.go +++ b/src/replication/ng/operation/flow/deletion.go @@ -65,12 +65,6 @@ func (d *deletionFlow) Run(interface{}) (int, error) { return 0, err } - for i := range dstResources { - if !dstAdapter.ValidResource(dstResources[i]) { - dstResources[i].Invalid = true - } - } - items, err := preprocess(d.scheduler, srcResources, dstResources) if err != nil { return 0, err @@ -79,12 +73,5 @@ func (d *deletionFlow) Run(interface{}) (int, error) { return 0, err } - var filtered []*scheduler.ScheduleItem - for _, item := range items { - if !item.DstResource.Invalid { - filtered = append(filtered, item) - } - } - - return schedule(d.scheduler, d.executionMgr, filtered) + return schedule(d.scheduler, d.executionMgr, items) } diff --git a/src/replication/ng/operation/flow/stage.go b/src/replication/ng/operation/flow/stage.go index 039cf4525..7d579c8d9 100644 --- a/src/replication/ng/operation/flow/stage.go +++ b/src/replication/ng/operation/flow/stage.go @@ -251,11 +251,6 @@ func createTasks(mgr execution.Manager, executionID int64, items []*scheduler.Sc Operation: operation, } - if item.DstResource.Invalid { - task.Status = models.TaskStatusFailed - task.EndTime = time.Now() - } - id, err := mgr.CreateTask(task) if err != nil { // if failed to create the task for one of the items, diff --git a/src/replication/ng/operation/flow/stage_test.go b/src/replication/ng/operation/flow/stage_test.go index 861ceae48..a6e3dfb32 100644 --- a/src/replication/ng/operation/flow/stage_test.go +++ b/src/replication/ng/operation/flow/stage_test.go @@ -62,9 +62,6 @@ func (f *fakedAdapter) PrepareForPush(*model.Resource) error { func (f *fakedAdapter) HealthCheck() (model.HealthStatus, error) { return model.Healthy, nil } -func (f *fakedAdapter) ValidResource(*model.Resource) bool { - return true -} func (f *fakedAdapter) GetNamespace(ns string) (*model.Namespace, error) { var namespace *model.Namespace if ns == "library" {