octopus_meta

package module
v1.0.8 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2023 License: Apache-2.0 Imports: 15 Imported by: 0

README

octopus-meta

octopus-meta是Apollo运行时的App 模型定义

拥有完整的测试用例

$ bash ./test.sh

模型

App | Meta 为octopus-meta定义的app模型

对外接口

AutoLoad

自动加载meta文件, 当环境变量APP_ROOT存在并且$APP_ROOT/.octopus$APP_ROOT/meta存在时 会自动从此目录加载模型文件

Load(p string)

传入指定的模型文件目录并加载模型文件

SetOctopusMetaDir(p string)

配置全局生效的模型文件路径,会在Load接口中生效,不影响Autoload逻辑

Octopus{}

Octopus结构体暴露了内部的json模型加载方法

var OctopusIterator = Octopus{Type: "default", AutoEnv: true}

在octopus-meta内部定义一个全局的OctopusIterator默认使用,通过AutoEnv可以控制meta的值是否支持从环境变量加载

Documentation

Overview

Package octopus_meta

Package octopus_meta

Package octopus_meta

Package octopus_meta

Package octopus_meta

Package octopus_meta

Package octopus_meta

Package octopus_meta

Package octopus_meta

Index

Constants

View Source
const (
	SourceOther     = "other"
	SourceApp       = "app"
	SourceSys       = "system"
	SourceContainer = "container"
)
View Source
const (
	MetaAutoLoadDir       = ".octopus"
	MetaAutoLoadDirNoHide = "octopusMeta"
	MetaSuffix            = ".pig"
)
View Source
const (
	TypeService    = "Service"    // 服务
	TypeWebFront   = "FrontEnd"   // 前端
	TypeNoEngine   = "NoEngine"   // 前端
	TypeMiddleWare = "MiddleWare" // 中间件
	TypeDataStore  = "DataStore"  // 数据层
	TypeModule     = "Module"     // 模块
	TypeContainer  = "Container"  // 容器
)
View Source
const (
	Published  = "published"  // 已发布
	Testing    = "testing"    // 测试中
	Unreleased = "unreleased" // 待发布
	Beta       = "beta"       // beta版本
)

app的发布状态

View Source
const (
	ConfNginx    = "nginx"
	ConfGunicorn = "gunicorn"
)

配置文件类型

Variables

View Source
var (
	ErrMetaDir     = errors.New("metadata dir is not exist")
	ErrWalkMetaDir = errors.New("failed to walk metadata to load app configs")
	ErrLoadPart    = errors.New("failed to load part of apps")
	ErrAPP         = errors.New("failed to find app by name")
	ErrNotPtr      = errors.New("v is not a pointer")
)
View Source
var DefaultApp = App{
	Type:          TypeService,
	ReleaseStatus: Published,
	EngDes:        "default english description",
	CHSDes:        "默认中文描述",
	ManageCMD: CMD{
		Start:     "start.sh",
		Stop:      "stop.sh",
		Restart:   "restart.sh",
		ForceKill: "kill.sh",
		Check:     "check.sh",
	},
	Meta: Meta{
		Author:      "",
		Domain:      "",
		Language:    []string{},
		CreateDate:  "",
		Version:     "1.0.0",
		DynamicConf: false,
		ConfType:    "",
		ConfPath:    "",
	},
	RunData: RunData{
		Envs:       []string{},
		Ports:      []int{},
		RandomPort: true,
		Host:       "localhost",
	},
}
View Source
var OctopusIterator = Octopus{Type: "default", AutoEnv: true}
View Source
var OctopusMetaDir = ""
View Source
var OriginJSON = originJSON{}

OriginJSON 使用go encoding/json

Functions

func AutoEnv

func AutoEnv()

AutoEnv 自动替换值为$val的变量为环境变量val

func AutoLoad

func AutoLoad() (map[string]App, error)

AutoLoad 从环境变量APP_ROOT下规定的路径自动加载

func DelAppMeta

func DelAppMeta(appName string) error

DelAppMeta 删除app

func Info

func Info() (string, string, string)

Info 返回版本信息

func Load

func Load(p string) (map[string]App, error)

Load 从指定路径加载模型 调用SetOctopusMetaDir来设置全局使用的路径

func NewAppMeta

func NewAppMeta(appName string) error

NewAppMeta 创建新的空app meta 自动加载目录和全局目录都不存在时 调用SetOctopusMetaDir来设置全局使用的路径

func NewMetaDir

func NewMetaDir(p string) error

NewMetaDir 创建新的meta目录 如果创建成功 默认会使用此目录作为全局目录

func SaveAppMeta

func SaveAppMeta(app App, appName string) error

SaveAppMeta 保存app meta

func SetOctopusMetaDir

func SetOctopusMetaDir(p string)

SetOctopusMetaDir 设置配置需要读取的默认路径 后续所有的读取都会走这个路径 autoload时不生效

Types

type Alarm added in v1.0.6

type Alarm struct {
	Title        string `json:"title" bson:"title"`
	Level        string `json:"level" bson:"level"`
	Message      string `json:"message" bson:"message"`
	AlarmExtends `json:",omitempty" bson:",inline"`
}

Alarm 告警信息模型 在使用时 存储数据库时增加mongo model

type AlarmExtends added in v1.0.6

type AlarmExtends struct {
	Source string `json:"source" bson:"source"` // 告警来源
	User   string `json:"user" bson:"user"`     // 操作用户
}

AlarmExtends 告警扩展信息

type App

type App struct {
	Name          string `json:"name" validate:"required" bson:"name" yaml:"name"`           // 服务名称
	ID            string `json:"id" validate:"required" bson:"id" yaml:"id"`                 // 服务唯一ID
	Type          string `json:"type" bson:"type" yaml:"type"`                               // service | middleware
	ReleaseStatus string `json:"release_status" bson:"release_status" yaml:"release_status"` // published | pending | testing
	EngDes        string `json:"eng_des" bson:"eng_des" yaml:"eng_des"`                      // 英文描述
	CHSDes        string `json:"chs_des" bson:"chs_des" yaml:"chs_des"`                      // 中文描述
	Link          string `json:"link" bson:"link" yaml:"link"`                               // 服务对外提供的URL链接
	// 管理项
	ManageCMD CMD `json:"manage_cmd" bson:"manage_cmd" yaml:"manage_cmd"` // 管理命令组
	// 元数据
	Meta Meta `json:"meta" bson:"meta" yaml:"meta"` // 服务元数据
	// 动态依赖配置
	RunData RunData `json:"run_data" bson:"run_data" yaml:"run_data"` // 服务运行依赖

	Runtime Runtime `json:"runtime" bson:"runtime" yaml:"runtime"` // 服务运行时数据

	ResourceLimit ResourceLimit `json:"resource_limit" bson:"resource_limit" yaml:"resource_limit"` // 运行时资源限制
}

App model for app

func LoadApp

func LoadApp(appName string) (App, error)

LoadApp 加载指定的app 仅在配置全局路径时生效

func NewApp added in v1.0.8

func NewApp(appName string) App

NewApp 返回一个默认的新APP

func (*App) Validate

func (app *App) Validate() bool

Validate 适用于model的检查器

type CMD

type CMD struct {
	Start     string `json:"start" bson:"start" yaml:"start"`
	Stop      string `json:"stop" bson:"stop" yaml:"stop"`
	Restart   string `json:"restart" bson:"restart" yaml:"restart"`
	ForceKill string `json:"force_kill" bson:"force_kill" yaml:"force_kill"`
	Check     string `json:"check" bson:"check" yaml:"check"`
}

CMD 服务的管理脚本

type Meta

type Meta struct {
	Author      string   `json:"author" bson:"author" yaml:"author"`
	Domain      string   `json:"domain" bson:"domain" yaml:"domain"`
	Language    []string `json:"language" bson:"language" yaml:"language"`
	CreateDate  string   `json:"create_date" bson:"create_date" yaml:"create_date"`
	Version     string   `json:"version" bson:"version" yaml:"version"`
	DynamicConf bool     `json:"dynamic_conf" bson:"dynamic_conf" yaml:"dynamic_conf"` // 是否需要生成配置文件 支持nginx | gunicorn
	ConfType    string   `json:"conf_type" bson:"conf_type" yaml:"conf_type"`          // nginx | gunicorn
	ConfPath    string   `json:"conf_path" bson:"conf_path" yaml:"conf_path"`          // 配置文件路径 支持绝对和相对路径
}

Meta 服务的元数据

type MetaData

type MetaData App

MetaData 导出App别名

type Octopus added in v1.0.1

type Octopus struct {
	Type    string
	AutoEnv bool
}

Octopus 初始化或使用全局定义的octopus

func (*Octopus) Parse added in v1.0.1

func (o *Octopus) Parse(v interface{}, f string) error

Parse 从meta文件中解析 v interface 必须是一个结构体指针

func (*Octopus) ParseString added in v1.0.1

func (o *Octopus) ParseString(v interface{}, s string) error

ParseString 从字符串中解析

func (*Octopus) ReadFile added in v1.0.1

func (o *Octopus) ReadFile(f string) ([]byte, error)

ReadFile 读取文件内容

func (*Octopus) Save added in v1.0.1

func (o *Octopus) Save(v interface{}, f string) error

Save 保存数据到文件

func (*Octopus) ToString added in v1.0.1

func (o *Octopus) ToString(v interface{}, f string) (string, error)

ToString 转为字符串

type OctopusJSON added in v1.0.5

type OctopusJSON interface {
	Marshal(v interface{}) ([]byte, error)
	MarshalIndent(v interface{}, prefix string, indent string) ([]byte, error)
	Unmarshal(data []byte, v interface{}) error
	UnmarshalFromString(str string, v interface{}) error
}

type ResourceLimit added in v1.0.4

type ResourceLimit struct {
	MinCpu     int `json:"min_cpu" bson:"min_cpu" yaml:"min_cpu"`                // 最小cpu使用率 %
	MaxCpu     int `json:"max_cpu" bson:"max_cpu" yaml:"max_cpu"`                // 最大cpu使用率 %
	MinMem     int `json:"min_mem" bson:"min_mem" yaml:"min_mem"`                // 最小内存使用率 bytes
	MaxMem     int `json:"max_mem" bson:"max_mem" yaml:"max_mem"`                // 最大内存使用率 bytes
	AveCpuPeak int `json:"ave_cpu_peak" bson:"ave_cpu_peak" yaml:"ave_cpu_peak"` // 稳定负载下平均cpu峰值
	AveMemPeak int `json:"ave_mem_peak" bson:"ave_mem_peak" yaml:"ave_mem_peak"` // 稳定负载下平均mem峰值
	MaxRead    int `json:"max_read" bson:"max_read" yaml:"max_read"`             // 最大读取速率
	MaxWrite   int `json:"max_write" bson:"max_write" yaml:"max_write"`          // 最大写入速率
	MaxRequest int `json:"max_request" bson:"max_request" yaml:"max_request"`    // 单位时间最大请求数
	MaxClient  int `json:"max_client" bson:"max_client" yaml:"max_client"`       // 单位时间最大客户端连接数
}

ResourceLimit 运行时资源限制

type RunData

type RunData struct {
	Envs       []string `json:"envs" bson:"envs" yaml:"envs"` // just like `Name=Diri`
	Ports      []int    `json:"ports" bson:"ports" yaml:"ports"`
	RandomPort bool     `json:"random_port" bson:"random_port" yaml:"random_port"` // if using random port
	Host       string   `json:"host" bson:"host" yaml:"host"`                      // always must be localhost
	RunDep     []string `json:"run_dep" bson:"run_dep" yaml:"run_dep"`             // 运行时依赖的其他模块 异常时无法启动此服务
	StopChain  []string `json:"stop_chain" bson:"stop_chain" yaml:"stop_chain"`    // 谨慎使用 停止调用链(与此服务相关的链上服务都将停止)
}

RunData 运行时依赖

type Runtime added in v1.0.7

type Runtime struct {
	Pid           string `json:"pid" bson:"pid" yaml:"pid"` // 仅记录主pid
	Ports         []int  `json:"ports" bson:"ports" yaml:"ports"`
	StopOperation bool   `json:"stop_operation" bson:"stop_operation" yaml:"stop_operation"` // 是否为手动停止的服务 手动停止后不再进行检查和尝试拉起
}

Runtime 运行时数据 不会持久化到文件内部 端口ports 拷贝自RunData

Jump to

Keyboard shortcuts

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