Merge pull request #3473 from steven-zou/master

Define filter interfaces for replication service
This commit is contained in:
Steven Zou 2017-10-29 23:37:30 -05:00 committed by GitHub
commit 3565f60f5b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 94 additions and 0 deletions

10
src/replication/consts.go Normal file
View File

@ -0,0 +1,10 @@
package replication
const (
//Kind of filter item is 'project'
filterItemKindProject = "project"
//Kind of filter item is 'repository'
filterItemKindRepository = "repository"
//Kind of filter item is 'tag'
filterItemKindTag = "tag"
)

View File

@ -0,0 +1,7 @@
package models
//FilterConfig is data model to provide configurations to the filters.
type FilterConfig struct {
//The pattern for fuzzy matching
pattern string
}

View File

@ -0,0 +1,19 @@
package models
//FilterItem is the general data model represents the filtering resources which are used as input and output for the filters.
type FilterItem struct {
//The kind of the filtering resources. Support 'project','repository' and 'tag' etc.
kind string
//The key value of resource which can be used to filter out the resource matched with specified pattern.
//E.g:
//kind == 'project', value will be project name;
//kind == 'repository', value will be repository name
//kind == 'tag', value will be tag name.
value string
//Extension placeholder.
//To append more additional information if required by the filter.
metadata map[string]interface{}
}

View File

@ -0,0 +1,16 @@
package source
import (
"github.com/vmware/harbor/src/replication/models"
)
//Convertor is designed to covert the format of output from upstream filter to the input format
//required by the downstream filter if needed.
//Each convertor covers only one specified conversion process between the two filters.
//E.g:
//If project filter connects to repository filter, then one convertor should be defined for this connection;
//If project filter connects to tag filter, then another one should be defined. The above one can not be reused.
type Convertor interface {
//Accept the items from upstream filter as input and then covert them to the required format and returned.
Convert(itemsOfUpstream []models.FilterItem) (itemsOfDownstream []models.FilterItem)
}

View File

@ -0,0 +1,21 @@
package source
import (
"github.com/vmware/harbor/src/replication/models"
)
//Filter define the operations of selecting the matched resources from the candidates
//according to the specified pattern.
type Filter interface {
//Initialize the filter with specified configurations like pattern definition
Init(config models.FilterConfig)
//Set Convertor if necessary
SetConvertor(convertor Convertor)
//Return the convertor if existing or nil if never set
GetConvertor() Convertor
//Filter the items
DoFilter(filterItems []models.FilterItem) []models.FilterItem
}

View File

@ -0,0 +1,21 @@
package source
import (
"github.com/vmware/harbor/src/replication/models"
)
//FilterChain is the interface to define the operations of coordinating multiple filters
//to work together as a whole pipeline.
//E.g:
//(original resources)---->[project filter]---->[repository filter]---->[tag filter]---->[......]---->(filter resources)
type FilterChain interface {
//Build the filter chain with the filters provided;
//if failed, an error will be returned.
Build(filter []Filter) error
//Return all the filters in the chain.
Filters() []Filter
//Filter the items and returned the filtered items via the appended filters in the chain.
DoFilter(filterItems []models.FilterItem) []models.FilterItem
}