util

package
v0.0.0-...-cc86db0 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2024 License: Apache-2.0 Imports: 29 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HYBRID_DOMAIN     = ".axt.aliyuncs.com"
	HYBRID_DOMAIN_VPC = ".axt.aliyun.com"
)

Variables

View Source
var (
	ErrRoleNameFailed              = errors.New("RoleNameFailed")
	ErrParameterStoreNotAccessible = errors.New("ParameterStoreNotAccessible")
	ErrParameterFailed             = errors.New("ParameterFailed")
)
View Source
var (
	ErrHTTPCode = errors.New("http code error")
)
View Source
var G_IsWindows bool
View Source
var (
	NilRequest *atomicutil.AtomicBoolean
)

Functions

func CallApi

func CallApi(httpMethod, url string, parameters map[string]interface{}, respObj interface{}, apiTimeout time.Duration, noLog bool) error

func ComputeBinMd5

func ComputeBinMd5(bin []byte) string

func ComputeMd5

func ComputeMd5(filePath string) (string, error)

func ComputeStrMd5

func ComputeStrMd5(str string) string

func ExeCmd

func ExeCmd(cmd string) (error, string, string)

func ExeCmdNoWait

func ExeCmdNoWait(cmd string) (error, int)

func ExeCmdWithContext

func ExeCmdWithContext(ctx context.Context, cmd string) (error, string, string)

Execute a command with timeout limit

func FileExist

func FileExist(path string) bool

func GetAzoneId

func GetAzoneId() string

func GetClientReportService

func GetClientReportService() string

func GetConnectDetectService

func GetConnectDetectService() string

func GetDeRegisterService

func GetDeRegisterService() string

func GetErrorOutputService

func GetErrorOutputService() string

func GetFetchSessionTaskListService

func GetFetchSessionTaskListService() string

func GetFetchTaskListService

func GetFetchTaskListService() string

func GetFinishOutputService

func GetFinishOutputService() string

func GetGshellCheckService

func GetGshellCheckService() string

func GetHTTPTransport

func GetHTTPTransport() *http.Transport

func GetInstanceId

func GetInstanceId() string

func GetInvalidTaskService

func GetInvalidTaskService() string

New version 1.0

func GetMetricsService

func GetMetricsService() string

func GetParam

func GetParam(name string) (string, error)

func GetPingService

func GetPingService() string

GetPingService returns heart-beat API but without the scheme part, unlike other API address provider function

func GetPluginHealthService

func GetPluginHealthService() string

func GetPluginListService

func GetPluginListService() string

func GetPluginUpdateCheckService

func GetPluginUpdateCheckService() string

func GetPutInstanceStateReportService

func GetPutInstanceStateReportService() string

func GetPutInventoryService

func GetPutInventoryService() string

func GetRegionId

func GetRegionId() string

func GetRegisterService

func GetRegisterService(region, networkmode string) string

func GetRoleName

func GetRoleName() (string, error)

func GetRoleNameTtl

func GetRoleNameTtl(ttl time.Duration) (string, error)

func GetRunningOutputService

func GetRunningOutputService() string

func GetSecretParam

func GetSecretParam(name string) (string, error)

func GetServerHost

func GetServerHost() string

GetServerHost returns empty string when region id is invalid as error handling

func GetSessionStatusService

func GetSessionStatusService() string

func GetStateConfigService

func GetStateConfigService() string

func GetStoppedOutputService

func GetStoppedOutputService() string

func GetTemplateService

func GetTemplateService() string

func GetTimeoutOutputService

func GetTimeoutOutputService() string

func GetUpdateService

func GetUpdateService() string

func GetVerifiedTaskService

func GetVerifiedTaskService() string

func HasCmdInLinux

func HasCmdInLinux(cmd string) bool

func HttpDownloadContext

func HttpDownloadContext(ctx context.Context, url string, FilePath string) error

func HttpDownloadWithTimeout

func HttpDownloadWithTimeout(url string, filePath string, timeout time.Duration) error

HttpDownloadWithTimeout downloads a file from url to filePath with specified timeout. Check if returned error is of type *url.Error and whether url.Error.Timeout method returns true for timeout request.

func HttpDownlod

func HttpDownlod(url string, FilePath string) error

func HttpGet

func HttpGet(url string) (error, string)

func HttpGetWithTimeout

func HttpGetWithTimeout(url string, timeout time.Duration, noLog bool) (error, string)

func HttpPost

func HttpPost(url string, data string, contentType string) (string, error)

func HttpPostWithTimeout

func HttpPostWithTimeout(url string, data string, contentType string, timeout time.Duration, noLog bool) (string, error)

func IsDirectory

func IsDirectory(path string) bool

func IsFile

func IsFile(path string) bool

func IsSelfHosted

func IsSelfHosted() bool

func IsServiceExist

func IsServiceExist(ServiceName string) bool

func IsServiceRunning

func IsServiceRunning(ServiceName string) bool

func IsSysVLinux

func IsSysVLinux() bool

func IsSystemdLinux

func IsSystemdLinux() bool

func IsUpstartLinux

func IsUpstartLinux() bool

func IsVerboseMode

func IsVerboseMode() bool

func ReplaceAllParameterStore

func ReplaceAllParameterStore(param string) (string, error)

func SetVerboseMode

func SetVerboseMode(mode bool)

func StartService

func StartService(ServiceName string) error

func StopService

func StopService(ServiceName string) error

Types

type CancelFlag

type CancelFlag interface {
	// Canceled returns true if a cancel or Shutdown has been requested, false otherwise.
	// This method should be called periodically in the job.
	Canceled() bool

	// Set sets the state of this flag and wakes up waiting callers.
	Set(state State)

	// ShutDown returns true if a ShutDown has been requested, false otherwise.
	// This method should be called periodically in the job.
	ShutDown() bool

	// State returns the current flag state
	State() State

	// Wait blocks the caller until either a cancel has been requested or the
	// task has completed normally. Returns Canceled if cancel has been requested,
	// or Completed if the task completed normally.
	// This is intended to be used to wake up a job that may be waiting on some resources, as follows:
	// The main job starts a go routine that calls Wait. The main job then does its processing.
	// During processing the job may be waiting on certain events/conditions.
	// In the go routine, once Wait returns, if the return value indicates that a cancel
	// request has been received, the go routine wakes up the running job.
	Wait() (state State)
}

CancelFlag is an object that is passed to any job submitted to a task in order to communicated job cancellation. Job cancellation has to be cooperative.

type ChanneledCancelFlag

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

ChanneledCancelFlag is a default implementation of the task.CancelFlag interface.

func NewChanneledCancelFlag

func NewChanneledCancelFlag() *ChanneledCancelFlag

NewChanneledCancelFlag creates a new instance of ChanneledCancelFlag.

func (*ChanneledCancelFlag) Canceled

func (t *ChanneledCancelFlag) Canceled() bool

Canceled returns true if this flag has been set to Cancel state, false otherwise.

func (*ChanneledCancelFlag) Set

func (t *ChanneledCancelFlag) Set(state State)

Set sets the state of this flag and wakes up waiting callers.

func (*ChanneledCancelFlag) ShutDown

func (t *ChanneledCancelFlag) ShutDown() bool

ShutDown returns true if this flag has been set to ShutDown state, false otherwise.

func (*ChanneledCancelFlag) State

func (t *ChanneledCancelFlag) State() State

State returns the current flag state.

func (*ChanneledCancelFlag) Wait

func (t *ChanneledCancelFlag) Wait() (state State)

Wait blocks until the flag is set to either Cancel or Completed state. Returns the state.

type State

type State int

State represents the state of a job.

const (
	// Canceled indicates a job for which cancellation has been requested.
	Canceled State = 1

	// Completed indicates a completed job.
	Completed State = 2

	// ShutDown indicates a job for which ShutDown has been requested.
	ShutDown State = 3
)

Jump to

Keyboard shortcuts

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