crm

package
v0.0.0-...-6ac6f58 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2024 License: Apache-2.0, BSD-3-Clause, MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ServiceStatusStaging = op.ServiceStatusStaging
	ServiceStatusRunning = op.ServiceStatusRunning
	ServiceStatusFailed  = op.ServiceStatusFailed
)

Variables

View Source
var (
	ErrorResourceAlreadyInit        = fmt.Errorf("resource already init")
	ErrorResourceNotRunning         = fmt.Errorf("resource not running")
	ErrorResourceNoExist            = fmt.Errorf("resource no exist")
	ErrorResourceAlreadyReleased    = fmt.Errorf("resource already released")
	ErrorApplicationNoFound         = fmt.Errorf("application no found")
	ErrorApplicationAlreadyLaunched = fmt.Errorf("application already launched")
	ErrorManagerNotRunning          = fmt.Errorf("manager not running")
	ErrorBrokerParamNotFit          = fmt.Errorf("broker parameters not fit")
	ErrorBrokerNotEnoughResources   = fmt.Errorf("broker not enough resources")
	ErrorBrokeringUnderCoolingTime  = fmt.Errorf("broker under cooling time")
)

Functions

This section is empty.

Types

type Basic

type Basic struct {
	UpdatedAt time.Time `gorm:"column:update_at" json:"-"`
	Disabled  bool      `gorm:"column:disabled;default:false;index" json:"-"`
}

Basic define the basic table columns.

type Broker

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

Broker maintains a type of pre-launch-server, it has following features:

  • When someone call the Broker for Applying, the Broker check if it matches the conditions, if so, give the caller the running server, and kicked the server out from its pool.
  • When the number of running servers in its pool is less or more than expected, the Broker launch or release servers to match the expect number.

func NewBroker

func NewBroker(
	name, user string,
	mgr *resourceManager,
	strategyType StrategyType,
	strategy BrokerStrategy,
	param BrokerParam) *Broker

NewBroker get a new broker. name and user define the broker name and the user in resource manager. mgr is the container resource manager instance. strategyType describe which strategy the broker runs and the strategy is a BrokerStrategy to do the strategy work. param describe the broker config such as resource and image.

func (*Broker) Apply

func (b *Broker) Apply(resourceID string, param ResourceParam, filterFunc op.InstanceFilterFunction) (string, error)

Apply receive origin resource's ID, params and filter function, and try to get a running-resource from broker pool to serve. First of all, the origin resource's params should match with the broker params Then use the provided filter function to check if the instances enough Then consume the running-resource from broker pool.

func (*Broker) CurrentNum

func (b *Broker) CurrentNum() int

CurrentNum return the current brokers number

func (*Broker) Launch

func (b *Broker) Launch() error

Launch a new resource and put it into pool

func (*Broker) Release

func (b *Broker) Release() error

Release a free resource from pool

func (*Broker) Run

func (b *Broker) Run() error

Run the broker, begins to provide the apply service and ensure the pre-launch-server number.

type BrokerParam

type BrokerParam struct {
	Param           ResourceParam
	Instance        int
	FitFunc         BrokerParamFitFunction
	ReleaseLoop     bool
	IdleKeepSeconds int
}

BrokerParam describe the params of one broker, contains the following fields:

  • Param resource param, use to launch broker resource automatically
  • Instance decide how many instances in one broker resource
  • FitFunc a function receive the broker resource param and request resource param,
  • ReleaseLoop indicate whether release resource with loop until succeed
  • IdleKeepSeconds to set wait seconds before release idle resource check if the broker can serve this request.

type BrokerParamFitFunction

type BrokerParamFitFunction func(brokerParam, requestParam ResourceParam) bool

BrokerParamFitFunction define the function type of broker condition checker. Aim to compare the resource request with the broker to check if the broker can handle this request.

type BrokerSet

type BrokerSet struct {
	sync.Mutex
	// contains filtered or unexported fields
}

BrokerSet contains multiple user's brokers. Each user has a list of brokers, calling apply will check every item in this list and use the first match broker to do the work.

func NewBrokerSet

func NewBrokerSet() *BrokerSet

NewBrokerSet get a new, empty broker set.

func (*BrokerSet) Add

func (bs *BrokerSet) Add(broker *Broker)

Add receive a new broker and add it into the user list which it belongs to.

func (*BrokerSet) Apply

func (bs *BrokerSet) Apply(
	resourceID, user string,
	param ResourceParam,
	filterFunc op.InstanceFilterFunction) (string, error)

Apply receive the broker Apply params and an user. User is used to find out the broker list in the set, and call the broker Apply.

func (*BrokerSet) List

func (bs *BrokerSet) List() []*Broker

List get all brokers from broker set.

func (*BrokerSet) Recover

func (bs *BrokerSet) Recover() error

Recover take the responsibility to run all brokers goroutines

type BrokerStrategy

type BrokerStrategy interface {
	// ask strategy now how many resources should we adjust? more(>0) or less(<0)
	Ask(param interface{}) int
}

BrokerStrategy describe a interface for strategy in broker launcher. It decides how many resource should the broker add or reduce in its pool.

func NewConstBrokerStrategy

func NewConstBrokerStrategy(num int) BrokerStrategy

NewConstBrokerStrategy get a new const strategy

type HandlerWithUser

type HandlerWithUser interface {
	Init(resourceID string, param ResourceParam) error
	Launch(resourceID, city string, function op.InstanceFilterFunction) error
	Scale(resourceID string, function op.InstanceFilterFunction) error
	GetServiceInfo(resourceID string) (*op.ServiceInfo, error)
	IsServicePreparing(resourceID string) (bool, error)
	Release(resourceID string) error
	AddBroker(name string, strategyType StrategyType, strategy BrokerStrategy,
		param BrokerParam) error
	GetInstanceType(platform, group string) *config.InstanceType
	GetNamespace() string
}

HandlerWithUser define all operations supported by resource manager.

type InstanceFilterFunction

type InstanceFilterFunction func(availableInstance int) (int, error)

InstanceFilterFunction describe the function that decide how many instance to launch/scale.

type MySQL

type MySQL interface {
	ListResource(opts commonMySQL.ListOptions) ([]*TableResource, int64, error)
	GetResource(resourceID string) (*TableResource, error)
	CreateResource(tr *TableResource) error
	PutResource(tr *TableResource) error
	DeleteResource(resourceID string) error
}

MySQL define the mysql operations to handle resources.

func NewMySQL

func NewMySQL(conf MySQLConf) (MySQL, error)

NewMySQL get a new MySQL instance.

type MySQLConf

type MySQLConf struct {
	MySQLStorage     string
	MySQLDatabase    string
	MySQLTable       string
	MySQLUser        string
	MySQLPwd         string
	Charset          string
	MysqlTableOption string
	SkipEnsure       bool
}

MySQLConf describe the mysql connection config need by resource manager.

type ResourceManager

type ResourceManager interface {
	// RegisterUser receive a user and return a HandlerWithUser which operates under this user.
	RegisterUser(user string) (HandlerWithUser, error)

	// GetResourceDetail return details of resource description.
	GetResourceDetail() *rsc.Details

	// Run the manager.
	Run() error
}

ResourceManager define a resource manager which provides multi-user handlers to operate container resources.

func NewResourceManager

func NewResourceManager(
	c *config.ContainerResourceConfig,
	event types.RoleChangeEvent,
	rdClient rd.RegisterDiscover) (ResourceManager, error)

NewResourceManager get a new container resource manager.

type ResourceParam

type ResourceParam struct {
	City string `json:"city"`

	Platform string `json:"platform"`

	// env key-values which will be inserted into containers
	Env map[string]string `json:"env"`

	// ports that implements with port_name:protocol
	// such as my_port_alpha:http, my_port_beta:tcp
	// port numbers are all generated by container scheduler with cnm HOST
	Ports map[string]string `json:"ports"`

	// volumes implements the hostPath volumes with name:settings
	Volumes map[string]op.BcsVolume

	// container images
	Image string `json:"image"`

	// if it is a broker resource, then broker name should be specified
	BrokerName string `json:"broker_name"`
}

ResourceParam describe the request parameters to container resource manager.

type StrategyType

type StrategyType int
const (
	StrategyConst StrategyType = iota
)

type TableResource

type TableResource struct {
	Basic
	ResourceID string `gorm:"column:resource_id;primary_key" json:"resource_id"`
	User       string `gorm:"column:user" json:"user"`
	Param      string `gorm:"column:param" sql:"type:text" json:"param"`

	ResourceBlockKey string `gorm:"column:resource_block_key" json:"resource_block_key"`
	NoReadyInstance  int    `gorm:"column:no_ready_instance" json:"no_ready_instance"`
	RequestInstance  int    `gorm:"column:request_instance" json:"request_instance"`
	Status           int    `gorm:"column:status;index" json:"status"`

	// broker attributes
	BrokerResourceID string `gorm:"column:broker_resource_id;index" json:"broker_resource_id"`
	BrokerName       string `gorm:"column:broker_name;index" json:"broker_name"`
	BrokerSold       bool   `gorm:"column:broker_sold;index" json:"broker_sold"`
	// contains filtered or unexported fields
}

TableResource describe the db columns of Resource. It will inherit the Basic.

func (TableResource) TableName

func (rt TableResource) TableName() string

TableName specific table name.

Directories

Path Synopsis
k8s

Jump to

Keyboard shortcuts

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