trigger

package
v1.4.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 10, 2018 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultWatchList = &WatchList{}

DefaultWatchList is the default instance of WatchList

Functions

This section is empty.

Types

type BasicParam

type BasicParam struct {
	//ID of the related policy
	PolicyID int64

	//Whether delete remote replicated images if local ones are deleted
	OnDeletion bool
}

BasicParam contains the general parameters for all triggers

type Cache

type Cache struct {
	// contains filtered or unexported fields
}

Cache is used to cache the enabled triggers with specified capacity. If exceed the capacity, cached items will be adjusted with the following rules: The item with least usage frequency will be replaced; If multiple items with same usage frequency, the oldest one will be replaced.

func NewCache

func NewCache(capacity int) *Cache

NewCache is constructor of cache

func (*Cache) Get

func (c *Cache) Get(policyID int64) Interface

Get the trigger interface with the specified policy ID

func (*Cache) Put

func (c *Cache) Put(policyID int64, trigger Interface)

Put the item into cache with ID of ploicy as key

func (*Cache) Remove

func (c *Cache) Remove(policyID int64) Interface

Remove the trigger attached to the specified policy

func (*Cache) Size

func (c *Cache) Size() int

Size return the count of triggers in the cache

type CacheItem

type CacheItem struct {
	// contains filtered or unexported fields
}

CacheItem is the data stored in the cache. It contains trigger and heap item references.

type ImmediateParam

type ImmediateParam struct {
	//Basic parameters
	BasicParam

	//Namepaces
	Namespaces []string
}

ImmediateParam defines the parameter of immediate trigger

func (ImmediateParam) Parse

func (ip ImmediateParam) Parse(param string) error

Parse is the implementation of same method in TriggerParam interface NOTES: No need to implement this method for 'Immediate' trigger as it does not have any parameters with json format.

type ImmediateTrigger

type ImmediateTrigger struct {
	// contains filtered or unexported fields
}

ImmediateTrigger will setup watcher at the image pushing action to fire replication event at pushing happening time.

func NewImmediateTrigger

func NewImmediateTrigger(params ImmediateParam) *ImmediateTrigger

NewImmediateTrigger is constructor of ImmediateTrigger

func (*ImmediateTrigger) Kind

func (st *ImmediateTrigger) Kind() string

Kind is the implementation of same method defined in Trigger interface

func (*ImmediateTrigger) Setup

func (st *ImmediateTrigger) Setup() error

Setup is the implementation of same method defined in Trigger interface

func (*ImmediateTrigger) Unset

func (st *ImmediateTrigger) Unset() error

Unset is the implementation of same method defined in Trigger interface

type Interface

type Interface interface {
	//Kind indicates what type of the trigger is.
	Kind() string

	//Setup/enable the trigger; if failed, an error would be returned.
	Setup() error

	//Remove/disable the trigger; if failed, an error would be returned.
	Unset() error
}

Interface is certian mechanism to know when fire the replication operation.

type Item

type Item struct {
	// contains filtered or unexported fields
}

Item keeps more metadata of the triggers which are stored in the heap.

type Manager

type Manager struct {
}

Manager provides unified methods to manage the triggers of policies; Cache the enabled triggers, setup/unset the trigger based on the parameters with json format.

func NewManager

func NewManager(capacity int) *Manager

NewManager is the constructor of trigger manager. capacity is the max number of trigger references manager can keep in memory

func (*Manager) SetupTrigger

func (m *Manager) SetupTrigger(policy *models.ReplicationPolicy) error

SetupTrigger will create the new trigger based on the provided policy. If failed, an error will be returned.

func (*Manager) UnsetTrigger

func (m *Manager) UnsetTrigger(policy *models.ReplicationPolicy) error

UnsetTrigger will disable the trigger which is not cached in the trigger cache.

type MetaQueue

type MetaQueue []*Item

MetaQueue implements heap.Interface and holds items which are metadata of trigger

func (MetaQueue) Len

func (mq MetaQueue) Len() int

Len return the size of the queue

func (MetaQueue) Less

func (mq MetaQueue) Less(i, j int) bool

Less is a comparator of heap

func (*MetaQueue) Pop

func (mq *MetaQueue) Pop() interface{}

Pop smallest item from heap

func (*MetaQueue) Push

func (mq *MetaQueue) Push(x interface{})

Push item into heap

func (MetaQueue) Swap

func (mq MetaQueue) Swap(i, j int)

Swap the items to rebuild heap

func (*MetaQueue) Update

func (mq *MetaQueue) Update(item *Item)

Update the frequency of item

type Parameter

type Parameter interface {
	//Decode parameter with json style to the owner struct
	//If failed, an error will be returned
	Parse(param string) error
}

Parameter defines operation of doing initialization from parameter json text

type ScheduleParam

type ScheduleParam struct {
	//Basic parameters
	BasicParam

	//Daily or weekly
	Type string

	//Optional, only used when type is 'weekly'
	Weekday int8

	//The time offset with the UTC 00:00 in seconds
	Offtime int64
}

ScheduleParam defines the parameter of schedule trigger

func (ScheduleParam) Parse

func (stp ScheduleParam) Parse(param string) error

Parse is the implementation of same method in TriggerParam interface

type ScheduleTrigger

type ScheduleTrigger struct {
	// contains filtered or unexported fields
}

ScheduleTrigger will schedule a alternate policy to provide 'daily' and 'weekly' trigger ways.

func NewScheduleTrigger

func NewScheduleTrigger(params ScheduleParam) *ScheduleTrigger

NewScheduleTrigger is constructor of ScheduleTrigger

func (*ScheduleTrigger) Kind

func (st *ScheduleTrigger) Kind() string

Kind is the implementation of same method defined in Trigger interface

func (*ScheduleTrigger) Setup

func (st *ScheduleTrigger) Setup() error

Setup is the implementation of same method defined in Trigger interface

func (*ScheduleTrigger) Unset

func (st *ScheduleTrigger) Unset() error

Unset is the implementation of same method defined in Trigger interface

type WatchItem

type WatchItem struct {
	//ID of policy
	PolicyID int64

	//Corresponding namespace
	Namespace string

	//For deletion event
	OnDeletion bool

	//For pushing event
	OnPush bool
}

WatchItem keeps the related data for evaluation in WatchList.

type WatchList

type WatchList struct{}

WatchList contains the items which should be evaluated for replication when image pushing or deleting happens.

func (*WatchList) Add

func (wl *WatchList) Add(item WatchItem) error

Add item to the list and persist into DB

func (*WatchList) Get

func (wl *WatchList) Get(namespace, operation string) ([]WatchItem, error)

Get the watch items according to the namespace and operation

func (*WatchList) Remove

func (wl *WatchList) Remove(policyID int64) error

Remove the specified watch item from list

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL