schema

package
v0.7.1 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2024 License: Apache-2.0 Imports: 33 Imported by: 0

Documentation

Overview

Package schema implements CRUD schema.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrGRPCResourceNotFound indicates the resource doesn't exist.
	ErrGRPCResourceNotFound = statusGRPCResourceNotFound.Err()
	// ErrClosed indicates the registry is closed.
	ErrClosed = errors.New("metadata registry is closed")
	// ErrGRPCAlreadyExists indicates the resource already exists.
	ErrGRPCAlreadyExists = statusGRPCAlreadyExists.Err()
)
View Source
var CheckerMap = map[Kind]EqualityChecker{
	KindIndexRuleBinding: func(a, b proto.Message) bool {
		return cmp.Equal(a, b,
			protocmp.IgnoreUnknown(),
			protocmp.IgnoreFields(&databasev1.IndexRuleBinding{}, "updated_at"),
			protocmp.IgnoreFields(&commonv1.Metadata{}, "id", "create_revision", "mod_revision"),
			protocmp.Transform(),
		)
	},
	KindIndexRule: func(a, b proto.Message) bool {
		return cmp.Equal(a, b,
			protocmp.IgnoreUnknown(),
			protocmp.IgnoreFields(&databasev1.IndexRule{}, "updated_at"),
			protocmp.IgnoreFields(&commonv1.Metadata{}, "id", "create_revision", "mod_revision"),
			protocmp.Transform(),
		)
	},
	KindMeasure: func(a, b proto.Message) bool {
		return cmp.Equal(a, b,
			protocmp.IgnoreUnknown(),
			protocmp.IgnoreFields(&databasev1.Measure{}, "updated_at"),
			protocmp.IgnoreFields(&commonv1.Metadata{}, "id", "create_revision", "mod_revision"),
			protocmp.Transform(),
		)
	},
	KindStream: func(a, b proto.Message) bool {
		return cmp.Equal(a, b,
			protocmp.IgnoreUnknown(),
			protocmp.IgnoreFields(&databasev1.Stream{}, "updated_at"),
			protocmp.IgnoreFields(&commonv1.Metadata{}, "id", "create_revision", "mod_revision"),
			protocmp.Transform())
	},
	KindGroup: func(a, b proto.Message) bool {
		return cmp.Equal(a, b,
			protocmp.IgnoreUnknown(),
			protocmp.IgnoreFields(&databasev1.Stream{}, "updated_at"),
			protocmp.IgnoreFields(&commonv1.Metadata{}, "id", "create_revision", "mod_revision"),
			protocmp.Transform())
	},
	KindTopNAggregation: func(a, b proto.Message) bool {
		return cmp.Equal(a, b,
			protocmp.IgnoreUnknown(),
			protocmp.IgnoreFields(&databasev1.TopNAggregation{}, "updated_at"),
			protocmp.IgnoreFields(&commonv1.Metadata{}, "id", "create_revision", "mod_revision"),
			protocmp.Transform())
	},
	KindProperty: func(a, b proto.Message) bool {
		return cmp.Equal(a, b,
			protocmp.IgnoreUnknown(),
			protocmp.IgnoreFields(&propertyv1.Property{}, "updated_at"),
			protocmp.IgnoreFields(&commonv1.Metadata{}, "id", "create_revision", "mod_revision"),
			protocmp.Transform())
	},
	KindNode: func(a, b proto.Message) bool {
		return cmp.Equal(a, b,
			protocmp.IgnoreUnknown(),
			protocmp.IgnoreFields(&databasev1.Node{}, "created_at"),
			protocmp.Transform())
	},
	KindMask: func(_, _ proto.Message) bool {
		return false
	},
}

CheckerMap to map each Kind to its EqualityChecker.

Functions

func BadRequest

func BadRequest(field, desc string) error

BadRequest creates a gRPC error with error details with type BadRequest, which describes violations in a client request.

Types

type EqualityChecker added in v0.6.1

type EqualityChecker func(a, b proto.Message) bool

EqualityChecker Type Function.

type EventHandler

type EventHandler interface {
	OnInit([]Kind) (bool, []int64)
	OnAddOrUpdate(Metadata)
	OnDelete(Metadata)
}

EventHandler allows receiving and handling the resource change events.

type Group

type Group interface {
	GetGroup(ctx context.Context, group string) (*commonv1.Group, error)
	ListGroup(ctx context.Context) ([]*commonv1.Group, error)
	// DeleteGroup delete all items belonging to the group
	DeleteGroup(ctx context.Context, group string) (bool, error)
	CreateGroup(ctx context.Context, group *commonv1.Group) error
	UpdateGroup(ctx context.Context, group *commonv1.Group) error
}

Group allows CRUD groups which is namespaces of resources.

type HasMetadata

type HasMetadata interface {
	GetMetadata() *commonv1.Metadata
	proto.Message
}

HasMetadata allows getting Metadata.

type IndexRule

type IndexRule interface {
	GetIndexRule(ctx context.Context, metadata *commonv1.Metadata) (*databasev1.IndexRule, error)
	ListIndexRule(ctx context.Context, opt ListOpt) ([]*databasev1.IndexRule, error)
	CreateIndexRule(ctx context.Context, indexRule *databasev1.IndexRule) error
	UpdateIndexRule(ctx context.Context, indexRule *databasev1.IndexRule) error
	DeleteIndexRule(ctx context.Context, metadata *commonv1.Metadata) (bool, error)
}

IndexRule allows CRUD index rule schemas in a group.

type IndexRuleBinding

type IndexRuleBinding interface {
	GetIndexRuleBinding(ctx context.Context, metadata *commonv1.Metadata) (*databasev1.IndexRuleBinding, error)
	ListIndexRuleBinding(ctx context.Context, opt ListOpt) ([]*databasev1.IndexRuleBinding, error)
	CreateIndexRuleBinding(ctx context.Context, indexRuleBinding *databasev1.IndexRuleBinding) error
	UpdateIndexRuleBinding(ctx context.Context, indexRuleBinding *databasev1.IndexRuleBinding) error
	DeleteIndexRuleBinding(ctx context.Context, metadata *commonv1.Metadata) (bool, error)
}

IndexRuleBinding allows CRUD index rule binding schemas in a group.

type Kind

type Kind int

Kind is the type of a resource.

const (
	KindGroup Kind = 1 << iota
	KindStream
	KindMeasure
	KindIndexRuleBinding
	KindIndexRule
	KindTopNAggregation
	KindProperty
	KindNode
	KindMask = KindGroup | KindStream | KindMeasure |
		KindIndexRuleBinding | KindIndexRule |
		KindTopNAggregation | KindProperty | KindNode
	KindSize = 9
)

KindMask tends to check whether an event is valid.

func (Kind) String added in v0.5.0

func (k Kind) String() string

func (Kind) Unmarshal added in v0.5.0

func (k Kind) Unmarshal(kv *mvccpb.KeyValue) (Metadata, error)

Unmarshal encode bytes to proto.Message.

type ListOpt

type ListOpt struct {
	Group string
}

ListOpt contains options to list resources.

type Measure

type Measure interface {
	GetMeasure(ctx context.Context, metadata *commonv1.Metadata) (*databasev1.Measure, error)
	ListMeasure(ctx context.Context, opt ListOpt) ([]*databasev1.Measure, error)
	CreateMeasure(ctx context.Context, measure *databasev1.Measure) (int64, error)
	UpdateMeasure(ctx context.Context, measure *databasev1.Measure) (int64, error)
	DeleteMeasure(ctx context.Context, metadata *commonv1.Metadata) (bool, error)
	TopNAggregations(ctx context.Context, metadata *commonv1.Metadata) ([]*databasev1.TopNAggregation, error)
}

Measure allows CRUD measure schemas in a group.

type Metadata

type Metadata struct {
	Spec Spec
	TypeMeta
}

Metadata wrap dedicated serialized resource and its TypeMeta.

type Node added in v0.5.0

type Node interface {
	ListNode(ctx context.Context, role databasev1.Role) ([]*databasev1.Node, error)
	RegisterNode(ctx context.Context, node *databasev1.Node, forced bool) error
	GetNode(ctx context.Context, node string) (*databasev1.Node, error)
}

Node allows CRUD node schemas in a group.

type Property

type Property interface {
	GetProperty(ctx context.Context, metadata *propertyv1.Metadata, tags []string) (*propertyv1.Property, error)
	ListProperty(ctx context.Context, container *commonv1.Metadata, ids []string, tags []string) ([]*propertyv1.Property, error)
	ApplyProperty(ctx context.Context, property *propertyv1.Property, strategy propertyv1.ApplyRequest_Strategy) (bool, uint32, int64, error)
	DeleteProperty(ctx context.Context, metadata *propertyv1.Metadata, tags []string) (bool, uint32, error)
	KeepAlive(ctx context.Context, leaseID int64) error
}

Property allows CRUD properties or tags in group.

type Registry

type Registry interface {
	io.Closer
	Stream
	IndexRule
	IndexRuleBinding
	Measure
	Group
	TopNAggregation
	Property
	Node
	RegisterHandler(string, Kind, EventHandler)
	NewWatcher(string, Kind, watchEventHandler) *watcher
	Register(context.Context, Metadata, bool) error
}

Registry allowing depositing resources.

func NewEtcdSchemaRegistry

func NewEtcdSchemaRegistry(options ...RegistryOption) (Registry, error)

NewEtcdSchemaRegistry returns a Registry powered by Etcd.

type RegistryOption

type RegistryOption func(*etcdSchemaRegistryConfig)

RegistryOption is the option to create Registry.

func ConfigureEtcdTLSCAFile added in v0.6.0

func ConfigureEtcdTLSCAFile(file string) RegistryOption

ConfigureEtcdTLSCAFile sets a trusted ca file of the etcd tls config.

func ConfigureEtcdTLSCertAndKey added in v0.6.0

func ConfigureEtcdTLSCertAndKey(certFile string, keyFile string) RegistryOption

ConfigureEtcdTLSCertAndKey sets a cert & key of the etcd tls config.

func ConfigureEtcdUser added in v0.6.0

func ConfigureEtcdUser(username string, password string) RegistryOption

ConfigureEtcdUser sets a username & password of the etcd.

func ConfigureServerEndpoints added in v0.5.0

func ConfigureServerEndpoints(url []string) RegistryOption

ConfigureServerEndpoints sets a list of the server urls.

func Namespace added in v0.5.0

func Namespace(namespace string) RegistryOption

Namespace sets the namespace of the registry.

type Spec

type Spec interface{}

Spec is a placeholder of a serialized resource.

type Stream

type Stream interface {
	GetStream(ctx context.Context, metadata *commonv1.Metadata) (*databasev1.Stream, error)
	ListStream(ctx context.Context, opt ListOpt) ([]*databasev1.Stream, error)
	CreateStream(ctx context.Context, stream *databasev1.Stream) (int64, error)
	UpdateStream(ctx context.Context, stream *databasev1.Stream) (int64, error)
	DeleteStream(ctx context.Context, metadata *commonv1.Metadata) (bool, error)
}

Stream allows CRUD stream schemas in a group.

type TopNAggregation

type TopNAggregation interface {
	GetTopNAggregation(ctx context.Context, metadata *commonv1.Metadata) (*databasev1.TopNAggregation, error)
	ListTopNAggregation(ctx context.Context, opt ListOpt) ([]*databasev1.TopNAggregation, error)
	CreateTopNAggregation(ctx context.Context, measure *databasev1.TopNAggregation) error
	UpdateTopNAggregation(ctx context.Context, measure *databasev1.TopNAggregation) error
	DeleteTopNAggregation(ctx context.Context, metadata *commonv1.Metadata) (bool, error)
}

TopNAggregation allows CRUD top-n aggregation schemas in a group.

type TypeMeta

type TypeMeta struct {
	Name        string
	Group       string
	ModRevision int64
	Kind        Kind
}

TypeMeta defines the identity and type of an Event.

type UnimplementedOnInitHandler added in v0.6.0

type UnimplementedOnInitHandler struct{}

UnimplementedOnInitHandler is a placeholder for unimplemented OnInitHandler.

func (UnimplementedOnInitHandler) OnInit added in v0.6.0

func (u UnimplementedOnInitHandler) OnInit([]Kind) (bool, []int64)

OnInit is a placeholder for unimplemented OnInitHandler.

Jump to

Keyboard shortcuts

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