utils

package
v0.0.0-...-fd40de8 Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2024 License: MIT Imports: 30 Imported by: 1

Documentation

Index

Constants

View Source
const (
	DASServerError
	DBSError
	PhedexError
	RucioError
	DynamoError
	ReqMgrError
	RunRegistryError
	McMError
	DashboardError
	SiteDBError
	CRICError
	CondDBError
	CombinedError
	MongoDBError
	DASProxyError
	DASQueryError
	DASParserError
	DASValidationError
)

DASServerError and others are represent different types of errors in DAS

View Source
const (
	DASServerErrorName     = "DAS error"
	DBSErrorName           = "DBS upstream error"
	PhedexErrorName        = "PhEDEx upstream error"
	RucioErrorName         = "Rucio upstream error"
	DynamoErrorName        = "Dynamo upstream error"
	ReqMgrErrorName        = "ReqMgr upstream error"
	RunRegistryErrorName   = "RunRegistry upstream error"
	McMErrorName           = "McM upstream error"
	DashboardErrorName     = "Dashboard upstream error"
	SiteDBErrorName        = "SiteDB upstream error"
	CRICErrorName          = "CRIC upstream error"
	CondDBErrorName        = "CondDB upstream error"
	CombinedErrorName      = "Combined error"
	MongoDBErrorName       = "MongoDB error"
	DASProxyErrorName      = "DAS proxy error"
	DASQueryErrorName      = "DAS query error"
	DASParserErrorName     = "DAS parser error"
	DASValidationErrorName = "DAS validation error"
)

DASServerErrorName and others provides human based definition of the DAS error

View Source
const BLACK = "0;30m"

BLACK color

View Source
const BLUE = "0;34m"

BLUE color

View Source
const BOLD = "\x1b[1m"

BOLD type

View Source
const BROWN = "0;33m"

BROWN color

View Source
const CYAN = "0;36m"

CYAN color

View Source
const GREEN = "0;32m"

GREEN color

View Source
const LIGHT_CYAN = "1;36m"

LIGHT_CYAN color

View Source
const LIGHT_PURPLE = "1;35m"

LIGHT_PURPLE color

View Source
const PLAIN = "\x1b[0m"

PLAIN type

View Source
const PURPLE = "0;35m"

PURPLE color

View Source
const RED = "0;31m"

RED color

Variables

View Source
var (
	// UrlQueueSize keeps track of running URL requests
	UrlQueueSize int32
	// UrlQueueLimit knows how many URL requests we can handle at a time, 0 means no limit
	UrlQueueLimit int32
	// UrlRetry knows  how many times we'll retry given url call
	UrlRetry int
	// UrlRequestChannel is a UrlRequest channel
	UrlRequestChannel = make(chan UrlRequest)
)
View Source
var CLIENT_VERSION string

CLIENT_VERSION represents client version

View Source
var DASMAPS string

DASMAPS specifies location of dasmaps

View Source
var DNSCacheMgr *dcr.DNSManager

DNSCacheMgr manager

View Source
var KEEP_ALIVE bool

KEEP_ALIVE defines to use Keep-Alive HTTP header in HTTP requests https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Keep-Alive

View Source
var PatternBlock = regexp.MustCompile("/[-a-zA-Z_0-9*]+/[-a-zA-Z_0-9*]+/[-a-zA-Z_0-9*]+#.*")

PatternBlock represents CMS block

View Source
var PatternDataset = regexp.MustCompile("/[-a-zA-Z_0-9*]+/[-a-zA-Z_0-9*]+/[-a-zA-Z_0-9*]+")

PatternDataset represents CMS dataset

View Source
var PatternFile = regexp.MustCompile("/[a-zA-Z_0-9].*\\.root$")

PatternFile represents CMS file

View Source
var PatternInt = regexp.MustCompile("(^[0-9-]$|^[0-9-][0-9]*$)")

PatternInt represents an integer pattern

View Source
var PatternRun = regexp.MustCompile("[0-9]+")

PatternRun represents CMS run

View Source
var PatternSE = regexp.MustCompile("^[a-z]+(\\.)[a-z]+(\\.)")

PatternSE represents StorageElement pattern

View Source
var PatternSite = regexp.MustCompile("^T[0-9]_[A-Z]+(_)[A-Z]+")

PatternSite represents a site name pattern

View Source
var PatternUrl = regexp.MustCompile("(https|http)://[-A-Za-z0-9_+&@#/%?=~_|!:,.;]*[-A-Za-z0-9+&@#/%=~_|]")

PatternUrl represents URL pattern

View Source
var Profiler *bufio.Writer

global variable

View Source
var RucioTokenCurl bool

RucioTokenCurl

View Source
var RucioValidity int64

RucioValidity

View Source
var TIMEOUT int

TIMEOUT defines timeout for net/url request

View Source
var TLSCertsRenewInterval time.Duration

TLSCertsRenewInterval controls interval to re-read TLS certs (in seconds)

View Source
var Token string

Token defines access token location

View Source
var TotalGetCalls uint64

TotalGetCalls counts total number of GET requests made by the server

View Source
var TotalPostCalls uint64

TotalPostCalls counts total number of POST requests made by the server

View Source
var UseDNSCache bool

UseDNSCache defines if we use DNS Cache resolver

View Source
var VERBOSE int

VERBOSE holds level of verbosity, it is set in main

View Source
var VERSION string

VERSION provides information about das2go build

View Source
var WEBSERVER int

WEBSERVER declares that web server will run, it is set in main

Functions

func AdjustUrl

func AdjustUrl(s string) string

AdjustUrl removes double slashes in URL

func Avg

func Avg(data []interface{}) float64

Avg helper function to perform Avg operation over provided array of values

func CertExpire

func CertExpire(certs []tls.Certificate) time.Time

CertExpire gets minimum certificate expire from list of certificates

func CheckEntries

func CheckEntries(list1, list2 []string) bool

CheckEntries helper function to check that entries from list1 are all appear in list2

func Color

func Color(col, text string) string

Color prints given string in color based on ANSI escape codes, see http://www.wikiwand.com/en/ANSI_escape_code#/Colors

func ColorUrl

func ColorUrl(rurl string) string

ColorUrl returns colored string of given url

func ConddbTime

func ConddbTime(ts string) string

ConddbTime helper function to convert given time into Conddb timestamp

func DASError

func DASError(args ...interface{})

DASError prints DAS error message with given arguments

func DASWarning

func DASWarning(args ...interface{})

DASWarning prints DAS error message with given arguments

func DashboardTime

func DashboardTime(ts string) string

DashboardTime helper function to convert given time into Dashboard timestamp

func EqualLists

func EqualLists(list1, list2 []string) bool

EqualLists helper function to compare list of strings

func ErrPropagate

func ErrPropagate(api string)

ErrPropagate error helper function which can be used in defer ErrPropagate()

func ErrPropagate2Channel

func ErrPropagate2Channel(api string, ch chan interface{})

ErrPropagate2Channel error helper function which can be used in goroutines as ch := make(chan interface{})

go func() {
   defer ErrPropagate2Channel(api, ch)
   someFunction()
}()

func Expire

func Expire(expire int) int64

Expire helper function to convert expire timestamp (int) into seconds since epoch

func Fetch

func Fetch(httpClient *http.Client, rurl string, args string, out chan<- ResponseType)

Fetch data for provided URL and redirect results to given channel This wrapper function look-up UrlQueueLimit and either redirect to URULFetchWorker go-routine or pass the call to local fetch function

func FetchRucioToken

func FetchRucioToken(rurl string) (string, int64, error)

run go-routine to periodically obtain rucio token FetchRucioToken request new Rucio token

func FetchRucioTokenViaCurl

func FetchRucioTokenViaCurl(rurl string) (string, int64, error)

FetchRucioTokenViaCurl is a helper function to get Rucio token by using curl command

func FindInList

func FindInList(a string, arr []string) bool

FindInList helper function to find item in a list

func GetBytes

func GetBytes(data interface{}) ([]byte, error)

GetBytes converts interface to bytes

func GetEnv

func GetEnv(key string) string

GetEnv fetches value from user environement

func GetFuncName

func GetFuncName(i interface{}) string

GetFuncName returns name of the function

func GetHostUrl

func GetHostUrl(s string) string

GetHostUrl return URL of given URL path

func GoDeferFunc

func GoDeferFunc(api string, f func())

GoDeferFunc helper function to run any given function in defered go routine

func HttpClient

func HttpClient() *http.Client

HttpClient is HTTP client for urlfetch server

func InList

func InList(a string, list []string) bool

InList helper function to check item in a list

func Init

func Init()

func InitFunctionProfiler

func InitFunctionProfiler(fname string)

func IsInt

func IsInt(val string) bool

IsInt helper function to test if given value is integer

func List2Set

func List2Set(arr []string) []string

List2Set helper function to convert input list into set

func LoadExamples

func LoadExamples(ename, home string) string

LoadExamples loads DAS examples from github or local file

func MapKeys

func MapKeys(rec map[string]interface{}) []string

MapKeys helper function to return keys from a map

func Max

func Max(data []interface{}) float64

Max helper function to perform Max operation over provided array of values

func Mean

func Mean(data []interface{}) float64

Mean helper function to perform Mean operation over provided array of values

func MeasureTime

func MeasureTime(funcName string) func()

Latency Measurement of individual component of the codebase https://medium.com/swlh/easy-guide-to-latency-measurement-in-golang-38c3297ebbd2 Usage, put the following statement in any function we need to measure: defer measureTime("funcName")

func Median

func Median(data []interface{}) float64

Median helper function to perform Median operation over provided array of values

func Min

func Min(data []interface{}) float64

Min helper function to perform Min operation over provided array of values

func Response

func Response(rurl string, data []byte) []byte

Response represents final response in a form of JSON structure we use custorm representation

func RunRegistryTime

func RunRegistryTime(ts string) string

RunRegistryTime helper function to convert given time into RunRegistry timestamp

func SizeFormat

func SizeFormat(val interface{}) string

SizeFormat helper function to convert size into human readable form

func Stack

func Stack() string

Stack helper function to return Stack

func Sum

func Sum(data []interface{}) float64

Sum helper function to perform sum operation over provided array of values

func TimeFormat

func TimeFormat(ts interface{}) string

TimeFormat helper function to convert Unix time into human readable form

func URLFetchWorker

func URLFetchWorker(in <-chan UrlRequest)

URLFetchWorker has three channels: in channel for incoming requests (in a form of URL strings), out channel for outgoing responses in a form of ResponseType structure and quit channel

func Unix2DASTime

func Unix2DASTime(ts int64) string

Unix2DASTime helper function to convert given time into Unix timestamp

func UnixTime

func UnixTime(ts string) int64

UnixTime helper function to convert given time into Unix timestamp

Types

type Int64List

type Int64List []int64

Int64List implement sort for []int type

func (Int64List) Len

func (s Int64List) Len() int

Len provides length of the []int64 type

func (Int64List) Less

func (s Int64List) Less(i, j int) bool

Less implements less function for []int64 type

func (Int64List) Swap

func (s Int64List) Swap(i, j int)

Swap implements swap function for []int64 type

type IntList

type IntList []int

IntList implement sort for []int type

func (IntList) Len

func (s IntList) Len() int

Len provides length of the []int type

func (IntList) Less

func (s IntList) Less(i, j int) bool

Less implements less function for []int type

func (IntList) Swap

func (s IntList) Swap(i, j int)

Swap implements swap function for []int type

type ResponseType

type ResponseType struct {
	Url       string
	Data      []byte
	Error     error
	Time      time.Duration
	Params    string
	Method    string
	SendBytes int
	RecvBytes int
}

ResponseType structure is what we expect to get for our URL call. It contains a request URL, the data chunk and possible error from remote

func FetchResponse

func FetchResponse(httpClient *http.Client, rurl, args string) ResponseType

FetchResponse fetches data for provided URL, args is a json dump of arguments

func (*ResponseType) Details

func (r *ResponseType) Details() string

Details returns ResponseType details

func (*ResponseType) String

func (r *ResponseType) String() string

String returns ResponseType representation

type RucioAuthModule

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

RucioAuthModule structure holds all information about Rucio authentication

var RucioAuth RucioAuthModule

RucioAuth represents instance of rucio authentication module

func (*RucioAuthModule) Account

func (r *RucioAuthModule) Account() string

Account returns Rucio authentication account

func (*RucioAuthModule) Agent

func (r *RucioAuthModule) Agent() string

Agent returns Rucio authentication agent

func (*RucioAuthModule) String

func (r *RucioAuthModule) String() string

String provides string representation of RucioAuthModule

func (*RucioAuthModule) Token

func (r *RucioAuthModule) Token() (string, error)

Token returns Rucio authentication token

func (*RucioAuthModule) Url

func (r *RucioAuthModule) Url() string

Url returns Rucio authentication url

type StringList

type StringList []string

StringList implement sort for []string type

func (StringList) Len

func (s StringList) Len() int

Len provides length of the []int type

func (StringList) Less

func (s StringList) Less(i, j int) bool

Less implements less function for []int type

func (StringList) Swap

func (s StringList) Swap(i, j int)

Swap implements swap function for []int type

type TLSCertsManager

type TLSCertsManager struct {
	Certs  []tls.Certificate
	Expire time.Time
}

TLSCerts holds TLS certificates for the server

func (*TLSCertsManager) GetCerts

func (t *TLSCertsManager) GetCerts() ([]tls.Certificate, error)

GetCerts return fresh copy of certificates

type UrlFetchQueue

type UrlFetchQueue []*UrlRequest

A UrlFetchQueue implements heap.Interface and holds UrlRequests

func (UrlFetchQueue) Len

func (q UrlFetchQueue) Len() int

Len provides len implemenation for UrlFetchQueue

func (UrlFetchQueue) Less

func (q UrlFetchQueue) Less(i, j int) bool

Less provides Less implemenation for UrlFetchQueue

func (*UrlFetchQueue) Pop

func (q *UrlFetchQueue) Pop() interface{}

Pop provides Pop implemenation for UrlFetchQueue

func (*UrlFetchQueue) Push

func (q *UrlFetchQueue) Push(x interface{})

Push provides push implemenation for UrlFetchQueue

func (UrlFetchQueue) Swap

func (q UrlFetchQueue) Swap(i, j int)

Swap provides swap implemenation for UrlFetchQueue

type UrlRequest

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

UrlRequest structure holds details about url request's attributes

Jump to

Keyboard shortcuts

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