Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Efforts to stabilize CB-DF monitoring agent installation #986

Merged
merged 3 commits into from
Nov 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/api/rest/server/mcis/control.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ func RestGetAllMcis(c echo.Context) error {
}
content := RestGetAllMcisStatusResponse{}
content.Mcis = result
common.PrintJsonPretty(content)
//common.PrintJsonPretty(content)
return c.JSON(http.StatusOK, &content)
} else if option == "simple" {
// MCIS in simple (without VM information)
Expand All @@ -218,7 +218,7 @@ func RestGetAllMcis(c echo.Context) error {
}
content := RestGetAllMcisResponse{}
content.Mcis = result
common.PrintJsonPretty(content)
//common.PrintJsonPretty(content)
return c.JSON(http.StatusOK, &content)
} else {
// MCIS in detail (with status information)
Expand All @@ -229,7 +229,7 @@ func RestGetAllMcis(c echo.Context) error {
}
content := RestGetAllMcisResponse{}
content.Mcis = result
common.PrintJsonPretty(content)
//common.PrintJsonPretty(content)
return c.JSON(http.StatusOK, &content)
}

Expand Down
59 changes: 29 additions & 30 deletions src/core/mcis/monitoring.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ func CallMonitoringAsync(wg *sync.WaitGroup, nsID string, mcisID string, mcisSer
errStr := ""
if err != nil {
common.CBLog.Error(err)
errStr += err.Error()
errStr += "/ " + err.Error()
}
fmt.Println("[CallMonitoringAsync] " + mcisID + "/" + vmID + "(" + vmIP + ")" + "with userName:" + userName)

Expand All @@ -191,14 +191,14 @@ func CallMonitoringAsync(wg *sync.WaitGroup, nsID string, mcisID string, mcisSer
vmInfoTmp.MonAgentStatus = "installing"
UpdateVmInfo(nsID, mcisID, vmInfoTmp)

url := common.DragonflyRestUrl + cmd
fmt.Println("\n[Calling DRAGONFLY] START")
fmt.Println("VM:" + nsID + "/" + mcisID + "/" + vmID + ", URL:" + url + ", userName:" + userName + ", cspType:" + vmInfoTmp.Location.CloudType + ", service_type:" + mcisServiceType)

if mcisServiceType == "" {
mcisServiceType = "default"
}

url := common.DragonflyRestUrl + cmd
fmt.Println("\n[Calling DRAGONFLY] START")
fmt.Println("VM:" + nsID + "/" + mcisID + "/" + vmID + ", URL:" + url + ", userName:" + userName + ", cspType:" + vmInfoTmp.Location.CloudType + ", service_type:" + mcisServiceType)

tempReq := monAgentInstallReq{
NsId: nsID,
McisId: mcisID,
Expand All @@ -211,17 +211,16 @@ func CallMonitoringAsync(wg *sync.WaitGroup, nsID string, mcisID string, mcisSer
ServiceType: mcisServiceType,
}
if tempReq.SshKey == "" {
fmt.Printf("\n[Request body to CB-DRAGONFLY]A problem detected.SshKey is empty.\n")
common.PrintJsonPretty(tempReq)
err = fmt.Errorf("/request body to install monitoring agent: sshKey is empty/")
err = fmt.Errorf("/request body to install monitoring agent: privateKey is empty/")
common.CBLog.Error(err)
errStr += err.Error()
errStr += "/ " + err.Error()
}

payload, err := json.Marshal(tempReq)
if err != nil {
common.CBLog.Error(err)
errStr += err.Error()
errStr += "/ " + err.Error()
}

responseLimit := 8
Expand All @@ -235,7 +234,7 @@ func CallMonitoringAsync(wg *sync.WaitGroup, nsID string, mcisID string, mcisSer

if err != nil {
common.CBLog.Error(err)
errStr += err.Error()
errStr += "/ " + err.Error()
}

req.Header.Add("Content-Type", "application/json")
Expand All @@ -247,21 +246,21 @@ func CallMonitoringAsync(wg *sync.WaitGroup, nsID string, mcisID string, mcisSer
fmt.Println("Called CB-DRAGONFLY API")
if err != nil {
common.CBLog.Error(err)
errStr += err.Error()
errStr += "/ " + err.Error()
} else {
fmt.Println("HTTP Status code: " + strconv.Itoa(res.StatusCode))
switch {
case res.StatusCode >= 400 || res.StatusCode < 200:
err = fmt.Errorf("HTTP Status: not in 200-399")
common.CBLog.Error(err)
errStr += err.Error()
errStr += "/ " + err.Error()
}

defer res.Body.Close()
body, err := ioutil.ReadAll(res.Body)
if err != nil {
common.CBLog.Error(err)
errStr += err.Error()
errStr += "/ " + err.Error()
}

result = string(body)
Expand All @@ -277,6 +276,7 @@ func CallMonitoringAsync(wg *sync.WaitGroup, nsID string, mcisID string, mcisSer
sshResultTmp.VmIp = vmIP

if err != nil {
common.CBLog.Error("[Monitoring Agent deployment errors] " + errStr)
sshResultTmp.Result = errStr
sshResultTmp.Err = err
*returnResult = append(*returnResult, sshResultTmp)
Expand Down Expand Up @@ -470,30 +470,29 @@ func CallGetMonitoringAsync(wg *sync.WaitGroup, nsID string, mcisID string, vmID
errStr = err.Error()
}

fmt.Print("[Call CB-DF Result (" + mcisID + "," + vmID + ")] ")
res, err := client.Do(req)

// result := ""

fmt.Print("[Call CB-DF Result (" + mcisID + "," + vmID + ")] ")
if err != nil {
common.CBLog.Error(err)
errStr = err.Error()
}
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)
errStr = err1.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)
errStr = err1.Error()
}

defer res.Body.Close()
body, err2 := ioutil.ReadAll(res.Body)
if err2 != nil {
common.CBLog.Error(err2)
errStr = err2.Error()
defer res.Body.Close()
body, err2 := ioutil.ReadAll(res.Body)
if err2 != nil {
common.CBLog.Error(err2)
errStr = err2.Error()
}
response = string(body)
}
response = string(body)
} else {
reqParams := df_pb.VMOnDemandMonQryRequest{
NsId: nsID,
Expand Down
24 changes: 13 additions & 11 deletions src/core/mcis/remoteCommand.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,17 +324,19 @@ func VerifySshUserName(nsId string, mcisId string, vmId string, vmIp string, ssh
fmt.Println("[Start SSH checking squence]")

// verify if vm is running with a public ip.
if vmIp == "" {
return "", "", fmt.Errorf("Cannot ssh, VM IP is null")
}
vmStatusInfoTmp, err := GetVmStatus(nsId, mcisId, vmId)
if err != nil {
common.CBLog.Error(err)
return "", "", err
}
if vmStatusInfoTmp.Status != StatusRunning || vmIp == "" {
return "", "", fmt.Errorf("Cannot ssh, VM is not Running")
}
/*
if vmIp == "" {
return "", "", fmt.Errorf("Cannot ssh, VM IP is null")
}
vmStatusInfoTmp, err := GetVmStatus(nsId, mcisId, vmId)
if err != nil {
common.CBLog.Error(err)
return "", "", err
}
if vmStatusInfoTmp.Status != StatusRunning || vmIp == "" {
return "", "", fmt.Errorf("Cannot ssh, VM is not Running")
}
*/

/* Code to check endpoint and port connectivity. (disabled for better speed)
// CheckConnectivity func checks if given port is open and ready.
Expand Down