common

package
v0.14.6 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	SeparatorComma = ","

	PrefixSchedule   = "schedule-"
	PrefixRun        = "run-"
	PrefixPipeline   = "ppl-"
	PrefixCache      = "cch-"
	PrefixGrant      = "grant"
	PrefixQueue      = "queue"
	PrefixCluster    = "cluster"
	PrefixFlavour    = "flavour"
	PrefixConnection = "conn"

	ResourceTypeSchedule      = "schedule"
	ResourceTypeRun           = "run"
	ResourceTypeRunCache      = "run_cache"
	ResourceTypeArtifactEvent = "artifact_event"
	ResourceTypeUser          = "user"
	ResourceTypeQueue         = "queue"
	ResourceTypeFlavour       = "flavour"
	ResourceTypeFs            = "fs"
	ResourceTypeImage         = "image"
	ResourceTypePipeline      = "pipeline"
	ResourceTypeCluster       = "cluster"
	ResourceTypeJob           = "job"

	HeaderKeyRequestID     = "x-pf-request-id"
	HeaderKeyUserName      = "x-pf-user-name"
	HeaderKeyAuthorization = "x-pf-authorization"
	HeaderClientIDKey      = "x-pf-client-id"

	ResponseCode      = "code"
	ResponseMessage   = "message"
	ResponseRequestID = "requestID"

	CFSSuccessMessage     = "create file system success"
	ClaimsSuccessMessage  = "create pv and pvc success"
	RegisterClientMessage = "register client success"
	HeartBeatMessage      = "heat beat client success"

	BeginFilePosition = "begin"
	EndFilePosition   = "end"

	LogPageSizeMax     = 100
	LogPageSizeDefault = 100
	LogPageNoDefault   = 1

	Pod = "pod"

	StsMaxSeqData = 1000

	PFTokenEnv = "PFToken"
	PFServer   = "PFServer"
)
View Source
const (
	AESEncryptKey    = "paddleflow123456" // 长度必须为16,分别对应加密算法AES-128
	AESEncryptKeyEnv = "AESEncryptKey"
	PFSecretName     = "pf-secret"
)
View Source
const (
	AccessDenied         = "AccessDenied"         // 无权限访问对应的资源
	ActionNotAllowed     = "ActionNotAllowed"     // 此操作不被允许
	InappropriateJSON    = "InappropriateJSON"    // 请求中的JSON格式正确,但语义上不符合要求。如缺少某个必需项,或者值类型不匹配等。出于兼容性考虑,对于所有无法识别的项应直接忽略,不应该返回这个错误。
	InternalError        = "InternalError"        // 所有未定义的其他错误
	InvalidHTTPRequest   = "InvalidHTTPRequest"   // HTTP body格式错误。例如不符合指定的Encoding等
	InvalidURI           = "InvalidURI"           // URI形式不正确。例如一些服务定义的关键词不匹配等。对于ID不匹配等问题,应定义更加具体的错误码,例如NoSuchKey。
	MalformedJSON        = "MalformedJSON"        // JSON格式不合法
	MalformedYaml        = "MalformedYaml"        // Yaml格式不合法
	DecodeBase64         = "Decode base64"        // base64 字符串不合法
	InvalidPipeline      = "InvalidPipeline"      // Pipeline校验不通过
	InvalidVersion       = "InvalidVersion"       // URI的版本号不合法
	FileTypeNotSupported = "FileTypeNotSupported" // 文件类型不支持
	InvalidNamePattern   = "InvalidNamePattern"   // 命名格式不规范
	RequestExpired       = "RequestExpired"       // 请求超时
	OnlyRootAllowed      = "OnlyRootAllowed"      // 仅限管理员操作
	InvalidMarker        = "InvalidMarker"        // 列表操作marker解析失败
	InvalidScaleResource = "InvalidScaleResource" // 扩展资源类型不支持
	IOOperationFailure   = "IOOperationFailure"   // I/O操作失败
	NamespaceNotFound    = "NamespaceNotFound"
	CPUNotFound          = "CPUNotFound"
	MemoryNotFound       = "MemoryNotFound"
	PathNotFound         = "PathNotFound"
	MethodNotAllowed     = "MethodNotAllowed"
	DuplicatedName       = "DuplicatedName"
	DuplicatedContent    = "DuplicatedContent"
	InvalidArguments     = "InvalidArguments"
	RecordNotFound       = "RecordNotFound"
	RequiredFieldEmpty   = "RequiredFieldEmpty"

	AuthWithoutToken = "AuthWithoutToken" // 请求没有携带token
	AuthInvalidToken = "AuthInvalidToken" // 无效token
	AuthFailed       = "AuthFailed"       // 用户名或者密码错误
	AuthIllegalUser  = "AuthIllegalUser"  // 非法用户

	DBUpdateFailed = "UpdateDatabaseFailed"

	UserNameDuplicated = "UserNameDuplicated"
	UserNotExist       = "UserNotExist"
	UserPasswordWeak   = "UserPasswordWeak"

	InvalidComputeResource = "InvalidComputeResource"

	QueueNameDuplicated          = "QueueNameDuplicated"
	QueueActionIsNotSupported    = "QueueActionIsNotSupported"
	QueueNameNotFound            = "QueueNameNotFound"
	QueueResourceNotMatch        = "QueueResourceNotMatch"
	QueueQuotaTypeIsNotSupported = "QueueQuotaTypeIsNotSupported"
	QueueIsNotClosed             = "QueueIsNotClosed"
	QueueIsInUse                 = "QueueIsInUse"
	QueueInvalidField            = "QueueInvalidField"
	QueueUpdateFailed            = "QueueUpdateFailed"

	GrantResourceTypeNotFound = "GrantResourceTypeNotFound"
	GrantNotFound             = "GrantNotFound"
	GrantAlreadyExist         = "GrantAlreadyExist"
	GrantRootActionNotSupport = "GrantRootActionNotSupport"

	RunNameDuplicated     = "RunNameDuplicated"
	RunNotFound           = "RunNotFound"
	PipelineNotFound      = "PipelineNotFound"
	RunCacheNotFound      = "RunCacheNotFound"
	ArtifactEventNotFound = "ArtifactEventNotFound"
	ReadYamlFileFailed    = "ReadYamlFileFailed"
	ScheduleNotFound      = "ScheduleNotFound"

	FlavourNotFound     = "FlavourNotFound"     // 未找到对应的资源套餐
	FlavourNameEmpty    = "FlavourNameEmpty"    // 资源套餐名称为空
	FlavourInvalidField = "FlavourInvalidField" // 资源套餐名称为空

	JobInvalidField = "JobInvalidField" // job field invalid
	JobCreateFailed = "JobCreateFailed" // job create failed
	JobNotFound     = "JobNotFound"

	ClusterNameNotFound      = "ClusterNameNotFound"
	ClusterIdNotFound        = "ClusterIdNotFound"
	ClusterNotFound          = "ClusterNotFound"
	InvalidClusterProperties = "InvalidClusterProperties"
	InvalidCredential        = "InvalidClusterCredential"
	InvalidClusterStatus     = "InvalidClusterStatus"

	InvalidFileSystemURL        = "InvalidFileSystemParamsURL"
	InvalidFileSystemProperties = "InvalidFileSystemParamsProperties"
	InvalidFileSystemMaxKeys    = "InvalidFileSystemMaxKeys"
	InvalidFileSystemFsName     = "InvalidFileSystemFsName"
	InvalidLinkURL              = "InvalidLinkURL"
	InvalidLinkProperties       = "InvalidLinkProperties"
	InvalidLinkMaxKeys          = "InvalidFileSystemMaxKeys"
	FileSystemDataBaseError     = "FileSystemDataBaseError"
	LinkModelError              = "LinkModelError"
	LinkPathExist               = "LinkPathExist"
	FileSystemClientBusy        = "FileSystemClientBusy"
	K8sOperatorError            = "K8sOperatorError"
	InvalidState                = "InvalidState"
	GrantUserNameAndFs          = "GrantUserNameAndFs"
	FileSystemNotExist          = "FileSystemNotExist"
	FileSystemNameFormatError   = "FileSystemNameFormatError"
	LinkFileSystemNotExist      = "LinkFileSystemNotExist"
	FuseClientError             = "FuseClientError"
	LinkFileSystemPathNotExist  = "LinkFileSystemPathNotExist"
	LinkNotExist                = "LinkNotExist"
	LinkPathMustBeEmpty         = "LinkPathMustBeEmpty"
	ConnectivityFailed          = "ConnectivityFailed"
	InvalidPVClaimsParams       = "InvalidPVClaimsParams"
	GetNamespaceFail            = "GetNamespaceFail"
	LinkMetaPersistError        = "LinkMetaPersistError"
)
View Source
const (
	StatusRunInitiating  = "initiating"
	StatusRunPending     = "pending"
	StatusRunRunning     = "running"
	StatusRunSucceeded   = "succeeded"
	StatusRunFailed      = "failed"
	StatusRunTerminating = "terminating"
	StatusRunTerminated  = "terminated"
	StatusRunSkipped     = "skipped"

	WfEventKeyRunID             = "runID"
	WfEventKeyPK                = "pk"
	WfEventKeyStatus            = "status"
	WfEventKeyView              = "runtime"
	WfEventKeyComponentName     = "componentName"
	WfEventKeyComponentFullName = "componentFullName"
	WfEventKeyStartTime         = "startTime"
)
View Source
const (
	RegPatternQueueName    = "^[a-z0-9][a-z0-9-]{0,8}[a-z0-9]$"
	RegPatternUserName     = "^[A-Za-z0-9]{4,16}$"
	RegPatternRunName      = "^[A-Za-z_][A-Za-z0-9_-]{0,127}$"
	RegPatternPipelineName = "^[A-Za-z_][A-Za-z0-9_-]{0,127}$"
	RegPatternScheduleName = "^[A-Za-z_][A-Za-z0-9_]{1,49}$"
	RegPatternResource     = "^[1-9][0-9]*([numkMGTPE]|Ki|Mi|Gi|Ti|Pi|Ei)?$"
	RegPatternClusterName  = "^[A-Za-z0-9_][A-Za-z0-9-_]{0,253}[A-Za-z0-9_]$"

	// DNS1123LabelMaxLength is a label's max length in DNS (RFC 1123)
	DNS1123LabelMaxLength = 63
	DNS1123LabelFmt       = "[a-z0-9]([-a-z0-9]*[a-z0-9])?"

	JobNameMaxLength = 512
	JobPortMaximums  = 65535

	IPDomainOrIPDomainPortPattern = "^([a-zA-Z0-9][-a-zA-Z0-9]{0,62}(\\.[a-zA-Z0-9][-a-zA-Z0-9]{0,62})+)" +
		"(:([1-9]|[1-9]\\d{1,3}|[1-5]\\d{4}|6[0-4]\\d{3}|65[0-4]\\d{2}|655[0-2]\\d|6553[0-5]))?$"

	TypeSplit          = 0
	HDFSSplit          = 3
	S3Split            = 3
	S3EndpointSplit    = 2
	S3SplitLen         = 3
	LocalSplit         = 2
	CFSSplit           = 3
	ServerAddressSplit = 2
	S3AddressLength    = 3
	IDSliceLen         = 3

	FsPrefix = "fs-"
	UserRoot = "root"
)

Variables

Functions

func AesDecrypt

func AesDecrypt(encrypted string, key string) (string, error)

func AesEncrypt

func AesEncrypt(orig string, key string) (string, error)

func BindJSON

func BindJSON(r *http.Request, data interface{}) error

func CheckFsNested

func CheckFsNested(path1, path2 string) bool

func CheckKerberosProperties

func CheckKerberosProperties(properties map[string]string) error

func CheckPermission added in v0.14.5

func CheckPermission(requestUserName, ownerUserName, resourceType, resourceID string) error

func ConnectionClosedError

func ConnectionClosedError() error

func DbDataNotExitError

func DbDataNotExitError(errMsg string) error

func DecryptPk

func DecryptPk(data string) (int64, error)

func DuplicatedContentError

func DuplicatedContentError(resourceType, md5, fsID string) error

func DuplicatedNameError

func DuplicatedNameError(resourceType, name, fsID string) error

func EncryptPk

func EncryptPk(pk int64) (string, error)

func FileTypeNotSupportedError

func FileTypeNotSupportedError(fileType, resourceType string) error

func FsBeingUsedError added in v0.14.3

func FsBeingUsedError(fsID string) error

func GetAESEncryptKey added in v0.14.6

func GetAESEncryptKey() string

func GetHttpStatusByCode

func GetHttpStatusByCode(code string) int

func GetMD5Hash

func GetMD5Hash(content []byte) string

func GetMessageByCode

func GetMessageByCode(code string) string

func GetRequestContext

func GetRequestContext(r *http.Request) logger.RequestContext

func ID

func ID(userName, fsName string) string

func InformationFromURL

func InformationFromURL(url string, properties map[string]string) (fileSystemType, serverAddress, subPath string)

InformationFromURL get fs system information from url

func InvalidField

func InvalidField(field string, info string) error

func InvalidMaxKeysError

func InvalidMaxKeysError(maxKeys string) error

func InvalidNamePatternError

func InvalidNamePatternError(name, resourceType, reg string) error

func InvalidStartEndParams added in v0.14.3

func InvalidStartEndParams() error

func InvalidStatisticsParams added in v0.14.3

func InvalidStatisticsParams(param string) error

func IsDNS1123Label

func IsDNS1123Label(value string) []string

IsDNS1123Label tests for a string that conforms to the definition of a label in DNS (RFC 1123).

func IsRootUser

func IsRootUser(userName string) bool

func IsRunFinalStatus

func IsRunFinalStatus(status string) bool

func IsValidQueueStatus

func IsValidQueueStatus(status string) bool

func LinkPathError

func LinkPathError(fsPath string) error

func LogFilePositionInvalidValueError

func LogFilePositionInvalidValueError() error

func LogPageSizeOverMaxError

func LogPageSizeOverMaxError() error

func New

func New(text string) error

func NoAccessError

func NoAccessError(user, resourceType, resourceID string) error

func NotFoundError

func NotFoundError(resourceType, ID string) error

func PKCS7Padding

func PKCS7Padding(ciphertext []byte, blocksize int) []byte

func PKCS7UnPadding

func PKCS7UnPadding(origData []byte) ([]byte, error)

func PVCNotFountError

func PVCNotFountError(pvc, namespace string) error

func RemoveDuplicateStr

func RemoveDuplicateStr(strSlice []string) []string

func Render

func Render(w http.ResponseWriter, httpCode int, data interface{})

func RenderErr

func RenderErr(w http.ResponseWriter, requestID string, code string)

func RenderErrWithMessage

func RenderErrWithMessage(w http.ResponseWriter, requestID string, code string, message string)

func RenderStatus

func RenderStatus(w http.ResponseWriter, httpCode int)

func SplitString

func SplitString(str, sep string) []string

func StringInSlice

func StringInSlice(s string, strSlice []string) bool

check string is slice or not

func SubPathError

func SubPathError(subPath string) error

func SubPathFromUrl

func SubPathFromUrl(urlSplit []string, split int) string

Types

type ErrorResponse

type ErrorResponse struct {
	RequestID    string `json:"requestID"`
	ErrorCode    string `json:"code"`
	ErrorMessage string `json:"message"`
}

type MarkerInfo

type MarkerInfo struct {
	MaxKeys     int    `json:"maxKeys"`
	IsTruncated bool   `json:"isTruncated"` // true表示后面还有数据,false表示已经是最后一页。
	NextMarker  string `json:"nextMarker,omitempty"`
}

Jump to

Keyboard shortcuts

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