From 0e63b5691c1bdc838c26e755cb1f5f55450a8213 Mon Sep 17 00:00:00 2001 From: Seokho Son Date: Tue, 6 Dec 2022 20:42:39 +0900 Subject: [PATCH] Add set monitoring agent status manually for Wins --- src/api/rest/docs/docs.go | 168 +++++++++++-------------- src/api/rest/docs/swagger.json | 168 +++++++++++-------------- src/api/rest/docs/swagger.yaml | 109 ++++++++-------- src/api/rest/server/mcis/monitoring.go | 38 ++++++ src/api/rest/server/server.go | 1 + src/core/mcis/monitoring.go | 24 ++++ 6 files changed, 265 insertions(+), 243 deletions(-) diff --git a/src/api/rest/docs/docs.go b/src/api/rest/docs/docs.go index 8fa6f87c..2093dae3 100644 --- a/src/api/rest/docs/docs.go +++ b/src/api/rest/docs/docs.go @@ -3421,6 +3421,67 @@ const docTemplate = `{ } } }, + "/ns/{nsId}/monitoring/status/mcis/{mcisId}/vm/{vmId}": { + "put": { + "description": "Set monitoring agent (CB-Dragonfly agent) installation status installed (for Windows VM only)", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "[Infra service] MCIS Resource monitor (for developer)" + ], + "summary": "Set monitoring agent (CB-Dragonfly agent) installation status installed (for Windows VM only)", + "parameters": [ + { + "type": "string", + "default": "ns01", + "description": "Namespace ID", + "name": "nsId", + "in": "path", + "required": true + }, + { + "type": "string", + "default": "mcis01", + "description": "MCIS ID", + "name": "mcisId", + "in": "path", + "required": true + }, + { + "type": "string", + "default": "vm01", + "description": "VM ID", + "name": "vmId", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/mcis.TbVmInfo" + } + }, + "404": { + "description": "Not Found", + "schema": { + "$ref": "#/definitions/common.SimpleMsg" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/common.SimpleMsg" + } + } + } + } + }, "/ns/{nsId}/network/mcis/{mcisId}": { "put": { "description": "Inject Cloud Information For Cloud Adaptive Network", @@ -7245,34 +7306,6 @@ const docTemplate = `{ } } }, - "mcir.CustomImageStatus": { - "type": "string", - "enum": [ - "Available", - "Unavailable" - ], - "x-enum-varnames": [ - "MyImageAvailable", - "MyImageUnavailable" - ] - }, - "mcir.DiskStatus": { - "type": "string", - "enum": [ - "Creating", - "Available", - "Attached", - "Deleting", - "Error" - ], - "x-enum-varnames": [ - "DiskCreating", - "DiskAvailable", - "DiskAttached", - "DiskDeleting", - "DiskError" - ] - }, "mcir.FilterSpecsByRangeRequest": { "type": "object", "properties": { @@ -7538,11 +7571,7 @@ const docTemplate = `{ }, "iid": { "description": "Fields for response", - "allOf": [ - { - "$ref": "#/definitions/common.IID" - } - ] + "$ref": "#/definitions/common.IID" }, "keyValueList": { "type": "array", @@ -7693,11 +7722,7 @@ const docTemplate = `{ "example": "aws-ap-southeast-1-1" }, "status": { - "allOf": [ - { - "$ref": "#/definitions/mcir.CustomImageStatus" - } - ], + "type": "string", "example": "Available" }, "systemLabel": { @@ -7787,11 +7812,7 @@ const docTemplate = `{ }, "status": { "description": "Available, Unavailable, Attached, ...", - "allOf": [ - { - "$ref": "#/definitions/mcir.DiskStatus" - } - ], + "type": "string", "example": "Available" }, "systemLabel": { @@ -8487,11 +8508,7 @@ const docTemplate = `{ }, "postCommand": { "description": "PostCommand is field for providing command to VMs after its creation. example:\"wget https://raw.githubusercontent.com/cloud-barista/cb-tumblebug/main/scripts/setweb.sh -O ~/setweb.sh; chmod +x ~/setweb.sh; sudo ~/setweb.sh\"", - "allOf": [ - { - "$ref": "#/definitions/mcis.McisCmdReq" - } - ] + "$ref": "#/definitions/mcis.McisCmdReq" }, "vmDynamicReq": { "$ref": "#/definitions/mcis.TbVmDynamicReq" @@ -9247,17 +9264,6 @@ const docTemplate = `{ } } }, - "mcis.SpiderImageType": { - "type": "string", - "enum": [ - "PublicImage", - "MyImage" - ], - "x-enum-varnames": [ - "PublicImage", - "MyImage" - ] - }, "mcis.SpiderVMInfo": { "type": "object", "properties": { @@ -9279,11 +9285,7 @@ const docTemplate = `{ }, "iid": { "description": "Fields for response", - "allOf": [ - { - "$ref": "#/definitions/common.IID" - } - ] + "$ref": "#/definitions/common.IID" }, "imageIId": { "$ref": "#/definitions/common.IID" @@ -9292,7 +9294,7 @@ const docTemplate = `{ "type": "string" }, "imageType": { - "$ref": "#/definitions/mcis.SpiderImageType" + "type": "string" }, "keyPairIId": { "$ref": "#/definitions/common.IID" @@ -9328,11 +9330,7 @@ const docTemplate = `{ }, "region": { "description": "ex) {us-east1, us-east1-c} or {ap-northeast-2}", - "allOf": [ - { - "$ref": "#/definitions/mcis.RegionInfo" - } - ] + "$ref": "#/definitions/mcis.RegionInfo" }, "rootDeviceName": { "description": "\"/dev/sda1\", ...", @@ -9367,11 +9365,7 @@ const docTemplate = `{ }, "subnetIID": { "description": "AWS, ex) subnet-8c4a53e4", - "allOf": [ - { - "$ref": "#/definitions/common.IID" - } - ] + "$ref": "#/definitions/common.IID" }, "subnetName": { "type": "string" @@ -9810,19 +9804,11 @@ const docTemplate = `{ }, "healthChecker": { "description": "HealthChecker", - "allOf": [ - { - "$ref": "#/definitions/mcis.TbNLBHealthCheckerReq" - } - ] + "$ref": "#/definitions/mcis.TbNLBHealthCheckerReq" }, "listener": { "description": "Frontend", - "allOf": [ - { - "$ref": "#/definitions/mcis.NLBListenerReq" - } - ] + "$ref": "#/definitions/mcis.NLBListenerReq" }, "scope": { "description": "REGION(V) | GLOBAL", @@ -9835,11 +9821,7 @@ const docTemplate = `{ }, "targetGroup": { "description": "Backend", - "allOf": [ - { - "$ref": "#/definitions/mcis.TbNLBTargetGroupReq" - } - ] + "$ref": "#/definitions/mcis.TbNLBTargetGroupReq" }, "type": { "description": "PUBLIC(V) | INTERNAL", @@ -10038,11 +10020,7 @@ const docTemplate = `{ }, "region": { "description": "AWS, ex) {us-east1, us-east1-c} or {ap-northeast-2}", - "allOf": [ - { - "$ref": "#/definitions/mcis.RegionInfo" - } - ] + "$ref": "#/definitions/mcis.RegionInfo" }, "rootDeviceName": { "type": "string" diff --git a/src/api/rest/docs/swagger.json b/src/api/rest/docs/swagger.json index 97fc271c..d0863938 100644 --- a/src/api/rest/docs/swagger.json +++ b/src/api/rest/docs/swagger.json @@ -3413,6 +3413,67 @@ } } }, + "/ns/{nsId}/monitoring/status/mcis/{mcisId}/vm/{vmId}": { + "put": { + "description": "Set monitoring agent (CB-Dragonfly agent) installation status installed (for Windows VM only)", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "[Infra service] MCIS Resource monitor (for developer)" + ], + "summary": "Set monitoring agent (CB-Dragonfly agent) installation status installed (for Windows VM only)", + "parameters": [ + { + "type": "string", + "default": "ns01", + "description": "Namespace ID", + "name": "nsId", + "in": "path", + "required": true + }, + { + "type": "string", + "default": "mcis01", + "description": "MCIS ID", + "name": "mcisId", + "in": "path", + "required": true + }, + { + "type": "string", + "default": "vm01", + "description": "VM ID", + "name": "vmId", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/mcis.TbVmInfo" + } + }, + "404": { + "description": "Not Found", + "schema": { + "$ref": "#/definitions/common.SimpleMsg" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/common.SimpleMsg" + } + } + } + } + }, "/ns/{nsId}/network/mcis/{mcisId}": { "put": { "description": "Inject Cloud Information For Cloud Adaptive Network", @@ -7237,34 +7298,6 @@ } } }, - "mcir.CustomImageStatus": { - "type": "string", - "enum": [ - "Available", - "Unavailable" - ], - "x-enum-varnames": [ - "MyImageAvailable", - "MyImageUnavailable" - ] - }, - "mcir.DiskStatus": { - "type": "string", - "enum": [ - "Creating", - "Available", - "Attached", - "Deleting", - "Error" - ], - "x-enum-varnames": [ - "DiskCreating", - "DiskAvailable", - "DiskAttached", - "DiskDeleting", - "DiskError" - ] - }, "mcir.FilterSpecsByRangeRequest": { "type": "object", "properties": { @@ -7530,11 +7563,7 @@ }, "iid": { "description": "Fields for response", - "allOf": [ - { - "$ref": "#/definitions/common.IID" - } - ] + "$ref": "#/definitions/common.IID" }, "keyValueList": { "type": "array", @@ -7685,11 +7714,7 @@ "example": "aws-ap-southeast-1-1" }, "status": { - "allOf": [ - { - "$ref": "#/definitions/mcir.CustomImageStatus" - } - ], + "type": "string", "example": "Available" }, "systemLabel": { @@ -7779,11 +7804,7 @@ }, "status": { "description": "Available, Unavailable, Attached, ...", - "allOf": [ - { - "$ref": "#/definitions/mcir.DiskStatus" - } - ], + "type": "string", "example": "Available" }, "systemLabel": { @@ -8479,11 +8500,7 @@ }, "postCommand": { "description": "PostCommand is field for providing command to VMs after its creation. example:\"wget https://raw.githubusercontent.com/cloud-barista/cb-tumblebug/main/scripts/setweb.sh -O ~/setweb.sh; chmod +x ~/setweb.sh; sudo ~/setweb.sh\"", - "allOf": [ - { - "$ref": "#/definitions/mcis.McisCmdReq" - } - ] + "$ref": "#/definitions/mcis.McisCmdReq" }, "vmDynamicReq": { "$ref": "#/definitions/mcis.TbVmDynamicReq" @@ -9239,17 +9256,6 @@ } } }, - "mcis.SpiderImageType": { - "type": "string", - "enum": [ - "PublicImage", - "MyImage" - ], - "x-enum-varnames": [ - "PublicImage", - "MyImage" - ] - }, "mcis.SpiderVMInfo": { "type": "object", "properties": { @@ -9271,11 +9277,7 @@ }, "iid": { "description": "Fields for response", - "allOf": [ - { - "$ref": "#/definitions/common.IID" - } - ] + "$ref": "#/definitions/common.IID" }, "imageIId": { "$ref": "#/definitions/common.IID" @@ -9284,7 +9286,7 @@ "type": "string" }, "imageType": { - "$ref": "#/definitions/mcis.SpiderImageType" + "type": "string" }, "keyPairIId": { "$ref": "#/definitions/common.IID" @@ -9320,11 +9322,7 @@ }, "region": { "description": "ex) {us-east1, us-east1-c} or {ap-northeast-2}", - "allOf": [ - { - "$ref": "#/definitions/mcis.RegionInfo" - } - ] + "$ref": "#/definitions/mcis.RegionInfo" }, "rootDeviceName": { "description": "\"/dev/sda1\", ...", @@ -9359,11 +9357,7 @@ }, "subnetIID": { "description": "AWS, ex) subnet-8c4a53e4", - "allOf": [ - { - "$ref": "#/definitions/common.IID" - } - ] + "$ref": "#/definitions/common.IID" }, "subnetName": { "type": "string" @@ -9802,19 +9796,11 @@ }, "healthChecker": { "description": "HealthChecker", - "allOf": [ - { - "$ref": "#/definitions/mcis.TbNLBHealthCheckerReq" - } - ] + "$ref": "#/definitions/mcis.TbNLBHealthCheckerReq" }, "listener": { "description": "Frontend", - "allOf": [ - { - "$ref": "#/definitions/mcis.NLBListenerReq" - } - ] + "$ref": "#/definitions/mcis.NLBListenerReq" }, "scope": { "description": "REGION(V) | GLOBAL", @@ -9827,11 +9813,7 @@ }, "targetGroup": { "description": "Backend", - "allOf": [ - { - "$ref": "#/definitions/mcis.TbNLBTargetGroupReq" - } - ] + "$ref": "#/definitions/mcis.TbNLBTargetGroupReq" }, "type": { "description": "PUBLIC(V) | INTERNAL", @@ -10030,11 +10012,7 @@ }, "region": { "description": "AWS, ex) {us-east1, us-east1-c} or {ap-northeast-2}", - "allOf": [ - { - "$ref": "#/definitions/mcis.RegionInfo" - } - ] + "$ref": "#/definitions/mcis.RegionInfo" }, "rootDeviceName": { "type": "string" diff --git a/src/api/rest/docs/swagger.yaml b/src/api/rest/docs/swagger.yaml index 62376320..366d680b 100644 --- a/src/api/rest/docs/swagger.yaml +++ b/src/api/rest/docs/swagger.yaml @@ -185,28 +185,6 @@ definitions: connectionName: type: string type: object - mcir.CustomImageStatus: - enum: - - Available - - Unavailable - type: string - x-enum-varnames: - - MyImageAvailable - - MyImageUnavailable - mcir.DiskStatus: - enum: - - Creating - - Available - - Attached - - Deleting - - Error - type: string - x-enum-varnames: - - DiskCreating - - DiskAvailable - - DiskAttached - - DiskDeleting - - DiskError mcir.FilterSpecsByRangeRequest: properties: connectionName: @@ -379,8 +357,7 @@ definitions: description: Windows7, Ubuntu etc. type: string iid: - allOf: - - $ref: '#/definitions/common.IID' + $ref: '#/definitions/common.IID' description: Fields for response keyValueList: items: @@ -484,9 +461,8 @@ definitions: example: aws-ap-southeast-1-1 type: string status: - allOf: - - $ref: '#/definitions/mcir.CustomImageStatus' example: Available + type: string systemLabel: description: SystemLabel is for describing the MCIR in a keyword (any string can be used) for special System purpose @@ -549,10 +525,9 @@ definitions: example: aws-ap-southeast-1-datadisk type: string status: - allOf: - - $ref: '#/definitions/mcir.DiskStatus' description: Available, Unavailable, Attached, ... example: Available + type: string systemLabel: description: SystemLabel is for describing the MCIR in a keyword (any string can be used) for special System purpose @@ -1035,8 +1010,7 @@ definitions: example: random type: string postCommand: - allOf: - - $ref: '#/definitions/mcis.McisCmdReq' + $ref: '#/definitions/mcis.McisCmdReq' description: PostCommand is field for providing command to VMs after its creation. example:"wget https://raw.githubusercontent.com/cloud-barista/cb-tumblebug/main/scripts/setweb.sh -O ~/setweb.sh; chmod +x ~/setweb.sh; sudo ~/setweb.sh" @@ -1553,14 +1527,6 @@ definitions: result: type: string type: object - mcis.SpiderImageType: - enum: - - PublicImage - - MyImage - type: string - x-enum-varnames: - - PublicImage - - MyImage mcis.SpiderVMInfo: properties: cspid: @@ -1575,15 +1541,14 @@ definitions: type: string type: array iid: - allOf: - - $ref: '#/definitions/common.IID' + $ref: '#/definitions/common.IID' description: Fields for response imageIId: $ref: '#/definitions/common.IID' imageName: type: string imageType: - $ref: '#/definitions/mcis.SpiderImageType' + type: string keyPairIId: $ref: '#/definitions/common.IID' keyPairName: @@ -1607,8 +1572,7 @@ definitions: publicIP: type: string region: - allOf: - - $ref: '#/definitions/mcis.RegionInfo' + $ref: '#/definitions/mcis.RegionInfo' description: ex) {us-east1, us-east1-c} or {ap-northeast-2} rootDeviceName: description: '"/dev/sda1", ...' @@ -1633,8 +1597,7 @@ definitions: startTime: type: string subnetIID: - allOf: - - $ref: '#/definitions/common.IID' + $ref: '#/definitions/common.IID' description: AWS, ex) subnet-8c4a53e4 subnetName: type: string @@ -1959,12 +1922,10 @@ definitions: description: type: string healthChecker: - allOf: - - $ref: '#/definitions/mcis.TbNLBHealthCheckerReq' + $ref: '#/definitions/mcis.TbNLBHealthCheckerReq' description: HealthChecker listener: - allOf: - - $ref: '#/definitions/mcis.NLBListenerReq' + $ref: '#/definitions/mcis.NLBListenerReq' description: Frontend scope: description: REGION(V) | GLOBAL @@ -1974,8 +1935,7 @@ definitions: example: REGION type: string targetGroup: - allOf: - - $ref: '#/definitions/mcis.TbNLBTargetGroupReq' + $ref: '#/definitions/mcis.TbNLBTargetGroupReq' description: Backend type: description: PUBLIC(V) | INTERNAL @@ -2132,8 +2092,7 @@ definitions: publicIP: type: string region: - allOf: - - $ref: '#/definitions/mcis.RegionInfo' + $ref: '#/definitions/mcis.RegionInfo' description: AWS, ex) {us-east1, us-east1-c} or {ap-northeast-2} rootDeviceName: type: string @@ -4742,6 +4701,50 @@ paths: (cpu, memory, disk, network) tags: - '[Infra service] MCIS Resource monitor (for developer)' + /ns/{nsId}/monitoring/status/mcis/{mcisId}/vm/{vmId}: + put: + consumes: + - application/json + description: Set monitoring agent (CB-Dragonfly agent) installation status installed + (for Windows VM only) + parameters: + - default: ns01 + description: Namespace ID + in: path + name: nsId + required: true + type: string + - default: mcis01 + description: MCIS ID + in: path + name: mcisId + required: true + type: string + - default: vm01 + description: VM ID + in: path + name: vmId + required: true + type: string + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/mcis.TbVmInfo' + "404": + description: Not Found + schema: + $ref: '#/definitions/common.SimpleMsg' + "500": + description: Internal Server Error + schema: + $ref: '#/definitions/common.SimpleMsg' + summary: Set monitoring agent (CB-Dragonfly agent) installation status installed + (for Windows VM only) + tags: + - '[Infra service] MCIS Resource monitor (for developer)' /ns/{nsId}/network/mcis/{mcisId}: post: consumes: diff --git a/src/api/rest/server/mcis/monitoring.go b/src/api/rest/server/mcis/monitoring.go index af537c70..3a80f2f7 100644 --- a/src/api/rest/server/mcis/monitoring.go +++ b/src/api/rest/server/mcis/monitoring.go @@ -47,6 +47,7 @@ func RestPostInstallMonitorAgentToMcis(c echo.Context) error { // mcisTmpSystemLabel := mcis.DefaultSystemLabel content, err := mcis.InstallMonitorAgentToMcis(nsId, mcisId, common.StrMCIS, req) + if err != nil { common.CBLog.Error(err) return err @@ -55,6 +56,43 @@ func RestPostInstallMonitorAgentToMcis(c echo.Context) error { return c.JSON(http.StatusOK, content) } +// RestPutMonitorAgentStatusInstalled godoc +// @Summary Set monitoring agent (CB-Dragonfly agent) installation status installed (for Windows VM only) +// @Description Set monitoring agent (CB-Dragonfly agent) installation status installed (for Windows VM only) +// @Tags [Infra service] MCIS Resource monitor (for developer) +// @Accept json +// @Produce json +// @Param nsId path string true "Namespace ID" default(ns01) +// @Param mcisId path string true "MCIS ID" default(mcis01) +// @Param vmId path string true "VM ID" default(vm01) +// @Success 200 {object} mcis.TbVmInfo +// @Failure 404 {object} common.SimpleMsg +// @Failure 500 {object} common.SimpleMsg +// @Router /ns/{nsId}/monitoring/status/mcis/{mcisId}/vm/{vmId} [put] +func RestPutMonitorAgentStatusInstalled(c echo.Context) error { + + nsId := c.Param("nsId") + mcisId := c.Param("mcisId") + vmId := c.Param("vmId") + + // mcisTmpSystemLabel := mcis.DefaultSystemLabel + err := mcis.SetMonitoringAgentStatusInstalled(nsId, mcisId, vmId) + if err != nil { + common.CBLog.Error(err) + return err + } + + result, err := mcis.CoreGetMcisVmInfo(nsId, mcisId, vmId) + if err != nil { + mapA := map[string]string{"message": err.Error()} + return c.JSON(http.StatusNotFound, &mapA) + } + + common.PrintJsonPretty(*result) + + return c.JSON(http.StatusOK, result) +} + // RestGetMonitorData godoc // @Summary Get monitoring data of specified MCIS for specified monitoring metric (cpu, memory, disk, network) // @Description Get monitoring data of specified MCIS for specified monitoring metric (cpu, memory, disk, network) diff --git a/src/api/rest/server/server.go b/src/api/rest/server/server.go index b457f77a..aa41dcf2 100644 --- a/src/api/rest/server/server.go +++ b/src/api/rest/server/server.go @@ -221,6 +221,7 @@ func RunServer(port string) { g.POST("/:nsId/monitoring/install/mcis/:mcisId", rest_mcis.RestPostInstallMonitorAgentToMcis) g.GET("/:nsId/monitoring/mcis/:mcisId/metric/:metric", rest_mcis.RestGetMonitorData) + g.PUT("/:nsId/monitoring/status/mcis/:mcisId/vm/:vmId", rest_mcis.RestPutMonitorAgentStatusInstalled) // MCIS Cloud Adaptive Network (for developer) g.POST("/:nsId/network/mcis/:mcisId", rest_mcis.RestPostConfigureCloudAdaptiveNetworkToMcis) diff --git a/src/core/mcis/monitoring.go b/src/core/mcis/monitoring.go index 7d973283..aaed32f9 100644 --- a/src/core/mcis/monitoring.go +++ b/src/core/mcis/monitoring.go @@ -372,6 +372,30 @@ func InstallMonitorAgentToMcis(nsId string, mcisId string, mcisServiceType strin } +// SetMonitoringAgentStatusInstalled is func to Set Monitoring Agent Status Installed +func SetMonitoringAgentStatusInstalled(nsId string, mcisId string, vmId string) error { + targetStatus := "installed" + return UpdateMonitoringAgentStatusManually(nsId, mcisId, vmId, targetStatus) +} + +// UpdateMonitoringAgentStatusManually is func to Update Monitoring Agent Installation Status Manually +func UpdateMonitoringAgentStatusManually(nsId string, mcisId string, vmId string, targetStatus string) error { + + vmInfoTmp, err := GetVmObject(nsId, mcisId, vmId) + if err != nil { + common.CBLog.Error(err) + return err + } + + // set vm MonAgentStatus + vmInfoTmp.MonAgentStatus = targetStatus + UpdateVmInfo(nsId, mcisId, vmInfoTmp) + + //TODO: add validation for monitoring + + return nil +} + // GetMonitoringData func retrieves monitoring data from cb-dragonfly func GetMonitoringData(nsId string, mcisId string, metric string) (MonResultSimpleResponse, error) {