From 10051f2f223879adb126672f3cbac62b2a90fa9c Mon Sep 17 00:00:00 2001 From: Yunkon Kim Date: Mon, 1 Apr 2024 23:38:01 +0900 Subject: [PATCH] Replace all with Zerolog --- src/api/rest/server/common/config.go | 7 +- src/api/rest/server/common/utility.go | 3 - src/api/rest/server/mcir/common.go | 2 +- src/api/rest/server/mcis/cluster.go | 17 +- src/api/rest/server/mcis/manageInfo.go | 3 +- src/core/common/client.go | 3 +- src/core/common/config.go | 18 +- src/core/common/namespace.go | 47 +++--- src/core/common/utility.go | 45 ++--- src/core/mcir/common.go | 206 +++++++++++------------ src/core/mcir/customimage.go | 19 ++- src/core/mcir/datadisk.go | 17 +- src/core/mcir/firewallrule.go | 37 +++-- src/core/mcir/image.go | 61 +++---- src/core/mcir/securitygroup.go | 23 +-- src/core/mcir/spec.go | 63 +++---- src/core/mcir/sshkey.go | 21 +-- src/core/mcir/subnet.go | 19 ++- src/core/mcir/vnet.go | 23 +-- src/core/mcis/benchmark.go | 29 ++-- src/core/mcis/cluster.go | 157 +++++++++--------- src/core/mcis/control.go | 39 ++--- src/core/mcis/manageInfo.go | 219 +++++++++++++------------ src/core/mcis/monitoring.go | 45 ++--- src/core/mcis/network.go | 209 +++++++++++------------ src/core/mcis/nlb.go | 165 ++++++++++--------- src/core/mcis/orchestration.go | 49 +++--- src/core/mcis/provisioning.go | 112 ++++++------- src/core/mcis/recommendation.go | 33 ++-- src/core/mcis/remoteCommand.go | 57 +++---- src/core/mcis/snapshot.go | 13 +- src/core/mcis/utility.go | 109 ++++++------ src/main.go | 28 ++-- 33 files changed, 965 insertions(+), 933 deletions(-) diff --git a/src/api/rest/server/common/config.go b/src/api/rest/server/common/config.go index ee00a884c..0987ea54d 100644 --- a/src/api/rest/server/common/config.go +++ b/src/api/rest/server/common/config.go @@ -25,6 +25,7 @@ import ( "time" "github.com/labstack/echo/v4" + "github.com/rs/zerolog/log" "github.com/cloud-barista/cb-tumblebug/src/core/common" ) @@ -46,7 +47,7 @@ func RestInitConfig(c echo.Context) error { return c.JSON(http.StatusBadRequest, map[string]string{"message": idErr.Error()}) } if err := Validate(c, []string{"configId"}); err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return common.EndRequestWithLog(c, reqID, err, nil) } @@ -55,7 +56,7 @@ func RestInitConfig(c echo.Context) error { err := fmt.Errorf("Failed to init the config " + c.Param("configId")) return common.EndRequestWithLog(c, reqID, err, nil) } else { - return SendMessage(c, http.StatusOK, "The config "+c.Param("configId")+" has been initialized.") + // return SendMessage(c, http.StatusOK, "The config "+c.Param("configId")+" has been initialized.") content := map[string]string{"message": "The config " + c.Param("configId") + " has been initialized."} return common.EndRequestWithLog(c, reqID, err, content) } @@ -78,7 +79,7 @@ func RestGetConfig(c echo.Context) error { return c.JSON(http.StatusBadRequest, map[string]string{"message": idErr.Error()}) } if err := Validate(c, []string{"configId"}); err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return SendMessage(c, http.StatusBadRequest, err.Error()) } diff --git a/src/api/rest/server/common/utility.go b/src/api/rest/server/common/utility.go index 1e7b4ad9b..bc2fce18c 100644 --- a/src/api/rest/server/common/utility.go +++ b/src/api/rest/server/common/utility.go @@ -23,7 +23,6 @@ import ( "github.com/go-playground/validator/v10" "github.com/labstack/echo/v4" - "github.com/rs/zerolog/log" "github.com/cloud-barista/cb-tumblebug/src/core/common" "github.com/cloud-barista/cb-tumblebug/src/core/mcis" @@ -85,8 +84,6 @@ func RestGetHealth(c echo.Context) error { okMessage := common.SimpleMsg{} okMessage.Message = "API server of CB-Tumblebug is alive" - log.Debug().Msg("Inside of RestGetHealth() handler") - return c.JSON(http.StatusOK, &okMessage) } diff --git a/src/api/rest/server/mcir/common.go b/src/api/rest/server/mcir/common.go index 5612d4019..a546df2a4 100644 --- a/src/api/rest/server/mcir/common.go +++ b/src/api/rest/server/mcir/common.go @@ -381,7 +381,7 @@ func RestRegisterExistingResources(c echo.Context) error { result, err := mcir.RegisterExistingResources(nsId, u.ConnectionName) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") mapA := map[string]string{"message": err.Error()} return c.JSON(http.StatusConflict, &mapA) } diff --git a/src/api/rest/server/mcis/cluster.go b/src/api/rest/server/mcis/cluster.go index c69d2c50e..e3a470fc3 100644 --- a/src/api/rest/server/mcis/cluster.go +++ b/src/api/rest/server/mcis/cluster.go @@ -21,6 +21,7 @@ import ( "github.com/cloud-barista/cb-tumblebug/src/core/common" "github.com/cloud-barista/cb-tumblebug/src/core/mcis" "github.com/labstack/echo/v4" + "github.com/rs/zerolog/log" ) // RestPostCluster godoc @@ -52,7 +53,7 @@ func RestPostCluster(c echo.Context) error { content, err := mcis.CreateCluster(nsId, u, optionFlag) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") mapA := map[string]string{"message": err.Error()} return c.JSON(http.StatusInternalServerError, &mapA) } @@ -111,7 +112,7 @@ func RestPostNodeGroup(c echo.Context) error { content, err := mcis.AddNodeGroup(nsId, clusterId, u) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") mapA := map[string]string{"message": err.Error()} return c.JSON(http.StatusInternalServerError, &mapA) } @@ -141,7 +142,7 @@ func RestDeleteNodeGroup(c echo.Context) error { res, err := mcis.RemoveNodeGroup(nsId, clusterId, nodeGroupName, forceFlag) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") mapA := map[string]string{"message": err.Error()} return c.JSON(http.StatusInternalServerError, &mapA) } @@ -185,7 +186,7 @@ func RestPutSetAutoscaling(c echo.Context) error { content, err := mcis.SetAutoscaling(nsId, clusterId, nodeGroupName, u) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") mapA := map[string]string{"message": err.Error()} return c.JSON(http.StatusInternalServerError, &mapA) } @@ -222,7 +223,7 @@ func RestPutChangeAutoscaleSize(c echo.Context) error { content, err := mcis.ChangeAutoscaleSize(nsId, clusterId, nodeGroupName, u) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") mapA := map[string]string{"message": err.Error()} return c.JSON(http.StatusInternalServerError, &mapA) } @@ -330,7 +331,7 @@ func RestDeleteCluster(c echo.Context) error { res, err := mcis.DeleteCluster(nsId, clusterId, forceFlag) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") mapA := map[string]string{"message": err.Error()} return c.JSON(http.StatusInternalServerError, &mapA) } @@ -365,7 +366,7 @@ func RestDeleteAllCluster(c echo.Context) error { output, err := mcis.DeleteAllCluster(nsId, subString, forceFlag) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") mapA := map[string]string{"message": err.Error()} return c.JSON(http.StatusConflict, &mapA) } @@ -400,7 +401,7 @@ func RestPutUpgradeCluster(c echo.Context) error { content, err := mcis.UpgradeCluster(nsId, clusterId, u) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") mapA := map[string]string{"message": err.Error()} return c.JSON(http.StatusInternalServerError, &mapA) } diff --git a/src/api/rest/server/mcis/manageInfo.go b/src/api/rest/server/mcis/manageInfo.go index 8d1776b46..35b165877 100644 --- a/src/api/rest/server/mcis/manageInfo.go +++ b/src/api/rest/server/mcis/manageInfo.go @@ -21,6 +21,7 @@ import ( "github.com/cloud-barista/cb-tumblebug/src/core/common" "github.com/cloud-barista/cb-tumblebug/src/core/mcis" "github.com/labstack/echo/v4" + "github.com/rs/zerolog/log" ) // JSONResult is a dummy struct for Swagger annotations. @@ -316,7 +317,7 @@ func RestDelMcisVm(c echo.Context) error { err := mcis.DelMcisVm(nsId, mcisId, vmId, option) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") err := fmt.Errorf("Failed to delete the VM info") return common.EndRequestWithLog(c, reqID, err, nil) } diff --git a/src/core/common/client.go b/src/core/common/client.go index 1e2ecc95e..94cfa942f 100644 --- a/src/core/common/client.go +++ b/src/core/common/client.go @@ -25,6 +25,7 @@ import ( "github.com/go-resty/resty/v2" "github.com/labstack/echo/v4" + "github.com/rs/zerolog/log" ) // CacheItem is a struct to store cached item @@ -345,7 +346,7 @@ func ForwardRequestToAny(reqPath string, method string, requestBody interface{}) ) if err != nil { - CBLog.Error(err) + log.Error().Err(err).Msg("") return nil, err } diff --git a/src/core/common/config.go b/src/core/common/config.go index 25800393b..47fd606ca 100644 --- a/src/core/common/config.go +++ b/src/core/common/config.go @@ -23,6 +23,8 @@ import ( "github.com/jedib0t/go-pretty/v6/table" cbstore_utils "github.com/cloud-barista/cb-store/utils" + + "github.com/rs/zerolog/log" ) type CloudInfo struct { @@ -188,7 +190,7 @@ func UpdateConfig(u *ConfigReq) (ConfigInfo, error) { val, _ := json.Marshal(content) err := CBStore.Put(key, string(val)) if err != nil { - CBLog.Error(err) + log.Error().Err(err).Msg("") return content, err } keyValue, _ := CBStore.Get(key) @@ -205,7 +207,7 @@ func UpdateGlobalVariable(id string) error { configInfo, err := GetConfig(id) if err != nil { - //CBLog.Error(err) + //log.Error().Err(err).Msg("") return err } @@ -274,7 +276,7 @@ func InitConfig(id string) error { CBStore.Delete(key) // if err != nil { - // CBLog.Error(err) + // log.Error().Err(err).Msg("") // return err // } } @@ -296,7 +298,7 @@ func GetConfig(id string) (ConfigInfo, error) { if err != nil { temp := ConfigInfo{} - CBLog.Error(err) + log.Error().Err(err).Msg("") return temp, err } @@ -305,7 +307,7 @@ func GetConfig(id string) (ConfigInfo, error) { keyValue, err := CBStore.Get(key) if err != nil { - //CBLog.Error(err) + //log.Error().Err(err).Msg("") return res, err } @@ -313,7 +315,7 @@ func GetConfig(id string) (ConfigInfo, error) { err = json.Unmarshal([]byte(keyValue.Value), &res) if err != nil { - CBLog.Error(err) + log.Error().Err(err).Msg("") return res, err } return res, nil @@ -328,7 +330,7 @@ func ListConfig() ([]ConfigInfo, error) { keyValue = cbstore_utils.GetChildList(keyValue, key) if err != nil { - CBLog.Error(err) + log.Error().Err(err).Msg("") return nil, err } if keyValue != nil { @@ -337,7 +339,7 @@ func ListConfig() ([]ConfigInfo, error) { tempObj := ConfigInfo{} err = json.Unmarshal([]byte(v.Value), &tempObj) if err != nil { - CBLog.Error(err) + log.Error().Err(err).Msg("") return nil, err } res = append(res, tempObj) diff --git a/src/core/common/namespace.go b/src/core/common/namespace.go index 30284c427..96d702e75 100644 --- a/src/core/common/namespace.go +++ b/src/core/common/namespace.go @@ -24,6 +24,7 @@ import ( //"github.com/cloud-barista/cb-tumblebug/src/core/mcir" //"github.com/cloud-barista/cb-tumblebug/src/core/mcis" "github.com/labstack/echo/v4" + "github.com/rs/zerolog/log" cbstore_utils "github.com/cloud-barista/cb-store/utils" ) @@ -67,7 +68,7 @@ func CreateNs(u *NsReq) (NsInfo, error) { err := CheckString(u.Name) if err != nil { temp := NsInfo{} - CBLog.Error(err) + log.Error().Err(err).Msg("") return temp, err } @@ -81,7 +82,7 @@ func CreateNs(u *NsReq) (NsInfo, error) { if err != nil { temp := NsInfo{} - CBLog.Error(err) + log.Error().Err(err).Msg("") return temp, err } @@ -99,7 +100,7 @@ func CreateNs(u *NsReq) (NsInfo, error) { Val, _ := json.Marshal(content) err = CBStore.Put(Key, string(Val)) if err != nil { - CBLog.Error(err) + log.Error().Err(err).Msg("") return content, err } keyValue, _ := CBStore.Get(Key) @@ -117,7 +118,7 @@ func UpdateNs(id string, u *NsReq) (NsInfo, error) { err := CheckString(id) if err != nil { - CBLog.Error(err) + log.Error().Err(err).Msg("") return emptyInfo, err } check, err := CheckNs(id) @@ -129,20 +130,20 @@ func UpdateNs(id string, u *NsReq) (NsInfo, error) { } if err != nil { - CBLog.Error(err) + log.Error().Err(err).Msg("") return emptyInfo, err } key := "/ns/" + id keyValue, err := CBStore.Get(key) if err != nil { - CBLog.Error(err) + log.Error().Err(err).Msg("") return emptyInfo, err } err = json.Unmarshal([]byte(keyValue.Value), &res) if err != nil { - CBLog.Error(err) + log.Error().Err(err).Msg("") return emptyInfo, err } @@ -154,22 +155,22 @@ func UpdateNs(id string, u *NsReq) (NsInfo, error) { //mapA := map[string]string{"name": content.Name, "description": content.Description} Val, err := json.Marshal(res) if err != nil { - CBLog.Error(err) + log.Error().Err(err).Msg("") return emptyInfo, err } err = CBStore.Put(Key, string(Val)) if err != nil { - CBLog.Error(err) + log.Error().Err(err).Msg("") return emptyInfo, err } keyValue, err = CBStore.Get(Key) if err != nil { - CBLog.Error(err) + log.Error().Err(err).Msg("") return emptyInfo, err } err = json.Unmarshal([]byte(keyValue.Value), &res) if err != nil { - CBLog.Error(err) + log.Error().Err(err).Msg("") return emptyInfo, err } return res, nil @@ -182,7 +183,7 @@ func GetNs(id string) (NsInfo, error) { err := CheckString(id) if err != nil { temp := NsInfo{} - CBLog.Error(err) + log.Error().Err(err).Msg("") return temp, err } check, err := CheckNs(id) @@ -197,7 +198,7 @@ func GetNs(id string) (NsInfo, error) { if err != nil { temp := NsInfo{} - CBLog.Error(err) + log.Error().Err(err).Msg("") return temp, err } @@ -207,7 +208,7 @@ func GetNs(id string) (NsInfo, error) { keyValue, err := CBStore.Get(key) if err != nil { - CBLog.Error(err) + log.Error().Err(err).Msg("") return res, err } @@ -216,7 +217,7 @@ func GetNs(id string) (NsInfo, error) { err = json.Unmarshal([]byte(keyValue.Value), &res) if err != nil { - CBLog.Error(err) + log.Error().Err(err).Msg("") return res, err } return res, nil @@ -231,7 +232,7 @@ func ListNs() ([]NsInfo, error) { keyValue = cbstore_utils.GetChildList(keyValue, key) if err != nil { - CBLog.Error(err) + log.Error().Err(err).Msg("") return nil, err } if keyValue != nil { @@ -240,7 +241,7 @@ func ListNs() ([]NsInfo, error) { tempObj := NsInfo{} err = json.Unmarshal([]byte(v.Value), &tempObj) if err != nil { - CBLog.Error(err) + log.Error().Err(err).Msg("") return nil, err } res = append(res, tempObj) @@ -293,7 +294,7 @@ func ListNsId() ([]string, error) { keyValue = cbstore_utils.GetChildList(keyValue, key) if err != nil { - CBLog.Error(err) + log.Error().Err(err).Msg("") return nil, err } if keyValue != nil { @@ -312,7 +313,7 @@ func DelNs(id string) error { err := CheckString(id) if err != nil { - CBLog.Error(err) + log.Error().Err(err).Msg("") return err } @@ -325,7 +326,7 @@ func DelNs(id string) error { } if err != nil { - CBLog.Error(err) + log.Error().Err(err).Msg("") return err } @@ -362,14 +363,14 @@ func DelNs(id string) error { //errString += " \n len(vNicList): " + strconv.Itoa(len(vNicList)) err := fmt.Errorf(errString) - CBLog.Error(err) + log.Error().Err(err).Msg("") return err } // delete ns info err = CBStore.Delete(key) if err != nil { - CBLog.Error(err) + log.Error().Err(err).Msg("") return err } @@ -406,7 +407,7 @@ func CheckNs(id string) (bool, error) { err := CheckString(id) if err != nil { - CBLog.Error(err) + log.Error().Err(err).Msg("") return false, err } diff --git a/src/core/common/utility.go b/src/core/common/utility.go index 8f1f3dbc3..e88c159f5 100644 --- a/src/core/common/utility.go +++ b/src/core/common/utility.go @@ -26,6 +26,7 @@ import ( cbstore_utils "github.com/cloud-barista/cb-store/utils" uid "github.com/rs/xid" + "github.com/rs/zerolog/log" "gopkg.in/yaml.v2" @@ -249,11 +250,11 @@ func GetCspResourceId(nsId string, resourceType string, resourceId string) (stri } keyValue, err := CBStore.Get(key) if err != nil { - CBLog.Error(err) + log.Error().Err(err).Msg("") return "", err } if keyValue == nil { - //CBLog.Error(err) + //log.Error().Err(err).Msg("") // if there is no matched value for the key, return empty string. Error will be handled in a parent function return "", fmt.Errorf("cannot find the key " + key) } @@ -300,7 +301,7 @@ func GetCspResourceId(nsId string, resourceType string, resourceId string) (stri content := mcirIds{} err = json.Unmarshal([]byte(keyValue.Value), &content) if err != nil { - CBLog.Error(err) + log.Error().Err(err).Msg("") // if there is no matched value for the key, return empty string. Error will be handled in a parent function return "" } @@ -356,7 +357,7 @@ func GetCloudLocation(cloudType string, nativeRegion string) GeoLocation { keyValue, err := CBStore.Get(key) if err != nil { - CBLog.Error(err) + log.Error().Err(err).Msg("") return location } @@ -364,7 +365,7 @@ func GetCloudLocation(cloudType string, nativeRegion string) GeoLocation { file, fileErr := os.Open("../assets/cloudlocation.csv") defer file.Close() if fileErr != nil { - CBLog.Error(fileErr) + log.Error().Err(fileErr).Msg("") return location } @@ -380,7 +381,7 @@ func GetCloudLocation(cloudType string, nativeRegion string) GeoLocation { valLoc, _ := json.Marshal(location) dbErr := CBStore.Put(keyLoc, string(valLoc)) if dbErr != nil { - CBLog.Error(dbErr) + log.Error().Err(dbErr).Msg("") return location } for j := range row { @@ -390,7 +391,7 @@ func GetCloudLocation(cloudType string, nativeRegion string) GeoLocation { } keyValue, err = CBStore.Get(key) if err != nil { - CBLog.Error(err) + log.Error().Err(err).Msg("") return location } } @@ -399,7 +400,7 @@ func GetCloudLocation(cloudType string, nativeRegion string) GeoLocation { //fmt.Printf("[GetCloudLocation] %+v %+v\n", keyValue.Key, keyValue.Value) err = json.Unmarshal([]byte(keyValue.Value), &location) if err != nil { - CBLog.Error(err) + log.Error().Err(err).Msg("") return location } } @@ -420,7 +421,7 @@ func GetConnConfig(ConnConfigName string) (ConnConfig, error) { Get(url) if err != nil { - CBLog.Error(err) + log.Error().Err(err).Msg("") content := ConnConfig{} err := fmt.Errorf("an error occurred while requesting to CB-Spider") return content, err @@ -430,7 +431,7 @@ func GetConnConfig(ConnConfigName string) (ConnConfig, error) { case resp.StatusCode() >= 400 || resp.StatusCode() < 200: fmt.Println(" - HTTP Status: " + strconv.Itoa(resp.StatusCode()) + " in " + GetFuncName()) err := fmt.Errorf(string(resp.Body())) - CBLog.Error(err) + log.Error().Err(err).Msg("") content := ConnConfig{} return content, err } @@ -440,7 +441,7 @@ func GetConnConfig(ConnConfigName string) (ConnConfig, error) { // Get geolocation nativeRegion, err := GetNativeRegion(temp.ConfigName) if err != nil { - CBLog.Error(err) + log.Error().Err(err).Msg("") content := ConnConfig{} return content, err } @@ -478,7 +479,7 @@ func GetConnConfigList() (ConnConfigList, error) { ) if err != nil { - CBLog.Error(err) + log.Error().Err(err).Msg("") content := ConnConfigList{} return content, err } @@ -487,7 +488,7 @@ func GetConnConfigList() (ConnConfigList, error) { for i, connConfig := range callResult.Connectionconfig { nativeRegion, err := GetNativeRegion(connConfig.ConfigName) if err != nil { - CBLog.Error(err) + log.Error().Err(err).Msg("") content := ConnConfigList{} return content, err } @@ -520,7 +521,7 @@ func GetRegion(RegionName string) (Region, error) { Get(url) if err != nil { - CBLog.Error(err) + log.Error().Err(err).Msg("") content := Region{} err := fmt.Errorf("an error occurred while requesting to CB-Spider") return content, err @@ -530,7 +531,7 @@ func GetRegion(RegionName string) (Region, error) { case resp.StatusCode() >= 400 || resp.StatusCode() < 200: fmt.Println(" - HTTP Status: " + strconv.Itoa(resp.StatusCode()) + " in " + GetFuncName()) err := fmt.Errorf(string(resp.Body())) - CBLog.Error(err) + log.Error().Err(err).Msg("") content := Region{} return content, err } @@ -547,14 +548,14 @@ func GetNativeRegion(connectionName string) (string, error) { file, fileErr := os.Open("../assets/cloudconnection.csv") defer file.Close() if fileErr != nil { - CBLog.Error(fileErr) + log.Error().Err(fileErr).Msg("") return "", fileErr } rdr := csv.NewReader(bufio.NewReader(file)) rows, err := rdr.ReadAll() if err != nil { - CBLog.Error(err) + log.Error().Err(err).Msg("") return "", err } @@ -601,7 +602,7 @@ func GetRegionList() (RegionList, error) { Get(url) if err != nil { - CBLog.Error(err) + log.Error().Err(err).Msg("") content := RegionList{} err := fmt.Errorf("an error occurred while requesting to CB-Spider") return content, err @@ -611,7 +612,7 @@ func GetRegionList() (RegionList, error) { case resp.StatusCode() >= 400 || resp.StatusCode() < 200: fmt.Println(" - HTTP Status: " + strconv.Itoa(resp.StatusCode()) + " in " + GetFuncName()) err := fmt.Errorf(string(resp.Body())) - CBLog.Error(err) + log.Error().Err(err).Msg("") content := RegionList{} return content, err } @@ -756,7 +757,7 @@ func GetObjectValue(key string) (string, error) { keyValue, err := CBStore.Get(key) if err != nil { - CBLog.Error(err) + log.Error().Err(err).Msg("") return "", err } if keyValue == nil { @@ -770,7 +771,7 @@ func DeleteObject(key string) error { err := CBStore.Delete(key) if err != nil { - CBLog.Error(err) + log.Error().Err(err).Msg("") return err } return nil @@ -782,7 +783,7 @@ func DeleteObjects(key string) error { for _, v := range keyValue { err := CBStore.Delete(v.Key) if err != nil { - CBLog.Error(err) + log.Error().Err(err).Msg("") return err } } diff --git a/src/core/mcir/common.go b/src/core/mcir/common.go index 9805af8d3..4b1b1bf73 100644 --- a/src/core/mcir/common.go +++ b/src/core/mcir/common.go @@ -89,7 +89,7 @@ func DelAllResources(nsId string, resourceType string, subString string, forceFl err := common.CheckString(nsId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return deletedResources, err } @@ -101,7 +101,7 @@ func DelAllResources(nsId string, resourceType string, subString string, forceFl if len(resourceIdList) == 0 { errString := "There is no " + resourceType + " resource in " + nsId err := fmt.Errorf(errString) - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return deletedResources, err } @@ -129,19 +129,19 @@ func DelResource(nsId string, resourceType string, resourceId string, forceFlag err := common.CheckString(nsId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return err } err = common.CheckString(resourceId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return err } check, err := CheckResource(nsId, resourceType, resourceId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return err } @@ -165,7 +165,7 @@ func DelResource(nsId string, resourceType string, resourceId string, forceFlag } else { errString := " [Failed]" + " Associated with [" + strings.Join(associatedList[:], ", ") + "]" err := fmt.Errorf(errString) - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return err } */ @@ -187,7 +187,7 @@ func DelResource(nsId string, resourceType string, resourceId string, forceFlag // delete image info err := common.CBStore.Delete(key) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return err } @@ -204,7 +204,7 @@ func DelResource(nsId string, resourceType string, resourceId string, forceFlag temp := TbCustomImageInfo{} err = json.Unmarshal([]byte(keyValue.Value), &temp) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return err } requestBody.ConnectionName = temp.ConnectionName @@ -214,7 +214,7 @@ func DelResource(nsId string, resourceType string, resourceId string, forceFlag // delete image info err := common.CBStore.Delete(key) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return err } @@ -236,13 +236,13 @@ func DelResource(nsId string, resourceType string, resourceId string, forceFlag content := TbSpecInfo{} err := json.Unmarshal([]byte(keyValue.Value), &content) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return err } err = common.CBStore.Delete(key) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return err } @@ -259,7 +259,7 @@ func DelResource(nsId string, resourceType string, resourceId string, forceFlag temp := TbSshKeyInfo{} err = json.Unmarshal([]byte(keyValue.Value), &temp) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return err } requestBody.ConnectionName = temp.ConnectionName @@ -268,7 +268,7 @@ func DelResource(nsId string, resourceType string, resourceId string, forceFlag temp := TbVNetInfo{} err = json.Unmarshal([]byte(keyValue.Value), &temp) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return err } requestBody.ConnectionName = temp.ConnectionName @@ -278,7 +278,7 @@ func DelResource(nsId string, resourceType string, resourceId string, forceFlag temp := TbSecurityGroupInfo{} err = json.Unmarshal([]byte(keyValue.Value), &temp) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return err } requestBody.ConnectionName = temp.ConnectionName @@ -287,7 +287,7 @@ func DelResource(nsId string, resourceType string, resourceId string, forceFlag temp := TbDataDiskInfo{} err = json.Unmarshal([]byte(keyValue.Value), &temp) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return err } requestBody.ConnectionName = temp.ConnectionName @@ -333,7 +333,7 @@ func DelResource(nsId string, resourceType string, resourceId string, forceFlag ) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return err } @@ -345,7 +345,7 @@ func DelResource(nsId string, resourceType string, resourceId string, forceFlag // subnetKeys = append(subnetKeys, subnetKey) err = common.CBStore.Delete(subnetKey) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") // return err } } @@ -361,7 +361,7 @@ func DelResource(nsId string, resourceType string, resourceId string, forceFlag err = common.CBStore.Delete(key) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return err } return nil @@ -381,19 +381,19 @@ func DelChildResource(nsId string, resourceType string, parentResourceId string, err := common.CheckString(nsId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return err } err = common.CheckString(parentResourceId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return err } err = common.CheckString(resourceId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return err } @@ -406,7 +406,7 @@ func DelChildResource(nsId string, resourceType string, parentResourceId string, } if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return err } @@ -419,7 +419,7 @@ func DelChildResource(nsId string, resourceType string, parentResourceId string, } if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return err } @@ -446,7 +446,7 @@ func DelChildResource(nsId string, resourceType string, parentResourceId string, temp := TbVNetInfo{} err = json.Unmarshal([]byte(parentKeyValue.Value), &temp) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return err } requestBody.ConnectionName = temp.ConnectionName @@ -476,13 +476,13 @@ func DelChildResource(nsId string, resourceType string, parentResourceId string, ) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return err } err = common.CBStore.Delete(childResourceKey) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return err } @@ -492,7 +492,7 @@ func DelChildResource(nsId string, resourceType string, parentResourceId string, oldVNet := TbVNetInfo{} err = json.Unmarshal([]byte(parentKeyValue.Value), &oldVNet) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return err } @@ -512,13 +512,13 @@ func DelChildResource(nsId string, resourceType string, parentResourceId string, DelEleInSlice(&newVNet.SubnetInfoList, subnetIndex) } else { err := fmt.Errorf("Failed to find and delete subnet %s in vNet %s.", resourceId, parentResourceId) - common.CBLog.Error(err) + log.Error().Err(err).Msg("") } Val, _ := json.Marshal(newVNet) err = common.CBStore.Put(parentResourceKey, string(Val)) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return err } // default: @@ -545,7 +545,7 @@ func ListResourceId(nsId string, resourceType string) ([]string, error) { err := common.CheckString(nsId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return nil, err } @@ -562,7 +562,7 @@ func ListResourceId(nsId string, resourceType string) ([]string, error) { // continue } else { err = fmt.Errorf("invalid resource type") - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return nil, err } @@ -570,14 +570,14 @@ func ListResourceId(nsId string, resourceType string) ([]string, error) { keyValue, err := common.CBStore.GetList(key, true) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return nil, err } /* if keyValue == nil, then for-loop below will not be executed, and the empty array will be returned in `resourceList` placeholder. if keyValue == nil { err = fmt.Errorf("ListResourceId(); %s is empty.", key) - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return nil, err } */ @@ -600,7 +600,7 @@ func ListResource(nsId string, resourceType string, filterKey string, filterVal err := common.CheckString(nsId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return nil, err } @@ -629,7 +629,7 @@ func ListResource(nsId string, resourceType string, filterKey string, filterVal keyValue = cbstore_utils.GetChildList(keyValue, key) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return nil, err } if keyValue != nil { @@ -641,7 +641,7 @@ func ListResource(nsId string, resourceType string, filterKey string, filterVal tempObj := TbImageInfo{} err = json.Unmarshal([]byte(v.Value), &tempObj) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return nil, err } // Check the JSON body inclues both filterKey and filterVal strings. (assume key and value) @@ -662,7 +662,7 @@ func ListResource(nsId string, resourceType string, filterKey string, filterVal tempObj := TbCustomImageInfo{} err = json.Unmarshal([]byte(v.Value), &tempObj) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return nil, err } @@ -676,7 +676,7 @@ func ListResource(nsId string, resourceType string, filterKey string, filterVal tempObj.Id = tempObj.Id } if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") tempObj.Description = err.Error() tempObj.Status = "Error" } @@ -698,7 +698,7 @@ func ListResource(nsId string, resourceType string, filterKey string, filterVal tempObj := TbSecurityGroupInfo{} err = json.Unmarshal([]byte(v.Value), &tempObj) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return nil, err } // Check the JSON body inclues both filterKey and filterVal strings. (assume key and value) @@ -718,7 +718,7 @@ func ListResource(nsId string, resourceType string, filterKey string, filterVal tempObj := TbSpecInfo{} err = json.Unmarshal([]byte(v.Value), &tempObj) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return nil, err } // Check the JSON body inclues both filterKey and filterVal strings. (assume key and value) @@ -738,7 +738,7 @@ func ListResource(nsId string, resourceType string, filterKey string, filterVal tempObj := TbSshKeyInfo{} err = json.Unmarshal([]byte(v.Value), &tempObj) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return nil, err } // Check the JSON body inclues both filterKey and filterVal strings. (assume key and value) @@ -758,7 +758,7 @@ func ListResource(nsId string, resourceType string, filterKey string, filterVal tempObj := TbVNetInfo{} err = json.Unmarshal([]byte(v.Value), &tempObj) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return nil, err } // Check the JSON body inclues both filterKey and filterVal strings. (assume key and value) @@ -778,7 +778,7 @@ func ListResource(nsId string, resourceType string, filterKey string, filterVal tempObj := TbDataDiskInfo{} err = json.Unmarshal([]byte(v.Value), &tempObj) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return nil, err } @@ -786,7 +786,7 @@ func ListResource(nsId string, resourceType string, filterKey string, filterVal // Just calling GetResource(dataDisk) once will update TB DataDisk object's 'status' field newObj, err := GetResource(nsId, common.StrDataDisk, tempObj.Id) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") tempObj.Status = "Failed" tempObj.SystemMessage = err.Error() } else { @@ -834,13 +834,13 @@ func GetAssociatedObjectCount(nsId string, resourceType string, resourceId strin err := common.CheckString(nsId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return -1, err } err = common.CheckString(resourceId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return -1, err } check, err := CheckResource(nsId, resourceType, resourceId) @@ -852,7 +852,7 @@ func GetAssociatedObjectCount(nsId string, resourceType string, resourceId strin } if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return -1, err } @@ -860,7 +860,7 @@ func GetAssociatedObjectCount(nsId string, resourceType string, resourceId strin keyValue, err := common.CBStore.Get(key) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return -1, err } if keyValue != nil { @@ -879,13 +879,13 @@ func GetAssociatedObjectList(nsId string, resourceType string, resourceId string err := common.CheckString(nsId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return nil, err } err = common.CheckString(resourceId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return nil, err } check, err := CheckResource(nsId, resourceType, resourceId) @@ -897,7 +897,7 @@ func GetAssociatedObjectList(nsId string, resourceType string, resourceId string } if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return nil, err } @@ -905,7 +905,7 @@ func GetAssociatedObjectList(nsId string, resourceType string, resourceId string keyValue, err := common.CBStore.Get(key) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return nil, err } if keyValue != nil { @@ -916,7 +916,7 @@ func GetAssociatedObjectList(nsId string, resourceType string, resourceId string res := stringList{} err = json.Unmarshal([]byte(keyValue.Value), &res) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return nil, err } result = res.AssociatedObjectList @@ -933,13 +933,13 @@ func UpdateAssociatedObjectList(nsId string, resourceType string, resourceId str err := common.CheckString(nsId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return nil, err } err = common.CheckString(resourceId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return nil, err } /* @@ -952,7 +952,7 @@ func UpdateAssociatedObjectList(nsId string, resourceType string, resourceId str } if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return -1, err } */ @@ -962,7 +962,7 @@ func UpdateAssociatedObjectList(nsId string, resourceType string, resourceId str keyValue, err := common.CBStore.Get(key) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return nil, err } @@ -1010,19 +1010,19 @@ func UpdateAssociatedObjectList(nsId string, resourceType string, resourceId str } else { keyValue.Value, err = sjson.Delete(keyValue.Value, "associatedObjectList."+strconv.Itoa(foundKey)) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return nil, err } } } if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return nil, err } err = common.CBStore.Put(key, keyValue.Value) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return nil, err } @@ -1039,18 +1039,18 @@ func GetResource(nsId string, resourceType string, resourceId string) (interface err := common.CheckString(nsId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return nil, err } err = common.CheckString(resourceId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return nil, err } check, err := CheckResource(nsId, resourceType, resourceId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return nil, err } @@ -1066,7 +1066,7 @@ func GetResource(nsId string, resourceType string, resourceId string) (interface keyValue, err := common.CBStore.Get(key) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return nil, err } if keyValue != nil { @@ -1075,7 +1075,7 @@ func GetResource(nsId string, resourceType string, resourceId string) (interface res := TbImageInfo{} err = json.Unmarshal([]byte(keyValue.Value), &res) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return nil, err } return res, nil @@ -1083,7 +1083,7 @@ func GetResource(nsId string, resourceType string, resourceId string) (interface res := TbCustomImageInfo{} err = json.Unmarshal([]byte(keyValue.Value), &res) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return nil, err } @@ -1105,7 +1105,7 @@ func GetResource(nsId string, resourceType string, resourceId string) (interface resp, err := req.Get(url) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return nil, err } @@ -1114,7 +1114,7 @@ func GetResource(nsId string, resourceType string, resourceId string) (interface case resp.StatusCode() >= 400 || resp.StatusCode() < 200: err := fmt.Errorf(string(resp.Body())) fmt.Println("body: ", string(resp.Body())) - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return nil, err } @@ -1128,7 +1128,7 @@ func GetResource(nsId string, resourceType string, resourceId string) (interface res := TbSecurityGroupInfo{} err = json.Unmarshal([]byte(keyValue.Value), &res) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return nil, err } return res, nil @@ -1136,7 +1136,7 @@ func GetResource(nsId string, resourceType string, resourceId string) (interface res := TbSpecInfo{} err = json.Unmarshal([]byte(keyValue.Value), &res) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return nil, err } return res, nil @@ -1144,7 +1144,7 @@ func GetResource(nsId string, resourceType string, resourceId string) (interface res := TbSshKeyInfo{} err = json.Unmarshal([]byte(keyValue.Value), &res) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return nil, err } return res, nil @@ -1152,7 +1152,7 @@ func GetResource(nsId string, resourceType string, resourceId string) (interface res := TbVNetInfo{} err = json.Unmarshal([]byte(keyValue.Value), &res) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return nil, err } return res, nil @@ -1160,7 +1160,7 @@ func GetResource(nsId string, resourceType string, resourceId string) (interface res := TbDataDiskInfo{} err = json.Unmarshal([]byte(keyValue.Value), &res) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return res, err } @@ -1182,7 +1182,7 @@ func GetResource(nsId string, resourceType string, resourceId string) (interface resp, err := req.Get(url) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return res, err } @@ -1191,7 +1191,7 @@ func GetResource(nsId string, resourceType string, resourceId string) (interface case resp.StatusCode() >= 400 || resp.StatusCode() < 200: err := fmt.Errorf(string(resp.Body())) fmt.Println("body: ", string(resp.Body())) - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return res, err } @@ -1244,13 +1244,13 @@ func CheckResource(nsId string, resourceType string, resourceId string) (bool, e err := common.CheckString(nsId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return false, err } err = common.CheckString(resourceId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return false, err } @@ -1258,7 +1258,7 @@ func CheckResource(nsId string, resourceType string, resourceId string) (bool, e keyValue, err := common.CBStore.Get(key) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return false, err } if keyValue != nil { @@ -1298,19 +1298,19 @@ func CheckChildResource(nsId string, resourceType string, parentResourceId strin err := common.CheckString(nsId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return false, err } err = common.CheckString(parentResourceId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return false, err } err = common.CheckString(resourceId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return false, err } @@ -1321,7 +1321,7 @@ func CheckChildResource(nsId string, resourceType string, parentResourceId strin keyValue, err := common.CBStore.Get(key) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return false, err } if keyValue != nil { @@ -1407,7 +1407,7 @@ func LoadCommonResource() (common.IdList, error) { nsReq.Description = "Namespace for common resources" _, nsErr := common.CreateNs(&nsReq) if nsErr != nil { - common.CBLog.Error(nsErr) + log.Error().Err(nsErr).Msg("") return regiesteredIds, nsErr } } @@ -1416,7 +1416,7 @@ func LoadCommonResource() (common.IdList, error) { file, fileErr := os.Open("../assets/cloudspec.csv") defer file.Close() if fileErr != nil { - common.CBLog.Error(fileErr) + log.Error().Err(fileErr).Msg("") return regiesteredIds, fileErr } @@ -1468,7 +1468,7 @@ func LoadCommonResource() (common.IdList, error) { // Register Spec object _, err1 := RegisterSpecWithCspSpecName(common.SystemCommonNs, &specReqTmp) if err1 != nil { - common.CBLog.Error(err1) + log.Error().Err(err1).Msg("") // If already exist, error will occur // Even if error, do not return here to update information // return err @@ -1485,14 +1485,14 @@ func LoadCommonResource() (common.IdList, error) { // Update registered Spec object with Cost info costPerHour, err2 := strconv.ParseFloat(strings.ReplaceAll(row[4], " ", ""), 32) if err2 != nil { - common.CBLog.Error(err2) + log.Error().Err(err2).Msg("") // If already exist, error will occur. Even if error, do not return here to update information // return err } evaluationScore01, err2 := strconv.ParseFloat(strings.ReplaceAll(row[5], " ", ""), 32) if err2 != nil { - common.CBLog.Error(err2) + log.Error().Err(err2).Msg("") // If already exist, error will occur. Even if error, do not return here to update information // return err } @@ -1509,7 +1509,7 @@ func LoadCommonResource() (common.IdList, error) { updatedSpecInfo, err3 := UpdateSpec(common.SystemCommonNs, specObjId, specUpdateRequest) if err3 != nil { - common.CBLog.Error(err3) + log.Error().Err(err3).Msg("") // If already exist, error will occur // Even if error, do not return here to update information // return err @@ -1541,7 +1541,7 @@ func LoadCommonResource() (common.IdList, error) { file, fileErr = os.Open("../assets/cloudimage.csv") defer file.Close() if fileErr != nil { - common.CBLog.Error(fileErr) + log.Error().Err(fileErr).Msg("") return regiesteredIds, fileErr } @@ -1580,7 +1580,7 @@ func LoadCommonResource() (common.IdList, error) { // Register Spec object _, err1 := RegisterImageWithId(common.SystemCommonNs, &imageReqTmp) if err1 != nil { - common.CBLog.Error(err1) + log.Error().Err(err1).Msg("") // If already exist, error will occur // Even if error, do not return here to update information //return err @@ -1593,7 +1593,7 @@ func LoadCommonResource() (common.IdList, error) { updatedImageInfo, err2 := UpdateImage(common.SystemCommonNs, imageObjId, imageUpdateRequest) if err2 != nil { - common.CBLog.Error(err2) + log.Error().Err(err2).Msg("") //return err } fmt.Printf("[%d] Registered Common Image\n", i) @@ -1629,7 +1629,7 @@ func LoadDefaultResource(nsId string, resType string, connectionName string) err // Check 'nsId' namespace. _, err := common.GetNs(nsId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return err } @@ -1647,14 +1647,14 @@ func LoadDefaultResource(nsId string, resType string, connectionName string) err file, fileErr := os.Open("../assets/cloudconnection.csv") defer file.Close() if fileErr != nil { - common.CBLog.Error(fileErr) + log.Error().Err(fileErr).Msg("") return fileErr } rdr := csv.NewReader(bufio.NewReader(file)) rows, err := rdr.ReadAll() if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return err } @@ -1801,7 +1801,7 @@ func DelAllDefaultResources(nsId string) (common.IdList, error) { output := common.IdList{} err := common.CheckString(nsId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return output, err } @@ -1809,21 +1809,21 @@ func DelAllDefaultResources(nsId string) (common.IdList, error) { list, err := DelAllResources(nsId, common.StrSecurityGroup, matchedSubstring, "false") if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") output.IdList = append(output.IdList, err.Error()) } output.IdList = append(output.IdList, list.IdList...) list, err = DelAllResources(nsId, common.StrSSHKey, matchedSubstring, "false") if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") output.IdList = append(output.IdList, err.Error()) } output.IdList = append(output.IdList, list.IdList...) list, err = DelAllResources(nsId, common.StrVNet, matchedSubstring, "false") if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") output.IdList = append(output.IdList, err.Error()) } output.IdList = append(output.IdList, list.IdList...) @@ -1869,18 +1869,18 @@ func UpdateResourceObject(nsId string, resourceType string, resourceObject inter oldJSON := keyValue.Value newJSON, err := json.Marshal(resourceObject) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") } isEqualJSON, err := AreEqualJSON(oldJSON, string(newJSON)) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") } if !isEqualJSON { err = common.CBStore.Put(key, string(newJSON)) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") } } */ @@ -1889,14 +1889,14 @@ func UpdateResourceObject(nsId string, resourceType string, resourceObject inter var oldObject interface{} err = json.Unmarshal([]byte(keyValue.Value), &oldObject) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") } if !reflect.DeepEqual(oldObject, resourceObject) { val, _ := json.Marshal(resourceObject) err = common.CBStore.Put(key, string(val)) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") } } diff --git a/src/core/mcir/customimage.go b/src/core/mcir/customimage.go index 448f3d218..7bf060e6e 100644 --- a/src/core/mcir/customimage.go +++ b/src/core/mcir/customimage.go @@ -23,6 +23,7 @@ import ( "github.com/cloud-barista/cb-tumblebug/src/core/common" validator "github.com/go-playground/validator/v10" "github.com/go-resty/resty/v2" + "github.com/rs/zerolog/log" ) type CustomImageStatus string @@ -109,12 +110,12 @@ func RegisterCustomImageWithInfo(nsId string, content TbCustomImageInfo) (TbCust err := common.CheckString(nsId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return TbCustomImageInfo{}, err } err = common.CheckString(content.Name) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return TbCustomImageInfo{}, err } check, err := CheckResource(nsId, resourceType, content.Name) @@ -138,7 +139,7 @@ func RegisterCustomImageWithInfo(nsId string, content TbCustomImageInfo) (TbCust Val, _ := json.Marshal(content) err = common.CBStore.Put(Key, string(Val)) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return TbCustomImageInfo{}, err } keyValue, err := common.CBStore.Get(Key) @@ -164,11 +165,11 @@ func LookupMyImage(connConfig string, myImageId string) (SpiderMyImageInfo, erro if connConfig == "" { err := fmt.Errorf("LookupMyImage() called with empty connConfig.") - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return SpiderMyImageInfo{}, err } else if myImageId == "" { err := fmt.Errorf("LookupMyImage() called with empty myImageId.") - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return SpiderMyImageInfo{}, err } @@ -192,7 +193,7 @@ func LookupMyImage(connConfig string, myImageId string) (SpiderMyImageInfo, erro ) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") content := SpiderMyImageInfo{} return content, err } @@ -237,7 +238,7 @@ func RegisterCustomImageWithId(nsId string, u *TbCustomImageReq) (TbCustomImageI err := common.CheckString(nsId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return TbCustomImageInfo{}, err } @@ -299,7 +300,7 @@ func RegisterCustomImageWithId(nsId string, u *TbCustomImageReq) (TbCustomImageI ) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return TbCustomImageInfo{}, err } @@ -330,7 +331,7 @@ func RegisterCustomImageWithId(nsId string, u *TbCustomImageReq) (TbCustomImageI Val, _ := json.Marshal(content) err = common.CBStore.Put(Key, string(Val)) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return content, err } return content, nil diff --git a/src/core/mcir/datadisk.go b/src/core/mcir/datadisk.go index e3b5f552b..dbaf744fd 100644 --- a/src/core/mcir/datadisk.go +++ b/src/core/mcir/datadisk.go @@ -21,6 +21,7 @@ import ( "time" "github.com/go-resty/resty/v2" + "github.com/rs/zerolog/log" "github.com/cloud-barista/cb-tumblebug/src/core/common" @@ -154,7 +155,7 @@ func CreateDataDisk(nsId string, u *TbDataDiskReq, option string) (TbDataDiskInf err := common.CheckString(nsId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return TbDataDiskInfo{}, err } @@ -219,7 +220,7 @@ func CreateDataDisk(nsId string, u *TbDataDiskReq, option string) (TbDataDiskInf } if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") err := fmt.Errorf("an error occurred while requesting to CB-Spider") return TbDataDiskInfo{}, err } @@ -229,7 +230,7 @@ func CreateDataDisk(nsId string, u *TbDataDiskReq, option string) (TbDataDiskInf case resp.StatusCode() >= 400 || resp.StatusCode() < 200: err := fmt.Errorf(string(resp.Body())) fmt.Println("body: ", string(resp.Body())) - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return TbDataDiskInfo{}, err } @@ -265,7 +266,7 @@ func CreateDataDisk(nsId string, u *TbDataDiskReq, option string) (TbDataDiskInf Val, _ := json.Marshal(content) err = common.CBStore.Put(Key, string(Val)) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return content, err } return content, nil @@ -284,7 +285,7 @@ func UpsizeDataDisk(nsId string, resourceId string, u *TbDataDiskUpsizeReq) (TbD err := common.CheckString(nsId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return TbDataDiskInfo{}, err } @@ -353,7 +354,7 @@ func UpsizeDataDisk(nsId string, resourceId string, u *TbDataDiskUpsizeReq) (TbD resp, err = req.Put(url) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") err := fmt.Errorf("an error occurred while requesting to CB-Spider") return TbDataDiskInfo{}, err } @@ -363,7 +364,7 @@ func UpsizeDataDisk(nsId string, resourceId string, u *TbDataDiskUpsizeReq) (TbD case resp.StatusCode() >= 400 || resp.StatusCode() < 200: err := fmt.Errorf(string(resp.Body())) fmt.Println("body: ", string(resp.Body())) - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return TbDataDiskInfo{}, err } @@ -385,7 +386,7 @@ func UpsizeDataDisk(nsId string, resourceId string, u *TbDataDiskUpsizeReq) (TbD Val, _ := json.Marshal(content) err = common.CBStore.Put(Key, string(Val)) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return content, err } return content, nil diff --git a/src/core/mcir/firewallrule.go b/src/core/mcir/firewallrule.go index a6f48333b..17e7fac17 100644 --- a/src/core/mcir/firewallrule.go +++ b/src/core/mcir/firewallrule.go @@ -24,6 +24,7 @@ import ( "github.com/cloud-barista/cb-tumblebug/src/core/common" validator "github.com/go-playground/validator/v10" "github.com/go-resty/resty/v2" + "github.com/rs/zerolog/log" ) // CreateFirewallRules accepts firewallRule creation request, creates and returns an TB securityGroup object @@ -33,14 +34,14 @@ func CreateFirewallRules(nsId string, securityGroupId string, req []TbFirewallRu err := common.CheckString(nsId) if err != nil { temp := TbSecurityGroupInfo{} - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return temp, err } err = common.CheckString(securityGroupId) if err != nil { temp := TbSecurityGroupInfo{} - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return temp, err } @@ -84,7 +85,7 @@ func CreateFirewallRules(nsId string, securityGroupId string, req []TbFirewallRu oldSecurityGroup := TbSecurityGroupInfo{} err = json.Unmarshal([]byte(securityGroupKeyValue.Value), &oldSecurityGroup) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return oldSecurityGroup, err } @@ -122,7 +123,7 @@ func CreateFirewallRules(nsId string, securityGroupId string, req []TbFirewallRu Post(url) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") content := TbSecurityGroupInfo{} err := fmt.Errorf("an error occurred while requesting to CB-Spider") return content, err @@ -132,7 +133,7 @@ func CreateFirewallRules(nsId string, securityGroupId string, req []TbFirewallRu switch { case resp.StatusCode() >= 400 || resp.StatusCode() < 200: err := fmt.Errorf(string(resp.Body())) - common.CBLog.Error(err) + log.Error().Err(err).Msg("") content := TbSecurityGroupInfo{} return content, err } @@ -155,7 +156,7 @@ func CreateFirewallRules(nsId string, securityGroupId string, req []TbFirewallRu err = common.CBStore.Put(securityGroupKey, string(Val)) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return oldSecurityGroup, err } @@ -166,7 +167,7 @@ func CreateFirewallRules(nsId string, securityGroupId string, req []TbFirewallRu // content := TbSecurityGroupInfo{} // err = json.Unmarshal([]byte(keyValue.Value), &content) // if err != nil { - // common.CBLog.Error(err) + // log.Error().Err(err).Msg("") // return err // } return newSecurityGroup, nil @@ -178,14 +179,14 @@ func DeleteFirewallRules(nsId string, securityGroupId string, req []TbFirewallRu err := common.CheckString(nsId) if err != nil { temp := TbSecurityGroupInfo{} - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return temp, err } err = common.CheckString(securityGroupId) if err != nil { temp := TbSecurityGroupInfo{} - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return temp, err } @@ -229,7 +230,7 @@ func DeleteFirewallRules(nsId string, securityGroupId string, req []TbFirewallRu oldSecurityGroup := TbSecurityGroupInfo{} err = json.Unmarshal([]byte(securityGroupKeyValue.Value), &oldSecurityGroup) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return oldSecurityGroup, err } @@ -262,7 +263,7 @@ func DeleteFirewallRules(nsId string, securityGroupId string, req []TbFirewallRu if found_flag == false { err := fmt.Errorf("Any of submitted firewall rules does not exist in the SG %s.", securityGroupId) - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return oldSecurityGroup, err } else { for _, v := range rulesToDelete { @@ -282,7 +283,7 @@ func DeleteFirewallRules(nsId string, securityGroupId string, req []TbFirewallRu Delete(url) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") content := TbSecurityGroupInfo{} err := fmt.Errorf("an error occurred while requesting to CB-Spider") return content, err @@ -292,7 +293,7 @@ func DeleteFirewallRules(nsId string, securityGroupId string, req []TbFirewallRu switch { case resp.StatusCode() >= 400 || resp.StatusCode() < 200: err := fmt.Errorf(string(resp.Body())) - common.CBLog.Error(err) + log.Error().Err(err).Msg("") content := TbSecurityGroupInfo{} return content, err } @@ -301,7 +302,7 @@ func DeleteFirewallRules(nsId string, securityGroupId string, req []TbFirewallRu if spiderDeleteSecurityRulesResp.Result != "true" { err := fmt.Errorf("Failed to delete Security Group rules with CB-Spider.") - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return oldSecurityGroup, err } @@ -323,7 +324,7 @@ func DeleteFirewallRules(nsId string, securityGroupId string, req []TbFirewallRu Get(url) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") content := TbSecurityGroupInfo{} err := fmt.Errorf("an error occurred while requesting to CB-Spider") return content, err @@ -333,7 +334,7 @@ func DeleteFirewallRules(nsId string, securityGroupId string, req []TbFirewallRu switch { case resp.StatusCode() >= 400 || resp.StatusCode() < 200: err := fmt.Errorf(string(resp.Body())) - common.CBLog.Error(err) + log.Error().Err(err).Msg("") content := TbSecurityGroupInfo{} return content, err } @@ -353,7 +354,7 @@ func DeleteFirewallRules(nsId string, securityGroupId string, req []TbFirewallRu err = common.CBStore.Put(securityGroupKey, string(Val)) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return oldSecurityGroup, err } @@ -364,7 +365,7 @@ func DeleteFirewallRules(nsId string, securityGroupId string, req []TbFirewallRu // content := TbSecurityGroupInfo{} // err = json.Unmarshal([]byte(keyValue.Value), &content) // if err != nil { - // common.CBLog.Error(err) + // log.Error().Err(err).Msg("") // return err // } return newSecurityGroup, nil diff --git a/src/core/mcir/image.go b/src/core/mcir/image.go index a55a6fa16..a0f258f31 100644 --- a/src/core/mcir/image.go +++ b/src/core/mcir/image.go @@ -22,6 +22,7 @@ import ( "time" "github.com/go-resty/resty/v2" + "github.com/rs/zerolog/log" "github.com/cloud-barista/cb-tumblebug/src/core/common" @@ -123,7 +124,7 @@ func RegisterImageWithId(nsId string, u *TbImageReq) (TbImageInfo, error) { err := common.CheckString(nsId) if err != nil { temp := TbImageInfo{} - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return temp, err } @@ -156,7 +157,7 @@ func RegisterImageWithId(nsId string, u *TbImageReq) (TbImageInfo, error) { res, err := LookupImage(u.ConnectionName, u.CspImageId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") //err := fmt.Errorf("an error occurred while lookup image via CB-Spider") emptyImageInfoObj := TbImageInfo{} return emptyImageInfoObj, err @@ -164,7 +165,7 @@ func RegisterImageWithId(nsId string, u *TbImageReq) (TbImageInfo, error) { content, err := ConvertSpiderImageToTumblebugImage(res) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") //err := fmt.Errorf("an error occurred while converting Spider image info to Tumblebug image info.") emptyImageInfoObj := TbImageInfo{} return emptyImageInfoObj, err @@ -181,7 +182,7 @@ func RegisterImageWithId(nsId string, u *TbImageReq) (TbImageInfo, error) { Val, _ := json.Marshal(content) err = common.CBStore.Put(Key, string(Val)) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return content, err } keyValue, err := common.CBStore.Get(Key) @@ -209,12 +210,12 @@ func RegisterImageWithInfo(nsId string, content *TbImageInfo) (TbImageInfo, erro err := common.CheckString(nsId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return TbImageInfo{}, err } err = common.CheckString(content.Name) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return TbImageInfo{}, err } check, err := CheckResource(nsId, resourceType, content.Name) @@ -239,7 +240,7 @@ func RegisterImageWithInfo(nsId string, content *TbImageInfo) (TbImageInfo, erro Val, _ := json.Marshal(content) err = common.CBStore.Put(Key, string(Val)) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return TbImageInfo{}, err } keyValue, err := common.CBStore.Get(Key) @@ -273,7 +274,7 @@ func LookupImageList(connConfig string) (SpiderImageList, error) { if connConfig == "" { content := SpiderImageList{} err := fmt.Errorf("LookupImage() called with empty connConfig.") - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return content, err } @@ -294,7 +295,7 @@ func LookupImageList(connConfig string) (SpiderImageList, error) { Get(url) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") content := SpiderImageList{} err := fmt.Errorf("an error occurred while requesting to CB-Spider") return content, err @@ -306,7 +307,7 @@ func LookupImageList(connConfig string) (SpiderImageList, error) { switch { case resp.StatusCode() >= 400 || resp.StatusCode() < 200: err := fmt.Errorf(string(resp.Body())) - common.CBLog.Error(err) + log.Error().Err(err).Msg("") content := SpiderImageList{} return content, err } @@ -322,12 +323,12 @@ func LookupImage(connConfig string, imageId string) (SpiderImageInfo, error) { if connConfig == "" { content := SpiderImageInfo{} err := fmt.Errorf("LookupImage() called with empty connConfig.") - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return content, err } else if imageId == "" { content := SpiderImageInfo{} err := fmt.Errorf("LookupImage() called with empty imageId.") - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return content, err } @@ -348,7 +349,7 @@ func LookupImage(connConfig string, imageId string) (SpiderImageInfo, error) { Get(url) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") content := SpiderImageInfo{} err := fmt.Errorf("an error occurred while requesting to CB-Spider") return content, err @@ -360,7 +361,7 @@ func LookupImage(connConfig string, imageId string) (SpiderImageInfo, error) { switch { case resp.StatusCode() >= 400 || resp.StatusCode() < 200: err := fmt.Errorf(string(resp.Body())) - common.CBLog.Error(err) + log.Error().Err(err).Msg("") content := SpiderImageInfo{} return content, err } @@ -376,14 +377,14 @@ func FetchImagesForConnConfig(connConfig string, nsId string) (imageCount uint, spiderImageList, err := LookupImageList(connConfig) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return 0, err } for _, spiderImage := range spiderImageList.Image { tumblebugImage, err := ConvertSpiderImageToTumblebugImage(spiderImage) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return 0, err } @@ -391,10 +392,10 @@ func FetchImagesForConnConfig(connConfig string, nsId string) (imageCount uint, check, err := CheckResource(nsId, common.StrImage, tumblebugImageId) if check { - common.CBLog.Infoln("The image " + tumblebugImageId + " already exists in TB; continue") + log.Info().Msgf("The image %s already exists in TB; continue", tumblebugImageId) continue } else if err != nil { - common.CBLog.Infoln("Cannot check the existence of " + tumblebugImageId + " in TB; continue") + log.Info().Msgf("Cannot check the existence of %s in TB; continue", tumblebugImageId) continue } else { tumblebugImage.Name = tumblebugImageId @@ -402,7 +403,7 @@ func FetchImagesForConnConfig(connConfig string, nsId string) (imageCount uint, _, err := RegisterImageWithInfo(nsId, &tumblebugImage) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return 0, err } imageCount++ @@ -416,13 +417,13 @@ func FetchImagesForAllConnConfigs(nsId string) (connConfigCount uint, imageCount err = common.CheckString(nsId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return 0, 0, err } connConfigs, err := common.GetConnConfigList() if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return 0, 0, err } @@ -439,7 +440,7 @@ func SearchImage(nsId string, keywords ...string) ([]TbImageInfo, error) { err := common.CheckString(nsId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return nil, err } @@ -456,7 +457,7 @@ func SearchImage(nsId string, keywords ...string) ([]TbImageInfo, error) { err = sqlQuery.Find(&tempList) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return tempList, err } return tempList, nil @@ -470,21 +471,21 @@ func UpdateImage(nsId string, imageId string, fieldsToUpdate TbImageInfo) (TbIma err := common.CheckString(nsId) if err != nil { temp := TbImageInfo{} - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return temp, err } if len(fieldsToUpdate.Namespace) > 0 { temp := TbImageInfo{} err := fmt.Errorf("You should not specify 'namespace' in the JSON request body.") - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return temp, err } if len(fieldsToUpdate.Id) > 0 { temp := TbImageInfo{} err := fmt.Errorf("You should not specify 'id' in the JSON request body.") - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return temp, err } @@ -492,7 +493,7 @@ func UpdateImage(nsId string, imageId string, fieldsToUpdate TbImageInfo) (TbIma if err != nil { temp := TbImageInfo{} - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return temp, err } @@ -528,14 +529,14 @@ func UpdateImage(nsId string, imageId string, fieldsToUpdate TbImageInfo) (TbIma err = common.CBStore.Put(Key, string(Val)) if err != nil { temp := TbImageInfo{} - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return temp, err } keyValue, err := common.CBStore.Get(Key) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") err = fmt.Errorf("In UpdateImage(); CBStore.Get() returned an error.") - common.CBLog.Error(err) + log.Error().Err(err).Msg("") // return nil, err } diff --git a/src/core/mcir/securitygroup.go b/src/core/mcir/securitygroup.go index bc796c848..64111c6ad 100644 --- a/src/core/mcir/securitygroup.go +++ b/src/core/mcir/securitygroup.go @@ -22,6 +22,7 @@ import ( "github.com/cloud-barista/cb-tumblebug/src/core/common" validator "github.com/go-playground/validator/v10" "github.com/go-resty/resty/v2" + "github.com/rs/zerolog/log" ) // SpiderSecurityReqInfoWrapper is a wrapper struct to create JSON body of 'Create security group request' @@ -129,7 +130,7 @@ func CreateSecurityGroup(nsId string, u *TbSecurityGroupReq, option string) (TbS err := common.CheckString(nsId) if err != nil { temp := TbSecurityGroupInfo{} - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return temp, err } @@ -177,7 +178,7 @@ func CreateSecurityGroup(nsId string, u *TbSecurityGroupReq, option string) (TbS return temp, err } if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") content := TbSecurityGroupInfo{} err := fmt.Errorf("Cannot create securityGroup") return content, err @@ -190,7 +191,7 @@ func CreateSecurityGroup(nsId string, u *TbSecurityGroupReq, option string) (TbS resourceList, err := ListResource(nsId, common.StrVNet, "", "") if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") err := fmt.Errorf("Cannot list vNet Ids for securityGroup") return TbSecurityGroupInfo{}, err } @@ -203,7 +204,7 @@ func CreateSecurityGroup(nsId string, u *TbSecurityGroupReq, option string) (TbS if len(content.VNet) == 0 { errString := "There is no " + common.StrVNet + " resource in " + nsId err := fmt.Errorf(errString) - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return TbSecurityGroupInfo{}, err } @@ -238,13 +239,13 @@ func CreateSecurityGroup(nsId string, u *TbSecurityGroupReq, option string) (TbS for _, v := range *u.FirewallRules { jsonBody, err := json.Marshal(v) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") } spiderSecurityRuleInfo := SpiderSecurityRuleInfo{} err = json.Unmarshal(jsonBody, &spiderSecurityRuleInfo) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") } requestBody.ReqInfo.SecurityRules = append(requestBody.ReqInfo.SecurityRules, spiderSecurityRuleInfo) @@ -277,7 +278,7 @@ func CreateSecurityGroup(nsId string, u *TbSecurityGroupReq, option string) (TbS } if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") content := TbSecurityGroupInfo{} err := fmt.Errorf("an error occurred while requesting to CB-Spider") return content, err @@ -287,7 +288,7 @@ func CreateSecurityGroup(nsId string, u *TbSecurityGroupReq, option string) (TbS switch { case resp.StatusCode() >= 400 || resp.StatusCode() < 200: err := fmt.Errorf(string(resp.Body())) - common.CBLog.Error(err) + log.Error().Err(err).Msg("") content := TbSecurityGroupInfo{} return content, err } @@ -325,15 +326,15 @@ func CreateSecurityGroup(nsId string, u *TbSecurityGroupReq, option string) (TbS Val, _ := json.Marshal(content) err = common.CBStore.Put(Key, string(Val)) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return content, err } keyValue, err := common.CBStore.Get(Key) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") err = fmt.Errorf("In CreateSecurityGroup(); CBStore.Get() returned an error.") - common.CBLog.Error(err) + log.Error().Err(err).Msg("") // return nil, err } diff --git a/src/core/mcir/spec.go b/src/core/mcir/spec.go index 4e19dece4..a408c9c58 100644 --- a/src/core/mcir/spec.go +++ b/src/core/mcir/spec.go @@ -27,6 +27,7 @@ import ( "github.com/cloud-barista/cb-tumblebug/src/core/common" validator "github.com/go-playground/validator/v10" "github.com/go-resty/resty/v2" + "github.com/rs/zerolog/log" //"github.com/cloud-barista/cb-tumblebug/src/core/mcis" @@ -197,7 +198,7 @@ func LookupSpecList(connConfig string) (SpiderSpecList, error) { if connConfig == "" { content := SpiderSpecList{} err := fmt.Errorf("LookupSpec() called with empty connConfig.") - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return content, err } @@ -221,7 +222,7 @@ func LookupSpecList(connConfig string) (SpiderSpecList, error) { ) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") content := SpiderSpecList{} return content, err } @@ -237,12 +238,12 @@ func LookupSpec(connConfig string, specName string) (SpiderSpecInfo, error) { if connConfig == "" { content := SpiderSpecInfo{} err := fmt.Errorf("LookupSpec() called with empty connConfig.") - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return content, err } else if specName == "" { content := SpiderSpecInfo{} err := fmt.Errorf("LookupSpec() called with empty specName.") - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return content, err } @@ -266,7 +267,7 @@ func LookupSpec(connConfig string, specName string) (SpiderSpecInfo, error) { ) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return callResult, err } @@ -279,14 +280,14 @@ func FetchSpecsForConnConfig(connConfig string, nsId string) (specCount uint, er spiderSpecList, err := LookupSpecList(connConfig) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return 0, err } for _, spiderSpec := range spiderSpecList.Vmspec { tumblebugSpec, err := ConvertSpiderSpecToTumblebugSpec(spiderSpec) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return 0, err } @@ -294,10 +295,10 @@ func FetchSpecsForConnConfig(connConfig string, nsId string) (specCount uint, er check, err := CheckResource(nsId, common.StrSpec, tumblebugSpecId) if check { - common.CBLog.Infoln("The spec " + tumblebugSpecId + " already exists in TB; continue") + log.Info().Msgf("The spec %s already exists in TB; continue", tumblebugSpecId) continue } else if err != nil { - common.CBLog.Infoln("Cannot check the existence of " + tumblebugSpecId + " in TB; continue") + log.Info().Msgf("Cannot check the existence of %s in TB; continue", tumblebugSpecId) continue } else { tumblebugSpec.Name = tumblebugSpecId @@ -305,7 +306,7 @@ func FetchSpecsForConnConfig(connConfig string, nsId string) (specCount uint, er _, err := RegisterSpecWithInfo(nsId, &tumblebugSpec) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return 0, err } specCount++ @@ -319,13 +320,13 @@ func FetchSpecsForAllConnConfigs(nsId string) (connConfigCount uint, specCount u err = common.CheckString(nsId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return 0, 0, err } connConfigs, err := common.GetConnConfigList() if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return 0, 0, err } @@ -345,7 +346,7 @@ func RegisterSpecWithCspSpecName(nsId string, u *TbSpecReq) (TbSpecInfo, error) err := common.CheckString(nsId) if err != nil { temp := TbSpecInfo{} - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return temp, err } @@ -366,7 +367,7 @@ func RegisterSpecWithCspSpecName(nsId string, u *TbSpecReq) (TbSpecInfo, error) if err != nil { temp := TbSpecInfo{} - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return temp, err } @@ -378,7 +379,7 @@ func RegisterSpecWithCspSpecName(nsId string, u *TbSpecReq) (TbSpecInfo, error) res, err := LookupSpec(u.ConnectionName, u.CspSpecName) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") err := fmt.Errorf("Error duing lookup spec from CB-Spider: " + err.Error()) emptySpecInfoObj := TbSpecInfo{} return emptySpecInfoObj, err @@ -410,7 +411,7 @@ func RegisterSpecWithCspSpecName(nsId string, u *TbSpecReq) (TbSpecInfo, error) Val, _ := json.Marshal(content) err = common.CBStore.Put(Key, string(Val)) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return content, err } keyValue, err := common.CBStore.Get(Key) @@ -439,20 +440,20 @@ func RegisterSpecWithInfo(nsId string, content *TbSpecInfo) (TbSpecInfo, error) err := common.CheckString(nsId) if err != nil { temp := TbSpecInfo{} - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return temp, err } err = common.CheckString(content.Name) if err != nil { temp := TbSpecInfo{} - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return temp, err } check, err := CheckResource(nsId, resourceType, content.Name) if err != nil { temp := TbSpecInfo{} - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return temp, err } @@ -472,7 +473,7 @@ func RegisterSpecWithInfo(nsId string, content *TbSpecInfo) (TbSpecInfo, error) Val, _ := json.Marshal(content) err = common.CBStore.Put(Key, string(Val)) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return *content, err } keyValue, err := common.CBStore.Get(Key) @@ -499,7 +500,7 @@ func FilterSpecs(nsId string, filter TbSpecInfo) ([]TbSpecInfo, error) { err := common.CheckString(nsId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return nil, err } @@ -655,7 +656,7 @@ func FilterSpecs(nsId string, filter TbSpecInfo) ([]TbSpecInfo, error) { err = sqlQuery.Find(&tempList) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return tempList, err } return tempList, nil @@ -672,7 +673,7 @@ func FilterSpecsByRange(nsId string, filter FilterSpecsByRangeRequest) ([]TbSpec err := common.CheckString(nsId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return nil, err } @@ -944,7 +945,7 @@ func FilterSpecsByRange(nsId string, filter FilterSpecsByRangeRequest) ([]TbSpec err = sqlQuery.Find(&tempList) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return tempList, err } @@ -1095,21 +1096,21 @@ func UpdateSpec(nsId string, specId string, fieldsToUpdate TbSpecInfo) (TbSpecIn err := common.CheckString(nsId) if err != nil { temp := TbSpecInfo{} - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return temp, err } if len(fieldsToUpdate.Namespace) > 0 { temp := TbSpecInfo{} err := fmt.Errorf("You should not specify 'namespace' in the JSON request body.") - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return temp, err } if len(fieldsToUpdate.Id) > 0 { temp := TbSpecInfo{} err := fmt.Errorf("You should not specify 'id' in the JSON request body.") - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return temp, err } @@ -1117,7 +1118,7 @@ func UpdateSpec(nsId string, specId string, fieldsToUpdate TbSpecInfo) (TbSpecIn if err != nil { temp := TbSpecInfo{} - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return temp, err } @@ -1153,14 +1154,14 @@ func UpdateSpec(nsId string, specId string, fieldsToUpdate TbSpecInfo) (TbSpecIn err = common.CBStore.Put(Key, string(Val)) if err != nil { temp := TbSpecInfo{} - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return temp, err } keyValue, err := common.CBStore.Get(Key) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") err = fmt.Errorf("In UpdateSpec(); CBStore.Get() returned an error.") - common.CBLog.Error(err) + log.Error().Err(err).Msg("") // return nil, err } diff --git a/src/core/mcir/sshkey.go b/src/core/mcir/sshkey.go index 30b622f34..cd44b8408 100644 --- a/src/core/mcir/sshkey.go +++ b/src/core/mcir/sshkey.go @@ -21,6 +21,7 @@ import ( "github.com/cloud-barista/cb-tumblebug/src/core/common" validator "github.com/go-playground/validator/v10" "github.com/go-resty/resty/v2" + "github.com/rs/zerolog/log" ) // SpiderKeyPairReqInfoWrapper is a wrapper struct to create JSON body of 'Create keypair request' @@ -107,7 +108,7 @@ func CreateSshKey(nsId string, u *TbSshKeyReq, option string) (TbSshKeyInfo, err err := common.CheckString(nsId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return emptyObj, err } @@ -180,7 +181,7 @@ func CreateSshKey(nsId string, u *TbSshKeyReq, option string) (TbSshKeyInfo, err } if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") err := fmt.Errorf("an error occurred while requesting to CB-Spider") return emptyObj, err } @@ -190,7 +191,7 @@ func CreateSshKey(nsId string, u *TbSshKeyReq, option string) (TbSshKeyInfo, err case resp.StatusCode() >= 400 || resp.StatusCode() < 200: err := fmt.Errorf(string(resp.Body())) fmt.Println("body: ", string(resp.Body())) - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return emptyObj, err } @@ -232,7 +233,7 @@ func CreateSshKey(nsId string, u *TbSshKeyReq, option string) (TbSshKeyInfo, err Val, _ := json.Marshal(content) err = common.CBStore.Put(Key, string(Val)) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return content, err } return content, nil @@ -248,20 +249,20 @@ func UpdateSshKey(nsId string, sshKeyId string, fieldsToUpdate TbSshKeyInfo) (Tb err := common.CheckString(nsId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return emptyObj, err } if len(fieldsToUpdate.Id) > 0 { err := fmt.Errorf("You should not specify 'id' in the JSON request body.") - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return emptyObj, err } check, err := CheckResource(nsId, resourceType, sshKeyId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return emptyObj, err } @@ -293,14 +294,14 @@ func UpdateSshKey(nsId string, sshKeyId string, fieldsToUpdate TbSshKeyInfo) (Tb Val, _ := json.Marshal(toBeSshKey) err = common.CBStore.Put(Key, string(Val)) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return emptyObj, err } keyValue, err := common.CBStore.Get(Key) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") err = fmt.Errorf("In UpdateSshKey(); CBStore.Get() returned an error.") - common.CBLog.Error(err) + log.Error().Err(err).Msg("") // return nil, err } diff --git a/src/core/mcir/subnet.go b/src/core/mcir/subnet.go index 678428519..8a29e0f6d 100644 --- a/src/core/mcir/subnet.go +++ b/src/core/mcir/subnet.go @@ -22,6 +22,7 @@ import ( "github.com/cloud-barista/cb-tumblebug/src/core/common" validator "github.com/go-playground/validator/v10" "github.com/go-resty/resty/v2" + "github.com/rs/zerolog/log" ) // CreateSubnet accepts subnet creation request, creates and returns an TB vNet object @@ -30,14 +31,14 @@ func CreateSubnet(nsId string, vNetId string, req TbSubnetReq, objectOnly bool) err := common.CheckString(nsId) if err != nil { temp := TbVNetInfo{} - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return temp, err } err = common.CheckString(vNetId) if err != nil { temp := TbVNetInfo{} - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return temp, err } @@ -89,7 +90,7 @@ func CreateSubnet(nsId string, vNetId string, req TbSubnetReq, objectOnly bool) oldVNet := TbVNetInfo{} err = json.Unmarshal([]byte(vNetKeyValue.Value), &oldVNet) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return oldVNet, err } @@ -111,7 +112,7 @@ func CreateSubnet(nsId string, vNetId string, req TbSubnetReq, objectOnly bool) Post(url) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") content := TbVNetInfo{} err := fmt.Errorf("an error occurred while requesting to CB-Spider") return content, err @@ -121,7 +122,7 @@ func CreateSubnet(nsId string, vNetId string, req TbSubnetReq, objectOnly bool) switch { case resp.StatusCode() >= 400 || resp.StatusCode() < 200: err := fmt.Errorf(string(resp.Body())) - common.CBLog.Error(err) + log.Error().Err(err).Msg("") content := TbVNetInfo{} return content, err } @@ -136,7 +137,7 @@ func CreateSubnet(nsId string, vNetId string, req TbSubnetReq, objectOnly bool) err = common.CBStore.Put(SubnetKey, string(Val)) if err != nil { temp := TbVNetInfo{} - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return temp, err } @@ -145,13 +146,13 @@ func CreateSubnet(nsId string, vNetId string, req TbSubnetReq, objectOnly bool) jsonBody, err := json.Marshal(req) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") } tbSubnetInfo := TbSubnetInfo{} err = json.Unmarshal(jsonBody, &tbSubnetInfo) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") } tbSubnetInfo.Id = req.Name tbSubnetInfo.Name = req.Name @@ -161,7 +162,7 @@ func CreateSubnet(nsId string, vNetId string, req TbSubnetReq, objectOnly bool) err = common.CBStore.Put(vNetKey, string(Val)) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return oldVNet, err } diff --git a/src/core/mcir/vnet.go b/src/core/mcir/vnet.go index 683d7f1f3..dd812442f 100644 --- a/src/core/mcir/vnet.go +++ b/src/core/mcir/vnet.go @@ -21,6 +21,7 @@ import ( "github.com/cloud-barista/cb-tumblebug/src/core/common" validator "github.com/go-playground/validator/v10" "github.com/go-resty/resty/v2" + "github.com/rs/zerolog/log" ) // 2020-04-09 https://github.com/cloud-barista/cb-spider/blob/master/cloud-control-manager/cloud-driver/interfaces/resources/VPCHandler.go @@ -156,7 +157,7 @@ func CreateVNet(nsId string, u *TbVNetReq, option string) (TbVNetInfo, error) { err := common.CheckString(nsId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return temp, err } @@ -192,13 +193,13 @@ func CreateVNet(nsId string, u *TbVNetReq, option string) (TbVNetInfo, error) { for _, v := range u.SubnetInfoList { jsonBody, err := json.Marshal(v) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") } spiderSubnetInfo := SpiderSubnetReqInfo{} err = json.Unmarshal(jsonBody, &spiderSubnetInfo) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") } requestBody.ReqInfo.SubnetInfoList = append(requestBody.ReqInfo.SubnetInfoList, spiderSubnetInfo) @@ -229,7 +230,7 @@ func CreateVNet(nsId string, u *TbVNetReq, option string) (TbVNetInfo, error) { common.MediumDuration, ) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return temp, err } @@ -257,34 +258,34 @@ func CreateVNet(nsId string, u *TbVNetReq, option string) (TbVNetInfo, error) { err = common.CBStore.Put(Key, string(Val)) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return content, err } for _, v := range callResult.SubnetInfoList { jsonBody, err := json.Marshal(v) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") } tbSubnetReq := TbSubnetReq{} err = json.Unmarshal(jsonBody, &tbSubnetReq) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") } tbSubnetReq.Name = v.IId.NameId _, err = CreateSubnet(nsId, content.Id, tbSubnetReq, true) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") } } keyValue, err := common.CBStore.Get(Key) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") err = fmt.Errorf("In CreateVNet(); CBStore.Get() returned an error.") - common.CBLog.Error(err) + log.Error().Err(err).Msg("") // return nil, err } @@ -294,7 +295,7 @@ func CreateVNet(nsId string, u *TbVNetReq, option string) (TbVNetInfo, error) { result := TbVNetInfo{} err = json.Unmarshal([]byte(keyValue.Value), &result) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") } return result, nil } diff --git a/src/core/mcis/benchmark.go b/src/core/mcis/benchmark.go index 863496dc0..6d30b5f15 100644 --- a/src/core/mcis/benchmark.go +++ b/src/core/mcis/benchmark.go @@ -35,6 +35,7 @@ import ( "github.com/cloud-barista/cb-tumblebug/src/core/common" "github.com/cloud-barista/cb-tumblebug/src/core/mcir" + "github.com/rs/zerolog/log" ) // SpecBenchmarkInfo is struct for SpecBenchmarkInfo @@ -112,7 +113,7 @@ func InstallBenchmarkAgentToMcis(nsId string, mcisId string, req *McisCmdReq, op if err != nil { temp := []SshCmdResult{} - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return temp, err } @@ -147,7 +148,7 @@ func CallMilkyway(wg *sync.WaitGroup, vmList []string, nsId string, mcisId strin vmIdTmp := vm vmIpTmp, _, _, err := GetVmIp(nsId, mcisId, vmIdTmp) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") } fmt.Println("[Test for vmList " + vmIdTmp + ", " + vmIpTmp + "]") @@ -170,12 +171,12 @@ func CallMilkyway(wg *sync.WaitGroup, vmList []string, nsId string, mcisId strin res, err := client.Do(req) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") errStr = err.Error() } else { body, err := ioutil.ReadAll(res.Body) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") errStr = err.Error() } defer res.Body.Close() @@ -185,7 +186,7 @@ func CallMilkyway(wg *sync.WaitGroup, vmList []string, nsId string, mcisId strin switch { case res.StatusCode >= 400 || res.StatusCode < 200: err := fmt.Errorf(string(body)) - common.CBLog.Error(err) + log.Error().Err(err).Msg("") errStr = err.Error() } @@ -193,7 +194,7 @@ func CallMilkyway(wg *sync.WaitGroup, vmList []string, nsId string, mcisId strin err2 := json.Unmarshal(body, &resultTmp) if err2 != nil { - common.CBLog.Error(err2) + log.Error().Err(err2).Msg("") errStr = err2.Error() } } @@ -212,14 +213,14 @@ func RunAllBenchmarks(nsId string, mcisId string, host string) (*BenchmarkInfoAr err = common.CheckString(nsId) if err != nil { temp := BenchmarkInfoArray{} - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return &temp, err } err = common.CheckString(mcisId) if err != nil { temp := BenchmarkInfoArray{} - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return &temp, err } check, _ := CheckMcis(nsId, mcisId) @@ -420,14 +421,14 @@ func RunLatencyBenchmark(nsId string, mcisId string, host string) (*BenchmarkInf err = common.CheckString(nsId) if err != nil { temp := BenchmarkInfoArray{} - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return &temp, err } err = common.CheckString(mcisId) if err != nil { temp := BenchmarkInfoArray{} - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return &temp, err } check, _ := CheckMcis(nsId, mcisId) @@ -560,14 +561,14 @@ func CoreGetBenchmark(nsId string, mcisId string, action string, host string) (* err = common.CheckString(nsId) if err != nil { temp := BenchmarkInfoArray{} - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return &temp, err } err = common.CheckString(mcisId) if err != nil { temp := BenchmarkInfoArray{} - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return &temp, err } check, _ := CheckMcis(nsId, mcisId) @@ -610,7 +611,7 @@ func BenchmarkAction(nsId string, mcisId string, action string, option string) ( vmList, err := ListVmId(nsId, mcisId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return BenchmarkInfoArray{}, err } @@ -622,7 +623,7 @@ func BenchmarkAction(nsId string, mcisId string, action string, option string) ( vmIp, _, _, err := GetVmIp(nsId, mcisId, vmId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") wg.Done() // continue to next vm even if error occurs } else { diff --git a/src/core/mcis/cluster.go b/src/core/mcis/cluster.go index 842e09fd1..49608d3b6 100644 --- a/src/core/mcis/cluster.go +++ b/src/core/mcis/cluster.go @@ -26,6 +26,7 @@ import ( "github.com/cloud-barista/cb-tumblebug/src/core/mcir" validator "github.com/go-playground/validator/v10" "github.com/go-resty/resty/v2" + "github.com/rs/zerolog/log" ) // 2023-11-13 https://github.com/cloud-barista/cb-spider/blob/fa4bd91fdaa6bb853ea96eca4a7b4f58a2abebf2/cloud-control-manager/cloud-driver/interfaces/resources/ClusterHandler.go#L1 @@ -416,13 +417,13 @@ func CreateCluster(nsId string, u *TbClusterReq, option string) (TbClusterInfo, /* err := common.CheckString(nsId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return emptyObj, err } err = common.CheckString(u.Id) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return emptyObj, err } */ @@ -438,7 +439,7 @@ func CreateCluster(nsId string, u *TbClusterReq, option string) (TbClusterInfo, check, err := CheckCluster(nsId, u.Id) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return emptyObj, err } @@ -493,7 +494,7 @@ func CreateCluster(nsId string, u *TbClusterReq, option string) (TbClusterInfo, spVPCName, err := common.GetCspResourceId(nsId, common.StrVNet, u.VNetId) if spVPCName == "" { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return emptyObj, err } @@ -502,7 +503,7 @@ func CreateCluster(nsId string, u *TbClusterReq, option string) (TbClusterInfo, for _, v := range u.SubnetIds { spSnName, err := common.GetCspResourceId(nsId, common.StrSubnet, v) if spSnName == "" { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return emptyObj, err } @@ -516,13 +517,13 @@ func CreateCluster(nsId string, u *TbClusterReq, option string) (TbClusterInfo, tmpInf, err := mcir.GetResource(nsId, common.StrVNet, u.VNetId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return emptyObj, err } tbVNetInfo := mcir.TbVNetInfo{} err = common.CopySrcToDest(&tmpInf, &tbVNetInfo) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return emptyObj, err } @@ -549,7 +550,7 @@ func CreateCluster(nsId string, u *TbClusterReq, option string) (TbClusterInfo, for _, v := range u.SecurityGroupIds { spSgName, err := common.GetCspResourceId(nsId, common.StrSecurityGroup, v) if spSgName == "" { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return emptyObj, err } @@ -560,7 +561,7 @@ func CreateCluster(nsId string, u *TbClusterReq, option string) (TbClusterInfo, for _, v := range u.NodeGroupList { err := common.CheckString(v.Name) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return emptyObj, err } @@ -568,20 +569,20 @@ func CreateCluster(nsId string, u *TbClusterReq, option string) (TbClusterInfo, if v.ImageId != "" { spImgName, err = common.GetCspResourceId(nsId, common.StrImage, v.ImageId) if spImgName == "" { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return emptyObj, err } } spSpecName, err := common.GetCspResourceId(nsId, common.StrSpec, v.SpecId) if spSpecName == "" { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return emptyObj, err } spKpName, err := common.GetCspResourceId(nsId, common.StrSSHKey, v.SshKeyId) if spKpName == "" { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return emptyObj, err } @@ -640,7 +641,7 @@ func CreateCluster(nsId string, u *TbClusterReq, option string) (TbClusterInfo, ) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return emptyObj, err } @@ -665,14 +666,14 @@ func CreateCluster(nsId string, u *TbClusterReq, option string) (TbClusterInfo, err = common.CBStore.Put(k, string(Val)) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return tbCInfo, err } kv, err := common.CBStore.Get(k) if err != nil { err = fmt.Errorf("In CreateCluster(); CBStore.Get() returned an error: " + err.Error()) - common.CBLog.Error(err) + log.Error().Err(err).Msg("") } fmt.Println("<" + kv.Key + "> \n" + kv.Value) @@ -681,7 +682,7 @@ func CreateCluster(nsId string, u *TbClusterReq, option string) (TbClusterInfo, storedTbCInfo := TbClusterInfo{} err = json.Unmarshal([]byte(kv.Value), &storedTbCInfo) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") } return storedTbCInfo, nil } @@ -694,13 +695,13 @@ func AddNodeGroup(nsId string, clusterId string, u *TbNodeGroupReq) (TbClusterIn /* err := common.CheckString(nsId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return emptyObj, err } err = common.CheckString(clusterId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return emptyObj, err } */ @@ -716,7 +717,7 @@ func AddNodeGroup(nsId string, clusterId string, u *TbNodeGroupReq) (TbClusterIn check, err := CheckCluster(nsId, clusterId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return emptyObj, err } @@ -733,7 +734,7 @@ func AddNodeGroup(nsId string, clusterId string, u *TbNodeGroupReq) (TbClusterIn kv, err := common.CBStore.Get(k) if err != nil { err = fmt.Errorf("In AddNodeGroup(); CBStore.Get() returned an error: " + err.Error()) - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return emptyObj, err } @@ -742,7 +743,7 @@ func AddNodeGroup(nsId string, clusterId string, u *TbNodeGroupReq) (TbClusterIn err = json.Unmarshal([]byte(kv.Value), &oldTbCInfo) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return emptyObj, err } @@ -790,7 +791,7 @@ func AddNodeGroup(nsId string, clusterId string, u *TbNodeGroupReq) (TbClusterIn spName := u.Name err = common.CheckString(spName) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return emptyObj, err } @@ -798,20 +799,20 @@ func AddNodeGroup(nsId string, clusterId string, u *TbNodeGroupReq) (TbClusterIn if u.ImageId != "" { spImgName, err = common.GetCspResourceId(nsId, common.StrImage, u.ImageId) if spImgName == "" { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return emptyObj, err } } spSpecName, err := common.GetCspResourceId(nsId, common.StrSpec, u.SpecId) if spSpecName == "" { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return emptyObj, err } spKpName, err := common.GetCspResourceId(nsId, common.StrSSHKey, u.SshKeyId) if spKpName == "" { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return emptyObj, err } @@ -854,7 +855,7 @@ func AddNodeGroup(nsId string, clusterId string, u *TbNodeGroupReq) (TbClusterIn ) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return emptyObj, err } @@ -872,14 +873,14 @@ func AddNodeGroup(nsId string, clusterId string, u *TbNodeGroupReq) (TbClusterIn err = common.CBStore.Put(k, string(Val)) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return newTbCInfo, err } kv, err = common.CBStore.Get(k) if err != nil { err = fmt.Errorf("In AddNodeGroup(); CBStore.Get() returned an error: " + err.Error()) - common.CBLog.Error(err) + log.Error().Err(err).Msg("") // return nil, err } @@ -889,7 +890,7 @@ func AddNodeGroup(nsId string, clusterId string, u *TbNodeGroupReq) (TbClusterIn storedTbCInfo := TbClusterInfo{} err = json.Unmarshal([]byte(kv.Value), &storedTbCInfo) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") } return storedTbCInfo, nil @@ -901,20 +902,20 @@ func RemoveNodeGroup(nsId string, clusterId string, nodeGroupName string, forceF /* err := common.CheckString(nsId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return err } err = common.CheckString(clusterId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return err } */ check, err := CheckCluster(nsId, clusterId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return false, err } @@ -938,7 +939,7 @@ func RemoveNodeGroup(nsId string, clusterId string, nodeGroupName string, forceF tbCInfo := TbClusterInfo{} err = json.Unmarshal([]byte(kv.Value), &tbCInfo) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return false, err } @@ -965,7 +966,7 @@ func RemoveNodeGroup(nsId string, clusterId string, nodeGroupName string, forceF ) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return false, err } @@ -987,20 +988,20 @@ func SetAutoscaling(nsId string, clusterId string, nodeGroupName string, u *TbSe /* err := common.CheckString(nsId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return err } err = common.CheckString(clusterId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return err } */ check, err := CheckCluster(nsId, clusterId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return false, err } @@ -1011,7 +1012,7 @@ func SetAutoscaling(nsId string, clusterId string, nodeGroupName string, u *TbSe err = common.CheckString(nodeGroupName) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return false, err } @@ -1027,7 +1028,7 @@ func SetAutoscaling(nsId string, clusterId string, nodeGroupName string, u *TbSe tbCInfo := TbClusterInfo{} err = json.Unmarshal([]byte(kv.Value), &tbCInfo) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return false, err } @@ -1055,7 +1056,7 @@ func SetAutoscaling(nsId string, clusterId string, nodeGroupName string, u *TbSe ) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return false, err } @@ -1070,20 +1071,20 @@ func ChangeAutoscaleSize(nsId string, clusterId string, nodeGroupName string, u /* err := common.CheckString(nsId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return err } err = common.CheckString(clusterId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return err } */ check, err := CheckCluster(nsId, clusterId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return emptyObj, err } @@ -1094,7 +1095,7 @@ func ChangeAutoscaleSize(nsId string, clusterId string, nodeGroupName string, u err = common.CheckString(nodeGroupName) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return emptyObj, err } @@ -1110,7 +1111,7 @@ func ChangeAutoscaleSize(nsId string, clusterId string, nodeGroupName string, u tbCInfo := TbClusterInfo{} err = json.Unmarshal([]byte(kv.Value), &tbCInfo) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return emptyObj, err } @@ -1140,7 +1141,7 @@ func ChangeAutoscaleSize(nsId string, clusterId string, nodeGroupName string, u ) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return emptyObj, err } @@ -1157,19 +1158,19 @@ func GetCluster(nsId string, clusterId string) (TbClusterInfo, error) { /* err := common.CheckString(nsId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return emptyObj, err } err = common.CheckString(clusterId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return emptyObj, err } */ check, err := CheckCluster(nsId, clusterId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return emptyObj, err } @@ -1187,7 +1188,7 @@ func GetCluster(nsId string, clusterId string) (TbClusterInfo, error) { kv, err := common.CBStore.Get(k) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return emptyObj, err } @@ -1199,7 +1200,7 @@ func GetCluster(nsId string, clusterId string) (TbClusterInfo, error) { err = json.Unmarshal([]byte(kv.Value), &storedTbCInfo) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return storedTbCInfo, err } @@ -1235,7 +1236,7 @@ func GetCluster(nsId string, clusterId string) (TbClusterInfo, error) { ) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return emptyObj, err } @@ -1286,13 +1287,13 @@ func CheckCluster(nsId string, clusterId string) (bool, error) { err := common.CheckString(nsId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return false, err } err = common.CheckString(clusterId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return false, err } @@ -1302,7 +1303,7 @@ func CheckCluster(nsId string, clusterId string) (bool, error) { keyValue, err := common.CBStore.Get(key) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return false, err } if keyValue != nil { @@ -1315,13 +1316,13 @@ func CheckCluster(nsId string, clusterId string) (bool, error) { func GenClusterKey(nsId string, clusterId string) string { err := common.CheckString(nsId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return "/invalidKey" } err = common.CheckString(clusterId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return "/invalidKey" } @@ -1333,7 +1334,7 @@ func ListClusterId(nsId string) ([]string, error) { err := common.CheckString(nsId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return nil, err } @@ -1345,14 +1346,14 @@ func ListClusterId(nsId string) ([]string, error) { kv, err := common.CBStore.GetList(k, true) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return nil, err } /* if keyValue == nil, then for-loop below will not be executed, and the empty array will be returned in `resourceList` placeholder. if keyValue == nil { err = fmt.Errorf("ListResourceId(); %s is empty.", key) - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return nil, err } */ @@ -1375,7 +1376,7 @@ func ListCluster(nsId string, filterKey string, filterVal string) (interface{}, err := common.CheckString(nsId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return nil, err } @@ -1391,7 +1392,7 @@ func ListCluster(nsId string, filterKey string, filterVal string) (interface{}, kv = cbstore_utils.GetChildList(kv, k) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return nil, err } @@ -1402,7 +1403,7 @@ func ListCluster(nsId string, filterKey string, filterVal string) (interface{}, tbCInfo := TbClusterInfo{} err = json.Unmarshal([]byte(v.Value), &tbCInfo) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return nil, err } // Check the JSON body includes both filterKey and filterVal strings. (assume key and value) @@ -1427,20 +1428,20 @@ func DeleteCluster(nsId string, clusterId string, forceFlag string) (bool, error /* err := common.CheckString(nsId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return err } err = common.CheckString(clusterId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return err } */ check, err := CheckCluster(nsId, clusterId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return false, err } @@ -1468,7 +1469,7 @@ func DeleteCluster(nsId string, clusterId string, forceFlag string) (bool, error tbCInfo := TbClusterInfo{} err = json.Unmarshal([]byte(kv.Value), &tbCInfo) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return false, err } @@ -1497,13 +1498,13 @@ func DeleteCluster(nsId string, clusterId string, forceFlag string) (bool, error if forceFlag == "true" { err = common.CBStore.Delete(k) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return false, err } } if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return false, err } @@ -1514,7 +1515,7 @@ func DeleteCluster(nsId string, clusterId string, forceFlag string) (bool, error if forceFlag != "true" { err = common.CBStore.Delete(k) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return false, err } } @@ -1535,7 +1536,7 @@ func DeleteAllCluster(nsId string, subString string, forceFlag string) (common.I err := common.CheckString(nsId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return deletedClusters, err } @@ -1581,7 +1582,7 @@ func UpgradeCluster(nsId string, clusterId string, u *TbUpgradeClusterReq) (TbCl check, err := CheckCluster(nsId, clusterId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return emptyObj, err } @@ -1598,7 +1599,7 @@ func UpgradeCluster(nsId string, clusterId string, u *TbUpgradeClusterReq) (TbCl kv, err := common.CBStore.Get(k) if err != nil { err = fmt.Errorf("In UpgradeCluster(); CBStore.Get() returned an error: " + err.Error()) - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return emptyObj, err } @@ -1607,7 +1608,7 @@ func UpgradeCluster(nsId string, clusterId string, u *TbUpgradeClusterReq) (TbCl err = json.Unmarshal([]byte(kv.Value), &oldTbCInfo) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return emptyObj, err } @@ -1676,7 +1677,7 @@ func UpgradeCluster(nsId string, clusterId string, u *TbUpgradeClusterReq) (TbCl ) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return emptyObj, err } @@ -1694,14 +1695,14 @@ func UpgradeCluster(nsId string, clusterId string, u *TbUpgradeClusterReq) (TbCl err = common.CBStore.Put(k, string(Val)) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return emptyObj, err } kv, err = common.CBStore.Get(k) if err != nil { err = fmt.Errorf("In UpgradeCluster(); CBStore.Get() returned an error: " + err.Error()) - common.CBLog.Error(err) + log.Error().Err(err).Msg("") // return nil, err } @@ -1711,7 +1712,7 @@ func UpgradeCluster(nsId string, clusterId string, u *TbUpgradeClusterReq) (TbCl storedTbCInfo := TbClusterInfo{} err = json.Unmarshal([]byte(kv.Value), &storedTbCInfo) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") } return storedTbCInfo, nil diff --git a/src/core/mcis/control.go b/src/core/mcis/control.go index 8ffb60879..85d5c3078 100644 --- a/src/core/mcis/control.go +++ b/src/core/mcis/control.go @@ -34,6 +34,7 @@ import ( "github.com/cloud-barista/cb-tumblebug/src/core/common" "github.com/cloud-barista/cb-tumblebug/src/core/mcir" "github.com/go-resty/resty/v2" + "github.com/rs/zerolog/log" ) // MCIS Control @@ -56,13 +57,13 @@ func HandleMcisAction(nsId string, mcisId string, action string, force bool) (st err := common.CheckString(nsId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return "", err } err = common.CheckString(mcisId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return "", err } check, _ := CheckMcis(nsId, mcisId) @@ -108,7 +109,7 @@ func HandleMcisAction(nsId string, mcisId string, action string, force bool) (st vmList, err := ListVmId(nsId, mcisId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return "", err } @@ -128,7 +129,7 @@ func HandleMcisAction(nsId string, mcisId string, action string, force bool) (st vmList, err := ListVmId(nsId, mcisId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return "", err } @@ -138,7 +139,7 @@ func HandleMcisAction(nsId string, mcisId string, action string, force bool) (st mcisStatus, err := GetMcisStatus(nsId, mcisId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return "", err } @@ -150,7 +151,7 @@ func HandleMcisAction(nsId string, mcisId string, action string, force bool) (st // Delete VM sequentially for safety (for performance, need to use goroutine) err := DelMcisVm(nsId, mcisId, v.Id, "force") if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return "", err } } @@ -168,19 +169,19 @@ func HandleMcisVmAction(nsId string, mcisId string, vmId string, action string, err := common.CheckString(nsId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return "", err } err = common.CheckString(mcisId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return "", err } err = common.CheckString(vmId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return "", err } check, _ := CheckVm(nsId, mcisId, vmId) @@ -194,7 +195,7 @@ func HandleMcisVmAction(nsId string, mcisId string, vmId string, action string, mcis, err := GetMcisStatus(nsId, mcisId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return "", err } @@ -202,7 +203,7 @@ func HandleMcisVmAction(nsId string, mcisId string, vmId string, action string, if mcis.TargetAction != "" && mcis.TargetAction != ActionComplete { err = fmt.Errorf("MCIS %s is under %s, please try later", mcisId, mcis.TargetAction) if !force { - common.CBLog.Info(err) + log.Info().Msg(err.Error()) return "", err } } @@ -210,7 +211,7 @@ func HandleMcisVmAction(nsId string, mcisId string, vmId string, action string, err = CheckAllowedTransition(nsId, mcisId, common.OptionalParameter{Set: true, Value: vmId}, action) if err != nil { if !force { - common.CBLog.Info(err) + log.Info().Msg(err.Error()) return "", err } } @@ -244,7 +245,7 @@ func ControlMcisAsync(nsId string, mcisId string, action string, force bool) err mcis, err := GetMcisObject(nsId, mcisId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return err } @@ -252,7 +253,7 @@ func ControlMcisAsync(nsId string, mcisId string, action string, force bool) err if mcis.TargetAction != "" && mcis.TargetAction != ActionComplete { err = fmt.Errorf("MCIS %s is under %s, please try later", mcisId, mcis.TargetAction) if !force { - common.CBLog.Info(err) + log.Info().Msg(err.Error()) return err } } @@ -266,7 +267,7 @@ func ControlMcisAsync(nsId string, mcisId string, action string, force bool) err vmList, err := ListVmId(nsId, mcisId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return err } if len(vmList) == 0 { @@ -399,7 +400,7 @@ func ControlVmAsync(wg *sync.WaitGroup, nsId string, mcisId string, vmId string, // Remove Bastion Info from all vNets if the terminating VM is a Bastion _, err := RemoveBastionNodes(nsId, mcisId, vmId) if err != nil { - common.CBLog.Info(err) + log.Info().Msg(err.Error()) } case ActionReboot: @@ -451,7 +452,7 @@ func ControlVmAsync(wg *sync.WaitGroup, nsId string, mcisId string, vmId string, common.MediumDuration, ) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") temp.Status = StatusFailed temp.SystemMessage = err.Error() UpdateVmInfo(nsId, mcisId, temp) @@ -512,7 +513,7 @@ func CheckAllowedTransition(nsId string, mcisId string, vmId common.OptionalPara if vmId.Set { vm, err := GetMcisVmStatus(nsId, mcisId, vmId.Value) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return err } @@ -544,7 +545,7 @@ func CheckAllowedTransition(nsId string, mcisId string, vmId common.OptionalPara } else { mcis, err := GetMcisStatus(nsId, mcisId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return err } diff --git a/src/core/mcis/manageInfo.go b/src/core/mcis/manageInfo.go index 6bbb039f4..89aeb2f1f 100644 --- a/src/core/mcis/manageInfo.go +++ b/src/core/mcis/manageInfo.go @@ -36,6 +36,7 @@ import ( "github.com/cloud-barista/cb-tumblebug/src/core/common" "github.com/cloud-barista/cb-tumblebug/src/core/mcir" "github.com/go-resty/resty/v2" + "github.com/rs/zerolog/log" ) // [MCIS and VM object information managemenet] @@ -98,7 +99,7 @@ func ListMcisId(nsId string) ([]string, error) { err := common.CheckString(nsId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return nil, err } @@ -111,7 +112,7 @@ func ListMcisId(nsId string) ([]string, error) { keyValue, err := common.CBStore.GetList(key, true) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return nil, err } @@ -133,13 +134,13 @@ func ListVmId(nsId string, mcisId string) ([]string, error) { err := common.CheckString(nsId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return nil, err } err = common.CheckString(mcisId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return nil, err } @@ -152,14 +153,14 @@ func ListVmId(nsId string, mcisId string) ([]string, error) { _, err = common.CBStore.Get(key) if err != nil { fmt.Println("[Not found] " + mcisId) - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return vmList, err } keyValue, err := common.CBStore.GetList(key, true) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return nil, err } @@ -187,7 +188,7 @@ func ListVmByLabel(nsId string, mcisId string, label string) ([]string, error) { vmList, err := ListVmId(nsId, mcisId) fmt.Println(vmList) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return nil, err } if len(vmList) == 0 { @@ -198,7 +199,7 @@ func ListVmByLabel(nsId string, mcisId string, label string) ([]string, error) { for _, v := range vmList { vmObj, vmErr := GetVmObject(nsId, mcisId, v) if vmErr != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return nil, vmErr } @@ -222,7 +223,7 @@ func ListVmByFilter(nsId string, mcisId string, filterKey string, filterVal stri vmList, err := ListVmId(nsId, mcisId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return nil, err } if len(vmList) == 0 { @@ -237,7 +238,7 @@ func ListVmByFilter(nsId string, mcisId string, filterKey string, filterVal stri for _, v := range vmList { vmObj, vmErr := GetVmObject(nsId, mcisId, v) if vmErr != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return nil, vmErr } vmObjReflect := reflect.ValueOf(&vmObj) @@ -274,13 +275,13 @@ func ListSubGroupId(nsId string, mcisId string) ([]string, error) { err := common.CheckString(nsId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return nil, err } err = common.CheckString(mcisId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return nil, err } @@ -290,7 +291,7 @@ func ListSubGroupId(nsId string, mcisId string) ([]string, error) { keyValue, err := common.CBStore.GetList(key, true) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return nil, err } var subGroupList []string @@ -312,14 +313,14 @@ func GetMcisInfo(nsId string, mcisId string) (*TbMcisInfo, error) { err := common.CheckString(nsId) if err != nil { temp := &TbMcisInfo{} - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return temp, err } err = common.CheckString(mcisId) if err != nil { temp := &TbMcisInfo{} - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return temp, err } check, _ := CheckMcis(nsId, mcisId) @@ -332,7 +333,7 @@ func GetMcisInfo(nsId string, mcisId string) (*TbMcisInfo, error) { mcisObj, err := GetMcisObject(nsId, mcisId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return nil, err } @@ -340,7 +341,7 @@ func GetMcisInfo(nsId string, mcisId string) (*TbMcisInfo, error) { mcisStatus, err := GetMcisStatus(nsId, mcisId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return nil, err } // common.PrintJsonPretty(mcisStatus) @@ -350,7 +351,7 @@ func GetMcisInfo(nsId string, mcisId string) (*TbMcisInfo, error) { vmList, err := ListVmId(nsId, mcisId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return nil, err } @@ -379,13 +380,13 @@ func GetMcisAccessInfo(nsId string, mcisId string, option string) (*McisAccessIn temp := &McisAccessInfo{} err := common.CheckString(nsId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return temp, err } err = common.CheckString(mcisId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return temp, err } check, _ := CheckMcis(nsId, mcisId) @@ -404,7 +405,7 @@ func GetMcisAccessInfo(nsId string, mcisId string, option string) (*McisAccessIn subGroupList, err := ListSubGroupId(nsId, mcisId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return temp, err } // TODO: make in parallel @@ -418,7 +419,7 @@ func GetMcisAccessInfo(nsId string, mcisId string, option string) (*McisAccessIn } vmList, err := ListVmBySubGroup(nsId, mcisId, groupId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return temp, err } var wg sync.WaitGroup @@ -431,7 +432,7 @@ func GetMcisAccessInfo(nsId string, mcisId string, option string) (*McisAccessIn vmInfo, err := GetVmCurrentPublicIp(nsId, mcisId, vmId) vmAccessInfo := McisVmAccessInfo{} if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") vmAccessInfo.PublicIP = "" vmAccessInfo.PrivateIP = "" vmAccessInfo.SSHPort = "" @@ -444,7 +445,7 @@ func GetMcisAccessInfo(nsId string, mcisId string, option string) (*McisAccessIn _, verifiedUserName, privateKey, err := GetVmSshKey(nsId, mcisId, vmId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") vmAccessInfo.PrivateKey = "" vmAccessInfo.VmUserAccount = "" } else { @@ -477,7 +478,7 @@ func ListMcisInfo(nsId string, option string) ([]TbMcisInfo, error) { err := common.CheckString(nsId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return nil, err } @@ -493,7 +494,7 @@ func ListMcisInfo(nsId string, option string) ([]TbMcisInfo, error) { mcisList, err := ListMcisId(nsId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return nil, err } @@ -502,9 +503,9 @@ func ListMcisInfo(nsId string, option string) ([]TbMcisInfo, error) { key := common.GenMcisKey(nsId, v, "") keyValue, err := common.CBStore.Get(key) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") err = fmt.Errorf("In CoreGetAllMcis(); CBStore.Get() returned an error.") - common.CBLog.Error(err) + log.Error().Err(err).Msg("") // return nil, err } @@ -520,7 +521,7 @@ func ListMcisInfo(nsId string, option string) ([]TbMcisInfo, error) { //get current mcis status mcisStatus, err := GetMcisStatus(nsId, mcisId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return nil, err } mcisTmp.Status = mcisStatus.Status @@ -533,7 +534,7 @@ func ListMcisInfo(nsId string, option string) ([]TbMcisInfo, error) { vmList, err := ListVmId(nsId, mcisId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return nil, err } @@ -542,7 +543,7 @@ func ListMcisInfo(nsId string, option string) ([]TbMcisInfo, error) { vmKeyValue, err := common.CBStore.Get(vmKey) if err != nil { err = fmt.Errorf("In CoreGetAllMcis(); CBStore.Get() returned an error") - common.CBLog.Error(err) + log.Error().Err(err).Msg("") // return nil, err } @@ -557,7 +558,7 @@ func ListMcisInfo(nsId string, option string) ([]TbMcisInfo, error) { //get current vm status vmStatusInfoTmp, err := FetchVmStatus(nsId, mcisId, v1) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") } vmTmp.Status = vmStatusInfoTmp.Status } else if option == "simple" { @@ -585,21 +586,21 @@ func ListVmInfo(nsId string, mcisId string, vmId string) (*TbVmInfo, error) { err := common.CheckString(nsId) if err != nil { temp := &TbVmInfo{} - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return temp, err } err = common.CheckString(mcisId) if err != nil { temp := &TbVmInfo{} - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return temp, err } err = common.CheckString(vmId) if err != nil { temp := &TbVmInfo{} - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return temp, err } check, _ := CheckVm(nsId, mcisId, vmId) @@ -617,9 +618,9 @@ func ListVmInfo(nsId string, mcisId string, vmId string) (*TbVmInfo, error) { vmKey := common.GenMcisKey(nsId, mcisId, vmId) vmKeyValue, err := common.CBStore.Get(vmKey) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") err = fmt.Errorf("In CoreGetMcisVmInfo(); CBStore.Get() returned an error.") - common.CBLog.Error(err) + log.Error().Err(err).Msg("") // return nil, err } @@ -633,7 +634,7 @@ func ListVmInfo(nsId string, mcisId string, vmId string) (*TbVmInfo, error) { //get current vm status vmStatusInfoTmp, err := FetchVmStatus(nsId, mcisId, vmId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") } vmTmp.Status = vmStatusInfoTmp.Status @@ -649,7 +650,7 @@ func GetMcisObject(nsId string, mcisId string) (TbMcisInfo, error) { key := common.GenMcisKey(nsId, mcisId, "") keyValue, err := common.CBStore.Get(key) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return TbMcisInfo{}, err } mcisTmp := TbMcisInfo{} @@ -657,14 +658,14 @@ func GetMcisObject(nsId string, mcisId string) (TbMcisInfo, error) { vmList, err := ListVmId(nsId, mcisId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return TbMcisInfo{}, err } for _, vmID := range vmList { vmtmp, err := GetVmObject(nsId, mcisId, vmID) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return TbMcisInfo{}, err } mcisTmp.Vm = append(mcisTmp.Vm, vmtmp) @@ -679,14 +680,14 @@ func GetVmObject(nsId string, mcisId string, vmId string) (TbVmInfo, error) { keyValue, err := common.CBStore.Get(key) if keyValue == nil || err != nil { err = fmt.Errorf("failed to get GetVmObject (ID: %s)", key) - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return TbVmInfo{}, err } vmTmp := TbVmInfo{} err = json.Unmarshal([]byte(keyValue.Value), &vmTmp) if err != nil { err = fmt.Errorf("failed to get GetVmObject (ID: %s), message: failed to unmarshal", key) - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return TbVmInfo{}, err } return vmTmp, nil @@ -697,7 +698,7 @@ func GetVmIdNameInDetail(nsId string, mcisId string, vmId string) (*TbIdNameInDe key := common.GenMcisKey(nsId, mcisId, vmId) keyValue, err := common.CBStore.Get(key) if keyValue == nil || err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return &TbIdNameInDetailInfo{}, err } vmTmp := TbVmInfo{} @@ -741,7 +742,7 @@ func GetVmIdNameInDetail(nsId string, mcisId string, vmId string) (*TbIdNameInDe ) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return &TbIdNameInDetailInfo{}, err } @@ -757,13 +758,13 @@ func GetMcisStatus(nsId string, mcisId string) (*McisStatusInfo, error) { err := common.CheckString(nsId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return &McisStatusInfo{}, err } err = common.CheckString(mcisId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return &McisStatusInfo{}, err } @@ -773,12 +774,12 @@ func GetMcisStatus(nsId string, mcisId string) (*McisStatusInfo, error) { keyValue, err := common.CBStore.Get(key) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return &McisStatusInfo{}, err } if keyValue == nil { err := fmt.Errorf("Not found [" + key + "]") - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return &McisStatusInfo{}, err } @@ -790,7 +791,7 @@ func GetMcisStatus(nsId string, mcisId string) (*McisStatusInfo, error) { vmList, err := ListVmId(nsId, mcisId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return &McisStatusInfo{}, err } if len(vmList) == 0 { @@ -929,7 +930,7 @@ func ListMcisStatus(nsId string) ([]McisStatusInfo, error) { //mcisStatuslist := []McisStatusInfo{} mcisList, err := ListMcisId(nsId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return []McisStatusInfo{}, err } @@ -943,7 +944,7 @@ func ListMcisStatus(nsId string) ([]McisStatusInfo, error) { defer wg.Done() mcisStatus, err := GetMcisStatus(nsId, mcisId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") } chanResults <- *mcisStatus }(nsId, mcisId, chanResults) @@ -971,21 +972,21 @@ func GetVmCurrentPublicIp(nsId string, mcisId string, vmId string) (TbVmStatusIn key := common.GenMcisKey(nsId, mcisId, vmId) keyValue, err := common.CBStore.Get(key) if err != nil || keyValue == nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return errorInfo, err } temp := TbVmInfo{} err = json.Unmarshal([]byte(keyValue.Value), &temp) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return errorInfo, err } cspVmId := temp.CspViewVmDetail.IId.NameId if cspVmId == "" { err = fmt.Errorf("cspVmId is empty (VmId: %s)", vmId) - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return errorInfo, err } @@ -1018,7 +1019,7 @@ func GetVmCurrentPublicIp(nsId string, mcisId string, vmId string) (TbVmStatusIn ) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return errorInfo, err } @@ -1035,7 +1036,7 @@ func GetVmIp(nsId string, mcisId string, vmId string) (string, string, string, e vmObject, err := GetVmObject(nsId, mcisId, vmId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return "", "", "", err } @@ -1054,9 +1055,9 @@ func GetVmSpecId(nsId string, mcisId string, vmId string) string { keyValue, err := common.CBStore.Get(key) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") err = fmt.Errorf("In GetVmSpecId(); CBStore.Get() returned an error.") - common.CBLog.Error(err) + log.Error().Err(err).Msg("") // return nil, err } @@ -1074,7 +1075,7 @@ func FetchVmStatusAsync(wg *sync.WaitGroup, nsId string, mcisId string, vmId str if nsId != "" && mcisId != "" && vmId != "" { vmStatusTmp, err := FetchVmStatus(nsId, mcisId, vmId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") vmStatusTmp.Status = StatusFailed vmStatusTmp.SystemMessage = err.Error() } @@ -1092,7 +1093,7 @@ func FetchVmStatus(nsId string, mcisId string, vmId string) (TbVmStatusInfo, err temp, err := GetVmObject(nsId, mcisId, vmId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return errorInfo, err } @@ -1114,7 +1115,7 @@ func FetchVmStatus(nsId string, mcisId string, vmId string) (TbVmStatusInfo, err if (temp.TargetAction != ActionCreate && temp.TargetAction != ActionTerminate) && cspVmId == "" { err = fmt.Errorf("cspVmId is empty (VmId: %s)", vmId) - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return errorInfo, err } @@ -1259,7 +1260,7 @@ func FetchVmStatus(nsId string, mcisId string, vmId string) (TbVmStatusInfo, err //Get current public IP when status has been changed. vmInfoTmp, err := GetVmCurrentPublicIp(nsId, mcisId, temp.Id) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") errorInfo.SystemMessage = err.Error() return errorInfo, err } @@ -1298,21 +1299,21 @@ func GetMcisVmStatus(nsId string, mcisId string, vmId string) (*TbVmStatusInfo, err := common.CheckString(nsId) if err != nil { temp := &TbVmStatusInfo{} - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return temp, err } err = common.CheckString(mcisId) if err != nil { temp := &TbVmStatusInfo{} - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return temp, err } err = common.CheckString(vmId) if err != nil { temp := &TbVmStatusInfo{} - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return temp, err } @@ -1327,7 +1328,7 @@ func GetMcisVmStatus(nsId string, mcisId string, vmId string) (*TbVmStatusInfo, vmStatusResponse, err := FetchVmStatus(nsId, mcisId, vmId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return nil, err } @@ -1356,7 +1357,7 @@ func UpdateMcisInfo(nsId string, mcisInfoData TbMcisInfo) { val, _ := json.Marshal(mcisInfoData) err = common.CBStore.Put(key, string(val)) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") } } } @@ -1378,7 +1379,7 @@ func UpdateVmInfo(nsId string, mcisId string, vmInfoData TbVmInfo) { val, _ := json.Marshal(vmInfoData) err = common.CBStore.Put(key, string(val)) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") } } } @@ -1387,7 +1388,7 @@ func UpdateVmInfo(nsId string, mcisId string, vmInfoData TbVmInfo) { func ProvisionDataDisk(nsId string, mcisId string, vmId string, u *mcir.TbDataDiskVmReq) (TbVmInfo, error) { vm, err := GetVmObject(nsId, mcisId, vmId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return TbVmInfo{}, err } @@ -1401,14 +1402,14 @@ func ProvisionDataDisk(nsId string, mcisId string, vmId string, u *mcir.TbDataDi newDataDisk, err := mcir.CreateDataDisk(nsId, &createDiskReq, "") if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return TbVmInfo{}, err } retry := 3 for i := 0; i < retry; i++ { vmInfo, err := AttachDetachDataDisk(nsId, mcisId, vmId, common.AttachDataDisk, newDataDisk.Id, false) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") } else { return vmInfo, nil } @@ -1425,7 +1426,7 @@ func AttachDetachDataDisk(nsId string, mcisId string, vmId string, command strin keyValue, err := common.CBStore.Get(vmKey) if keyValue == nil || err != nil { err := fmt.Errorf("Failed to find 'ns/mcis/vm': %s/%s/%s \n", nsId, mcisId, vmId) - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return TbVmInfo{}, err } @@ -1435,11 +1436,11 @@ func AttachDetachDataDisk(nsId string, mcisId string, vmId string, command strin isInList := common.CheckElement(dataDiskId, vm.DataDiskIds) if command == common.DetachDataDisk && !isInList && !force { err := fmt.Errorf("Failed to find the dataDisk %s in the attached dataDisk list %v", dataDiskId, vm.DataDiskIds) - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return TbVmInfo{}, err } else if command == common.AttachDataDisk && isInList && !force { err := fmt.Errorf("The dataDisk %s is already in the attached dataDisk list %v", dataDiskId, vm.DataDiskIds) - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return TbVmInfo{}, err } @@ -1498,7 +1499,7 @@ func AttachDetachDataDisk(nsId string, mcisId string, vmId string, command strin ) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return TbVmInfo{}, err } @@ -1525,7 +1526,7 @@ func AttachDetachDataDisk(nsId string, mcisId string, vmId string, command strin // Below is just a code snippet of 'defensive programming'. if !flag && !force { err := fmt.Errorf("Failed to find the dataDisk %s in the attached dataDisk list.", dataDiskId) - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return TbVmInfo{}, err } else { vm.DataDiskIds = newDataDiskIds @@ -1552,7 +1553,7 @@ func AttachDetachDataDisk(nsId string, mcisId string, vmId string, command strin ) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return vm, err } @@ -1583,7 +1584,7 @@ func AttachDetachDataDisk(nsId string, mcisId string, vmId string, command strin case resp.StatusCode() >= 400 || resp.StatusCode() < 200: err := fmt.Errorf(string(resp.Body())) fmt.Println("body: ", string(resp.Body())) - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return vm, err } @@ -1603,7 +1604,7 @@ func GetAvailableDataDisks(nsId string, mcisId string, vmId string, option strin keyValue, err := common.CBStore.Get(vmKey) if keyValue == nil || err != nil { err := fmt.Errorf("Failed to find 'ns/mcis/vm': %s/%s/%s \n", nsId, mcisId, vmId) - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return nil, err } @@ -1613,14 +1614,14 @@ func GetAvailableDataDisks(nsId string, mcisId string, vmId string, option strin tbDataDisksInterface, err := mcir.ListResource(nsId, common.StrDataDisk, "", "") if err != nil { err := fmt.Errorf("Failed to get dataDisk List. \n") - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return nil, err } jsonString, err := json.Marshal(tbDataDisksInterface) if err != nil { err := fmt.Errorf("Failed to marshal dataDisk list into JSON string. \n") - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return nil, err } @@ -1636,7 +1637,7 @@ func GetAvailableDataDisks(nsId string, mcisId string, vmId string, option strin // Update Tb dataDisk object's status newObj, err := mcir.GetResource(nsId, common.StrDataDisk, v.Id) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return nil, err } tempObj := newObj.(mcir.TbDataDiskInfo) @@ -1661,13 +1662,13 @@ func DelMcis(nsId string, mcisId string, option string) (common.IdList, error) { err := common.CheckString(nsId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return deletedResources, err } err = common.CheckString(mcisId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return deletedResources, err } check, _ := CheckMcis(nsId, mcisId) @@ -1683,7 +1684,7 @@ func DelMcis(nsId string, mcisId string, option string) (common.IdList, error) { mcisStatus, _ := GetMcisStatus(nsId, mcisId) if mcisStatus == nil { err := fmt.Errorf("MCIS " + mcisId + " status nil, Deletion is not allowed (use option=force for force deletion)") - common.CBLog.Error(err) + log.Error().Err(err).Msg("") if option != "force" { return deletedResources, err } @@ -1697,14 +1698,14 @@ func DelMcis(nsId string, mcisId string, option string) (common.IdList, error) { // ActionRefine _, err := HandleMcisAction(nsId, mcisId, ActionRefine, true) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return deletedResources, err } // ActionTerminate _, err = HandleMcisAction(nsId, mcisId, ActionTerminate, true) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return deletedResources, err } // for deletion, need to wait until termination is finished @@ -1719,7 +1720,7 @@ func DelMcis(nsId string, mcisId string, option string) (common.IdList, error) { // Check MCIS status is Terminated (not Partial) if mcisStatus.Id != "" && !(!strings.Contains(mcisStatus.Status, "Partial-") && (strings.Contains(mcisStatus.Status, StatusTerminated) || strings.Contains(mcisStatus.Status, StatusUndefined) || strings.Contains(mcisStatus.Status, StatusFailed))) { err := fmt.Errorf("MCIS " + mcisId + " is " + mcisStatus.Status + " and not " + StatusTerminated + "/" + StatusUndefined + "/" + StatusFailed + ", Deletion is not allowed (use option=force for force deletion)") - common.CBLog.Error(err) + log.Error().Err(err).Msg("") if option != "force" { return deletedResources, err } @@ -1731,13 +1732,13 @@ func DelMcis(nsId string, mcisId string, option string) (common.IdList, error) { // delete associated MCIS Policy err = DelMcisPolicy(nsId, mcisId) if err == nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") deletedResources.IdList = append(deletedResources.IdList, "Policy: "+mcisId+deleteStatus) } vmList, err := ListVmId(nsId, mcisId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return deletedResources, err } @@ -1749,13 +1750,13 @@ func DelMcis(nsId string, mcisId string, option string) (common.IdList, error) { // get vm info vmInfo, err := GetVmObject(nsId, mcisId, v) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return deletedResources, err } err = common.CBStore.Delete(vmKey) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return deletedResources, err } @@ -1781,7 +1782,7 @@ func DelMcis(nsId string, mcisId string, option string) (common.IdList, error) { // delete subGroup info subGroupList, err := ListSubGroupId(nsId, mcisId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return deletedResources, err } for _, v := range subGroupList { @@ -1789,7 +1790,7 @@ func DelMcis(nsId string, mcisId string, option string) (common.IdList, error) { fmt.Println(subGroupKey) err := common.CBStore.Delete(subGroupKey) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return deletedResources, err } deletedResources.IdList = append(deletedResources.IdList, "SubGroup: "+v+deleteStatus) @@ -1802,7 +1803,7 @@ func DelMcis(nsId string, mcisId string, option string) (common.IdList, error) { } output, err := DelAllNLB(nsId, mcisId, "", forceFlag) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return deletedResources, err } deletedResources.IdList = append(deletedResources.IdList, output.IdList...) @@ -1813,7 +1814,7 @@ func DelMcis(nsId string, mcisId string, option string) (common.IdList, error) { if check { mcisNlbDeleteResult, err := DelMcis(nsId, mcisNlbId, option) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return deletedResources, err } deletedResources.IdList = append(deletedResources.IdList, mcisNlbDeleteResult.IdList...) @@ -1822,7 +1823,7 @@ func DelMcis(nsId string, mcisId string, option string) (common.IdList, error) { // delete mcis info err = common.CBStore.Delete(key) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return deletedResources, err } deletedResources.IdList = append(deletedResources.IdList, "MCIS: "+mcisId+deleteStatus) @@ -1835,19 +1836,19 @@ func DelMcisVm(nsId string, mcisId string, vmId string, option string) error { err := common.CheckString(nsId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return err } err = common.CheckString(mcisId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return err } err = common.CheckString(vmId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return err } check, _ := CheckVm(nsId, mcisId, vmId) @@ -1870,7 +1871,7 @@ func DelMcisVm(nsId string, mcisId string, vmId string, option string) error { wg.Wait() close(results) if checkErr.Error != nil { - common.CBLog.Info(checkErr.Error) + log.Info().Msg(checkErr.Error.Error()) if option != "force" { return checkErr.Error } @@ -1889,7 +1890,7 @@ func DelMcisVm(nsId string, mcisId string, vmId string, option string) error { key := common.GenMcisKey(nsId, mcisId, vmId) err = common.CBStore.Delete(key) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return err } @@ -1918,13 +1919,13 @@ func DelAllMcis(nsId string, option string) (string, error) { err := common.CheckString(nsId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return "", err } mcisList, err := ListMcisId(nsId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return "", err } @@ -1935,7 +1936,7 @@ func DelAllMcis(nsId string, option string) (string, error) { for _, v := range mcisList { _, err := DelMcis(nsId, v, option) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return "", fmt.Errorf("Failed to delete All MCISs") } } @@ -1948,7 +1949,7 @@ func UpdateVmPublicIp(nsId string, mcisId string, vmInfoData TbVmInfo) error { vmInfoTmp, err := GetVmCurrentPublicIp(nsId, mcisId, vmInfoData.Id) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return err } if vmInfoData.PublicIP != vmInfoTmp.PublicIp || vmInfoData.SSHPort != vmInfoTmp.SSHPort { @@ -1966,7 +1967,7 @@ func GetVmTemplate(nsId string, mcisId string, algo string) (TbVmInfo, error) { vmList, err := ListVmId(nsId, mcisId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return TbVmInfo{}, err } if len(vmList) == 0 { @@ -1991,7 +1992,7 @@ func GetVmTemplate(nsId string, mcisId string, algo string) (TbVmInfo, error) { vmTemplate.VmUserPassword = vmObj.VmUserPassword if vmErr != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return TbVmInfo{}, vmErr } diff --git a/src/core/mcis/monitoring.go b/src/core/mcis/monitoring.go index d2bd8a220..3ff23c7c0 100644 --- a/src/core/mcis/monitoring.go +++ b/src/core/mcis/monitoring.go @@ -19,6 +19,7 @@ import ( "time" validator "github.com/go-playground/validator/v10" + "github.com/rs/zerolog/log" "github.com/tidwall/gjson" "fmt" @@ -162,12 +163,12 @@ func CallMonitoringAsync(wg *sync.WaitGroup, nsID string, mcisID string, mcisSer vmIP, _, sshPort, err := GetVmIp(nsID, mcisID, vmID) errStr := "" if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") errStr += "/ " + err.Error() } userName, privateKey, err := VerifySshUserName(nsID, mcisID, vmID, vmIP, sshPort, givenUserName) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") errStr += "/ " + err.Error() } fmt.Println("[CallMonitoringAsync] " + mcisID + "/" + vmID + "(" + vmIP + ")" + "with userName:" + userName) @@ -199,13 +200,13 @@ func CallMonitoringAsync(wg *sync.WaitGroup, nsID string, mcisID string, mcisSer if requestBody.SshKey == "" { common.PrintJsonPretty(requestBody) err = fmt.Errorf("/request body to install monitoring agent: privateKey is empty/") - common.CBLog.Error(err) + log.Error().Err(err).Msg("") errStr += "/ " + err.Error() } payload, err := json.Marshal(requestBody) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") errStr += "/ " + err.Error() } @@ -219,7 +220,7 @@ func CallMonitoringAsync(wg *sync.WaitGroup, nsID string, mcisID string, mcisSer req, err := http.NewRequest(method, url, strings.NewReader(string(payload))) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") errStr += "/ " + err.Error() } @@ -231,13 +232,13 @@ func CallMonitoringAsync(wg *sync.WaitGroup, nsID string, mcisID string, mcisSer fmt.Println("Called CB-DRAGONFLY API") if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") errStr += "/ " + err.Error() } else { body, err := ioutil.ReadAll(res.Body) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") errStr += "/ " + err.Error() } defer res.Body.Close() @@ -246,7 +247,7 @@ func CallMonitoringAsync(wg *sync.WaitGroup, nsID string, mcisID string, mcisSer switch { case res.StatusCode >= 400 || res.StatusCode < 200: err = fmt.Errorf("CB-DF HTTP Status: " + strconv.Itoa(res.StatusCode) + " / " + string(body)) - common.CBLog.Error(err) + log.Error().Err(err).Msg("") errStr += "/ " + err.Error() } @@ -266,7 +267,7 @@ func CallMonitoringAsync(wg *sync.WaitGroup, nsID string, mcisID string, mcisSer sshResultTmp.Stderr = make(map[int]string) if err != nil || errStr != "" { - common.CBLog.Error("[Monitoring Agent deployment errors] " + errStr) + log.Error().Err(err).Msgf("[Monitoring Agent deployment errors] %s", errStr) sshResultTmp.Stderr[0] = errStr sshResultTmp.Err = err *returnResult = append(*returnResult, sshResultTmp) @@ -288,14 +289,14 @@ func InstallMonitorAgentToMcis(nsId string, mcisId string, mcisServiceType strin err := common.CheckString(nsId) if err != nil { temp := AgentInstallContentWrapper{} - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return temp, err } err = common.CheckString(mcisId) if err != nil { temp := AgentInstallContentWrapper{} - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return temp, err } check, _ := CheckMcis(nsId, mcisId) @@ -313,7 +314,7 @@ func InstallMonitorAgentToMcis(nsId string, mcisId string, mcisServiceType strin vmList, err := ListVmId(nsId, mcisId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return content, err } @@ -338,7 +339,7 @@ func InstallMonitorAgentToMcis(nsId string, mcisId string, mcisServiceType strin wg.Add(1) go CallMonitoringAsync(&wg, nsId, mcisId, mcisServiceType, v, req.UserName, method, cmd, &resultArray) } else { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") } } @@ -372,7 +373,7 @@ func UpdateMonitoringAgentStatusManually(nsId string, mcisId string, vmId string vmInfoTmp, err := GetVmObject(nsId, mcisId, vmId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return err } @@ -391,14 +392,14 @@ func GetMonitoringData(nsId string, mcisId string, metric string) (MonResultSimp err := common.CheckString(nsId) if err != nil { temp := MonResultSimpleResponse{} - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return temp, err } err = common.CheckString(mcisId) if err != nil { temp := MonResultSimpleResponse{} - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return temp, err } check, _ := CheckMcis(nsId, mcisId) @@ -413,7 +414,7 @@ func GetMonitoringData(nsId string, mcisId string, metric string) (MonResultSimp vmList, err := ListVmId(nsId, mcisId) if err != nil { - //common.CBLog.Error(err) + //log.Error().Err(err).Msg("") return content, err } @@ -429,7 +430,7 @@ func GetMonitoringData(nsId string, mcisId string, metric string) (MonResultSimp vmIp, _, _, err := GetVmIp(nsId, mcisId, vmId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") wg.Done() // continue to next vm even if error occurs } else { @@ -476,7 +477,7 @@ func CallGetMonitoringAsync(wg *sync.WaitGroup, nsID string, mcisID string, vmID } req, err := http.NewRequest(method, url, nil) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") errStr = err.Error() } @@ -484,20 +485,20 @@ func CallGetMonitoringAsync(wg *sync.WaitGroup, nsID string, mcisID string, vmID res, err := client.Do(req) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") errStr = err.Error() } else { fmt.Println("HTTP Status code: " + strconv.Itoa(res.StatusCode)) switch { case res.StatusCode >= 400 || res.StatusCode < 200: err1 := fmt.Errorf("HTTP Status: not in 200-399") - common.CBLog.Error(err1) + log.Error().Err(err1).Msg("") errStr = err1.Error() } body, err2 := ioutil.ReadAll(res.Body) if err2 != nil { - common.CBLog.Error(err2) + log.Error().Err(err2).Msg("") errStr = err2.Error() } defer res.Body.Close() diff --git a/src/core/mcis/network.go b/src/core/mcis/network.go index d57e0aa90..06eba73d2 100644 --- a/src/core/mcis/network.go +++ b/src/core/mcis/network.go @@ -18,12 +18,13 @@ import ( "encoding/json" "errors" "fmt" - "log" "os" "strings" "sync" "time" + "github.com/rs/zerolog/log" + model "github.com/cloud-barista/cb-larva/poc-cb-net/pkg/cb-network/model" nethelper "github.com/cloud-barista/cb-larva/poc-cb-net/pkg/network-helper" ruletype "github.com/cloud-barista/cb-larva/poc-cb-net/pkg/rule-type" @@ -40,15 +41,15 @@ type NetworkReq struct { // ConfigureCloudAdaptiveNetwork configures a cloud adaptive network to VMs in an MCIS func ConfigureCloudAdaptiveNetwork(nsId string, mcisId string, netReq *NetworkReq) (AgentInstallContentWrapper, error) { - common.CBLog.Debug("Start.........") + log.Debug().Msg("Start.........") if err := common.CheckString(nsId); err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return AgentInstallContentWrapper{}, err } if err := common.CheckString(mcisId); err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return AgentInstallContentWrapper{}, err } @@ -59,38 +60,38 @@ func ConfigureCloudAdaptiveNetwork(nsId string, mcisId string, netReq *NetworkRe // Get a list of VM ID vmIdList, err := ListVmId(nsId, mcisId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return AgentInstallContentWrapper{}, err } serviceEndpoint := netReq.ServiceEndpoint // if the parameter is not passed, try to read from the environment variable if serviceEndpoint == "" { - common.CBLog.Printf("read env for CB_NETWORK_SERVICE_ENDPOINT") + log.Debug().Msg("read env for CB_NETWORK_SERVICE_ENDPOINT") // Get an endpoint of cb-network service serviceEndpoint = os.Getenv("CB_NETWORK_SERVICE_ENDPOINT") if serviceEndpoint == "" { return AgentInstallContentWrapper{}, errors.New("there is no CB_NETWORK_SERVICE_ENDPOINT") } } - common.CBLog.Printf("Network service endpoint: %+v", serviceEndpoint) + log.Debug().Msgf("Network service endpoint: %+v", serviceEndpoint) etcdEndpoints := netReq.EtcdEndpoints // if the parameter is not passed, try to read from the environment variable if len(etcdEndpoints) == 0 { - common.CBLog.Printf("read env for CB_NETWORK_ETCD_ENDPOINTS") + log.Debug().Msg("read env for CB_NETWORK_ETCD_ENDPOINTS") // Get endpoints of cb-network etcd which should be accessible from the remote etcdEndpoints = strings.Split(os.Getenv("CB_NETWORK_ETCD_ENDPOINTS"), ",") if len(etcdEndpoints) == 0 { return AgentInstallContentWrapper{}, errors.New("there is no CB_NETWORK_ETCD_ENDPOINTS") } } - common.CBLog.Printf("etcd endpoints: %+v", etcdEndpoints) + log.Debug().Msgf("etcd endpoints: %+v", etcdEndpoints) // Get Cloud Adaptive Network cladnetSpec, err := getCloudAdaptiveNetwork(serviceEndpoint, mcisId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return AgentInstallContentWrapper{}, err } @@ -107,22 +108,22 @@ func ConfigureCloudAdaptiveNetwork(nsId string, mcisId string, netReq *NetworkRe cladnetDescription := fmt.Sprintf("A cladnet for %s", mcisId) cladnetSpec, err = createProperCloudAdaptiveNetwork(serviceEndpoint, ipNetworksInMCIS, mcisId, cladnetDescription) if err != nil { - common.CBLog.Printf("could not create a cloud adaptive network: %v\n", err) + log.Debug().Msgf("could not create a cloud adaptive network: %v", err) return AgentInstallContentWrapper{}, err } } - common.CBLog.Printf("CLADNet spec: %#v\n", cladnetSpec) + log.Debug().Msgf("CLADNet spec: %#v", cladnetSpec) // Prepare the installation command etcdEndpointsJSON, _ := json.Marshal(etcdEndpoints) command, err := getAgentInstallationCommand(string(etcdEndpointsJSON), cladnetSpec.CladnetID) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return AgentInstallContentWrapper{}, err } - common.CBLog.Printf("Command: %#v\n", command) + log.Debug().Msgf("Command: %#v", command) // Replace given parameter with the installation cmd mcisCmdReq := McisCmdReq{} @@ -138,7 +139,7 @@ func ConfigureCloudAdaptiveNetwork(nsId string, mcisId string, netReq *NetworkRe var sshCmdResults []SshCmdResult - common.CBLog.Printf("VM list: %v\n", vmIdList) + log.Debug().Msgf("VM list: %v", vmIdList) for _, vmId := range vmIdList { wg.Add(1) @@ -147,7 +148,7 @@ func ConfigureCloudAdaptiveNetwork(nsId string, mcisId string, netReq *NetworkRe // Check NetworkAgentStatus vmObject, _ := GetVmObject(nsId, mcisId, vmId) - common.CBLog.Printf("NetworkAgentStatus: %+v\n" + vmObject.NetworkAgentStatus) + log.Debug().Msgf("NetworkAgentStatus: %+v" + vmObject.NetworkAgentStatus) // Skip if in installing or installed status) if vmObject.NetworkAgentStatus != "installed" && vmObject.NetworkAgentStatus != "installing" { @@ -188,13 +189,13 @@ func ConfigureCloudAdaptiveNetwork(nsId string, mcisId string, netReq *NetworkRe } common.PrintJsonPretty(sshCmdResults) - common.CBLog.Debug("End.........") + log.Debug().Msg("End.........") return contents, nil } // // readCBNetworkEndpoints checks endpoints of cb-network service and etcd. // func readCBNetworkEndpoints() (string, string, error) { -// common.CBLog.Debug("Start.........") +// log.Debug().Msg("Start.........") // // Get an endpoint of cb-network service // serviceEndpoint := os.Getenv("CB_NETWORK_SERVICE_ENDPOINT") @@ -208,13 +209,13 @@ func ConfigureCloudAdaptiveNetwork(nsId string, mcisId string, netReq *NetworkRe // return "", "", errors.New("could not load CB_NETWORK_ETCD_ENDPOINTS") // } -// common.CBLog.Debug("End.........") +// log.Debug().Msg("End.........") // return serviceEndpoint, etcdEndpoints, nil // } // getCloudAdaptiveNetwork retrieves a Cloud Adaptive Network func getCloudAdaptiveNetwork(networkServiceEndpoint string, cladnetId string) (model.CLADNetSpecification, error) { - common.CBLog.Debug("Start.........") + log.Debug().Msg("Start.........") var cladnetSpec model.CLADNetSpecification client := resty.New() @@ -228,26 +229,26 @@ func getCloudAdaptiveNetwork(networkServiceEndpoint string, cladnetId string) (m }). Get(fmt.Sprintf("http://%s/v1/cladnet/{cladnetId}", networkServiceEndpoint)) // Output print - log.Printf("\nError: %v\n", err) - common.CBLog.Printf("Time: %v\n", resp.Time()) - common.CBLog.Printf("Body: %v\n", resp) + log.Error().Err(err).Msg("") + log.Debug().Msgf("Time: %v", resp.Time()) + log.Debug().Msgf("Body: %v", resp) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return model.CLADNetSpecification{}, err } json.Unmarshal(resp.Body(), &cladnetSpec) - common.CBLog.Printf("%+v\n", cladnetSpec) - common.CBLog.Printf("The specification of a Cloud Adaptive Network: %+v", cladnetSpec) + log.Debug().Msgf("%+v", cladnetSpec) + log.Debug().Msgf("The specification of a Cloud Adaptive Network: %+v", cladnetSpec) - common.CBLog.Debug("End.........") + log.Debug().Msg("End.........") return cladnetSpec, nil } // getSubnetsInMCIS extracts all subnets in MCIS. func getSubnetsInMCIS(nsId string, mcisId string, vmList []string) ([]string, error) { - common.CBLog.Debug("Start.........") + log.Debug().Msg("Start.........") ipNetsInMCIS := make([]string, 0) @@ -256,21 +257,21 @@ func getSubnetsInMCIS(nsId string, mcisId string, vmList []string) ([]string, er // Get vNet info tbVmInfo, err := GetVmObject(nsId, mcisId, vmId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return ipNetsInMCIS, err } // getVNet res, err := mcir.GetResource(nsId, common.StrVNet, tbVmInfo.VNetId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return ipNetsInMCIS, err } // type casting tempVNetInfo, ok := res.(mcir.TbVNetInfo) if !ok { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return ipNetsInMCIS, err } @@ -281,15 +282,15 @@ func getSubnetsInMCIS(nsId string, mcisId string, vmList []string) ([]string, er } // Trace - common.CBLog.Tracef("%#v", ipNetsInMCIS) + log.Trace().Msgf("%#v", ipNetsInMCIS) - common.CBLog.Debug("End.........") + log.Debug().Msg("End.........") return ipNetsInMCIS, nil } // createProperCloudAdaptiveNetwork requests available IPv4 private address spaces and uses the recommended address space. func createProperCloudAdaptiveNetwork(networkServiceEndpoint string, ipCIDRs []string, cladnetName string, cladnetDescription string) (model.CLADNetSpecification, error) { - common.CBLog.Debug("Start.........") + log.Debug().Msg("Start.........") ipv4CidrsHolder := `{"ipv4Cidrs": %s}` tempJSON, _ := json.Marshal(ipCIDRs) @@ -305,20 +306,20 @@ func createProperCloudAdaptiveNetwork(networkServiceEndpoint string, ipCIDRs []s SetBody(ipv4CidrsString). Post(fmt.Sprintf("http://%s/v1/cladnet/availableIPv4AddressSpaces", networkServiceEndpoint)) // Output print - common.CBLog.Printf("\nError: %v\n", err) - common.CBLog.Printf("Time: %v\n", resp.Time()) - common.CBLog.Printf("Body: %v\n", resp) + log.Error().Err(err).Msg("") + log.Debug().Msgf("Time: %v", resp.Time()) + log.Debug().Msgf("Body: %v", resp) if err != nil { - common.CBLog.Printf("Could not request: %v\n", err) + log.Error().Err(err).Msgf("Could not request") return model.CLADNetSpecification{}, err } var availableIPv4PrivateAddressSpaces nethelper.AvailableIPv4PrivateAddressSpaces json.Unmarshal(resp.Body(), &availableIPv4PrivateAddressSpaces) - common.CBLog.Printf("%+v\n", availableIPv4PrivateAddressSpaces) - common.CBLog.Printf("RecommendedIpv4PrivateAddressSpace: %#v", availableIPv4PrivateAddressSpaces.RecommendedIPv4PrivateAddressSpace) + log.Debug().Msgf("%+v", availableIPv4PrivateAddressSpaces) + log.Debug().Msgf("RecommendedIpv4PrivateAddressSpace: %#v", availableIPv4PrivateAddressSpaces.RecommendedIPv4PrivateAddressSpace) // if the cladnetName is unique, it can be used CladnetID. reqSpec := &model.CLADNetSpecification{ @@ -335,7 +336,7 @@ func createProperCloudAdaptiveNetwork(networkServiceEndpoint string, ipCIDRs []s if errMarshal != nil { return model.CLADNetSpecification{}, err } - common.CBLog.Printf("%#v\n", cladnetSpecString) + log.Debug().Msgf("%#v", cladnetSpecString) // Request to create a Cloud Adaptive Network resp, err = client.R(). @@ -344,12 +345,12 @@ func createProperCloudAdaptiveNetwork(networkServiceEndpoint string, ipCIDRs []s SetBody(cladnetSpecString). Post(fmt.Sprintf("http://%s/v1/cladnet", networkServiceEndpoint)) // Output print - common.CBLog.Printf("\nError: %v\n", err) - common.CBLog.Printf("Time: %v\n", resp.Time()) - common.CBLog.Printf("Body: %v\n", resp) + log.Error().Err(err).Msg("") + log.Debug().Msgf("Time: %v", resp.Time()) + log.Debug().Msgf("Body: %v", resp) if err != nil { - common.CBLog.Printf("Could not request: %v\n", err) + log.Error().Err(err).Msg("Could not request") return model.CLADNetSpecification{}, err } @@ -359,7 +360,7 @@ func createProperCloudAdaptiveNetwork(networkServiceEndpoint string, ipCIDRs []s return model.CLADNetSpecification{}, err } - common.CBLog.Debug("End.........") + log.Debug().Msg("End.........") return tempSpec, nil } @@ -382,11 +383,11 @@ func getAgentInstallationCommand(etcdEndpoints, cladnetId string) (string, error // installCBNetworkAgentToMcis installs cb-network agent to VMs in an MCIS by the remote command func installCBNetworkAgentToVM(nsId, mcisId, vmId string, mcisCmdReq McisCmdReq) (SshCmdResult, error) { - common.CBLog.Debug("Start.........") + log.Debug().Msg("Start.........") vmIp, _, sshPort, err := GetVmIp(nsId, mcisId, vmId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return SshCmdResult{}, err } @@ -396,7 +397,7 @@ func installCBNetworkAgentToVM(nsId, mcisId, vmId string, mcisCmdReq McisCmdReq) // With RunRemoteCommand, error will be checked again if err == nil { // Just logging the error (but it is net a faultal ) - common.CBLog.Info(err) + log.Info().Msg(err.Error()) } stdout, stderr, err := RunRemoteCommand(vmIp, sshPort, userName, sshKey, mcisCmdReq.Command) @@ -417,37 +418,37 @@ func installCBNetworkAgentToVM(nsId, mcisId, vmId string, mcisCmdReq McisCmdReq) sshResultTmp.Err = nil } - common.CBLog.Debug("End.........") + log.Debug().Msg("End.........") return sshResultTmp, err } // // installCBNetworkAgentToMcis installs cb-network agent to VMs in an MCIS by the remote command // func installCBNetworkAgentToMcis(nsId, mcisId string, mcisCmdReq McisCmdReq) ([]SshCmdResult, error) { -// common.CBLog.Debug("Start.........") +// log.Debug().Msg("Start.........") // sshCmdResult, err := RemoteCommandToMcis(nsId, mcisId, &mcisCmdReq) // if err != nil { // temp := []SshCmdResult{} -// common.CBLog.Error(err) +// log.Error().Err(err).Msg("") // return temp, err // } -// common.CBLog.Debug("End.........") +// log.Debug().Msg("End.........") // return sshCmdResult, nil // } // InjectCloudInformationForCloudAdaptiveNetwork injects cloud information for a cloud adaptive network func InjectCloudInformationForCloudAdaptiveNetwork(nsId string, mcisId string, netReq *NetworkReq) (AgentInstallContentWrapper, error) { - common.CBLog.Debug("Start.........") + log.Debug().Msg("Start.........") if err := common.CheckString(nsId); err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return AgentInstallContentWrapper{}, err } if err := common.CheckString(mcisId); err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return AgentInstallContentWrapper{}, err } @@ -458,59 +459,59 @@ func InjectCloudInformationForCloudAdaptiveNetwork(nsId string, mcisId string, n serviceEndpoint := netReq.ServiceEndpoint // if the parameter is not passed, try to read from the environment variable if serviceEndpoint == "" { - common.CBLog.Printf("read env for CB_NETWORK_SERVICE_ENDPOINT") + log.Debug().Msg("read env for CB_NETWORK_SERVICE_ENDPOINT") // Get an endpoint of cb-network service serviceEndpoint = os.Getenv("CB_NETWORK_SERVICE_ENDPOINT") if serviceEndpoint == "" { return AgentInstallContentWrapper{}, errors.New("there is no CB_NETWORK_SERVICE_ENDPOINT") } } - common.CBLog.Printf("Network service endpoint: %+v", serviceEndpoint) + log.Debug().Msgf("Network service endpoint: %+v", serviceEndpoint) // etcdEndpoints := netReq.EtcdEndpoints // // if the parameter is not passed, try to read from the environment variable // if len(etcdEndpoints) == 0 { - // common.CBLog.Printf("read env for CB_NETWORK_ETCD_ENDPOINTS") + // log.Debug().Msg("read env for CB_NETWORK_ETCD_ENDPOINTS") // // Get endpoints of cb-network etcd which should be accessible from the remote // etcdEndpoints = strings.Split(os.Getenv("CB_NETWORK_ETCD_ENDPOINTS"), ",") // if len(etcdEndpoints) == 0 { // return AgentInstallContentWrapper{}, errors.New("there is no CB_NETWORK_ETCD_ENDPOINTS") // } // } - // common.CBLog.Printf("etcd endpoints: %+v", etcdEndpoints) + // log.Debug().Msgf("etcd endpoints: %+v", etcdEndpoints) // Get Cloud Adaptive Network cladnetSpec, err := getCloudAdaptiveNetwork(serviceEndpoint, mcisId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return AgentInstallContentWrapper{}, err } - common.CBLog.Printf("CLADNet spec: %#v\n", cladnetSpec) + log.Debug().Msgf("CLADNet spec: %#v", cladnetSpec) // Get Peers in Cloud Adaptive Network (NOTE - mcisId is equal to cladnetID) peers, err := getPeersInCloudAdaptiveNetwork(serviceEndpoint, cladnetSpec.CladnetID) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return AgentInstallContentWrapper{}, err } - common.CBLog.Printf("Peers: %#v\n", peers) + log.Debug().Msgf("Peers: %#v", peers) // Get a list of VM ID vmIdList, err := ListVmId(nsId, mcisId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return AgentInstallContentWrapper{}, err } - common.CBLog.Printf("VM list: %v\n", vmIdList) + log.Debug().Msgf("VM list: %v", vmIdList) // Change the rule type of cloud adaptive network cladnetSpec.RuleType = ruletype.CostPrioritized cladnetSpec, err = updateCloudAdaptiveNetwork(serviceEndpoint, cladnetSpec) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return AgentInstallContentWrapper{}, err } - common.CBLog.Printf("CLADNet spec: %#v\n", cladnetSpec) + log.Debug().Msgf("CLADNet spec: %#v", cladnetSpec) //// Inject cloud information to each peer in the Cloud Adaptive network contents := AgentInstallContentWrapper{} @@ -519,7 +520,7 @@ func InjectCloudInformationForCloudAdaptiveNetwork(nsId string, mcisId string, n vmObject, _ := GetVmObject(nsId, mcisId, vmId) // jsonBytes, _ := json.Marshal(vmObject) // doc := string(jsonBytes) - // common.CBLog.Printf("## vmObject ==> %+v\n", doc) + // log.Debug().Msgf("## vmObject ==> %+v", doc) for _, peer := range peers.Peers { @@ -534,19 +535,19 @@ func InjectCloudInformationForCloudAdaptiveNetwork(nsId string, mcisId string, n VirtualNetworkID: vmObject.CspViewVmDetail.VpcIID.SystemId, SubnetID: vmObject.CspViewVmDetail.SubnetIID.SystemId, } - common.CBLog.Printf("## vmId: %+v\n", vmId) - common.CBLog.Printf("## %#v\n", tempCloudInfo) + log.Debug().Msgf("## vmId: %+v", vmId) + log.Debug().Msgf("## %#v", tempCloudInfo) // Update the peer updatedPeer, err := updateDetailsOfPeer(serviceEndpoint, cladnetSpec.CladnetID, peer.HostID, tempCloudInfo) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") } - common.CBLog.Printf("The updated peer: %#v\n", updatedPeer) + log.Debug().Msgf("The updated peer: %#v", updatedPeer) updatedPeerBytes, err := json.Marshal(updatedPeer) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") tempPeer := model.Peer{} updatedPeerBytes, _ = json.Marshal(tempPeer) } @@ -563,13 +564,13 @@ func InjectCloudInformationForCloudAdaptiveNetwork(nsId string, mcisId string, n } } - common.CBLog.Debug("End.........") + log.Debug().Msg("End.........") return contents, nil } // getPeersInCloudAdaptiveNetwork retrieves peers in a Cloud Adaptive Network func getPeersInCloudAdaptiveNetwork(networkServiceEndpoint string, cladnetId string) (model.Peers, error) { - common.CBLog.Debug("Start.........") + log.Debug().Msg("Start.........") client := resty.New() @@ -582,12 +583,12 @@ func getPeersInCloudAdaptiveNetwork(networkServiceEndpoint string, cladnetId str }). Get(fmt.Sprintf("http://%s/v1/cladnet/{cladnetId}/peer", networkServiceEndpoint)) // Output print - log.Printf("\nError: %v\n", err) - common.CBLog.Printf("Time: %v\n", resp.Time()) - common.CBLog.Printf("Body: %v\n", resp) + log.Error().Err(err).Msg("") + log.Debug().Msgf("Time: %v", resp.Time()) + log.Debug().Msgf("Body: %v", resp) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return model.Peers{}, err } @@ -595,30 +596,30 @@ func getPeersInCloudAdaptiveNetwork(networkServiceEndpoint string, cladnetId str err = json.Unmarshal(resp.Body(), &peers) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return model.Peers{}, err } - common.CBLog.Printf("%+v\n", peers) - common.CBLog.Printf("Peers in a Cloud Adaptive Network: %+v", peers) + log.Debug().Msgf("%+v", peers) + log.Debug().Msgf("Peers in a Cloud Adaptive Network: %+v", peers) if len(peers.Peers) == 0 { return model.Peers{}, errors.New("could not find any Peers") } - common.CBLog.Debug("End.........") + log.Debug().Msg("End.........") return peers, nil } // updateCloudAdaptiveNetwork updates the specification of a Cloud Adaptive Network. func updateCloudAdaptiveNetwork(networkServiceEndpoint string, cladnetSpec model.CLADNetSpecification) (model.CLADNetSpecification, error) { - common.CBLog.Debug("Start.........") + log.Debug().Msg("Start.........") jsonBytes, errMarshal := json.Marshal(cladnetSpec) if errMarshal != nil { return model.CLADNetSpecification{}, errMarshal } doc := string(jsonBytes) - common.CBLog.Printf("CLADNetSpecification (JSON string): %v\n", doc) + log.Debug().Msgf("CLADNetSpecification (JSON string): %v", doc) client := resty.New() // Request a recommendation of available IPv4 private address spaces. @@ -631,12 +632,12 @@ func updateCloudAdaptiveNetwork(networkServiceEndpoint string, cladnetSpec model SetBody(doc). Put(fmt.Sprintf("http://%s/v1/cladnet/{cladnetId}", networkServiceEndpoint)) // Output print - log.Printf("\nError: %v\n", err) - common.CBLog.Printf("Time: %v\n", resp.Time()) - common.CBLog.Printf("Body: %v\n", resp) + log.Error().Err(err).Msg("") + log.Debug().Msgf("Time: %v", resp.Time()) + log.Debug().Msgf("Body: %v", resp) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return model.CLADNetSpecification{}, err } @@ -644,20 +645,20 @@ func updateCloudAdaptiveNetwork(networkServiceEndpoint string, cladnetSpec model err = json.Unmarshal(resp.Body(), &spec) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return model.CLADNetSpecification{}, err } - common.CBLog.Printf("%+v\n", spec) - common.CBLog.Printf("The updated CLADNetSpecification: %+v", spec) + log.Debug().Msgf("%+v", spec) + log.Debug().Msgf("The updated CLADNetSpecification: %+v", spec) - common.CBLog.Debug("End.........") + log.Debug().Msg("End.........") return spec, nil } // updateDetailsOfPeer updates the peers with cloud information (i.e., details). func updateDetailsOfPeer(networkServiceEndpoint string, cladnetId string, hostId string, details model.CloudInformation) (model.Peer, error) { - common.CBLog.Debug("Start.........") + log.Debug().Msg("Start.........") cloudInformationHolder := `{"cloudInformation": %s}` jsonBytes, errMarshal := json.Marshal(details) @@ -666,7 +667,7 @@ func updateDetailsOfPeer(networkServiceEndpoint string, cladnetId string, hostId } doc := fmt.Sprintf(cloudInformationHolder, string(jsonBytes)) - common.CBLog.Printf("CloudInforamtion (JSON string): %v\n", doc) + log.Debug().Msgf("CloudInforamtion (JSON string): %v", doc) client := resty.New() // Request a recommendation of available IPv4 private address spaces. @@ -680,12 +681,12 @@ func updateDetailsOfPeer(networkServiceEndpoint string, cladnetId string, hostId SetBody(doc). Put(fmt.Sprintf("http://%s/v1/cladnet/{cladnetId}/peer/{hostId}/details", networkServiceEndpoint)) // Output print - log.Printf("\nError: %v\n", err) - common.CBLog.Printf("Time: %v\n", resp.Time()) - common.CBLog.Printf("Body: %v\n", resp) + log.Error().Err(err).Msg("") + log.Debug().Msgf("Time: %v", resp.Time()) + log.Debug().Msgf("Body: %v", resp) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return model.Peer{}, err } @@ -693,12 +694,12 @@ func updateDetailsOfPeer(networkServiceEndpoint string, cladnetId string, hostId err = json.Unmarshal(resp.Body(), &peer) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return model.Peer{}, err } - common.CBLog.Printf("%+v\n", peer) - common.CBLog.Printf("The updated peer: %+v", peer) + log.Debug().Msgf("%+v", peer) + log.Debug().Msgf("The updated peer: %+v", peer) - common.CBLog.Debug("End.........") + log.Debug().Msg("End.........") return peer, nil } diff --git a/src/core/mcis/nlb.go b/src/core/mcis/nlb.go index 897e51f40..f663a7730 100644 --- a/src/core/mcis/nlb.go +++ b/src/core/mcis/nlb.go @@ -27,6 +27,7 @@ import ( "github.com/cloud-barista/cb-tumblebug/src/core/mcir" validator "github.com/go-playground/validator/v10" "github.com/go-resty/resty/v2" + "github.com/rs/zerolog/log" ) const nlbPostfix = "-nlb" @@ -286,13 +287,13 @@ func CreateMcSwNlb(nsId string, mcisId string, req *TbNLBReq, option string) (Mc err := common.CheckString(nsId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return emptyObj, err } err = common.CheckString(mcisId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return emptyObj, err } @@ -317,7 +318,7 @@ func CreateMcSwNlb(nsId string, mcisId string, req *TbNLBReq, option string) (Mc mcis, err := GetMcisObject(nsId, mcisId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return emptyObj, err } for _, vm := range mcis.Vm { @@ -327,7 +328,7 @@ func CreateMcSwNlb(nsId string, mcisId string, req *TbNLBReq, option string) (Mc specList, err := RecommendVm(common.SystemCommonNs, deploymentPlan) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return emptyObj, err } if len(specList) != 0 { @@ -340,7 +341,7 @@ func CreateMcSwNlb(nsId string, mcisId string, req *TbNLBReq, option string) (Mc mcisInfo, err := CreateMcisDynamic(nsId, &mcisDynamicReq) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return emptyObj, err } @@ -360,7 +361,7 @@ func CreateMcSwNlb(nsId string, mcisId string, req *TbNLBReq, option string) (Mc // targetPort=${3:-80} accessList, err := GetMcisAccessInfo(nsId, mcisId, "") if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return emptyObj, err } for _, v := range accessList.McisSubGroupAccessInfo { @@ -374,7 +375,7 @@ func CreateMcSwNlb(nsId string, mcisId string, req *TbNLBReq, option string) (Mc cmds = append(cmds, cmd) output, err := RemoteCommandToMcis(nsId, nlbMcisId, "", "", &McisCmdReq{Command: cmds}) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return emptyObj, err } result := McisSshCmdResult{Results: output} @@ -392,19 +393,19 @@ func CreateNLB(nsId string, mcisId string, u *TbNLBReq, option string) (TbNLBInf err := common.CheckString(nsId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return emptyObj, err } err = common.CheckString(mcisId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return emptyObj, err } err = common.CheckString(u.TargetGroup.SubGroupId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return emptyObj, err } @@ -531,7 +532,7 @@ func CreateNLB(nsId string, mcisId string, u *TbNLBReq, option string) (TbNLBInf for _, v := range vmIDs { vm, err := GetVmObject(nsId, mcisId, v) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return emptyObj, err } // fmt.Println("vm:") // for debug @@ -574,7 +575,7 @@ func CreateNLB(nsId string, mcisId string, u *TbNLBReq, option string) (TbNLBInf } if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") err := fmt.Errorf("an error occurred while requesting to CB-Spider") return emptyObj, err } @@ -583,7 +584,7 @@ func CreateNLB(nsId string, mcisId string, u *TbNLBReq, option string) (TbNLBInf switch { case resp.StatusCode() >= 400 || resp.StatusCode() < 200: err := fmt.Errorf(string(resp.Body())) - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return emptyObj, err } @@ -648,15 +649,15 @@ func CreateNLB(nsId string, mcisId string, u *TbNLBReq, option string) (TbNLBInf err = common.CBStore.Put(Key, string(Val)) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return content, err } keyValue, err := common.CBStore.Get(Key) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") err = fmt.Errorf("In CreateNLB(); CBStore.Get() returned an error.") - common.CBLog.Error(err) + log.Error().Err(err).Msg("") // return nil, err } @@ -666,7 +667,7 @@ func CreateNLB(nsId string, mcisId string, u *TbNLBReq, option string) (TbNLBInf result := TbNLBInfo{} err = json.Unmarshal([]byte(keyValue.Value), &result) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") } return result, nil } @@ -678,24 +679,24 @@ func GetNLB(nsId string, mcisId string, resourceId string) (TbNLBInfo, error) { err := common.CheckString(nsId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return emptyObj, err } err = common.CheckString(mcisId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return emptyObj, err } err = common.CheckString(resourceId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return emptyObj, err } check, err := CheckNLB(nsId, mcisId, resourceId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return emptyObj, err } @@ -712,7 +713,7 @@ func GetNLB(nsId string, mcisId string, resourceId string) (TbNLBInfo, error) { keyValue, err := common.CBStore.Get(key) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return emptyObj, err } @@ -721,7 +722,7 @@ func GetNLB(nsId string, mcisId string, resourceId string) (TbNLBInfo, error) { if keyValue != nil { err = json.Unmarshal([]byte(keyValue.Value), &res) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return emptyObj, err } return res, nil @@ -751,19 +752,19 @@ func CheckNLB(nsId string, mcisId string, resourceId string) (bool, error) { err := common.CheckString(nsId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return false, err } err = common.CheckString(mcisId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return false, err } err = common.CheckString(resourceId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return false, err } @@ -774,7 +775,7 @@ func CheckNLB(nsId string, mcisId string, resourceId string) (bool, error) { keyValue, err := common.CBStore.Get(key) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return false, err } if keyValue != nil { @@ -788,19 +789,19 @@ func CheckNLB(nsId string, mcisId string, resourceId string) (bool, error) { func GenNLBKey(nsId string, mcisId string, resourceId string) string { err := common.CheckString(nsId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return "/invalidKey" } err = common.CheckString(mcisId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return "/invalidKey" } err = common.CheckString(resourceId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return "/invalidKey" } @@ -812,13 +813,13 @@ func ListNLBId(nsId string, mcisId string) ([]string, error) { err := common.CheckString(nsId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return nil, err } err = common.CheckString(mcisId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return nil, err } @@ -830,14 +831,14 @@ func ListNLBId(nsId string, mcisId string) ([]string, error) { keyValue, err := common.CBStore.GetList(key, true) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return nil, err } /* if keyValue == nil, then for-loop below will not be executed, and the empty array will be returned in `resourceList` placeholder. if keyValue == nil { err = fmt.Errorf("ListResourceId(); %s is empty.", key) - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return nil, err } */ @@ -860,13 +861,13 @@ func ListNLB(nsId string, mcisId string, filterKey string, filterVal string) (in err := common.CheckString(nsId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return nil, err } err = common.CheckString(mcisId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return nil, err } @@ -878,7 +879,7 @@ func ListNLB(nsId string, mcisId string, filterKey string, filterVal string) (in keyValue = cbstore_utils.GetChildList(keyValue, key) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return nil, err } if keyValue != nil { @@ -888,7 +889,7 @@ func ListNLB(nsId string, mcisId string, filterKey string, filterVal string) (in tempObj := TbNLBInfo{} err = json.Unmarshal([]byte(v.Value), &tempObj) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return nil, err } // Check the JSON body inclues both filterKey and filterVal strings. (assume key and value) @@ -918,25 +919,25 @@ func DelNLB(nsId string, mcisId string, resourceId string, forceFlag string) err err := common.CheckString(nsId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return err } err = common.CheckString(mcisId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return err } err = common.CheckString(resourceId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return err } check, err := CheckNLB(nsId, mcisId, resourceId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return err } @@ -962,7 +963,7 @@ func DelNLB(nsId string, mcisId string, resourceId string, forceFlag string) err } else { errString := " [Failed]" + " Associated with [" + strings.Join(associatedList[:], ", ") + "]" err := fmt.Errorf(errString) - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return err } */ @@ -983,7 +984,7 @@ func DelNLB(nsId string, mcisId string, resourceId string, forceFlag string) err temp := TbNLBInfo{} err = json.Unmarshal([]byte(keyValue.Value), &temp) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return err } requestBody.ConnectionName = temp.ConnectionName @@ -1001,7 +1002,7 @@ func DelNLB(nsId string, mcisId string, resourceId string, forceFlag string) err Delete(url) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") err := fmt.Errorf("an error occurred while requesting to CB-Spider") return err } @@ -1020,14 +1021,14 @@ func DelNLB(nsId string, mcisId string, resourceId string, forceFlag string) err Delete(url) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") err := fmt.Errorf("an error occurred while requesting to CB-Spider") return err } case resp.StatusCode() >= 400 || resp.StatusCode() < 200: err := fmt.Errorf(string(resp.Body())) - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return err default: @@ -1035,7 +1036,7 @@ func DelNLB(nsId string, mcisId string, resourceId string, forceFlag string) err err = common.CBStore.Delete(key) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return err } return nil @@ -1049,13 +1050,13 @@ func DelAllNLB(nsId string, mcisId string, subString string, forceFlag string) ( err := common.CheckString(nsId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return deletedResources, err } err = common.CheckString(mcisId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return deletedResources, err } @@ -1068,7 +1069,7 @@ func DelAllNLB(nsId string, mcisId string, subString string, forceFlag string) ( // if len(resourceIdList) == 0 { // errString := "There is no NLB in " + nsId // err := fmt.Errorf(errString) - // common.CBLog.Error(err) + // log.Error().Err(err).Msg("") // return deletedResources, err // } @@ -1097,19 +1098,19 @@ func GetNLBHealth(nsId string, mcisId string, nlbId string) (TbNLBHealthInfo, er err := common.CheckString(nsId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return TbNLBHealthInfo{}, err } err = common.CheckString(mcisId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return TbNLBHealthInfo{}, err } err = common.CheckString(nlbId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return TbNLBHealthInfo{}, err } @@ -1156,7 +1157,7 @@ func GetNLBHealth(nsId string, mcisId string, nlbId string) (TbNLBHealthInfo, er resp, err = req.Get(url) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") err := fmt.Errorf("an error occurred while requesting to CB-Spider") return TbNLBHealthInfo{}, err } @@ -1165,7 +1166,7 @@ func GetNLBHealth(nsId string, mcisId string, nlbId string) (TbNLBHealthInfo, er switch { case resp.StatusCode() >= 400 || resp.StatusCode() < 200: err := fmt.Errorf(string(resp.Body())) - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return TbNLBHealthInfo{}, err } @@ -1205,15 +1206,15 @@ func GetNLBHealth(nsId string, mcisId string, nlbId string) (TbNLBHealthInfo, er err = common.CBStore.Put(Key, string(Val)) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return content, err } keyValue, err := common.CBStore.Get(Key) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") err = fmt.Errorf("In CreateNLB(); CBStore.Get() returned an error.") - common.CBLog.Error(err) + log.Error().Err(err).Msg("") // return nil, err } @@ -1223,7 +1224,7 @@ func GetNLBHealth(nsId string, mcisId string, nlbId string) (TbNLBHealthInfo, er result := TbNLBInfo{} err = json.Unmarshal([]byte(keyValue.Value), &result) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") } */ @@ -1237,14 +1238,14 @@ func AddNLBVMs(nsId string, mcisId string, resourceId string, u *TbNLBAddRemoveV err := common.CheckString(nsId) if err != nil { temp := TbNLBInfo{} - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return temp, err } err = common.CheckString(mcisId) if err != nil { temp := TbNLBInfo{} - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return temp, err } @@ -1301,7 +1302,7 @@ func AddNLBVMs(nsId string, mcisId string, resourceId string, u *TbNLBAddRemoveV for _, v := range u.TargetGroup.VMs { vm, err := GetVmObject(nsId, mcisId, v) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return TbNLBInfo{}, err } // fmt.Println("vm:") // for debug @@ -1317,13 +1318,13 @@ func AddNLBVMs(nsId string, mcisId string, resourceId string, u *TbNLBAddRemoveV mcisId_vmId := strings.Split(v, "/") if len(mcisId_vmId) != 2 { err := fmt.Errorf("Cannot retrieve VM info: " + v) - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return TbNLBInfo{}, err } vm, err := mcis.GetVmObject(nsId, mcisId_vmId[0], mcisId_vmId[1]) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return TbNLBInfo{}, err } @@ -1353,7 +1354,7 @@ func AddNLBVMs(nsId string, mcisId string, resourceId string, u *TbNLBAddRemoveV resp, err = req.Post(url) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") content := TbNLBInfo{} err := fmt.Errorf("an error occurred while requesting to CB-Spider") return content, err @@ -1363,7 +1364,7 @@ func AddNLBVMs(nsId string, mcisId string, resourceId string, u *TbNLBAddRemoveV switch { case resp.StatusCode() >= 400 || resp.StatusCode() < 200: err := fmt.Errorf(string(resp.Body())) - common.CBLog.Error(err) + log.Error().Err(err).Msg("") content := TbNLBInfo{} return content, err } @@ -1415,15 +1416,15 @@ func AddNLBVMs(nsId string, mcisId string, resourceId string, u *TbNLBAddRemoveV err = common.CBStore.Put(Key, string(Val)) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return content, err } keyValue, err := common.CBStore.Get(Key) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") err = fmt.Errorf("In CreateNLB(); CBStore.Get() returned an error.") - common.CBLog.Error(err) + log.Error().Err(err).Msg("") // return nil, err } @@ -1433,7 +1434,7 @@ func AddNLBVMs(nsId string, mcisId string, resourceId string, u *TbNLBAddRemoveV result := TbNLBInfo{} err = json.Unmarshal([]byte(keyValue.Value), &result) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") } return result, nil } @@ -1445,13 +1446,13 @@ func RemoveNLBVMs(nsId string, mcisId string, resourceId string, u *TbNLBAddRemo err := common.CheckString(nsId) if err != nil { // temp := TbNLBInfo{} - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return err } err = common.CheckString(mcisId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return err } @@ -1510,7 +1511,7 @@ func RemoveNLBVMs(nsId string, mcisId string, resourceId string, u *TbNLBAddRemo for _, v := range u.TargetGroup.VMs { vm, err := GetVmObject(nsId, mcisId, v) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return err } // fmt.Println("vm:") // for debug @@ -1529,13 +1530,13 @@ func RemoveNLBVMs(nsId string, mcisId string, resourceId string, u *TbNLBAddRemo mcisId_vmId := strings.Split(v, "/") if len(mcisId_vmId) != 2 { err := fmt.Errorf("Cannot retrieve VM info: " + v) - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return TbNLBInfo{}, err } vm, err := mcis.GetVmObject(nsId, mcisId_vmId[0], mcisId_vmId[1]) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return TbNLBInfo{}, err } @@ -1565,7 +1566,7 @@ func RemoveNLBVMs(nsId string, mcisId string, resourceId string, u *TbNLBAddRemo resp, err = req.Delete(url) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") // content := TbNLBInfo{} err := fmt.Errorf("an error occurred while requesting to CB-Spider") return err @@ -1575,7 +1576,7 @@ func RemoveNLBVMs(nsId string, mcisId string, resourceId string, u *TbNLBAddRemo switch { case resp.StatusCode() >= 400 || resp.StatusCode() < 200: err := fmt.Errorf(string(resp.Body())) - common.CBLog.Error(err) + log.Error().Err(err).Msg("") // content := TbNLBInfo{} return err } @@ -1624,15 +1625,15 @@ func RemoveNLBVMs(nsId string, mcisId string, resourceId string, u *TbNLBAddRemo err = common.CBStore.Put(Key, string(Val)) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return err } keyValue, err := common.CBStore.Get(Key) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") err = fmt.Errorf("In CreateNLB(); CBStore.Get() returned an error.") - common.CBLog.Error(err) + log.Error().Err(err).Msg("") // return nil, err } @@ -1643,7 +1644,7 @@ func RemoveNLBVMs(nsId string, mcisId string, resourceId string, u *TbNLBAddRemo result := TbNLBInfo{} err = json.Unmarshal([]byte(keyValue.Value), &result) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") } */ return nil diff --git a/src/core/mcis/orchestration.go b/src/core/mcis/orchestration.go index 423a61d16..827d0d960 100644 --- a/src/core/mcis/orchestration.go +++ b/src/core/mcis/orchestration.go @@ -21,6 +21,7 @@ import ( "strings" "github.com/cloud-barista/cb-tumblebug/src/core/common" + "github.com/rs/zerolog/log" ) // Status for mcis automation @@ -109,7 +110,7 @@ func OrchestrationController() { nsList, err := common.ListNsId() if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") err = fmt.Errorf("an error occurred while getting namespaces' list: " + err.Error()) return } @@ -127,9 +128,9 @@ func OrchestrationController() { key := common.GenMcisPolicyKey(nsId, v, "") keyValue, err := common.CBStore.Get(key) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") err = fmt.Errorf("In OrchestrationController(); CBStore.Get() returned an error.") - common.CBLog.Error(err) + log.Error().Err(err).Msg("") // return nil, err } @@ -179,7 +180,7 @@ func OrchestrationController() { fmt.Println("[MCIS is exist] " + mcisPolicyTmp.Id) content, err := GetMonitoringData(nsId, mcisPolicyTmp.Id, mcisPolicyTmp.Policy[policyIndex].AutoCondition.Metric) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") mcisPolicyTmp.Policy[policyIndex].Status = AutoStatusError break } @@ -428,7 +429,7 @@ func UpdateMcisPolicyInfo(nsId string, mcisPolicyInfoData McisPolicyInfo) { val, _ := json.Marshal(mcisPolicyInfoData) err := common.CBStore.Put(key, string(val)) if err != nil && !strings.Contains(err.Error(), common.CbStoreKeyNotFoundErrorString) { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") } } @@ -438,14 +439,14 @@ func CreateMcisPolicy(nsId string, mcisId string, u *McisPolicyReq) (McisPolicyI err := common.CheckString(nsId) if err != nil { temp := McisPolicyInfo{} - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return temp, err } err = common.CheckString(mcisId) if err != nil { temp := McisPolicyInfo{} - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return temp, err } check, _ := CheckMcisPolicy(nsId, mcisId) @@ -475,14 +476,14 @@ func CreateMcisPolicy(nsId string, mcisId string, u *McisPolicyReq) (McisPolicyI err = common.CBStore.Put(Key, string(Val)) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return obj, err } keyValue, err := common.CBStore.Get(Key) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") err = fmt.Errorf("In CreateMcisPolicy(); CBStore.Get() returned an error.") - common.CBLog.Error(err) + log.Error().Err(err).Msg("") // return nil, err } @@ -498,21 +499,21 @@ func GetMcisPolicyObject(nsId string, mcisId string) (McisPolicyInfo, error) { err := common.CheckString(nsId) if err != nil { temp := McisPolicyInfo{} - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return temp, err } err = common.CheckString(mcisId) if err != nil { temp := McisPolicyInfo{} - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return temp, err } key := common.GenMcisPolicyKey(nsId, mcisId, "") fmt.Println("Key: ", key) keyValue, err := common.CBStore.Get(key) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return McisPolicyInfo{}, err } if keyValue == nil { @@ -531,7 +532,7 @@ func GetAllMcisPolicyObject(nsId string) ([]McisPolicyInfo, error) { err := common.CheckString(nsId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return nil, err } Mcis := []McisPolicyInfo{} @@ -542,9 +543,9 @@ func GetAllMcisPolicyObject(nsId string) ([]McisPolicyInfo, error) { key := common.GenMcisPolicyKey(nsId, v, "") keyValue, err := common.CBStore.Get(key) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") err = fmt.Errorf("In GetAllMcisPolicyObject(); CBStore.Get() returned an error.") - common.CBLog.Error(err) + log.Error().Err(err).Msg("") // return nil, err } @@ -564,16 +565,16 @@ func ListMcisPolicyId(nsId string) []string { err := common.CheckString(nsId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return nil } key := "/ns/" + nsId + "/policy/mcis" keyValue, err := common.CBStore.GetList(key, true) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") err = fmt.Errorf("In ListMcisPolicyId(); CBStore.Get() returned an error.") - common.CBLog.Error(err) + log.Error().Err(err).Msg("") // return nil, err } @@ -591,13 +592,13 @@ func DelMcisPolicy(nsId string, mcisId string) error { err := common.CheckString(nsId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return err } err = common.CheckString(mcisId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return err } check, _ := CheckMcisPolicy(nsId, mcisId) @@ -615,7 +616,7 @@ func DelMcisPolicy(nsId string, mcisId string) error { // delete mcis Policy info err = common.CBStore.Delete(key) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return err } @@ -627,7 +628,7 @@ func DelAllMcisPolicy(nsId string) (string, error) { err := common.CheckString(nsId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return "", err } mcisList := ListMcisPolicyId(nsId) @@ -637,7 +638,7 @@ func DelAllMcisPolicy(nsId string) (string, error) { for _, v := range mcisList { err := DelMcisPolicy(nsId, v) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return "", fmt.Errorf("Failed to delete All MCIS Policies") } diff --git a/src/core/mcis/provisioning.go b/src/core/mcis/provisioning.go index d21e46000..0f12497c9 100644 --- a/src/core/mcis/provisioning.go +++ b/src/core/mcis/provisioning.go @@ -518,20 +518,20 @@ func CreateMcisVm(nsId string, mcisId string, vmInfoData *TbVmInfo) (*TbVmInfo, err := common.CheckString(nsId) if err != nil { temp := &TbVmInfo{} - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return temp, err } err = common.CheckString(mcisId) if err != nil { temp := &TbVmInfo{} - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return temp, err } err = common.CheckString(vmInfoData.Name) if err != nil { temp := &TbVmInfo{} - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return temp, err } check, _ := CheckVm(nsId, mcisId, vmInfoData.Name) @@ -589,7 +589,7 @@ func CreateMcisVm(nsId string, mcisId string, vmInfoData *TbVmInfo) (*TbVmInfo, fmt.Printf("\n[InstallMonitorAgentToMcis]\n\n") content, err := InstallMonitorAgentToMcis(nsId, mcisId, common.StrMCIS, reqToMon) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") //mcisTmp.InstallMonAgent = "no" } common.PrintJsonPretty(content) @@ -643,14 +643,14 @@ func CreateMcisGroupVm(nsId string, mcisId string, vmRequest *TbVmReq, newSubGro err := common.CheckString(nsId) if err != nil { temp := &TbMcisInfo{} - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return temp, err } err = common.CheckString(mcisId) if err != nil { temp := &TbMcisInfo{} - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return temp, err } @@ -714,7 +714,7 @@ func CreateMcisGroupVm(nsId string, mcisId string, vmRequest *TbVmReq, newSubGro err = common.CheckString(tentativeVmId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return &TbMcisInfo{}, err } @@ -731,7 +731,7 @@ func CreateMcisGroupVm(nsId string, mcisId string, vmRequest *TbVmReq, newSubGro keyValue, err := common.CBStore.Get(key) if err != nil { err = fmt.Errorf("In CreateMcisGroupVm(); CBStore.Get(): " + err.Error()) - common.CBLog.Error(err) + log.Error().Err(err).Msg("") } if keyValue != nil { if newSubGroup { @@ -739,14 +739,14 @@ func CreateMcisGroupVm(nsId string, mcisId string, vmRequest *TbVmReq, newSubGro existingVmSize, err := strconv.Atoi(subGroupInfoData.SubGroupSize) if err != nil { err = fmt.Errorf("In CreateMcisGroupVm(); CBStore.Get(): " + err.Error()) - common.CBLog.Error(err) + log.Error().Err(err).Msg("") } // add the number of existing VMs in the SubGroup with requested number for additions subGroupInfoData.SubGroupSize = strconv.Itoa(existingVmSize + subGroupSize) vmStartIndex = existingVmSize + 1 } else { err = fmt.Errorf("Duplicated SubGroup ID") - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return nil, err } } @@ -758,13 +758,13 @@ func CreateMcisGroupVm(nsId string, mcisId string, vmRequest *TbVmReq, newSubGro val, _ := json.Marshal(subGroupInfoData) err = common.CBStore.Put(key, string(val)) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") } // check stored subGroup object keyValue, err = common.CBStore.Get(key) if err != nil { err = fmt.Errorf("In CreateMcisGroupVm(); CBStore.Get(): " + err.Error()) - common.CBLog.Error(err) + log.Error().Err(err).Msg("") // return nil, err } @@ -803,7 +803,7 @@ func CreateMcisGroupVm(nsId string, mcisId string, vmRequest *TbVmReq, newSubGro vmInfoData.ConnectionConfig, err = common.GetConnConfig(vmRequest.ConnectionName) if err != nil { err = fmt.Errorf("Cannot retrieve ConnectionConfig" + err.Error()) - common.CBLog.Error(err) + log.Error().Err(err).Msg("") } vmInfoData.SpecId = vmRequest.SpecId vmInfoData.ImageId = vmRequest.ImageId @@ -867,7 +867,7 @@ func CreateMcisGroupVm(nsId string, mcisId string, vmRequest *TbVmReq, newSubGro fmt.Printf("\n[InstallMonitorAgentToMcis]\n\n") content, err := InstallMonitorAgentToMcis(nsId, mcisId, common.StrMCIS, reqToMon) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") //mcisTmp.InstallMonAgent = "no" } common.PrintJsonPretty(content) @@ -894,7 +894,7 @@ func CreateMcis(nsId string, req *TbMcisReq, option string) (*TbMcisInfo, error) err := common.CheckString(nsId) if err != nil { temp := &TbMcisInfo{} - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return temp, err } @@ -941,14 +941,14 @@ func CreateMcis(nsId string, req *TbMcisReq, option string) (*TbMcisInfo, error) val, err := json.Marshal(mapA) if err != nil { err := fmt.Errorf("System Error: CreateMcis json.Marshal(mapA) Error") - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return nil, err } err = common.CBStore.Put(key, string(val)) if err != nil { err := fmt.Errorf("System Error: CreateMcis CBStore.Put Error") - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return nil, err } @@ -956,7 +956,7 @@ func CreateMcis(nsId string, req *TbMcisReq, option string) (*TbMcisInfo, error) for _, k := range vmRequest { err = common.CheckString(k.Name) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return &TbMcisInfo{}, err } } @@ -992,7 +992,7 @@ func CreateMcis(nsId string, req *TbMcisReq, option string) (*TbMcisInfo, error) val, _ := json.Marshal(subGroupInfoData) err := common.CBStore.Put(key, string(val)) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") } } @@ -1026,7 +1026,7 @@ func CreateMcis(nsId string, req *TbMcisReq, option string) (*TbMcisInfo, error) vmInfoData.ConnectionConfig, err = common.GetConnConfig(k.ConnectionName) if err != nil { err = fmt.Errorf("Cannot retrieve ConnectionConfig" + err.Error()) - common.CBLog.Error(err) + log.Error().Err(err).Msg("") } vmInfoData.SpecId = k.SpecId vmInfoData.ImageId = k.ImageId @@ -1058,13 +1058,13 @@ func CreateMcis(nsId string, req *TbMcisReq, option string) (*TbMcisInfo, error) mcisTmp, err := GetMcisObject(nsId, mcisId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return nil, err } mcisStatusTmp, err := GetMcisStatus(nsId, mcisId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return nil, err } @@ -1102,7 +1102,7 @@ func CreateMcis(nsId string, req *TbMcisReq, option string) (*TbMcisInfo, error) fmt.Printf("\n[InstallMonitorAgentToMcis]\n\n") content, err := InstallMonitorAgentToMcis(nsId, mcisId, common.StrMCIS, reqToMon) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") //mcisTmp.InstallMonAgent = "no" } common.PrintJsonPretty(content) @@ -1112,7 +1112,7 @@ func CreateMcis(nsId string, req *TbMcisReq, option string) (*TbMcisInfo, error) mcisResult, err := GetMcisInfo(nsId, mcisId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return nil, err } return mcisResult, nil @@ -1126,7 +1126,7 @@ func CheckMcisDynamicReq(req *McisConnectionConfigCandidatesReq) (*CheckMcisDyna connectionConfigList, err := common.GetConnConfigList() if err != nil { err := fmt.Errorf("Cannot load ConnectionConfigList in MCIS dynamic request check.") - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return &mcisReqInfo, err } @@ -1183,7 +1183,7 @@ func CreateSystemMcisDynamic(option string) (*TbMcisInfo, error) { case "probe": connections, err := common.GetConnConfigList() if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return nil, err } for _, v := range connections.Connectionconfig { @@ -1204,7 +1204,7 @@ func CreateSystemMcisDynamic(option string) (*TbMcisInfo, error) { specList, err := RecommendVm(common.SystemCommonNs, deploymentPlan) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return nil, err } if len(specList) != 0 { @@ -1245,12 +1245,12 @@ func CreateMcisDynamic(nsId string, req *TbMcisDynamicReq) (*TbMcisInfo, error) emptyMcis := &TbMcisInfo{} err := common.CheckString(nsId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return emptyMcis, err } check, err := CheckMcis(nsId, req.Name) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return emptyMcis, err } if check { @@ -1293,7 +1293,7 @@ func CreateMcisVmDynamic(nsId string, mcisId string, req *TbVmDynamicReq) (*TbMc subGroupId := req.Name check, err := CheckSubGroup(nsId, mcisId, subGroupId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return emptyMcis, err } if check { @@ -1303,7 +1303,7 @@ func CreateMcisVmDynamic(nsId string, mcisId string, req *TbVmDynamicReq) (*TbMc vmReq, err := getVmReqFromDynamicReq(nsId, req) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return emptyMcis, err } @@ -1323,14 +1323,14 @@ func getVmReqFromDynamicReq(nsId string, req *TbVmDynamicReq) (*TbVmReq, error) tempInterface, err := mcir.GetResource(common.SystemCommonNs, common.StrSpec, k.CommonSpec) if err != nil { err := fmt.Errorf("Failed to get the spec " + k.CommonSpec) - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return &TbVmReq{}, err } specInfo := mcir.TbSpecInfo{} err = common.CopySrcToDest(&tempInterface, &specInfo) if err != nil { err := fmt.Errorf("Failed to CopySrcToDest() " + k.CommonSpec) - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return &TbVmReq{}, err } @@ -1345,14 +1345,14 @@ func getVmReqFromDynamicReq(nsId string, req *TbVmDynamicReq) (*TbVmReq, error) _, err = common.GetConnConfig(specInfo.RegionName) if err != nil { err := fmt.Errorf("Failed to get RegionName (" + specInfo.RegionName + ") for Spec (" + k.CommonSpec + ") is not found.") - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return &TbVmReq{}, err } // validate the GetConnConfig for spec _, err = common.GetConnConfig(vmReq.ConnectionName) if err != nil { err := fmt.Errorf("Failed to get ConnectionName (" + vmReq.ConnectionName + ") for Spec (" + k.CommonSpec + ") is not found.") - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return &TbVmReq{}, err } @@ -1364,7 +1364,7 @@ func getVmReqFromDynamicReq(nsId string, req *TbVmDynamicReq) (*TbVmReq, error) tempInterface, err = mcir.GetResource(common.SystemCommonNs, common.StrImage, vmReq.ImageId) if err != nil { err := fmt.Errorf("Failed to get the Image " + vmReq.ImageId + " from " + vmReq.ConnectionName) - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return &TbVmReq{}, err } @@ -1451,9 +1451,9 @@ func AddVmToMcis(wg *sync.WaitGroup, nsId string, mcisId string, vmInfoData *TbV key := common.GenMcisKey(nsId, mcisId, "") keyValue, err := common.CBStore.Get(key) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") err = fmt.Errorf("In AddVmToMcis(); CBStore.Get() returned an error.") - common.CBLog.Error(err) + log.Error().Err(err).Msg("") // return nil, err } @@ -1466,7 +1466,7 @@ func AddVmToMcis(wg *sync.WaitGroup, nsId string, mcisId string, vmInfoData *TbV val, _ := json.Marshal(vmInfoData) err = common.CBStore.Put(key, string(val)) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return err } @@ -1488,7 +1488,7 @@ func AddVmToMcis(wg *sync.WaitGroup, nsId string, mcisId string, vmInfoData *TbV val, _ = json.Marshal(vmInfoData) err = common.CBStore.Put(key, string(val)) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return err } @@ -1499,7 +1499,7 @@ func AddVmToMcis(wg *sync.WaitGroup, nsId string, mcisId string, vmInfoData *TbV vmInfoData.Status = StatusFailed vmInfoData.SystemMessage = err.Error() UpdateVmInfo(nsId, mcisId, *vmInfoData) - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return err } @@ -1511,7 +1511,7 @@ func AddVmToMcis(wg *sync.WaitGroup, nsId string, mcisId string, vmInfoData *TbV vmStatusInfoTmp, err := FetchVmStatus(nsId, mcisId, vmInfoData.Id) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return err } @@ -1561,7 +1561,7 @@ func CreateVm(nsId string, mcisId string, vmInfoData *TbVmInfo, option string) e default: } if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return err } @@ -1570,7 +1570,7 @@ func CreateVm(nsId string, mcisId string, vmInfoData *TbVmInfo, option string) e // IdByCSP is required if vmInfoData.IdByCSP == "" { err := fmt.Errorf("vmInfoData.IdByCSP is empty (required for register VM)") - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return err } } @@ -1615,7 +1615,7 @@ func CreateVm(nsId string, mcisId string, vmInfoData *TbVmInfo, option string) e if requestBody.ReqInfo.ImageName == "" || err != nil { errAgg += err.Error() err = fmt.Errorf(errAgg) - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return err } } @@ -1630,28 +1630,28 @@ func CreateVm(nsId string, mcisId string, vmInfoData *TbVmInfo, option string) e requestBody.ReqInfo.VMSpecName, err = common.GetCspResourceId(nsId, common.StrSpec, vmInfoData.SpecId) if requestBody.ReqInfo.VMSpecName == "" || err != nil { - common.CBLog.Info(err) + log.Info().Msg(err.Error()) errAgg := err.Error() // If cannot find the resource, use common resource requestBody.ReqInfo.VMSpecName, err = common.GetCspResourceId(common.SystemCommonNs, common.StrSpec, vmInfoData.SpecId) if requestBody.ReqInfo.ImageName == "" || err != nil { errAgg += err.Error() err = fmt.Errorf(errAgg) - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return err } } requestBody.ReqInfo.VPCName, err = common.GetCspResourceId(nsId, common.StrVNet, vmInfoData.VNetId) if requestBody.ReqInfo.VPCName == "" { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return err } // TODO: needs to be enhnaced to use GetCspResourceId (GetCspResourceId needs to be updated as well) requestBody.ReqInfo.SubnetName = vmInfoData.SubnetId //common.GetCspResourceId(nsId, common.StrVNet, vmInfoData.SubnetId) if requestBody.ReqInfo.SubnetName == "" { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return err } @@ -1659,7 +1659,7 @@ func CreateVm(nsId string, mcisId string, vmInfoData *TbVmInfo, option string) e for _, v := range vmInfoData.SecurityGroupIds { CspSgId, err := common.GetCspResourceId(nsId, common.StrSecurityGroup, v) if CspSgId == "" { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return err } @@ -1673,7 +1673,7 @@ func CreateVm(nsId string, mcisId string, vmInfoData *TbVmInfo, option string) e if v != "" { CspDataDiskId, err := common.GetCspResourceId(nsId, common.StrDataDisk, v) if err != nil || CspDataDiskId == "" { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return err } DataDiskIdsTmp = append(DataDiskIdsTmp, CspDataDiskId) @@ -1683,7 +1683,7 @@ func CreateVm(nsId string, mcisId string, vmInfoData *TbVmInfo, option string) e requestBody.ReqInfo.KeyPairName, err = common.GetCspResourceId(nsId, common.StrSSHKey, vmInfoData.SshKeyId) if requestBody.ReqInfo.KeyPairName == "" { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return err } } @@ -1711,7 +1711,7 @@ func CreateVm(nsId string, mcisId string, vmInfoData *TbVmInfo, option string) e ) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return err } @@ -1739,7 +1739,7 @@ func CreateVm(nsId string, mcisId string, vmInfoData *TbVmInfo, option string) e // vNet resourceListInNs, err := mcir.ListResource(nsId, common.StrVNet, "cspVNetName", callResult.VpcIID.NameId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") } else { resourcesInNs := resourceListInNs.([]mcir.TbVNetInfo) // type assertion for _, resource := range resourcesInNs { @@ -1753,7 +1753,7 @@ func CreateVm(nsId string, mcisId string, vmInfoData *TbVmInfo, option string) e // access Key resourceListInNs, err = mcir.ListResource(nsId, common.StrSSHKey, "cspSshKeyName", callResult.KeyPairIId.NameId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") } else { resourcesInNs := resourceListInNs.([]mcir.TbSshKeyInfo) // type assertion for _, resource := range resourcesInNs { @@ -1811,7 +1811,7 @@ func CreateVm(nsId string, mcisId string, vmInfoData *TbVmInfo, option string) e _, err = SetBastionNodes(nsId, mcisId, vmInfoData.Id, "") if err != nil { // just log error and continue - common.CBLog.Error(err) + log.Error().Err(err).Msg("") } return nil diff --git a/src/core/mcis/recommendation.go b/src/core/mcis/recommendation.go index 1092e0883..39291048e 100644 --- a/src/core/mcis/recommendation.go +++ b/src/core/mcis/recommendation.go @@ -27,6 +27,7 @@ import ( "github.com/cloud-barista/cb-tumblebug/src/core/common" "github.com/cloud-barista/cb-tumblebug/src/core/mcir" + "github.com/rs/zerolog/log" cbstore_utils "github.com/cloud-barista/cb-store/utils" ) @@ -102,7 +103,7 @@ func RecommendVm(nsId string, plan DeploymentPlan) ([]mcir.TbSpecInfo, error) { operand64, err = strconv.ParseFloat(strings.ReplaceAll(condition.Operand, " ", ""), 32) operand = float32(operand64) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return []mcir.TbSpecInfo{}, err } } @@ -153,7 +154,7 @@ func RecommendVm(nsId string, plan DeploymentPlan) ([]mcir.TbSpecInfo, error) { filteredSpecs, err := mcir.FilterSpecsByRange(nsId, *u) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return []mcir.TbSpecInfo{}, err } if len(filteredSpecs) == 0 { @@ -312,12 +313,12 @@ func RecommendVmLocation(nsId string, specList *[]mcir.TbSpecInfo, param *[]Para slice := strings.Split(coordinateStr, "/") latitude, err := strconv.ParseFloat(strings.ReplaceAll(slice[0], " ", ""), 32) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return []mcir.TbSpecInfo{}, err } longitude, err := strconv.ParseFloat(strings.ReplaceAll(slice[1], " ", ""), 32) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return []mcir.TbSpecInfo{}, err } @@ -340,7 +341,7 @@ func RecommendVmLocation(nsId string, specList *[]mcir.TbSpecInfo, param *[]Para distance, err := getDistance(latitude, longitude, (*specList)[i].ConnectionName) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") mu.Lock() globalErr = err // Capture the error in globalErr mu.Unlock() @@ -409,12 +410,12 @@ func RecommendVmLocation(nsId string, specList *[]mcir.TbSpecInfo, param *[]Para slice := strings.Split(coordinateStr, "/") latitudeEach, err := strconv.ParseFloat(strings.ReplaceAll(slice[0], " ", ""), 32) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return []mcir.TbSpecInfo{}, err } longitudeEach, err := strconv.ParseFloat(strings.ReplaceAll(slice[1], " ", ""), 32) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return []mcir.TbSpecInfo{}, err } latitudeSum += latitudeEach @@ -444,7 +445,7 @@ func RecommendVmLocation(nsId string, specList *[]mcir.TbSpecInfo, param *[]Para distance, err := getDistance(latitude, longitude, (*specList)[i].ConnectionName) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") mu.Lock() globalErr = err // Capture the error in globalErr mu.Unlock() @@ -546,12 +547,12 @@ func getDistance(latitude float64, longitude float64, ConnectionName string) (fl cloudLatitude, err := strconv.ParseFloat(strings.ReplaceAll(Location.Latitude, " ", ""), 32) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return 0, err } cloudLongitude, err := strconv.ParseFloat(strings.ReplaceAll(Location.Longitude, " ", ""), 32) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return 0, err } @@ -567,7 +568,7 @@ func GetLatency(src string, dest string) (float64, error) { latencyString := common.RuntimeLatancyMap[common.RuntimeLatancyMapIndex[src]][common.RuntimeLatancyMapIndex[dest]] latency, err := strconv.ParseFloat(strings.ReplaceAll(latencyString, " ", ""), 32) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return 999999, err } return latency, nil @@ -674,7 +675,7 @@ func GetRecommendList(nsId string, cpuSize string, memSize string, diskSize stri keyValue, err := common.CBStore.GetList(key, true) keyValue = cbstore_utils.GetChildList(keyValue, key) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return []TbVmPriority{}, err } @@ -684,7 +685,7 @@ func GetRecommendList(nsId string, cpuSize string, memSize string, diskSize stri fmt.Println("getRecommendList1: " + v.Key) err = json.Unmarshal([]byte(v.Value), &content) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return []TbVmPriority{}, err } @@ -693,7 +694,7 @@ func GetRecommendList(nsId string, cpuSize string, memSize string, diskSize stri keyValue2, err := common.CBStore.Get(key2) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return []TbVmPriority{}, err } json.Unmarshal([]byte(keyValue2.Value), &content2) @@ -717,7 +718,7 @@ func CorePostMcisRecommend(nsId string, req *McisRecommendReq) ([]TbVmRecommendI err := common.CheckString(nsId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return nil, err } @@ -749,7 +750,7 @@ func CorePostMcisRecommend(nsId string, req *McisRecommendReq) ([]TbVmRecommendI vmTmp.VmPriority, err = GetRecommendList(nsId, v.VcpuSize, v.MemorySize, v.DiskSize) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return nil, fmt.Errorf("Failed to recommend MCIS") } diff --git a/src/core/mcis/remoteCommand.go b/src/core/mcis/remoteCommand.go index 13c659336..b3b8ead6f 100644 --- a/src/core/mcis/remoteCommand.go +++ b/src/core/mcis/remoteCommand.go @@ -25,6 +25,7 @@ import ( "github.com/cloud-barista/cb-tumblebug/src/core/common" "github.com/cloud-barista/cb-tumblebug/src/core/mcir" validator "github.com/go-playground/validator/v10" + "github.com/rs/zerolog/log" "golang.org/x/crypto/ssh" ) @@ -70,13 +71,13 @@ func RemoteCommandToMcis(nsId string, mcisId string, subGroupId string, vmId str err := common.CheckString(nsId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return nil, err } err = common.CheckString(mcisId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return nil, err } @@ -122,13 +123,13 @@ func RemoteCommandToMcis(nsId string, mcisId string, subGroupId string, vmId str vmList, err := ListVmId(nsId, mcisId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return nil, err } if subGroupId != "" { vmListInGroup, err := ListVmBySubGroup(nsId, mcisId, subGroupId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return nil, err } if vmListInGroup == nil { @@ -162,26 +163,26 @@ func RunRemoteCommand(nsId string, mcisId string, vmId string, givenUserName str // use privagte IP of the target VM _, targetVmIP, targetSshPort, err := GetVmIp(nsId, mcisId, vmId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return map[int]string{}, map[int]string{}, err } targetUserName, targetPrivateKey, err := VerifySshUserName(nsId, mcisId, vmId, targetVmIP, targetSshPort, givenUserName) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return map[int]string{}, map[int]string{}, err } // Set Bastion SSH config (bastionEndpoint, userName, Private Key) bastionNodes, err := GetBastionNodes(nsId, mcisId, vmId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return map[int]string{}, map[int]string{}, err } bastionNode := bastionNodes[0] // use public IP of the bastion VM bastionIp, _, bastionSshPort, err := GetVmIp(nsId, bastionNode.McisId, bastionNode.VmId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return map[int]string{}, map[int]string{}, err } bastionUserName, bastionSshKey, err := VerifySshUserName(nsId, bastionNode.McisId, bastionNode.VmId, bastionIp, bastionSshPort, givenUserName) @@ -307,7 +308,7 @@ func VerifySshUserName(nsId string, mcisId string, vmId string, vmIp string, ssh userName, _, privateKey, err := GetVmSshKey(nsId, mcisId, vmId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return "", "", err } @@ -322,7 +323,7 @@ func VerifySshUserName(nsId string, mcisId string, vmId string, vmIp string, ssh if theUserName == "" { err := fmt.Errorf("Could not find a valid username") - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return "", "", err } @@ -331,7 +332,7 @@ func VerifySshUserName(nsId string, mcisId string, vmId string, vmIp string, ssh // if theUserName != "" { // err := UpdateVmSshKey(nsId, mcisId, vmId, theUserName) // if err != nil { - // common.CBLog.Error(err) + // log.Error().Err(err).Msg("") // return "", "", err // } // } else { @@ -376,21 +377,21 @@ func GetVmSshKey(nsId string, mcisId string, vmId string) (string, string, strin keyValue, err := common.CBStore.Get(key) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") err = fmt.Errorf("Cannot find the key from DB. key: " + key) return "", "", "", err } err = json.Unmarshal([]byte(keyValue.Value), &content) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return "", "", "", err } sshKey := common.GenResourceKey(nsId, common.StrSSHKey, content.SshKeyId) keyValue, err = common.CBStore.Get(sshKey) if err != nil || keyValue == nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return "", "", "", err } @@ -401,7 +402,7 @@ func GetVmSshKey(nsId string, mcisId string, vmId string) (string, string, strin } err = json.Unmarshal([]byte(keyValue.Value), &keyContent) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return "", "", "", err } @@ -418,9 +419,9 @@ func UpdateVmSshKey(nsId string, mcisId string, vmId string, verifiedUserName st key := common.GenMcisKey(nsId, mcisId, vmId) keyValue, err := common.CBStore.Get(key) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") err = fmt.Errorf("In UpdateVmSshKey(); CBStore.Get() returned an error.") - common.CBLog.Error(err) + log.Error().Err(err).Msg("") // return nil, err } @@ -437,7 +438,7 @@ func UpdateVmSshKey(nsId string, mcisId string, vmId string, verifiedUserName st val, _ := json.Marshal(tmpSshKeyInfo) err = common.CBStore.Put(keyValue.Key, string(val)) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return err } return nil @@ -556,7 +557,7 @@ func SetBastionNodes(nsId string, mcisId string, targetVmId string, bastionVmId // Check if bastion node already exists for the target VM (for random assignment) currentBastion, err := GetBastionNodes(nsId, mcisId, targetVmId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return "", err } if len(currentBastion) > 0 && bastionVmId == "" { @@ -566,19 +567,19 @@ func SetBastionNodes(nsId string, mcisId string, targetVmId string, bastionVmId vmObj, err := GetVmObject(nsId, mcisId, targetVmId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return "", err } res, err := mcir.GetResource(nsId, common.StrVNet, vmObj.VNetId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return "", err } tempVNetInfo, ok := res.(mcir.TbVNetInfo) if !ok { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return "", err } @@ -589,12 +590,12 @@ func SetBastionNodes(nsId string, mcisId string, targetVmId string, bastionVmId if bastionVmId == "" { vmIdsInSubnet, err := ListVmByFilter(nsId, mcisId, "SubnetId", subnetInfo.Id) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") } for _, v := range vmIdsInSubnet { tmpPublicIp, _, _, err := GetVmIp(nsId, mcisId, v) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") } if tmpPublicIp != "" { bastionVmId = v @@ -628,7 +629,7 @@ func SetBastionNodes(nsId string, mcisId string, targetVmId string, bastionVmId func RemoveBastionNodes(nsId string, mcisId string, bastionVmId string) (string, error) { resourceListInNs, err := mcir.ListResource(nsId, common.StrVNet, "mcisId", mcisId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return "", err } else { vNets := resourceListInNs.([]mcir.TbVNetInfo) // type assertion @@ -657,21 +658,21 @@ func GetBastionNodes(nsId string, mcisId string, targetVmId string) ([]mcir.Bast // Fetch VM object based on nsId, mcisId, and targetVmId vmObj, err := GetVmObject(nsId, mcisId, targetVmId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return returnValue, err } // Fetch VNet resource information res, err := mcir.GetResource(nsId, common.StrVNet, vmObj.VNetId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return returnValue, err } // Type assertion for VNet information tempVNetInfo, ok := res.(mcir.TbVNetInfo) if !ok { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return returnValue, err } diff --git a/src/core/mcis/snapshot.go b/src/core/mcis/snapshot.go index ad353c78b..311832b68 100644 --- a/src/core/mcis/snapshot.go +++ b/src/core/mcis/snapshot.go @@ -21,6 +21,7 @@ import ( "github.com/cloud-barista/cb-tumblebug/src/core/common" "github.com/cloud-barista/cb-tumblebug/src/core/mcir" "github.com/go-resty/resty/v2" + "github.com/rs/zerolog/log" ) type TbVmSnapshotReq struct { @@ -35,7 +36,7 @@ func CreateVmSnapshot(nsId string, mcisId string, vmId string, snapshotName stri keyValue, err := common.CBStore.Get(vmKey) if keyValue == nil || err != nil { err := fmt.Errorf("Failed to find 'ns/mcis/vm': %s/%s/%s \n", nsId, mcisId, vmId) - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return mcir.TbCustomImageInfo{}, err } @@ -72,7 +73,7 @@ func CreateVmSnapshot(nsId string, mcisId string, vmId string, snapshotName stri // dataDisks_before_snapshot := inspect_result_before_snapshot.Resources.OnTumblebug.Info // if err != nil { // err := fmt.Errorf("Failed to get current datadisks' info. \n") - // common.CBLog.Error(err) + // log.Error().Err(err).Msg("") // return mcir.TbCustomImageInfo{}, err // } @@ -86,7 +87,7 @@ func CreateVmSnapshot(nsId string, mcisId string, vmId string, snapshotName stri case resp.StatusCode() >= 400 || resp.StatusCode() < 200: err := fmt.Errorf(string(resp.Body())) fmt.Println("body: ", string(resp.Body())) - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return mcir.TbCustomImageInfo{}, err } @@ -113,7 +114,7 @@ func CreateVmSnapshot(nsId string, mcisId string, vmId string, snapshotName stri result, err := mcir.RegisterCustomImageWithInfo(nsId, tempTbCustomImageInfo) if err != nil { err := fmt.Errorf("Failed to find 'ns/mcis/vm': %s/%s/%s \n", nsId, mcisId, vmId) - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return mcir.TbCustomImageInfo{}, err } @@ -123,7 +124,7 @@ func CreateVmSnapshot(nsId string, mcisId string, vmId string, snapshotName stri // dataDisks_after_snapshot := inspect_result_after_snapshot.Resources.OnTumblebug.Info // if err != nil { // err := fmt.Errorf("Failed to get current datadisks' info. \n") - // common.CBLog.Error(err) + // log.Error().Err(err).Msg("") // return mcir.TbCustomImageInfo{}, err // } @@ -140,7 +141,7 @@ func CreateVmSnapshot(nsId string, mcisId string, vmId string, snapshotName stri // _, err = mcir.CreateDataDisk(nsId, &tempTbDataDiskReq, "register") // if err != nil { // err := fmt.Errorf("Failed to register the created dataDisk %s to TB. \n", v.IdByCsp) - // common.CBLog.Error(err) + // log.Error().Err(err).Msg("") // continue // } // } diff --git a/src/core/mcis/utility.go b/src/core/mcis/utility.go index b63772073..acf276ee6 100644 --- a/src/core/mcis/utility.go +++ b/src/core/mcis/utility.go @@ -24,6 +24,7 @@ import ( "github.com/cloud-barista/cb-tumblebug/src/core/common" "github.com/cloud-barista/cb-tumblebug/src/core/mcir" + "github.com/rs/zerolog/log" "github.com/go-resty/resty/v2" @@ -114,13 +115,13 @@ func CheckMcis(nsId string, mcisId string) (bool, error) { err := common.CheckString(nsId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return false, err } err = common.CheckString(mcisId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return false, err } fmt.Println("[Check mcis] " + mcisId) @@ -129,9 +130,9 @@ func CheckMcis(nsId string, mcisId string) (bool, error) { keyValue, err := common.CBStore.Get(key) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") err = fmt.Errorf("In CheckMcis(); CBStore.Get() returned an error.") - common.CBLog.Error(err) + log.Error().Err(err).Msg("") // return nil, err } @@ -147,19 +148,19 @@ func CheckSubGroup(nsId string, mcisId string, subGroupId string) (bool, error) err := common.CheckString(nsId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return false, err } err = common.CheckString(mcisId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return false, err } subGroupList, err := ListSubGroupId(nsId, mcisId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return false, err } for _, v := range subGroupList { @@ -186,18 +187,18 @@ func CheckVm(nsId string, mcisId string, vmId string) (bool, error) { err := common.CheckString(nsId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return false, err } err = common.CheckString(mcisId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return false, err } err = common.CheckString(vmId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return false, err } fmt.Println("[Check vm] " + mcisId + ", " + vmId) @@ -206,9 +207,9 @@ func CheckVm(nsId string, mcisId string, vmId string) (bool, error) { keyValue, err := common.CBStore.Get(key) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") err = fmt.Errorf("In CheckVm(); CBStore.Get() returned an error.") - common.CBLog.Error(err) + log.Error().Err(err).Msg("") // return nil, err } @@ -232,13 +233,13 @@ func CheckMcisPolicy(nsId string, mcisId string) (bool, error) { err := common.CheckString(nsId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return false, err } err = common.CheckString(mcisId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return false, err } fmt.Println("[Check McisPolicy] " + mcisId) @@ -247,9 +248,9 @@ func CheckMcisPolicy(nsId string, mcisId string) (bool, error) { keyValue, err := common.CBStore.Get(key) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") err = fmt.Errorf("In CheckMcisPolicy(); CBStore.Get() returned an error.") - common.CBLog.Error(err) + log.Error().Err(err).Msg("") // return nil, err } @@ -366,7 +367,7 @@ func InspectResources(connConfig string, resourceType string) (InspectResource, nsList, err := common.ListNsId() nullObj := InspectResource{} if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") err = fmt.Errorf("an error occurred while getting namespaces' list: " + err.Error()) return nullObj, err } @@ -383,7 +384,7 @@ func InspectResources(connConfig string, resourceType string) (InspectResource, for _, mcis := range mcisListinNs { nlbListInMcis, err := ListNLBId(ns, mcis) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") err := fmt.Errorf("an error occurred while getting resource list") return nullObj, err } @@ -394,7 +395,7 @@ func InspectResources(connConfig string, resourceType string) (InspectResource, for _, nlbId := range nlbListInMcis { nlb, err := GetNLB(ns, mcis, nlbId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") err := fmt.Errorf("an error occurred while getting resource list") return nullObj, err } @@ -419,7 +420,7 @@ func InspectResources(connConfig string, resourceType string) (InspectResource, for _, mcis := range mcisListinNs { vmListInMcis, err := ListVmId(ns, mcis) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") err := fmt.Errorf("an error occurred while getting resource list") return nullObj, err } @@ -430,7 +431,7 @@ func InspectResources(connConfig string, resourceType string) (InspectResource, for _, vmId := range vmListInMcis { vm, err := GetVmObject(ns, mcis, vmId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") err := fmt.Errorf("an error occurred while getting resource list") return nullObj, err } @@ -450,7 +451,7 @@ func InspectResources(connConfig string, resourceType string) (InspectResource, case common.StrVNet: resourceListInNs, err := mcir.ListResource(ns, resourceType, "", "") if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") err := fmt.Errorf("an error occurred while getting resource list") return nullObj, err } @@ -472,7 +473,7 @@ func InspectResources(connConfig string, resourceType string) (InspectResource, case common.StrSecurityGroup: resourceListInNs, err := mcir.ListResource(ns, resourceType, "", "") if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") err := fmt.Errorf("an error occurred while getting resource list") return nullObj, err } @@ -494,7 +495,7 @@ func InspectResources(connConfig string, resourceType string) (InspectResource, case common.StrSSHKey: resourceListInNs, err := mcir.ListResource(ns, resourceType, "", "") if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") err := fmt.Errorf("an error occurred while getting resource list") return nullObj, err } @@ -516,7 +517,7 @@ func InspectResources(connConfig string, resourceType string) (InspectResource, case common.StrDataDisk: resourceListInNs, err := mcir.ListResource(ns, resourceType, "", "") if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") err := fmt.Errorf("an error occurred while getting resource list") return nullObj, err } @@ -538,7 +539,7 @@ func InspectResources(connConfig string, resourceType string) (InspectResource, case common.StrCustomImage: resourceListInNs, err := mcir.ListResource(ns, resourceType, "", "") if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") err := fmt.Errorf("an error occurred while getting resource list") return nullObj, err } @@ -602,7 +603,7 @@ func InspectResources(connConfig string, resourceType string) (InspectResource, Get(spiderRequestURL) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") err := fmt.Errorf("an error occurred while requesting to CB-Spider") return nullObj, err } @@ -611,7 +612,7 @@ func InspectResources(connConfig string, resourceType string) (InspectResource, switch { case resp.StatusCode() >= 400 || resp.StatusCode() < 200: err := fmt.Errorf(string(resp.Body())) - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return nullObj, err default: } @@ -717,7 +718,7 @@ func InspectResourcesOverview() (InspectResourceAllResult, error) { connectionConfigList, err := common.GetConnConfigList() if err != nil { err := fmt.Errorf("Cannot load ConnectionConfigList") - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return InspectResourceAllResult{}, err } @@ -736,7 +737,7 @@ func InspectResourcesOverview() (InspectResourceAllResult, error) { inspectResult, err := InspectResources(k.ConfigName, common.StrVNet) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") temp.SystemMessage = err.Error() } // retry if request rateLimitExceeded occurs. (GCP has ratelimiting) @@ -747,7 +748,7 @@ func InspectResourcesOverview() (InspectResourceAllResult, error) { common.RandomSleep(40, 80) inspectResult, err = InspectResources(k.ConfigName, common.StrVNet) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") temp.SystemMessage = err.Error() } else { temp.SystemMessage = "" @@ -760,7 +761,7 @@ func InspectResourcesOverview() (InspectResourceAllResult, error) { inspectResult, err = InspectResources(k.ConfigName, common.StrSecurityGroup) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") temp.SystemMessage += err.Error() } temp.TumblebugOverview.SecurityGroup = inspectResult.ResourceOverview.OnTumblebug @@ -768,7 +769,7 @@ func InspectResourcesOverview() (InspectResourceAllResult, error) { inspectResult, err = InspectResources(k.ConfigName, common.StrSSHKey) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") temp.SystemMessage += err.Error() } temp.TumblebugOverview.SshKey = inspectResult.ResourceOverview.OnTumblebug @@ -776,7 +777,7 @@ func InspectResourcesOverview() (InspectResourceAllResult, error) { inspectResult, err = InspectResources(k.ConfigName, common.StrDataDisk) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") temp.SystemMessage += err.Error() } temp.TumblebugOverview.DataDisk = inspectResult.ResourceOverview.OnTumblebug @@ -784,7 +785,7 @@ func InspectResourcesOverview() (InspectResourceAllResult, error) { inspectResult, err = InspectResources(k.ConfigName, common.StrCustomImage) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") temp.SystemMessage += err.Error() } temp.TumblebugOverview.CustomImage = inspectResult.ResourceOverview.OnTumblebug @@ -792,7 +793,7 @@ func InspectResourcesOverview() (InspectResourceAllResult, error) { inspectResult, err = InspectResources(k.ConfigName, common.StrVM) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") temp.SystemMessage += err.Error() } temp.TumblebugOverview.Vm = inspectResult.ResourceOverview.OnTumblebug @@ -800,7 +801,7 @@ func InspectResourcesOverview() (InspectResourceAllResult, error) { inspectResult, err = InspectResources(k.ConfigName, common.StrNLB) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") temp.SystemMessage += err.Error() } temp.TumblebugOverview.NLB = inspectResult.ResourceOverview.OnTumblebug @@ -884,7 +885,7 @@ func RegisterCspNativeResourcesAll(nsId string, mcisId string, option string, mc connectionConfigList, err := common.GetConnConfigList() if err != nil { err := fmt.Errorf("Cannot load ConnectionConfigList") - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return RegisterResourceAllResult{}, err } @@ -915,7 +916,7 @@ func RegisterCspNativeResourcesAll(nsId string, mcisId string, option string, mc registerResult, err := RegisterCspNativeResources(nsId, k.ConfigName, mcisNameForRegister, option, mcisFlag) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") } output.RegisterationResult = append(output.RegisterationResult, registerResult) @@ -966,7 +967,7 @@ func RegisterCspNativeResources(nsId string, connConfig string, mcisId string, o // bring vNet list and register all inspectedResources, err := InspectResources(connConfig, common.StrVNet) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") result.SystemMessage = err.Error() } for _, r := range inspectedResources.Resources.OnCspOnly.Info { @@ -981,7 +982,7 @@ func RegisterCspNativeResources(nsId string, connConfig string, mcisId string, o registeredStatus = "" if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") registeredStatus = " [Failed] " + err.Error() result.RegisterationOverview.VNet-- result.RegisterationOverview.Failed++ @@ -996,7 +997,7 @@ func RegisterCspNativeResources(nsId string, connConfig string, mcisId string, o // bring SecurityGroup list and register all inspectedResources, err = InspectResources(connConfig, common.StrSecurityGroup) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") result.SystemMessage += "//" + err.Error() } for _, r := range inspectedResources.Resources.OnCspOnly.Info { @@ -1012,7 +1013,7 @@ func RegisterCspNativeResources(nsId string, connConfig string, mcisId string, o registeredStatus = "" if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") registeredStatus = " [Failed] " + err.Error() result.RegisterationOverview.SecurityGroup-- result.RegisterationOverview.Failed++ @@ -1027,7 +1028,7 @@ func RegisterCspNativeResources(nsId string, connConfig string, mcisId string, o // bring SSHKey list and register all inspectedResources, err = InspectResources(connConfig, common.StrSSHKey) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") result.SystemMessage += "//" + err.Error() } for _, r := range inspectedResources.Resources.OnCspOnly.Info { @@ -1047,7 +1048,7 @@ func RegisterCspNativeResources(nsId string, connConfig string, mcisId string, o registeredStatus = "" if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") registeredStatus = " [Failed] " + err.Error() result.RegisterationOverview.SshKey-- result.RegisterationOverview.Failed++ @@ -1063,7 +1064,7 @@ func RegisterCspNativeResources(nsId string, connConfig string, mcisId string, o // bring DataDisk list and register all inspectedResources, err = InspectResources(connConfig, common.StrDataDisk) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") result.SystemMessage += "//" + err.Error() } for _, r := range inspectedResources.Resources.OnCspOnly.Info { @@ -1078,7 +1079,7 @@ func RegisterCspNativeResources(nsId string, connConfig string, mcisId string, o registeredStatus = "" if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") registeredStatus = " [Failed] " + err.Error() result.RegisterationOverview.DataDisk-- result.RegisterationOverview.Failed++ @@ -1094,7 +1095,7 @@ func RegisterCspNativeResources(nsId string, connConfig string, mcisId string, o // bring CustomImage list and register all inspectedResources, err = InspectResources(connConfig, common.StrCustomImage) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") result.SystemMessage += "//" + err.Error() } for _, r := range inspectedResources.Resources.OnCspOnly.Info { @@ -1109,7 +1110,7 @@ func RegisterCspNativeResources(nsId string, connConfig string, mcisId string, o registeredStatus = "" if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") registeredStatus = " [Failed] " + err.Error() result.RegisterationOverview.CustomImage-- result.RegisterationOverview.Failed++ @@ -1128,7 +1129,7 @@ func RegisterCspNativeResources(nsId string, connConfig string, mcisId string, o // bring VM list and register all inspectedResourcesVm, err := InspectResources(connConfig, common.StrVM) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") result.SystemMessage += "//" + err.Error() } for _, r := range inspectedResourcesVm.Resources.OnCspOnly.Info { @@ -1163,7 +1164,7 @@ func RegisterCspNativeResources(nsId string, connConfig string, mcisId string, o registeredStatus = "" if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") registeredStatus = " [Failed] " + err.Error() result.RegisterationOverview.Vm-- result.RegisterationOverview.Failed++ @@ -1188,19 +1189,19 @@ func FindTbVmByCspId(nsId string, mcisId string, vmIdByCsp string) (TbVmInfo, er err := common.CheckString(nsId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return TbVmInfo{}, err } err = common.CheckString(mcisId) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return TbVmInfo{}, err } err = common.CheckString(vmIdByCsp) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("") return TbVmInfo{}, err } diff --git a/src/main.go b/src/main.go index e0ac20ce2..0cf43f27a 100644 --- a/src/main.go +++ b/src/main.go @@ -26,6 +26,7 @@ import ( // Black import (_) is for running a package's init() function without using its other contents. _ "github.com/cloud-barista/cb-tumblebug/src/core/common/logger" + "github.com/rs/zerolog/log" //_ "github.com/go-sql-driver/mysql" "github.com/fsnotify/fsnotify" @@ -57,11 +58,13 @@ func setConfig() { viper.SetConfigType("yaml") err := viper.ReadInConfig() if err != nil { + log.Error().Err(err).Msg("") panic(fmt.Errorf("fatal error reading cloud_conf: %w", err)) } fmt.Println(viper.ConfigFileUsed()) err = viper.Unmarshal(&common.RuntimeConf) if err != nil { + log.Error().Err(err).Msg("") panic(err) } @@ -79,6 +82,7 @@ func setConfig() { fmt.Println(cloudInfoViper.ConfigFileUsed()) err = cloudInfoViper.Unmarshal(&common.RuntimeCloudInfo) if err != nil { + log.Error().Err(err).Msg("") panic(err) } // fmt.Printf("%+v\n", common.RuntimeCloudInfo) @@ -92,7 +96,7 @@ func setConfig() { file, fileErr := os.Open("../assets/cloudlatencymap.csv") defer file.Close() if fileErr != nil { - common.CBLog.Error(fileErr) + log.Error().Err(fileErr).Msg("") panic(fileErr) } rdr := csv.NewReader(bufio.NewReader(file)) @@ -177,15 +181,15 @@ func main() { err := os.MkdirAll("../meta_db/dat/", os.ModePerm) if err != nil { - fmt.Println(err.Error()) + log.Error().Err(err).Msg("") } //err = common.OpenSQL("../meta_db/dat/cbtumblebug.s3db") // commented out to move to use XORM common.ORM, err = xorm.NewEngine("sqlite3", "../meta_db/dat/cbtumblebug.s3db") if err != nil { - fmt.Println(err.Error()) + log.Error().Err(err).Msg("") } else { - fmt.Println("Database access info set successfully") + log.Info().Msg("Database access info set successfully") } //common.ORM.SetMapper(names.SameMapper{}) common.ORM.SetTableMapper(names.SameMapper{}) @@ -204,25 +208,25 @@ func main() { //err = common.CreateSpecTable() // commented out to move to use XORM err = common.ORM.Sync2(new(mcir.TbSpecInfo)) if err != nil { - fmt.Println(err.Error()) + log.Error().Err(err).Msg("") } else { - fmt.Println("Table spec set successfully..") + log.Info().Msg("Table spec set successfully..") } // "CREATE Table IF NOT EXISTS image(...)" //err = common.CreateImageTable() // commented out to move to use XORM err = common.ORM.Sync2(new(mcir.TbImageInfo)) if err != nil { - fmt.Println(err.Error()) + log.Error().Err(err).Msg("") } else { - fmt.Println("Table image set successfully..") + log.Info().Msg("Table image set successfully..") } err = common.ORM.Sync2(new(mcir.TbCustomImageInfo)) if err != nil { - fmt.Println(err.Error()) + log.Error().Err(err).Msg("") } else { - fmt.Println("Table customImage set successfully..") + log.Info().Msg("Table customImage set successfully..") } //defer db.Close() @@ -246,13 +250,15 @@ func main() { go func() { viper.WatchConfig() viper.OnConfigChange(func(e fsnotify.Event) { - fmt.Println("Config file changed:", e.Name) + log.Info().Msgf("Config file changed: %s", e.Name) err := viper.ReadInConfig() if err != nil { // Handle errors reading the config file + log.Error().Err(err).Msg("") panic(fmt.Errorf("fatal error config file: %w", err)) } err = viper.Unmarshal(&common.RuntimeConf) if err != nil { + log.Error().Err(err).Msg("") panic(err) } })