Skip to content

Commit

Permalink
feat: 支持配置发布状态回显 (#93)
Browse files Browse the repository at this point in the history
* 修复容器集群发布,配置文件路径回显

* 配置文件列表中增加配置状态回显

* 优化mysql查询语句
  • Loading branch information
jarily committed Jul 29, 2021
1 parent f4c8933 commit b58feb8
Show file tree
Hide file tree
Showing 8 changed files with 415 additions and 20 deletions.
10 changes: 9 additions & 1 deletion api/apiv1/confgov2/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package confgov2

import (
"regexp"
"strconv"
"strings"

"github.com/douyu/juno/pkg/cfg"
"github.com/douyu/jupiter/pkg/xlog"
Expand All @@ -21,8 +23,12 @@ func List(c echo.Context) (err error) {
param := view.ReqListConfig{}
cluster := c.QueryParam("cluster")
if cluster != "" {
configId, pErr := strconv.ParseUint(strings.TrimSpace(c.QueryParam("id")), 10, 64)
if pErr != nil {
return output.JSON(c, output.MsgErr, "参数无效:"+pErr.Error())
}
//集群配置信息
configuration, _ := confgov2.ClusterPublishConfigInfo(cluster)
configuration, _ := confgov2.ClusterPublishConfigInfo(cluster, configId)
return output.JSON(c, output.MsgOk, "success", configuration)
}

Expand All @@ -41,6 +47,8 @@ func List(c echo.Context) (err error) {
return output.JSON(c, output.MsgErr, err.Error())
}

list = confgov2.HandleConfigPublishStatus(list)

return output.JSON(c, output.MsgOk, "", list)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import React from 'react'
import {connect} from 'dva'
import styles from './index.less'
import {DeleteOutlined, FileOutlined, HistoryOutlined, SaveOutlined, StopOutlined} from '@ant-design/icons'
import {DeleteOutlined, FileOutlined, HistoryOutlined, StopOutlined} from '@ant-design/icons'
import OptionButton from "@/pages/app/components/Config/components/OptionButton";
import {Popconfirm, Spin} from 'antd'
import {useKeyPress} from "ahooks";
import {Popconfirm, Spin, Tag} from 'antd'
import confirm from "antd/es/modal/confirm";

function Files(props) {
Expand Down Expand Up @@ -56,7 +55,9 @@ function Files(props) {
}
}}
>
<div>{cfg.name}.{cfg.format}</div>
<div>{cfg.config_status === 1 ?
<Tag color="green">已发布</Tag> : cfg.config_status === 2 ?
<Tag color="yellow">未发布</Tag> : ""}{cfg.name}.{cfg.format}</div>
<div>
{currentConfig && currentConfig.content !== currentContent && cfg.id === currentConfig.id &&
<span className={styles.notSavedTip}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function ClusterDetail(props) {

useEffect(() => {
if (k8sClusters2 == undefined){
getCluterInfo(currentInstance.name,appName,env,currentInstance).then(res=>{
getCluterInfo(currentInstance.name,appName,env,config.id,currentInstance).then(res=>{
setK8sClusters2(res.data)

})
Expand Down
4 changes: 2 additions & 2 deletions assets/src/services/config_resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ export async function batchCheckVersion(payload: any[]) {
})
}

export async function getCluterInfo(clusterName,appName,env,payload) {
return request(`/api/admin/confgov2/config/list?cluster=`+clusterName+`&app_name=`+appName+"&env="+env, {
export async function getCluterInfo(clusterName,appName,env,id,payload) {
return request(`/api/admin/confgov2/config/list?cluster=`+clusterName+`&app_name=`+appName+"&env="+env+"&id="+id, {
method: 'GET',
data: payload,
})
Expand Down
10 changes: 8 additions & 2 deletions internal/pkg/service/confgov2/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ const (
DiffSpecifyScene = 2 //指定版本与最新版本对比
)

const (
ConfigStatusUnknown uint32 = 0 // 配置发布状态未知
ConfigStatusAlreadyPublish uint32 = 1 // 配置已经发布
ConfigStatusNotPublish uint32 = 2 // 配置未发布
)

func List(param view.ReqListConfig) (resp view.RespListConfig, err error) {
var app db.AppInfo

Expand Down Expand Up @@ -561,7 +567,7 @@ func Instances(param view.ReqConfigInstanceList) (resp view.RespConfigInstanceLi
}

// ClusterPublishConfigInfo ..
func ClusterPublishConfigInfo(clusterName string) (configurationRes view.ClusterConfigInfo, err error) {
func ClusterPublishConfigInfo(clusterName string, configId uint64) (configurationRes view.ClusterConfigInfo, err error) {
// process
var (
configurationPublish db.ConfigurationPublish
Expand All @@ -571,7 +577,7 @@ func ClusterPublishConfigInfo(clusterName string) (configurationRes view.Cluster
appInfo db.AppInfo
)
// get configurationClusterStatus info
query := mysql.Order("id desc").Where("cluster_name=?", clusterName).First(&configurationClusterStatus)
query := mysql.Order("id desc").Where("cluster_name=? AND configuration_id = ?", clusterName, configId).First(&configurationClusterStatus)

if query.Error != nil {
configurationRes.Doc = cfg.Cfg.K8s.Doc
Expand Down
Loading

0 comments on commit b58feb8

Please sign in to comment.