本文整理汇总了Golang中github.com/cloudawan/cloudone_utility/logger.GetStackTrace函数的典型用法代码示例。如果您正苦于以下问题:Golang GetStackTrace函数的具体用法?Golang GetStackTrace怎么用?Golang GetStackTrace使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了GetStackTrace函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: GetAllNamespaceName
func GetAllNamespaceName(kubeApiServerEndPoint string, kubeApiServerToken string) (returnedNameSlice []string, returnedError error) {
defer func() {
if err := recover(); err != nil {
log.Error("GetAllNamespaceName Error: %s", err)
log.Error(logger.GetStackTrace(4096, false))
returnedNameSlice = nil
returnedError = err.(error)
}
}()
headerMap := make(map[string]string)
headerMap["Authorization"] = kubeApiServerToken
result, err := restclient.RequestGet(kubeApiServerEndPoint+"/api/v1/namespaces/", headerMap, true)
if err != nil {
log.Error("Fail to get all namespace name with endpoint: %s, token: %s, error: %s", kubeApiServerEndPoint, kubeApiServerToken, err.Error())
return nil, err
}
jsonMap, _ := result.(map[string]interface{})
nameSlice := make([]string, 0)
for _, data := range jsonMap["items"].([]interface{}) {
name, ok := data.(map[string]interface{})["metadata"].(map[string]interface{})["name"].(string)
if ok {
statusJsonMap, _ := data.(map[string]interface{})["status"].(map[string]interface{})
phase, _ := statusJsonMap["phase"].(string)
if phase == "Active" {
nameSlice = append(nameSlice, name)
}
}
}
return nameSlice, nil
}
示例2: GetKeysAPI
func (etcdClient *EtcdClient) GetKeysAPI() (returnedKeysAPI client.KeysAPI, returnedError error) {
defer func() {
if err := recover(); err != nil {
log.Error("GetKeysAPI Error: %s", err)
log.Error(logger.GetStackTrace(4096, false))
etcdClient.KeysAPI = nil
returnedKeysAPI = nil
returnedError = err.(error)
}
}()
if etcdClient.KeysAPI != nil {
return etcdClient.KeysAPI, nil
} else {
config := client.Config{
Endpoints: etcdClient.EtcdEndpoints,
Transport: client.DefaultTransport,
HeaderTimeoutPerRequest: etcdClient.EtcdHeaderTimeoutPerRequest,
}
configuredClient, err := client.New(config)
if err != nil {
etcdClient.KeysAPI = nil
log.Error(err)
return nil, err
}
keysAPI := client.NewKeysAPI(configuredClient)
etcdClient.KeysAPI = keysAPI
return keysAPI, nil
}
}
示例3: UpdateReplicationControllerSize
func UpdateReplicationControllerSize(kubeApiServerEndPoint string, kubeApiServerToken string, namespace string, replicationControllerName string, size int) (returnedError error) {
defer func() {
if err := recover(); err != nil {
log.Error("UpdateReplicationControllerSize Error: %s", err)
log.Error(logger.GetStackTrace(4096, false))
returnedError = err.(error)
}
}()
headerMap := make(map[string]string)
headerMap["Authorization"] = kubeApiServerToken
url := kubeApiServerEndPoint + "/api/v1/namespaces/" + namespace + "/replicationcontrollers/" + replicationControllerName + "/"
result, err := restclient.RequestGet(url, headerMap, true)
jsonMap, _ := result.(map[string]interface{})
if err != nil {
log.Error("Get replication controller information failure where size: %d, endpoint: %s, token: %s, namespace: %s, replicationControllerName: %s, err: %s", size, kubeApiServerEndPoint, kubeApiServerToken, namespace, replicationControllerName, err.Error())
return err
} else {
jsonMap["spec"].(map[string]interface{})["replicas"] = float64(size)
_, err := restclient.RequestPut(url, jsonMap, headerMap, true)
if err != nil {
return err
} else {
return nil
}
}
}
示例4: CreateTableIfNotExist
func (cassandraClient *CassandraClient) CreateTableIfNotExist(tableSchema string, retryAmount int, retryInterval time.Duration) (returnedError error) {
defer func() {
if err := recover(); err != nil {
log.Error("CreateTableIfNotExist Error: %s", err)
log.Error(logger.GetStackTrace(4096, false))
returnedError = err.(error)
}
}()
session, err := cassandraClient.GetSession()
if err != nil {
return err
}
for i := 0; i < retryAmount; i++ {
if err := session.Query(tableSchema).Exec(); err == nil {
return nil
} else {
log.Error("Check if not exist then create table schema %s error: %s", tableSchema, err)
returnedError = err
}
time.Sleep(retryInterval)
}
return returnedError
}
示例5: createConfigurationFileIfNotExist
func (configuration *Configuration) createConfigurationFileIfNotExist(programName string, configurationContent string) (returnedError error) {
defer func() {
if err := recover(); err != nil {
log.Error("configuration Error: %s", err)
log.Error(logger.GetStackTrace(4096, false))
returnedError = err.(error)
}
}()
directoryPath := rootPath + string(os.PathSeparator) + programName
if err := os.MkdirAll(directoryPath, os.ModePerm); err != nil {
return err
}
fileNameAndPath := directoryPath + string(os.PathSeparator) + fileName
if _, err := os.Stat(fileNameAndPath); os.IsNotExist(err) {
outputFile, err := os.Create(fileNameAndPath)
if err != nil {
log.Error("createConfigurationFileIfNotExist create file %s with error: %s", fileNameAndPath, err)
return err
}
outputFile.WriteString(configurationContent)
}
configuration.fileNameAndPath = fileNameAndPath
return nil
}
示例6: GetAllEvent
func GetAllEvent(kubeApiServerEndPoint string, kubeApiServerToken string) (returnedEventSlice []map[string]interface{}, returnedError error) {
defer func() {
if err := recover(); err != nil {
log.Error("GetAllEvent Error: %s", err)
log.Error(logger.GetStackTrace(4096, false))
returnedEventSlice = nil
returnedError = err.(error)
}
}()
headerMap := make(map[string]string)
headerMap["Authorization"] = kubeApiServerToken
jsonMap, err := restclient.RequestGet(kubeApiServerEndPoint+"/api/v1/events/", headerMap, true)
if err != nil {
log.Error("Fail to get all event with endpoint: %s, token: %s, error: %s", kubeApiServerEndPoint, kubeApiServerToken, err.Error())
return nil, err
}
eventSlice := make([]map[string]interface{}, 0)
for _, data := range jsonMap.(map[string]interface{})["items"].([]interface{}) {
value, ok := data.(map[string]interface{})
if ok {
eventSlice = append(eventSlice, value)
}
}
return eventSlice, nil
}
示例7: GetAllReplicationControllerName
func GetAllReplicationControllerName(kubeApiServerEndPoint string, kubeApiServerToken string, namespace string) (returnedNameSlice []string, returnedError error) {
defer func() {
if err := recover(); err != nil {
log.Error("GetAllReplicationController Error: %s", err)
log.Error(logger.GetStackTrace(4096, false))
returnedNameSlice = nil
returnedError = err.(error)
}
}()
url := kubeApiServerEndPoint + "/api/v1/namespaces/" + namespace + "/replicationcontrollers/"
headerMap := make(map[string]string)
headerMap["Authorization"] = kubeApiServerToken
jsonMap, err := restclient.RequestGet(url, headerMap, true)
if err != nil {
log.Error(err)
return nil, err
} else {
nameSlice := make([]string, 0)
for _, item := range jsonMap.(map[string]interface{})["items"].([]interface{}) {
name, ok := item.(map[string]interface{})["metadata"].(map[string]interface{})["name"].(string)
if ok {
nameSlice = append(nameSlice, name)
}
}
return nameSlice, nil
}
}
示例8: DeleteReplicationControllerAndRelatedPod
func DeleteReplicationControllerAndRelatedPod(kubeApiServerEndPoint string, kubeApiServerToken string, namespace string, replicationControllerName string) (returnedError error) {
defer func() {
if err := recover(); err != nil {
log.Error("DeleteReplicationControllerAndRelatedPod Error: %s", err)
log.Error(logger.GetStackTrace(4096, false))
returnedError = err.(error)
}
}()
err := DeleteReplicationController(kubeApiServerEndPoint, kubeApiServerToken, namespace, replicationControllerName)
if err != nil {
return err
} else {
nameSlice, err := GetAllPodNameBelongToReplicationController(kubeApiServerEndPoint, kubeApiServerToken, namespace, replicationControllerName)
if err != nil {
return err
} else {
for _, name := range nameSlice {
err := DeletePod(kubeApiServerEndPoint, kubeApiServerToken, namespace, name)
if err != nil {
return err
}
}
return nil
}
}
}
示例9: parseSize
func (glusterfsCluster *GlusterfsCluster) parseSize(field string) (returnedSize int, returnedError error) {
defer func() {
if err := recover(); err != nil {
log.Error("Parse size error: %s", err)
log.Error(logger.GetStackTrace(4096, false))
returnedSize = -1
returnedError = err.(error)
}
}()
var value string
if strings.Contains(field, "=") {
value = strings.Split(field, "=")[1]
} else {
value = field
}
size, err := strconv.Atoi(strings.TrimSpace(value))
if err != nil {
log.Error("Parse size error %s", err)
return -1, err
} else {
return size, nil
}
}
示例10: parseVolumeInfo
func (glusterfsCluster *GlusterfsCluster) parseVolumeInfo(text string) (returnedGlusterfsVolumeSlice []GlusterfsVolume, returnedError error) {
defer func() {
if err := recover(); err != nil {
log.Error("parseVolumeInfo Error: %s", err)
log.Error(logger.GetStackTrace(4096, false))
returnedGlusterfsVolumeSlice = nil
returnedError = err.(error)
}
}()
glusterfsVolumeSlice := make([]GlusterfsVolume, 0)
scanner := bufio.NewScanner(bytes.NewBufferString(text))
var glusterfsVolume *GlusterfsVolume = nil
for scanner.Scan() {
line := scanner.Text()
if line == " " {
if glusterfsVolume != nil {
glusterfsVolumeSlice = append(glusterfsVolumeSlice, *glusterfsVolume)
}
glusterfsVolume = &GlusterfsVolume{}
} else if strings.HasPrefix(line, "Volume Name: ") {
glusterfsVolume.VolumeName = line[len("Volume Name: "):]
} else if strings.HasPrefix(line, "Type: ") {
glusterfsVolume.Type = line[len("Type: "):]
} else if strings.HasPrefix(line, "Volume ID: ") {
glusterfsVolume.VolumeID = line[len("Volume ID: "):]
} else if strings.HasPrefix(line, "Status: ") {
glusterfsVolume.Status = line[len("Status: "):]
} else if strings.HasPrefix(line, "Number of Bricks: ") {
glusterfsVolume.NumberOfBricks = line[len("Number of Bricks: "):]
glusterfsVolume.Size, _ = glusterfsCluster.parseSize(glusterfsVolume.NumberOfBricks)
} else if strings.HasPrefix(line, "Transport-type: ") {
glusterfsVolume.TransportType = line[len("Transport-type: "):]
} else if line == "Bricks:" {
brickSlice := make([]string, 0)
for i := 0; i < glusterfsVolume.Size; i++ {
scanner.Scan()
brickSlice = append(brickSlice, scanner.Text())
}
glusterfsVolume.Bricks = brickSlice
} else {
// Ignore unexpected data
}
}
if glusterfsVolume != nil {
glusterfsVolumeSlice = append(glusterfsVolumeSlice, *glusterfsVolume)
}
if err := scanner.Err(); err != nil {
log.Error("Scanner error %s", err)
return nil, err
}
return glusterfsVolumeSlice, nil
}
示例11: MonitorReplicationController
func MonitorReplicationController(kubeApiServerEndPoint string, kubeApiServerToken string, namespace string, replicationControllerName string) (returnedReplicationControllerMetric *ReplicationControllerMetric, returnedError error) {
defer func() {
if err := recover(); err != nil {
log.Error("MonitorReplicationController Error: %s", err)
log.Error(logger.GetStackTrace(4096, false))
returnedReplicationControllerMetric = nil
returnedError = err.(error)
}
}()
exist, err := ExistReplicationController(kubeApiServerEndPoint, kubeApiServerToken, namespace, replicationControllerName)
if err != nil {
log.Error("Fail to get the replication controller with endpoint: %s, token: %s, namespace: %s, replication controller name: %s", kubeApiServerEndPoint, kubeApiServerToken, namespace, replicationControllerName)
return nil, err
}
if exist == false {
log.Error("Replication controller doesn't exist with endpoint: %s, token: %s, namespace: %s, replication controller name: %s", kubeApiServerEndPoint, kubeApiServerToken, namespace, replicationControllerName)
return nil, err
}
podNameSlice, err := control.GetAllPodNameBelongToReplicationController(kubeApiServerEndPoint, kubeApiServerToken, namespace, replicationControllerName)
if err != nil {
log.Error("Fail to get all pod name belong to the replication controller with endpoint: %s, token: %s, namespace: %s, replication controller name: %s", kubeApiServerEndPoint, kubeApiServerToken, namespace, replicationControllerName)
return nil, err
}
replicationControllerMetric := &ReplicationControllerMetric{}
replicationControllerMetric.Namespace = namespace
replicationControllerMetric.ReplicationControllerName = replicationControllerName
replicationControllerMetric.Size = len(podNameSlice)
replicationControllerMetric.ValidPodSlice = make([]bool, replicationControllerMetric.Size)
replicationControllerMetric.PodMetricSlice = make([]PodMetric, replicationControllerMetric.Size)
errorMessage := "The following index of pod has error: "
errorHappened := false
for index, podName := range podNameSlice {
podMetric, err := MonitorPod(kubeApiServerEndPoint, kubeApiServerToken, namespace, podName)
if err != nil {
errorMessage = errorMessage + err.Error()
errorHappened = true
replicationControllerMetric.ValidPodSlice[index] = false
} else {
replicationControllerMetric.ValidPodSlice[index] = true
replicationControllerMetric.PodMetricSlice[index] = *podMetric
}
}
if errorHappened {
log.Error("Fail to get all pod inofrmation with endpoint: %s, token: %s, namespace: %s, replication controller name: %s, error %s", kubeApiServerEndPoint, kubeApiServerToken, namespace, replicationControllerName, errorMessage)
return replicationControllerMetric, errors.New(errorMessage)
} else {
return replicationControllerMetric, nil
}
}
示例12: BuildUpgrade
func BuildUpgrade(imageInformationName string, description string) (returnedOutputMessage string, returnedError error) {
defer func() {
if err := recover(); err != nil {
log.Error("BuildUpgrade Error: %s", err)
log.Error(logger.GetStackTrace(4096, false))
returnedOutputMessage = ""
returnedError = err.(error)
}
}()
imageInformation, err := GetStorage().LoadImageInformation(imageInformationName)
if err != nil {
log.Error("Load image information error: %s", err)
return "", err
}
var buildError error = nil
imageRecord, outputMessage, err := Build(imageInformation, description)
if err != nil {
log.Error("Build error: %s Output message: %s", err, outputMessage)
if imageRecord == nil {
return outputMessage, err
} else {
buildError = err
outputMessage = outputMessage + "\n" + err.Error()
}
}
// Save image record
err = GetStorage().saveImageRecord(imageRecord)
if err != nil {
log.Error("Save image record error: %s", err)
return outputMessage, err
}
imageInformation.CurrentVersion = imageRecord.Version
// Save image information
err = GetStorage().SaveImageInformation(imageInformation)
if err != nil {
log.Error("Save image information error: %s", err)
return outputMessage, err
}
// Save build log
err = SendBuildLog(imageRecord, outputMessage)
if err != nil {
log.Error("Save build log error: %s", err)
return outputMessage, err
}
return outputMessage, buildError
}
示例13: GetAvailablekubeApiServerEndPoint
func GetAvailablekubeApiServerEndPoint() (returnedEndPoint string, returnedToken string, returnedError error) {
defer func() {
if err := recover(); err != nil {
returnedEndPoint = ""
returnedToken = ""
returnedError = err.(error)
log.Error("GetAvailablekubeApiServerEndPoint Error: %s", err)
log.Error(logger.GetStackTrace(4096, false))
}
}()
kubeApiServerEndPointSlice, ok := LocalConfiguration.GetStringSlice("kubeApiServerEndPoints")
if ok == false {
log.Error("Fail to get configuration kubeApiServerEndPoints")
return "", "", errors.New("Fail to get configuration kubeApiServerEndPoints")
}
kubeApiServerHealthCheckTimeoutInMilliSecond, ok := LocalConfiguration.GetInt("kubeApiServerHealthCheckTimeoutInMilliSecond")
if ok == false {
kubeApiServerHealthCheckTimeoutInMilliSecond = KubeApiServerHealthCheckTimeoutInMilliSecond
}
kubeApiServerToken, ok := LocalConfiguration.GetString("kubeApiServerToken")
if ok == false {
log.Error("Fail to get configuration kubeApiServerToken")
return "", "", errors.New("Fail to get configuration kubeApiServerToken")
}
token := "Bearer " + kubeApiServerToken
headerMap := make(map[string]string)
headerMap["Authorization"] = token
for _, kubeApiServerEndPoint := range kubeApiServerEndPointSlice {
result, err := restclient.HealthCheck(
kubeApiServerEndPoint,
headerMap,
time.Duration(kubeApiServerHealthCheckTimeoutInMilliSecond)*time.Millisecond)
if result {
return kubeApiServerEndPoint, token, nil
} else {
if err != nil {
log.Error(err)
}
}
}
log.Error("No available kube apiserver endpoint")
return "", "", errors.New("No available kube apiserver endpoint")
}
示例14: DeleteReplicationController
func DeleteReplicationController(kubeApiServerEndPoint string, kubeApiServerToken string, namespace string, replicationControllerName string) (returnedError error) {
defer func() {
if err := recover(); err != nil {
log.Error("DeleteReplicationController Error: %s", err)
log.Error(logger.GetStackTrace(4096, false))
returnedError = err.(error)
}
}()
headerMap := make(map[string]string)
headerMap["Authorization"] = kubeApiServerToken
url := kubeApiServerEndPoint + "/api/v1/namespaces/" + namespace + "/replicationcontrollers/" + replicationControllerName
_, err := restclient.RequestDelete(url, nil, headerMap, true)
return err
}
示例15: GetAllNodeIP
func GetAllNodeIP(kubeApiServerEndPoint string, kubeApiServerToken string) (returnedIpSlice []string, returnedError error) {
defer func() {
if err := recover(); err != nil {
log.Error("GetAllNodeIP Error: %s", err)
log.Error(logger.GetStackTrace(4096, false))
returnedIpSlice = nil
returnedError = err.(error)
}
}()
jsonMap := make(map[string]interface{})
headerMap := make(map[string]string)
headerMap["Authorization"] = kubeApiServerToken
url := kubeApiServerEndPoint + "/api/v1/nodes/"
_, err := restclient.RequestGetWithStructure(url, &jsonMap, headerMap)
if err != nil {
log.Error(err)
return nil, err
}
ipSlice := make([]string, 0)
itemSlice, _ := jsonMap["items"].([]interface{})
for _, item := range itemSlice {
itemJsonMap, _ := item.(map[string]interface{})
statusJsonMap, _ := itemJsonMap["status"].(map[string]interface{})
addressesJsonSlice, _ := statusJsonMap["addresses"].([]interface{})
address := ""
for _, value := range addressesJsonSlice {
addressJsonMap, _ := value.(map[string]interface{})
addressType, _ := addressJsonMap["type"].(string)
addressAddress, _ := addressJsonMap["address"].(string)
if addressType == "InternalIP" {
address = addressAddress
break
}
}
if len(address) > 0 {
ipSlice = append(ipSlice, address)
}
}
return ipSlice, nil
}