discovery

package
v1.4.8 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2021 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

* Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You 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.

* Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You 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.

* Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You 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.

* Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You 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.

* Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You 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.

* Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You 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.

* Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You 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.

* Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You 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.

* Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You 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.

* Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You 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.

* Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You 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.

* Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You 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.

Index

Constants

View Source
const (
	DefaultTimeout       = 30 * time.Second
	DefaultCacheInitSize = 100
)
View Source
const (
	TypeError = Type(-1)
)

Variables

View Source
var (
	NullCache  = &nullCache{}
	NullCacher = &nullCacher{}
)
View Source
var (
	Types []Type
)

Functions

func AddEventHandleFunc

func AddEventHandleFunc(t Type, f KvEventFunc)

the event handler/func must be good performance, or will block the event bus.

func AddEventHandler

func AddEventHandler(h KvEventHandler)

func ReportProcessEventCompleted

func ReportProcessEventCompleted(prefix string, evts []KvEvent)

Types

type Adaptor

type Adaptor interface {
	Runnable
	// Indexer is used to search data from the registry.
	Indexer
	// Cacher is used to manage the registry's cache.
	Cacher
}

Adaptor is used to do service discovery. To improve the performance, Adaptor may use cache firstly in service discovery.

type AdaptorRepository

type AdaptorRepository interface {
	// New news an instance of specify Type adaptor
	New(t Type, cfg *Config) Adaptor
}

AdaptorRepository creates Adaptors

type Cache

type Cache interface {
	CacheReader
	// Put puts a k-v
	Put(k string, v *KeyValue)
	// Remove removes a k-v data
	Remove(k string)
	// MarkDirty mark k-v data dirty
	MarkDirty()
	// Dirty k-v data is dirty or not
	Dirty() bool
	// Clear clear all k-v data
	Clear()
}

Cache stores k-v data.

type CacheIndexer

type CacheIndexer struct {
	Cache CacheReader
}

CacheIndexer implements discovery.Indexer. CacheIndexer searches data from cache.

func NewCacheIndexer

func NewCacheIndexer(cache CacheReader) *CacheIndexer

func (*CacheIndexer) Creditable

func (i *CacheIndexer) Creditable() bool

Creditable implements discovery.Indexer.Creditable.

func (*CacheIndexer) Search

func (i *CacheIndexer) Search(ctx context.Context, opts ...registry.PluginOpOption) (resp *Response, _ error)

type CacheReader

type CacheReader interface {
	Name() string // The name of implementation
	Size() int    // the bytes size of the cache
	// Get gets a value by input key
	Get(k string) *KeyValue
	// GetAll gets all the data stored in Cache
	GetAll(arr *[]*KeyValue) int
	// GetPrefix gets values by the key prefix
	GetPrefix(prefix string, arr *[]*KeyValue) int
	// ForEach executes the given function for each of the k-v
	ForEach(iter func(k string, v *KeyValue) (next bool))
}

CacheReader reads k-v data.

type Cacher

type Cacher interface {
	// Cache gets the cache that Cacher manages.
	Cache() CacheReader
}

Cacher manages cache of some data source, e.g. etcd, kubernetes. An user can do nothing but read the managed cache.

type CommonCacher

type CommonCacher struct {
	Cfg *Config
	// contains filtered or unexported fields
}

CommonCacher implements discovery.Cacher. CommonCacher is universal to manage cache of any registry. Use Cfg to set it's behavior.

func NewCommonCacher

func NewCommonCacher(cfg *Config, cache Cache) *CommonCacher

func (*CommonCacher) Cache

func (c *CommonCacher) Cache() CacheReader

func (*CommonCacher) Notify

func (c *CommonCacher) Notify(action types.EventType, key string, kv *KeyValue)

func (*CommonCacher) OnEvent

func (c *CommonCacher) OnEvent(evt KvEvent)

func (*CommonCacher) Ready

func (c *CommonCacher) Ready() <-chan struct{}

func (*CommonCacher) Run

func (c *CommonCacher) Run()

func (*CommonCacher) Stop

func (c *CommonCacher) Stop()

type Config

type Config struct {
	// Key is the prefix to unique specify resource type
	Key          string
	InitSize     int
	Timeout      time.Duration
	Period       time.Duration
	DeferHandler DeferHandler
	OnEvent      KvEventFunc
	Parser       proto.Parser
}

func Configure

func Configure() *Config

func (*Config) AppendEventFunc

func (cfg *Config) AppendEventFunc(f KvEventFunc) *Config

func (*Config) String

func (cfg *Config) String() string

func (*Config) WithDeferHandler

func (cfg *Config) WithDeferHandler(h DeferHandler) *Config

func (*Config) WithEventFunc

func (cfg *Config) WithEventFunc(f KvEventFunc) *Config

func (*Config) WithInitSize

func (cfg *Config) WithInitSize(size int) *Config

func (*Config) WithParser

func (cfg *Config) WithParser(parser proto.Parser) *Config

func (*Config) WithPeriod

func (cfg *Config) WithPeriod(ot time.Duration) *Config

func (*Config) WithPrefix

func (cfg *Config) WithPrefix(key string) *Config

func (*Config) WithTimeout

func (cfg *Config) WithTimeout(ot time.Duration) *Config

type DeferHandler

type DeferHandler interface {
	OnCondition(CacheReader, []KvEvent) bool
	HandleChan() <-chan KvEvent
	Reset() bool
}

type Indexer

type Indexer interface {
	// Search searches k-v data based on the input options
	Search(ctx context.Context, opts ...registry.PluginOpOption) (*Response, error)
	// Creditable judges whether Indexer's search results are creditable
	// It is recommended to use cache only and not to call the backend
	// directly, If Indexer is not creditable.
	Creditable() bool
}

Indexer searches k-v data. An indexer may search k-v data from many data sources, e.g. cache, registry, file, other Indexers...

type KeyValue

type KeyValue struct {
	Key            []byte
	Value          interface{}
	Version        int64
	CreateRevision int64
	ModRevision    int64
	ClusterName    string
}

func NewKeyValue

func NewKeyValue() *KeyValue

func (*KeyValue) String

func (kv *KeyValue) String() string

type KvCache

type KvCache struct {
	Cfg *Config
	// contains filtered or unexported fields
}

KvCache implements Cache. KvCache is dedicated to stores service discovery data, e.g. service, instance, lease.

func NewKvCache

func NewKvCache(name string, cfg *Config) *KvCache

func (*KvCache) Clear

func (c *KvCache) Clear()

func (*KvCache) Dirty

func (c *KvCache) Dirty() bool

func (*KvCache) ForEach

func (c *KvCache) ForEach(iter func(k string, v *KeyValue) (next bool))

func (*KvCache) Get

func (c *KvCache) Get(key string) (v *KeyValue)

func (*KvCache) GetAll

func (c *KvCache) GetAll(arr *[]*KeyValue) (count int)

func (*KvCache) GetPrefix

func (c *KvCache) GetPrefix(prefix string, arr *[]*KeyValue) (count int)

func (*KvCache) MarkDirty

func (c *KvCache) MarkDirty()

func (*KvCache) Name

func (c *KvCache) Name() string

func (*KvCache) Put

func (c *KvCache) Put(key string, v *KeyValue)

func (*KvCache) Remove

func (c *KvCache) Remove(key string)

func (*KvCache) Size

func (c *KvCache) Size() (l int)

type KvEvent

type KvEvent struct {
	Revision int64
	Type     types.EventType
	KV       *KeyValue
	CreateAt simple.Time
}

func NewKvEvent

func NewKvEvent(action types.EventType, kv *KeyValue, rev int64) KvEvent

type KvEventFunc

type KvEventFunc func(evt KvEvent)

type KvEventHandler

type KvEventHandler interface {
	Type() Type
	OnEvent(evt KvEvent)
}

type KvEventProxy

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

func EventProxy

func EventProxy(t Type) *KvEventProxy

unsafe

func (*KvEventProxy) AddHandleFunc

func (h *KvEventProxy) AddHandleFunc(f KvEventFunc)

func (*KvEventProxy) InjectConfig

func (h *KvEventProxy) InjectConfig(cfg *Config) *Config

InjectConfig will inject a resource changed event callback function in Config

func (*KvEventProxy) OnEvent

func (h *KvEventProxy) OnEvent(evt KvEvent)

type Response

type Response struct {
	Kvs   []*KeyValue
	Count int64
}

type Runnable

type Runnable interface {
	Run()
	Stop()
	Ready() <-chan struct{}
}

type Type

type Type int

func RegisterType

func RegisterType(name string) (newID Type, err error)

func (Type) String

func (st Type) String() string

Directories

Path Synopsis
* Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements.
* Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements.
k8s

Jump to

Keyboard shortcuts

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