mirror of
https://github.com/datarhei/core.git
synced 2025-10-04 15:42:57 +08:00
Refactor cluster node code
This commit is contained in:
@@ -8,7 +8,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/datarhei/core/v16/cluster"
|
||||
"github.com/datarhei/core/v16/cluster/proxy"
|
||||
"github.com/datarhei/core/v16/cluster/node"
|
||||
"github.com/datarhei/core/v16/encoding/json"
|
||||
"github.com/datarhei/core/v16/http/api"
|
||||
"github.com/datarhei/core/v16/http/handler/util"
|
||||
@@ -21,7 +21,7 @@ import (
|
||||
// The ClusterHandler type provides handler functions for manipulating the cluster config.
|
||||
type ClusterHandler struct {
|
||||
cluster cluster.Cluster
|
||||
proxy proxy.ProxyReader
|
||||
proxy *node.Manager
|
||||
iam iam.IAM
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ type ClusterHandler struct {
|
||||
func NewCluster(cluster cluster.Cluster, iam iam.IAM) (*ClusterHandler, error) {
|
||||
h := &ClusterHandler{
|
||||
cluster: cluster,
|
||||
proxy: cluster.ProxyReader(),
|
||||
proxy: cluster.Manager(),
|
||||
iam: iam,
|
||||
}
|
||||
|
||||
@@ -68,7 +68,7 @@ func (h *ClusterHandler) About(c echo.Context) error {
|
||||
Address: state.Leader.Address,
|
||||
ElectedSince: uint64(state.Leader.ElectedSince.Seconds()),
|
||||
},
|
||||
Status: state.Status,
|
||||
Status: state.State,
|
||||
Raft: api.ClusterRaft{
|
||||
Address: state.Raft.Address,
|
||||
State: state.Raft.State,
|
||||
@@ -77,13 +77,13 @@ func (h *ClusterHandler) About(c echo.Context) error {
|
||||
LogTerm: state.Raft.LogTerm,
|
||||
LogIndex: state.Raft.LogIndex,
|
||||
},
|
||||
Nodes: []api.ClusterNode{},
|
||||
Version: state.Version.String(),
|
||||
Degraded: state.Degraded,
|
||||
Nodes: []api.ClusterNode{},
|
||||
Version: state.Version.String(),
|
||||
}
|
||||
|
||||
if state.DegradedErr != nil {
|
||||
about.DegradedErr = state.DegradedErr.Error()
|
||||
if state.Error != nil {
|
||||
about.Degraded = true
|
||||
about.DegradedErr = state.Error.Error()
|
||||
}
|
||||
|
||||
for _, node := range state.Nodes {
|
||||
@@ -98,7 +98,7 @@ func (h *ClusterHandler) marshalClusterNode(node cluster.ClusterNode) api.Cluste
|
||||
ID: node.ID,
|
||||
Name: node.Name,
|
||||
Version: node.Version,
|
||||
Status: node.Status,
|
||||
Status: node.State,
|
||||
Voter: node.Voter,
|
||||
Leader: node.Leader,
|
||||
Address: node.Address,
|
||||
@@ -108,7 +108,7 @@ func (h *ClusterHandler) marshalClusterNode(node cluster.ClusterNode) api.Cluste
|
||||
Latency: node.Latency.Seconds() * 1000,
|
||||
Core: api.ClusterNodeCore{
|
||||
Address: node.Core.Address,
|
||||
Status: node.Core.Status,
|
||||
Status: node.Core.State,
|
||||
LastContact: node.Core.LastContact.Seconds() * 1000,
|
||||
Latency: node.Core.Latency.Seconds() * 1000,
|
||||
Version: node.Core.Version,
|
||||
@@ -148,9 +148,9 @@ func (h *ClusterHandler) marshalClusterNode(node cluster.ClusterNode) api.Cluste
|
||||
// @Security ApiKeyAuth
|
||||
// @Router /api/v3/cluster/healthy [get]
|
||||
func (h *ClusterHandler) Healthy(c echo.Context) error {
|
||||
degraded, _ := h.cluster.IsDegraded()
|
||||
hasLeader := h.cluster.HasRaftLeader()
|
||||
|
||||
return c.JSON(http.StatusOK, !degraded)
|
||||
return c.JSON(http.StatusOK, hasLeader)
|
||||
}
|
||||
|
||||
// TransferLeadership transfers the leadership to another node
|
||||
@@ -266,7 +266,7 @@ func (h *ClusterHandler) Reallocation(c echo.Context) error {
|
||||
}
|
||||
}
|
||||
|
||||
err := h.cluster.RelocateProcesses("", relocations)
|
||||
err := h.cluster.ProcessesRelocate("", relocations)
|
||||
if err != nil {
|
||||
return api.Err(http.StatusInternalServerError, "", "%s", err.Error())
|
||||
}
|
||||
|
Reference in New Issue
Block a user