product

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2021 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ComponentFormPod    = "pod"
	ComponentFormServer = "server"
)
View Source
const DefaultPlaybook string = "sail"
View Source
const DefaultPlaybookFile string = ".sail.yaml"

Variables

This section is empty.

Functions

func FilterOptionDisabled

func FilterOptionDisabled(c *Component) bool

func FilterOptionEnabled

func FilterOptionEnabled(c *Component) bool

func FilterOptionFormPod

func FilterOptionFormPod(c *Component) bool

func FilterOptionFormServer

func FilterOptionFormServer(c *Component) bool

Types

type Component

type Component struct {
	Name    string `yaml:"-"`
	Version string `yaml:"version"`

	// Group can be used to group by components.
	Group string `yaml:"group"`

	// If RoleName is empty, it will be set to component Name.
	RoleName string `yaml:"roleName"`

	// Form represents the installation method of this component, valid values:
	//  * server
	//  * pod
	// (组件的部署形态)
	Form string `yaml:"form"`

	// Pkgs hold all files that are used to complete the deployment of the component.
	Pkgs []Pkg `yaml:"pkgs"`

	// Enabled represents whether this component will be deployed in the specific environment.
	Enabled bool `yaml:"enabled"`

	// External represents whether this component is provided by external system like cloud, and thus no need to be deployed.
	External bool `yaml:"external"`

	// Services holds all exposed service of the component.
	// Each service is exposed by a specific port.
	Services map[string]Service `yaml:"services"`

	// Computed holds all auto computed service info.
	// This field SHOULD NEVER be edited or changed by operators.
	// The field is always automaticllay computed based on other fields of Component.
	Computed map[string]ServiceComputed `yaml:"computed"`

	// Requires represents the other components on which this component depends on.
	// If this component is activated (enabled:true or external:true), then all these required components also need to be activated.
	// 依赖的服务(其它组件提供的服务,不能依赖自身组件)
	// Todo, check cycle
	Requires []Require `yaml:"requires"`

	// The list value of `deps` represents the other services which depend on this service.
	// If the number of hosts of this service changed, it required that
	// those services who depend on it also need to be reconfigured or restarted.
	// For `service-scaleup` and `service-scaledown`, these dependencies will be used
	Dependencies []string `yaml:"dependencies"`

	// Children represents some children-level components of this component.
	// The children components have the following characteristics:
	// * They can declared to be activated or not enabled: true or false.
	// * They can be upgraded like normal components.
	// * They DO NOT have their own hosts group in ansible inventory, they share the hosts group of its parent component.
	Children []string `yaml:"children"`

	// Applied roles for this component.
	// The empty list will apply at least one role with the component's RoleName.
	Roles []string `yaml:"roles"`

	Vars map[string]interface{} `yaml:"vars"`
	Tags map[string]interface{} `yaml:"tags"`
}

Component represents the configuration of a component.

func NewComponent

func NewComponent(name string) *Component

NewComponent returns a Component.

func (*Component) Check

func (c *Component) Check() error

func (*Component) Compute

func (c *Component) Compute(cm *cmdb.CMDB) error

func (*Component) DownloadPkg

func (c *Component) DownloadPkg(dstDir string) error

func (*Component) GenAnsiblePlay

func (c *Component) GenAnsiblePlay() (*ansible.Play, error)

GenAnsiblePlay generatea a ansible play for this component.

func (*Component) GetRoleName

func (c *Component) GetRoleName() string

func (*Component) GetRoles

func (c *Component) GetRoles() []string

GetRoles return the ansible roles which will be applied to this component.

func (*Component) Merge

func (c *Component) Merge(in *Component)

type FilterOption

type FilterOption func(c *Component) bool

func NewFilterOptionByComponentsMap

func NewFilterOptionByComponentsMap(m map[string]string) FilterOption

type Pkg

type Pkg struct {
	File *string `yaml:"file"`
	URL  *string `yaml:"url"`
}

Pkg represents a package file. We can use the Pkg.File field to check whether those pkg files exists and use the Pkg.URL field to download the file.

type Product

type Product struct {
	Name string `json:"Name,omitempty"  yaml:"Name,omitempty"`

	// zone specific vars of product
	Vars map[string]interface{} `json:"Vars,omitempty" yaml:"Vars,omitempty"`
	// zone specific components of product
	Components map[string]*Component `json:"Components,omitempty" yaml:"Components,omitempty"`

	// default vars of product, it is loaded from products/<productName>/vars.yaml
	DefaultVars map[string]interface{}
	// default components of product, it is loaded from products/<productName>/{components.yaml,components/*.yaml}
	DefaultComponents map[string]Component

	Dir string

	RolesDir string
	// contains filtered or unexported fields
}

func NewProduct

func NewProduct(name string, baseDir string) *Product

func (*Product) Check

func (p *Product) Check(cm *cmdb.CMDB) error

func (*Product) ComponentList

func (p *Product) ComponentList() []string

func (*Product) ComponentListWithFilterOptionsAnd

func (p *Product) ComponentListWithFilterOptionsAnd(filterOptions ...FilterOption) []string

func (*Product) ComponentListWithFitlerOptionsOr

func (p *Product) ComponentListWithFitlerOptionsOr(filterOptions ...FilterOption) []string

func (*Product) Compute

func (p *Product) Compute(cm *cmdb.CMDB) error

func (*Product) DefaultPlaybook

func (p *Product) DefaultPlaybook() string

func (*Product) GenSail

func (p *Product) GenSail() (ansible.Playbook, error)

GenSail generate the default sail.yaml ansible playbook file

func (*Product) HasComponent

func (p *Product) HasComponent(name string) bool

func (*Product) Init

func (p *Product) Init() error

Init will init product internal fields

func (*Product) LoadZone

func (p *Product) LoadZone(zoneVarsFile string) error

LoadZone will fill zone's specific variables from zoneVarsFile into the Vars and Components fields of product p.

func (*Product) SailPlaybookFile

func (p *Product) SailPlaybookFile() string

func (*Product) SetComponentEnabled

func (p *Product) SetComponentEnabled(name string, flag bool) error

func (*Product) SetComponentExternalEnabled

func (p *Product) SetComponentExternalEnabled(name string, flag bool) error

type Require

type Require struct {
	Component *string `yaml:"component,omitempty"`
	Service   *string `yaml:"service,omitempty"`
}

type Role

type Role struct {
}

Todo currently this is not used

type Service

type Service struct {
	ComponentName string `yaml:"-"`
	Name          string `yaml:"-"`

	Scheme string `yaml:"scheme"`

	// Host, IPv4, IPv6 does not means where the component installed.
	// Host can be domain name or ip address
	Host string `yaml:"host"`
	IPv4 string `yaml:"ipv4"`
	IPv6 string `yaml:"ipv6"`

	// The port should be set to the actual port on which the process listend,
	// thus ansible playbook can use this variable to render configuration files.
	Port int `yaml:"port"`

	Addr string `yaml:"addr"`
	Path string `yaml:"path"`

	Addrs     []string `yaml:"addrs"`
	Endpoints []string `yaml:"endpoints"`
	URLs      []string `yaml:"urls"`

	PubPort int `yaml:"pubPort"`
	LBPort  int `yaml:"lbPort"`
}

Service represents the service exposed by component.

func NewService

func NewService(componentName string, serviceName string) *Service

NewService returns a service

func (*Service) Check

func (s *Service) Check() error

func (*Service) Compute

func (s *Service) Compute(external bool, cm *cmdb.CMDB) (*ServiceComputed, error)

Compute return a ServiceComputed for this service.

type ServiceComputed

type ServiceComputed struct {
	Scheme    string   `yaml:"scheme"`
	Host      string   `yaml:"host"`
	Port      int      `yaml:"port"`
	Addr      string   `yaml:"addr"`
	Path      string   `yaml:"path"`
	Hosts     []string `yaml:"hosts"`
	Addrs     []string `yaml:"addrs"`
	Endpoints []string `yaml:"endpoints"`
	URLs      []string `yaml:"urls"`
}

ServiceComputed represents the computed configuration for a service.

func NewServiceComputed

func NewServiceComputed() *ServiceComputed

NewServiceComputed returns a computed service.

Jump to

Keyboard shortcuts

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