common

package
v2.6.1 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2023 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// TimeFormat
	TimeFormat = "2006-01-02T15:04:05Z"
	// KeyContextNamespace the key of namespace in context
	KeyContextNamespace = "namespace"

	// ResourceName resource name
	ResourceName = "resourceName"
	// ResourceVersion resource version
	ResourceVersion = "resourceVersion"
	// ResourceInvisible resource invisible
	ResourceInvisible = "resource-invisible"
	// Application application resource
	Application Resource = "application"
	// App alias of application resource
	APP Resource = "app"
	// Configuration configuration resource
	Configuration Resource = "configuration"
	// Config config resource
	Config Resource = "config"
	// Secret secret resource
	Secret Resource = "secret"
	// Certificate certificate resource
	Certificate Resource = "certificate"
	// Registry registry resource
	Registry Resource = "registry"
	// Deprecated
	// Deployment deployment resource
	Deployment Resource = "deployment"
	// Node node resource
	Node Resource = "node"
	// Shadow shadow resource
	Shadow Resource = "shadow"
	// NodeDesire nodedesire resource
	NodeDesire Resource = "nodedesire"
	// NodeReport nodereport resource
	NodeReport Resource = "nodereport"
	// Batch batch resource
	Batch Resource = "batch"
	// Device device resource
	Device Resource = "device"
	// Driver driver resource
	Driver Resource = "driver"
	// AccessTemplate accesstemplate resource
	AccessTemplate Resource = "accesstemplate"
	// DeviceModel devicemodel resource
	DeviceModel Resource = "devicemodel"
	// BusinessTemplate businesstemplate resource
	BusinessTemplate Resource = "businesstemplate"
	// Index index resource
	Index Resource = "index"
	// !deprecated
	// DefaultConfigDir default host dir of config
	DefaultConfigDir = "var/db/baetyl"
	// DefaultLibDir lib dir of the service by default
	DefaultLibDir = "var/lib/baetyl"
	// DefaultBinDir the file path of master binary
	DefaultBinDir = "bin"
	// DefaultBinFile the file of master binary
	DefaultBinFile = "baetyl"
	// DefaultActiveWebPort the port of web active
	DefaultActiveWebPort = 30007 // The range of valid ports is 30000-32767
	// AppConfFileName application config file name
	AppConfFileName = "application.yml"
	// DefaultSetupFile
	DefaultSetupFile = "setup.sh"
	// DefaultOffActivationFile
	DefaultOffActivationFile = "offlineActivation.sh"
	// DefaultOnActivationFile
	DefaultOnActivationFile = "onlineActivation.sh"
	// DefaultMasterConfDir master config dir by default
	DefaultMasterConfDir = "etc/baetyl"
	// DefaultMasterConfFile master config file by default
	DefaultMasterConfFile = "conf.yml"
	// DefaultMasterPlistFile
	DefaultMasterPlistFile = "baetyl.plist"
	// DefaultMasterDaemonFile
	DefaultMasterDaemonFile = "baetyl.service"
	// DefaultCoreFrequency
	DefaultCoreFrequency = "20"
	// DefaultCoreAPIPort
	DefaultCoreAPIPort = "30050"
	// DefaultAgentPort
	DefaultAgentPort = "30080"
	// ComposeVersion compose version
	ComposeVersion = "3"
	// Bind bind
	Bind VolumeType = "bind"
	// Volume volume
	Volume VolumeType = "volume"

	DesiredApplications    = "apps"
	DesiredSysApplications = "sysapps"

	// Receive receive
	Receive State = "RECEIVE"
	// Deploy deploy
	Deploy State = "DEPLOYED"
	// Updating updating
	Updating State = "UPDATING"
	// Updated updated
	Updated State = "UPDATED"
	// Timeout timeout
	Timeout State = "TIMEOUT"
	// Failure failure
	Failure State = "FAILURE"

	// Secret type
	SecretRegistry = "registry"
	SecretConfig   = "config"
	MaxRetryNum    = 20

	// LabelKeyFunction tag of function
	LabelKeyFunction = "baetyl-function"
	LabelNodeName    = "baetyl-node-name"
	LabelAppName     = "baetyl-app-name"
	LabelSystem      = "baetyl-cloud-system"
	LabelBatch       = "baetyl-batch"
	LabelAccelerator = "baetyl-accelerator"
	LabelCluster     = "baetyl-cluster"
	LabelNodeMode    = "baetyl-node-mode"
	LabelAppMode     = "baetyl-app-mode"
)
View Source
const (
	BaetylCloud      = "baetyl-cloud"
	BaetylCloudGroup = "cloud.baetyl.io"
	Description      = "description"
	UpdateTimestamp  = "updateTimestamp"
	Metadata         = "matadata"
	PkiCertID        = "pkiCertID"
	NodeSelector     = "nodeSelector"
	WorkLoad         = "workLoad"
	JobConfig        = "jobConfig"

	AnnotationDescription     = BaetylCloudGroup + "/" + Description
	AnnotationUpdateTimestamp = BaetylCloudGroup + "/" + UpdateTimestamp
	AnnotationMetadata        = BaetylCloudGroup + "/" + Metadata
	AnnotationPkiCertID       = BaetylCloudGroup + "/" + PkiCertID
	AnnotationNodeSelector    = BaetylCloudGroup + "/" + NodeSelector
	AnnotationWorkLoad        = BaetylCloudGroup + "/" + WorkLoad
	AnnotationJobConfig       = BaetylCloudGroup + "/" + JobConfig
)
View Source
const (
	None                    Security = "None"
	Token                   Security = "Token"
	Cert                    Security = "Cert"
	Dongle                  Security = "Dongle"
	DefaultActiveTime                = 1167580800 //todo avoid mysql ERROR 1292. "2007-01-01 00:00:00" s
	DefaultSN                        = "agent-sn"
	DefaultSNPath                    = "/var/lib/baetyl/sn"
	DefaultSNFile                    = "fingerprint.txt"
	DefaultInputField                = "sn"
	DefaultAgentConfigMount          = "/etc/baetyl"
	FingerprintSN                    = 0x1
	FingerprintInput                 = 0x2
	FingerprintHostName              = 0x4
	FingerprintBootID                = 0x8
	FingerprintSystemUUID            = 0x10
	FingerprintMachineID             = 0x20

	FilenameYamlService       = "service.yml"
	PageSize                  = 20
	Online                    = "online"
	Offline                   = "offline"
	Success             Event = "success"
	Nothing             Event = "nothing"
	Failed              Event = "failed"
	Inactivated               = 0x0
	Activated                 = 0x1
	DisableWhitelist          = 0x0
	EnableWhitelist           = 0x1
)
View Source
const (
	AWSS3ReadPermission    = "public-read"
	AWSS3WritePermission   = "public-read-write"
	AWSS3PrivatePermission = "private"
)
View Source
const (
	ContainerApp = "container"
	FunctionApp  = "function"
)
View Source
const (
	ReportMeta = "reportMeta"
	DesireMeta = "desireMeta"
	NodeProps  = "nodeprops"
	NodeInfo   = "node"
	NodeStats  = "nodestats"
)
View Source
const (
	KeyConfFile      = "ConfFile"
	ValueConfFile    = "etc/baetyl/cloud.yml"
	KeyTraceKey      = "TraceKey"
	ValueTraceKey    = "requestId"
	KeyTraceHeader   = "TraceHeader"
	ValueTraceHeader = "x-bce-request-id" // TODO: change to x-baetyl-request-id when support configuration

	RegistryAuth = "system-registry-auth"
)
View Source
const (
	// * plugin
	ErrPluginNotFound Code = "ErrPluginNotFound"
	ErrPluginInvalid       = "ErrPluginInvalid"

	// * request
	ErrRequestAccessDenied   = "ErrRequestAccessDenied"
	ErrRequestMethodNotFound = "ErrRequestMethodNotFound"
	ErrRequestParamInvalid   = "ErrRequestParamInvalid"
	// * resource
	ErrResourceNotFound        = "ErrResourceNotFound"
	ErrResourceAccessForbidden = "ErrResourceAccessForbidden"
	ErrResourceConflict        = "ErrResourceConflict"
	ErrResourceDeleteForbidden = "ErrResourceDeleteForbidden"
	ErrResourceHasBeenUsed     = "ErrResourceHasBeenUsed"
	ErrSubResourceExist        = "ErrSubResourceExist"
	ErrNodeNotReady            = "ErrNodeNotReady"
	ErrInvalidToken            = "ErrInvalidToken"

	// * volumes
	ErrVolumeType = "ErrVolumeType"
	// * unknown
	ErrUnknown = "UnknownError"
	// * application
	ErrAppNameConflict         = "ErrAppNameConflict"
	ErrVolumeNotFoundWhenMount = "ErrVolumeNotFoundWhenMount"
	ErrAppReferencedByNode     = "ErrAppReferencedByNode"
	// * node
	ErrNodeNumMaxLimit       = "ErrNodeNumMaxLimit"
	ErrNodeNumQueryException = "ErrNodeNumQueryException"

	// * config
	ErrConfigInUsed = "ErrConfigInUsed"
	// * register
	ErrRegisterQuotaNumOut     = "ErrRegisterQuotaNumOut"
	ErrRegisterDeleteRecord    = "ErrRegisterDeleteRecord"
	ErrRegisterDeleteCallback  = "ErrRegisterDeleteCallback"
	ErrRegisterPackage         = "ErrRegisterPackage"
	ErrRegisterRecordActivated = "ErrRegisterRecordActivated"
	// * db
	ErrDatabase  = "ErrDatabase"
	ErrUpdateCas = "ErrUpdateCas"
	// * k8s
	ErrK8S = "ErrK8S"
	// * ceph
	ErrCeph = "ErrCeph"
	// * io
	ErrIO = "ErrIO"
	// * template
	ErrTemplate = "ErrTemplate"
	// * function
	ErrFunction = "ErrFunction"
	// * resourceName
	ErrInvalidResourceName = "resourceName"
	ErrInvalidLabels       = "validLabels"
	ErrInvalidRequired     = "required"
	// * batchOp
	ErrInvalidArrayLength = "maxLength"
	// * fingerprintValue
	ErrInvalidFingerprintValue = "fingerprintValue"
	// * memory
	ErrInvalidMemory = "memory"
	// * duration
	ErrInvalidDuration = "duration"
	// * setcpus
	ErrInvalidSetcpus = "setcpus"
	// * nonBaetyl
	ErrInvalidName = "nonBaetyl"
	// * license
	ErrLicenseExpired      = "ErrLicenseExpired"
	ErrLicenseQuota        = "ErrLicenseQuota"
	ErrLicenseQuotaAcquire = "ErrLicenseQuotaAcquire"
	ErrLicenseQuotaRelease = "ErrLicenseQuotaRelease"
	// * third server error
	ErrThirdServer = "ErrThirdServer"
	// * object error
	ErrObjectOperationException = "ErrObjectOperationException"

	ErrResourceInvisible = "ErrResourceInvisible"
	ErrConvertConflict   = "ErrConvertConflict"

	ErrPubsubTimeout   = "ErrPubsubTimeout"
	ErrUpdateSubLabels = "ErrUpdateSubLabels"
	ErrDataTooLarge    = "ErrDataTooLarge"
)

all codes

View Source
const (
	ConfigObjectPrefix = "_object_"
)
View Source
const (
	TaskNamespaceDelete = "namespace-delete"
)
View Source
const (
	UnpackTypeZip = "zip"
)

Variables

View Source
var (
	// Todo use global.go
	Cache          map[string]string
	FingerprintMap = map[int]string{
		FingerprintSN:         "sn",
		FingerprintInput:      "input",
		FingerprintHostName:   "hostName",
		FingerprintBootID:     "bootID",
		FingerprintSystemUUID: "systemUUID",
		FingerprintMachineID:  "machineID",
	}
)

Functions

func AddSystemLabel

func AddSystemLabel(labels map[string]string, infos map[string]string) map[string]string

func CompareNumericalString

func CompareNumericalString(a, b string) int

func Error

func Error(c Code, fs ...*F) error

Error returns an error with code and fields

func GetConfFile

func GetConfFile() string

func GetTraceHeader

func GetTraceHeader() string

func GetTraceKey

func GetTraceKey() string

func LoadConfig

func LoadConfig(cfg interface{}, files ...string) error

func LogDirtyData

func LogDirtyData(err error, fields ...log.Field)

func PackageResponse

func PackageResponse(res interface{}) (int, interface{})

PackageResponse PackageResponse

func PopulateFailedMisResponse

func PopulateFailedMisResponse(cc *Context, err error, abort bool)

PopulateFailedMisResponse PopulateFailedMisResponse

func PopulateFailedResponse

func PopulateFailedResponse(cc *Context, err error, abort bool)

PopulateFailedResponse PopulateFailedResponse

func RandString

func RandString(n int) string

RandString

  • param n: suggest at least 10 to avoid conflict

referred to https://stackoverflow.com/questions/22892120/how-to-generate-a-random-string-of-a-fixed-length-in-go

func SetConfFile

func SetConfFile(v string)

func SetTraceHeader

func SetTraceHeader(v string)

func SetTraceKey

func SetTraceKey(v string)

func UUID

func UUID() string

UUID generate uuid

func UUIDPrune

func UUIDPrune() string

UUIDPrune generate uuid without '-'

func UpdateSysAppByAccelerator added in v2.2.0

func UpdateSysAppByAccelerator(accelerator string, sysApps []string) []string

func ValidIsInvisible added in v2.2.0

func ValidIsInvisible(labels map[string]string) bool

func ValidNonBaetyl added in v2.2.0

func ValidNonBaetyl(name string) bool

func ValidateKeyValue added in v2.4.3

func ValidateKeyValue(k string) error

func ValidateResourceName added in v2.4.3

func ValidateResourceName(s string) error

func Wrapper

func Wrapper(handler HandlerFunc) func(c *gin.Context)

Wrapper Wrapper TODO: to use gin.HandlerFunc ?

func WrapperMis

func WrapperMis(handler HandlerFunc) func(c *gin.Context)

func WrapperNative added in v2.4.3

func WrapperNative(handler HandlerFunc, abort bool) func(c *gin.Context)

func WrapperRaw

func WrapperRaw(handler HandlerFunc, abort bool) func(c *gin.Context)

func WrapperWithLock added in v2.2.0

func WrapperWithLock(lockFunc LockFunc, unlockFunc UnlockFunc) func(c *gin.Context)

WrapperWithLock wrap handler with lock

Types

type CertType

type CertType string
const (
	Sync     CertType = "sync"
	Internal CertType = "internal"

	ObjectSource = "object-source"
)

type Code

type Code string

Code code

func (Code) String

func (c Code) String() string

type Context

type Context struct {
	*gin.Context
}

Context context

func NewContext

func NewContext(inner *gin.Context) *Context

NewContext create a new context with gin context

func NewContextEmpty

func NewContextEmpty() *Context

NewContextEmpty create a new empty context

func (*Context) GetName

func (c *Context) GetName() string

GetName gets name from context if exists

func (*Context) GetNameFromParam

func (c *Context) GetNameFromParam() string

GetNameFromParam gets name from param if exists

func (*Context) GetNamespace

func (c *Context) GetNamespace() string

GetNamespace gets namespace from context if exists

func (*Context) GetTrace

func (c *Context) GetTrace() (k string, v string)

GetTrace gets the trace key and value

func (*Context) GetUser

func (c *Context) GetUser() User

GetUser gets user from context if exists

func (*Context) GetUserInfo added in v2.3.0

func (c *Context) GetUserInfo() UserInfo

GetUserInfo gets user info from context if exists

func (*Context) LoadBody

func (c *Context) LoadBody(obj interface{}) error

LoadBody loads json data from body into object and set defaults

func (*Context) LoadBodyMulti added in v2.3.0

func (c *Context) LoadBodyMulti(obj interface{}) error

func (*Context) SetName

func (c *Context) SetName(n string)

SetName sets name into context

func (*Context) SetNamespace

func (c *Context) SetNamespace(ns string)

SetNamespace sets namespace into context

func (*Context) SetTrace

func (c *Context) SetTrace()

SetTrace set the trace key and value

func (*Context) SetUser

func (c *Context) SetUser(user User)

SetUser sets user into context

func (*Context) SetUserInfo added in v2.3.0

func (c *Context) SetUserInfo(info UserInfo)

SetUserInfo sets user info into context

type Domain added in v2.3.0

type Domain struct {
	ID   string
	Name string
}

type Event

type Event string

type F

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

Field field

func Field

func Field(k string, v interface{}) *F

Field returns a field

type HandlerFunc

type HandlerFunc func(c *Context) (interface{}, error)

HandlerFunc HandlerFunc

type LockFunc added in v2.2.0

type LockFunc func(ctx context.Context, name string, ttl int64) (string, error)

type ModuleType added in v2.2.0

type ModuleType string
const (
	TypeUser           ModuleType = "user"
	TypeUserRuntime    ModuleType = "runtime_user"
	TypeSystem         ModuleType = "system"
	TypeSystemOptional ModuleType = "opt_system"
	TypeSystemKube     ModuleType = "opt_system_kube"
	TypeSystemNative   ModuleType = "opt_system_native"
)

type Resource

type Resource string

type Role added in v2.3.0

type Role struct {
	ID   string
	Type string
}

type Security

type Security string

type State

type State string

type SyncMode added in v2.1.1

type SyncMode string

type SystemApplication

type SystemApplication string

type UnlockFunc added in v2.2.0

type UnlockFunc func(ctx context.Context, name, version string)

type User

type User struct {
	ID   string
	Name string
}

type UserInfo added in v2.3.0

type UserInfo struct {
	User   User
	Roles  []Role
	Domain Domain
}

type VolumeType

type VolumeType string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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