集群增加自动同步时钟选项

This commit is contained in:
刘祥超
2022-09-15 15:57:53 +08:00
parent e6e62bbd24
commit b8b10b5176
2 changed files with 52 additions and 1 deletions

View File

@@ -1,6 +1,7 @@
package settings
import (
"encoding/json"
"github.com/TeaOSLab/EdgeAdmin/internal/oplogs"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/grants/grantutils"
@@ -65,6 +66,19 @@ func (this *IndexAction) RunGet(params struct {
}
this.Data["timeZoneLocation"] = nodeconfigs.FindTimeZoneLocation(cluster.TimeZone)
// 时钟
var clockConfig = nodeconfigs.DefaultClockConfig()
if len(cluster.ClockJSON) > 0 {
err = json.Unmarshal(cluster.ClockJSON, clockConfig)
if err != nil {
this.ErrorPage(err)
return
}
if clockConfig == nil {
clockConfig = nodeconfigs.DefaultClockConfig()
}
}
this.Data["cluster"] = maps.Map{
"id": cluster.Id,
"name": cluster.Name,
@@ -72,6 +86,7 @@ func (this *IndexAction) RunGet(params struct {
"timeZone": cluster.TimeZone,
"nodeMaxThreads": cluster.NodeMaxThreads,
"autoOpenPorts": cluster.AutoOpenPorts,
"clock": clockConfig,
}
// 默认值
@@ -91,6 +106,8 @@ func (this *IndexAction) RunPost(params struct {
TimeZone string
NodeMaxThreads int32
AutoOpenPorts bool
ClockAutoSync bool
ClockServer string
Must *actions.Must
}) {
@@ -108,7 +125,22 @@ func (this *IndexAction) RunPost(params struct {
Lte(int64(nodeconfigs.DefaultMaxThreadsMax), "单节点最大线程数最大值不能大于"+types.String(nodeconfigs.DefaultMaxThreadsMax))
}
_, err := this.RPC().NodeClusterRPC().UpdateNodeCluster(this.AdminContext(), &pb.UpdateNodeClusterRequest{
var clockConfig = nodeconfigs.DefaultClockConfig()
clockConfig.AutoSync = params.ClockAutoSync
clockConfig.Server = params.ClockServer
clockConfigJSON, err := json.Marshal(clockConfig)
if err != nil {
this.ErrorPage(err)
return
}
err = clockConfig.Init()
if err != nil {
this.ErrorPage(err)
return
}
_, err = this.RPC().NodeClusterRPC().UpdateNodeCluster(this.AdminContext(), &pb.UpdateNodeClusterRequest{
NodeClusterId: params.ClusterId,
Name: params.Name,
NodeGrantId: params.GrantId,
@@ -116,6 +148,7 @@ func (this *IndexAction) RunPost(params struct {
TimeZone: params.TimeZone,
NodeMaxThreads: params.NodeMaxThreads,
AutoOpenPorts: params.AutoOpenPorts,
ClockJSON: clockConfigJSON,
})
if err != nil {
this.ErrorPage(err)

View File

@@ -60,6 +60,24 @@
<p class="comment">选中后会自动尝试在边缘节点正在运行的firewalld中开放所需端口如果有别的防火墙或者安全策略仍然需要手工操作。</p>
</td>
</tr>
<tr>
<td class="color-border">自动同步节点时钟</td>
<td>
<div class="ui fields inline">
<div class="ui field">
<checkbox name="clockAutoSync" v-model="cluster.clock.autoSync"></checkbox>
</div>
</div>
<p class="comment">选中后表示尝试自动同步节点时钟。</p>
</td>
</tr>
<tr v-show="cluster.clock.autoSync">
<td class="color-border">NTP时钟服务器</td>
<td>
<input type="text" name="clockServer" v-model="cluster.clock.server" maxlength="100"/>
<p class="comment">可选项。默认使用<code-label>pool.ntp.org</code-label></p>
</td>
</tr>
</tbody>
</table>
<submit-btn></submit-btn>