util

package
v1.0.6 Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2025 License: AGPL-3.0 Imports: 35 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultConfigPath   = "/etc/crane/config.yaml"
	DefaultCraneBaseDir = "/var/crane/"

	DefaultPlugindSocketPath = "cplugind/cplugind.sock"

	DefaultCforedSocketPath          = "craned/cfored.sock"
	DefaultCforedServerListenAddress = "0.0.0.0"
	DefaultCforedServerListenPort    = "10012"

	MaxJobNameLength               = 50
	MaxJobFileNameLength           = 127
	MaxJobFilePathLengthForWindows = 260 - MaxJobFileNameLength
	MaxJobFilePathLengthForUnix    = 4096 - MaxJobFileNameLength

	MaxJobTimeLimit = 315576000000 // 10000 years
	MaxJobTimeStamp = 253402300799 // 9999-12-31 23:59:59
)

Path = BaseDir + Dir + Name

Variables

View Source
var BUILD_TIME = "Unknown"
View Source
var FmtJson = FormatterJson{}
View Source
var VERSION = "Unknown"

Functions

func AmendTaskExtraAttr

func AmendTaskExtraAttr(origin, new string) string

Merge two JSON strings. If there are overlapping keys, values from the second JSON take precedence.

func CheckFileLength

func CheckFileLength(filepath string) error

CheckFileLength check if the file length is within the limit.

func CheckMailType

func CheckMailType(mailtype string) bool

func CheckNameValid

func CheckNameValid(name string) bool

func CheckNodeList

func CheckNodeList(nodeStr string) bool

CheckNodeList check if the node list is comma separated node names. The node name should contain only letters and numbers, and start with a letter, end with a number.

func CheckTaskArgs

func CheckTaskArgs(task *protos.TaskToCtld) error

func CheckTaskExtraAttr

func CheckTaskExtraAttr(attr string) bool

func DetectNetworkProxy

func DetectNetworkProxy()

func ErrMsg

func ErrMsg(err_code protos.ErrCode) string

func FormatTable

func FormatTable(tableOutputWidth []int, tableHeader []string,
	tableData [][]string) (formatTableHeader []string, formatTableData [][]string)

func FoundFirstNumberWithoutBrackets

func FoundFirstNumberWithoutBrackets(input string) (int, int, bool)

func GetParentProcessID

func GetParentProcessID(pid int) (int, error)

func GetPidFromPort

func GetPidFromPort(port uint16) (int, error)

func GetStubToCtldByConfig

func GetStubToCtldByConfig(config *Config) protos.CraneCtldClient

TODO: Refactor this to return ErrCodes instead of exiting.

func GetTCPSocket

func GetTCPSocket(bindAddr string, config *Config) (net.Listener, error)

func GetUnixSocket

func GetUnixSocket(path string, mode fs.FileMode) (net.Listener, error)

func GrpcErrorPrintf

func GrpcErrorPrintf(err error, format string, a ...any)

func HostNameListToStr

func HostNameListToStr(hostList []string) string

func HostNameListToStr_

func HostNameListToStr_(hostList []string) ([]string, bool)

func InitLogger

func InitLogger(level string)

func InvalidDuration

func InvalidDuration() *durationpb.Duration

func IsForeground

func IsForeground() bool

IsForeground returns true if the calling process is a foreground process.

Note that the foreground/background status of a process can change at any moment if the user utilizes the shell job control commands (fg/bg).

Example use for command line tools: suppress extra output if a process is running in background, provide verbose output when running on foreground.

func NixShell

func NixShell(uid string) (string, error)

func ParseDuration

func ParseDuration(time string, duration *durationpb.Duration) bool

func ParseFloatWithPrecision

func ParseFloatWithPrecision(val string, decimalPlaces int) (float64, error)

Parses a string containing a float number with a given precision.

func ParseGres

func ParseGres(gres string) *protos.DeviceMap

func ParseHostList

func ParseHostList(hostStr string) ([]string, bool)

func ParseInRamTaskStatusList

func ParseInRamTaskStatusList(statesStr string) ([]protos.TaskStatus, error)

func ParseInterval

func ParseInterval(interval string, intervalpb *protos.TimeInterval) (err error)

func ParseJobIdList

func ParseJobIdList(jobIds string, splitStr string) ([]uint32, error)

func ParseMemStringAsByte

func ParseMemStringAsByte(mem string) (uint64, error)

func ParseNodeList

func ParseNodeList(nodeStr string) ([]string, bool)

func ParseStringParamList

func ParseStringParamList(parameters string, splitStr string) ([]string, error)

func ParseTaskStatusList

func ParseTaskStatusList(statesStr string) ([]protos.TaskStatus, error)

func ParseTaskStatusName

func ParseTaskStatusName(state string) (protos.TaskStatus, error)

func ParseTime

func ParseTime(ts string) (time.Time, error)

func RemoveBracketsWithoutDashOrComma

func RemoveBracketsWithoutDashOrComma(input string) string

func RemoveFileIfExists

func RemoveFileIfExists(path string) bool

func SecondTimeFormat

func SecondTimeFormat(second int64) string

func SetBorderTable

func SetBorderTable(table *tablewriter.Table)

func SetBorderlessTable

func SetBorderlessTable(table *tablewriter.Table)

func SetPropagatedEnviron

func SetPropagatedEnviron(task *protos.TaskToCtld)

func SplitEnvironEntry

func SplitEnvironEntry(env *string) (string, string, bool)

func TcGetpgrp

func TcGetpgrp(fd int) (pgrp int, err error)

TcGetpgrp gets the process group ID of the foreground process group associated with the terminal referred to by fd.

See POSIX.1 documentation for more details: http://pubs.opengroup.org/onlinepubs/009695399/functions/tcgetpgrp.html

func TcSetpgrp

func TcSetpgrp(fd int, pgrp int) (err error)

TcSetpgrp sets the foreground process group ID associated with the terminal referred to by fd to pgrp.

See POSIX.1 documentation for more details: https://pubs.opengroup.org/onlinepubs/9699919799/functions/tcsetpgrp.html

func TrimTable

func TrimTable(rows *[][]string)

Trim the cell of the table, if the cell is longer than 30 characters, the rest of the characters will be replaced by `...`.

func TrimTableExcept

func TrimTableExcept(rows *[][]string, excepts ...int)

Trim the cell of the table, if the cell is longer than 30 characters, the rest of the characters will be replaced by `...`. `excepts` means do not trim the specified columns

func Version

func Version() string

func VersionTemplate

func VersionTemplate() string

Types

type Config

type Config struct {
	ControlMachine      string `yaml:"ControlMachine"`
	CraneCtldListenPort string `yaml:"CraneCtldListenPort"`

	UseTls             bool   `yaml:"UseTls"`
	ServerCertFilePath string `yaml:"ServerCertFilePath"`
	ServerKeyFilePath  string `yaml:"ServerKeyFilePath"`
	CaCertFilePath     string `yaml:"CaCertFilePath"`
	DomainSuffix       string `yaml:"DomainSuffix"`

	CraneBaseDir         string       `yaml:"CraneBaseDir"`
	CranedCforedSockPath string       `yaml:"CranedCforedSockPath"`
	Plugin               PluginConfig `yaml:"Plugin"`
}

func ParseConfig

func ParseConfig(configFilePath string) *Config

TODO: Refactor this to return ErrCodes instead of exiting.

type CraneCmdError

type CraneCmdError = int
const (
	ErrorSuccess       CraneCmdError = 0
	ErrorGeneric       CraneCmdError = 1
	ErrorCmdArg        CraneCmdError = 2
	ErrorNetwork       CraneCmdError = 3
	ErrorBackend       CraneCmdError = 4
	ErrorInvalidFormat CraneCmdError = 5
)

general

type Formatter

type Formatter interface {
	FormatReply(reply interface{}) string
}

type FormatterJson

type FormatterJson struct {
}

JSON

func (FormatterJson) FormatReply

func (f FormatterJson) FormatReply(reply interface{}) string

type PluginConfig

type PluginConfig struct {
	Enabled  bool             `yaml:"Enabled"`
	SockPath string           `yaml:"PlugindSockPath"`
	LogLevel string           `yaml:"PlugindDebugLevel"`
	Plugins  []api.PluginMeta `yaml:"Plugins"`
}

Jump to

Keyboard shortcuts

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