Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
shiguanghuxian committed Jan 18, 2019
2 parents 0f754ff + 5999591 commit db009bf
Show file tree
Hide file tree
Showing 3 changed files with 708 additions and 22 deletions.
62 changes: 62 additions & 0 deletions program/v1/v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ func V1(v1 *gin.RouterGroup) {
v1.PUT("/key", putEtcdKey) // 修改key
v1.DELETE("/key", delEtcdKey) // 删除key

v1.GET("/restore", restoreDirKey) // 修复目录不兼容问题

v1.GET("/key/format", getValueToFormat) // 格式化为json或toml

v1.GET("/server", getEtcdServerList) // 获取etcd服务列表
Expand Down Expand Up @@ -518,3 +520,63 @@ func saveLog(c *gin.Context, msg string) {
// 存储日志
logger.Log.Infow(msg, "user", user, "role", userRole)
}

// 修复老数据目录问题
func restoreDirKey(c *gin.Context) {
var err error
defer func() {
if err != nil {
logger.Log.Errorw("修复数据错误", "err", err)
c.JSON(http.StatusBadRequest, gin.H{
"msg": err.Error(),
})
}
}()

etcdCli, exists := c.Get("EtcdServer")
if exists == false {
err = errors.New("Etcd client is empty")
return
}
cli := etcdCli.(*etcdv3.Etcd3Client)

list, err := cli.GetRecursiveValue("")
if err != nil {
return
}

// 检查所有key
for _, one := range list {
// fmt.Println(one.FullDir)
keys := strings.Split(one.FullDir, "/")
if len(keys) == 0 {
continue
}
key := ""
for ki, k := range keys {
// 不处理最后一个
if len(keys)-1 == ki {
continue
}
if key != "/" { // 防止两个//和兼容key不是从/开始
key += "/"
}
key += k
if keys[0] != "" {
key = strings.TrimLeft(key, "/")
}
/* 设置此路径为新建,并且值为目录 */
// 判断是否存在
if _, keyExistErr := cli.Value(key); keyExistErr == etcdv3.ErrorKeyNotFound {
err = cli.Put(key, etcdv3.DEFAULT_DIR_VALUE, true)
if err != nil {
return
}
}

// fmt.Println(key)
}
}

c.JSON(http.StatusOK, list)
}
49 changes: 49 additions & 0 deletions static/src/views/EtcdServer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,37 @@ export default {
{
title: 'Desc',
key: 'Desc'
},
{
title: 'Action',
key: 'action',
width: 150,
align: 'center',
render: (h, params) => {
return h('div', [
h('Poptip', {
props: {
confirm: true,
title:'确定修复etcd key的目录问题?'
},
on: {
"on-ok": () => {
this.restore(params.row);
}
}
},[
h('Button', {
props: {
type: 'primary',
size: 'small'
},
style: {
marginRight: '5px'
}
}, '修复目录'),
])
]);
}
}
],
data:[],
Expand Down Expand Up @@ -74,6 +105,24 @@ export default {
this.pageSize = pageSize;
this.changeListPage(1);
this.page = 1;
},
// 修复该服务目录问题
restore(row){
// console.log(row)
this.$http.get(`/v1/restore`,{
headers:{
"EtcdServerName":row.Name,
}
}).then(response=>{
if(response.status == 200){
this.$Message.info('OK');
}
}).catch(error=>{
if (error.response){
this.$Message.error(error.response.data.msg);
}
});
}
},
mounted(){
Expand Down
Loading

0 comments on commit db009bf

Please sign in to comment.