[agent-operator] - 增加镜像同步的消息通知内容
This commit is contained in:
70
message_pusher/cmii/ImageSyncMessage.go
Normal file
70
message_pusher/cmii/ImageSyncMessage.go
Normal file
@@ -0,0 +1,70 @@
|
||||
package cmii
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"io.wdd.message_pusher/pusher"
|
||||
"text/template"
|
||||
)
|
||||
|
||||
type ImageSyncMessage struct {
|
||||
ImageFullName string `json:"imageFullName"`
|
||||
ProjectName string `json:"projectName"`
|
||||
ProjectNameSpace string `json:"projectNameSpace"`
|
||||
ProjectMasterIP string `json:"projectMasterIP"`
|
||||
ProjectMasterTopicName string `json:"projectMasterTopicName"`
|
||||
InnerWorkTopicName string `json:"innerWorkTopicName"`
|
||||
CurrentProcedure string `json:"currentProcedure"`
|
||||
IsSyncFinished bool `json:"isSyncFinished"`
|
||||
}
|
||||
|
||||
const imageSyncTemplate = `
|
||||
{{if .IsSyncFinished}}
|
||||
镜像更新状态: 成功😍
|
||||
{{- else }}
|
||||
镜像更新状态: 失败👿👿👿
|
||||
{{- end}}
|
||||
当前步骤: {{.CurrentProcedure}}
|
||||
更新镜像: {{.ImageFullName}}
|
||||
项目名称: {{.ProjectName}}
|
||||
项目空间: {{.ProjectNameSpace}}
|
||||
项目MasterIP: {{.ProjectMasterIP}}
|
||||
项目Master名称: {{.ProjectMasterTopicName}}
|
||||
中转节点名称: {{.InnerWorkTopicName}}
|
||||
`
|
||||
|
||||
var ImageSyncPushOptions = []pusher.PublishOption{
|
||||
pusher.WithTitle("镜像同步更新"),
|
||||
pusher.WithPriority("3"),
|
||||
}
|
||||
|
||||
func (d *ImageSyncMessage) ParseTemplate() bytes.Buffer {
|
||||
// 解析模板
|
||||
tmpl, err := template.New("imageSyncTemplate").Parse(imageSyncTemplate)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// 应用数据并打印结果
|
||||
var result bytes.Buffer
|
||||
err = tmpl.Execute(&result, d)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
// PublishMessage 使用默认的Client 发布更新的消息
|
||||
func (d *ImageSyncMessage) PublishMessage() *pusher.Message {
|
||||
|
||||
parseTemplate := d.ParseTemplate()
|
||||
|
||||
result, err := pusher.DefaultPusherClient.PublishDefault(parseTemplate, ImageSyncPushOptions)
|
||||
if err != nil {
|
||||
log.ErrorF("[ImageSyncMessage] - message push error ! %s", err.Error())
|
||||
return result
|
||||
}
|
||||
|
||||
return result
|
||||
|
||||
}
|
||||
@@ -45,6 +45,7 @@ func main() {
|
||||
{
|
||||
router.CMIIRouter(engine)
|
||||
router.OctopusRouter(engine)
|
||||
router.ImageSyncRouter(engine)
|
||||
}
|
||||
|
||||
engine.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
|
||||
|
||||
38
message_pusher/router/ImageSyncRouter.go
Normal file
38
message_pusher/router/ImageSyncRouter.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package router
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"io.wdd.message_pusher/cmii"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func ImageSyncRouter(r *gin.Engine) {
|
||||
octopusGroup := r.Group("/image")
|
||||
{
|
||||
octopusGroup.POST("/sync", ImageSync)
|
||||
}
|
||||
}
|
||||
|
||||
// ImageSync godoc
|
||||
// @Summary 镜像同步消息
|
||||
// @Schemes
|
||||
// @Description response to cmii update notification
|
||||
// @Tags ImageSync
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param body body cmii.ImageSyncMessage true "请求体"
|
||||
// @Success 200 {object} pusher.Message
|
||||
// @Router /image/sync [post]
|
||||
func ImageSync(c *gin.Context) {
|
||||
// 获取请求中的参数
|
||||
var imageSyncMessage cmii.ImageSyncMessage
|
||||
if err := c.ShouldBindJSON(&imageSyncMessage); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "Invalid request body"})
|
||||
return
|
||||
}
|
||||
// 处理请求
|
||||
upgradeMessage := imageSyncMessage.PublishMessage()
|
||||
|
||||
// *pusher.Message
|
||||
c.JSON(http.StatusOK, upgradeMessage)
|
||||
}
|
||||
Reference in New Issue
Block a user