Skip to content

Commit

Permalink
server: Add connection info status count to ListSourceGroup
Browse files Browse the repository at this point in the history
  • Loading branch information
ish-hcc committed Oct 3, 2024
1 parent d557f18 commit 9c279ae
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 8 deletions.
37 changes: 32 additions & 5 deletions server/pkg/api/rest/controller/sourceGroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,9 +254,9 @@ func GetSourceGroup(c echo.Context) error {
// @Param row query string false "Row of the source group list."
// @Param name query string false "Name of the source group."
// @Param description query string false "Description of the source group."
// @Success 200 {object} []model.SourceGroup "Successfully get a list of source group."
// @Failure 400 {object} common.ErrorResponse "Sent bad request."
// @Failure 500 {object} common.ErrorResponse "Failed to get a list of source group."
// @Success 200 {object} []model.ListSourceGroupRes "Successfully get a list of source group."
// @Failure 400 {object} common.ErrorResponse "Sent bad request."
// @Failure 500 {object} common.ErrorResponse "Failed to get a list of source group."
// @Router /source_group [get]
func ListSourceGroup(c echo.Context) error {
page, row, err := common.CheckPageRow(c)
Expand All @@ -269,12 +269,39 @@ func ListSourceGroup(c echo.Context) error {
Description: c.QueryParam("description"),
}

SourceGroups, err := dao.SourceGroupGetList(sourceGroup, page, row)
sourceGroups, err := dao.SourceGroupGetList(sourceGroup, page, row)
if err != nil {
return common.ReturnErrorMsg(c, err.Error())
}

return c.JSONPretty(http.StatusOK, SourceGroups, " ")
var listSourceGroupRes model.ListSourceGroupRes
listSourceGroupRes.SourceGroup = *sourceGroups

for _, sg := range *sourceGroups {
connectionInfo := &model.ConnectionInfo{
SourceGroupID: sg.ID,
}
connectionInfos, err := dao.ConnectionInfoGetList(connectionInfo, 0, 0)
if err != nil {
return common.ReturnErrorMsg(c, err.Error())
}

for _, ci := range *connectionInfos {
listSourceGroupRes.ConnectionInfoStatusCount.ConnectionInfoTotal++
if ci.ConnectionStatus == model.ConnectionInfoStatusSuccess {
listSourceGroupRes.ConnectionInfoStatusCount.CountConnectionSuccess++
} else {
listSourceGroupRes.ConnectionInfoStatusCount.CountConnectionFailed++
}
if ci.AgentStatus == model.ConnectionInfoStatusSuccess {
listSourceGroupRes.ConnectionInfoStatusCount.CountAgentSuccess++
} else {
listSourceGroupRes.ConnectionInfoStatusCount.CountAgentFailed++
}
}
}

return c.JSONPretty(http.StatusOK, &listSourceGroupRes, " ")
}

// UpdateSourceGroup godoc
Expand Down
16 changes: 15 additions & 1 deletion server/pkg/api/rest/docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ const docTemplate = `{
"schema": {
"type": "array",
"items": {
"$ref": "#/definitions/github_com_cloud-barista_cm-honeybee_server_pkg_api_rest_model.SourceGroup"
"$ref": "#/definitions/github_com_cloud-barista_cm-honeybee_server_pkg_api_rest_model.ListSourceGroupRes"
}
}
},
Expand Down Expand Up @@ -1779,6 +1779,20 @@ const docTemplate = `{
}
}
},
"github_com_cloud-barista_cm-honeybee_server_pkg_api_rest_model.ListSourceGroupRes": {
"type": "object",
"properties": {
"connection_info_status_count": {
"$ref": "#/definitions/github_com_cloud-barista_cm-honeybee_server_pkg_api_rest_model.ConnectionInfoStatusCount"
},
"source_group": {
"type": "array",
"items": {
"$ref": "#/definitions/github_com_cloud-barista_cm-honeybee_server_pkg_api_rest_model.SourceGroup"
}
}
}
},
"github_com_cloud-barista_cm-honeybee_server_pkg_api_rest_model.RegisterTargetInfoReq": {
"type": "object",
"required": [
Expand Down
16 changes: 15 additions & 1 deletion server/pkg/api/rest/docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@
"schema": {
"type": "array",
"items": {
"$ref": "#/definitions/github_com_cloud-barista_cm-honeybee_server_pkg_api_rest_model.SourceGroup"
"$ref": "#/definitions/github_com_cloud-barista_cm-honeybee_server_pkg_api_rest_model.ListSourceGroupRes"
}
}
},
Expand Down Expand Up @@ -1772,6 +1772,20 @@
}
}
},
"github_com_cloud-barista_cm-honeybee_server_pkg_api_rest_model.ListSourceGroupRes": {
"type": "object",
"properties": {
"connection_info_status_count": {
"$ref": "#/definitions/github_com_cloud-barista_cm-honeybee_server_pkg_api_rest_model.ConnectionInfoStatusCount"
},
"source_group": {
"type": "array",
"items": {
"$ref": "#/definitions/github_com_cloud-barista_cm-honeybee_server_pkg_api_rest_model.SourceGroup"
}
}
}
},
"github_com_cloud-barista_cm-honeybee_server_pkg_api_rest_model.RegisterTargetInfoReq": {
"type": "object",
"required": [
Expand Down
11 changes: 10 additions & 1 deletion server/pkg/api/rest/docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,15 @@ definitions:
connection_info_status_count:
$ref: '#/definitions/github_com_cloud-barista_cm-honeybee_server_pkg_api_rest_model.ConnectionInfoStatusCount'
type: object
github_com_cloud-barista_cm-honeybee_server_pkg_api_rest_model.ListSourceGroupRes:
properties:
connection_info_status_count:
$ref: '#/definitions/github_com_cloud-barista_cm-honeybee_server_pkg_api_rest_model.ConnectionInfoStatusCount'
source_group:
items:
$ref: '#/definitions/github_com_cloud-barista_cm-honeybee_server_pkg_api_rest_model.SourceGroup'
type: array
type: object
github_com_cloud-barista_cm-honeybee_server_pkg_api_rest_model.RegisterTargetInfoReq:
properties:
description:
Expand Down Expand Up @@ -1434,7 +1443,7 @@ paths:
description: Successfully get a list of source group.
schema:
items:
$ref: '#/definitions/github_com_cloud-barista_cm-honeybee_server_pkg_api_rest_model.SourceGroup'
$ref: '#/definitions/github_com_cloud-barista_cm-honeybee_server_pkg_api_rest_model.ListSourceGroupRes'
type: array
"400":
description: Sent bad request.
Expand Down
5 changes: 5 additions & 0 deletions server/pkg/api/rest/model/sourceGroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ type SourceGroupRes struct {
ConnectionInfoStatusCount ConnectionInfoStatusCount `json:"connection_info_status_count"`
}

type ListSourceGroupRes struct {
SourceGroup []SourceGroup `json:"source_group"`
ConnectionInfoStatusCount ConnectionInfoStatusCount `json:"connection_info_status_count"`
}

func (t TargetInfo) Value() (driver.Value, error) {
return json.Marshal(t)
}
Expand Down

0 comments on commit 9c279ae

Please sign in to comment.