diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..13566b81b018ad684f3a35fee301741b2734c8f4 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/ha-api.iml b/.idea/ha-api.iml new file mode 100644 index 0000000000000000000000000000000000000000..5e764c4f0b9a64bb78a5babfdd583713b2df47bf --- /dev/null +++ b/.idea/ha-api.iml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000000000000000000000000000000000000..8150a2729f28c2c62a9eb98917d40d75a96d05ca --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000000000000000000000000000000000000..35eb1ddfbbc029bcab630581847471d7f238ec53 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/controllers/cluster.go b/controllers/cluster.go index e6885c0c33de12141ae68327dc9f1ec1b078336d..ba6ce6e8b88fc554cd5b0b0b8697bded4162a910 100644 --- a/controllers/cluster.go +++ b/controllers/cluster.go @@ -42,6 +42,10 @@ type ClusterDestroyController struct { web.Controller } +type ClustersStatusController struct { + web.Controller +} + func (mcc *MultipleClustersController) Post() { logs.Debug("Handle post request in MultipleClustersController.") result := map[string]interface{}{} @@ -105,6 +109,13 @@ func (cc *ClustersController) Get() { cc.ServeJSON() } +func (csc *ClustersStatusController) Get() { + logs.Debug("handle get request in ClustersController.") + result := models.GetClusterInfo() + csc.Data["json"] = &result + csc.ServeJSON() +} + func (cc *ClustersController) Post() { logs.Debug("handle post request in ClustersController.") cc.ServeJSON() diff --git a/models/manage_clusters.go b/models/manage_clusters.go index ef64e9ff49f1ac9cec0e2bced2cdbec7fa6fcb9e..9828e0aff32b29be18acc4ef913d62270dcb20dd 100644 --- a/models/manage_clusters.go +++ b/models/manage_clusters.go @@ -99,7 +99,7 @@ func (ci *ClusterInfo) SetVersion(version int) { // localClusterInfo retrieves the cluster information locally and returns it as a map. // If no cluster exists, an empty map is returned. func localClusterInfo() map[string]interface{} { - allInfo := getClusterInfo() + allInfo := GetClusterInfo() if allInfo["cluster_exist"] == true { clusterInfo := clusterInfoParse(allInfo) return clusterInfo @@ -172,6 +172,7 @@ func readFile(filename string) map[string]interface{} { return newDict } +//comment out due to type error as localconf could not be {}, it should be of type *ClusterInfo // SyncConfig synchronizes the local configuration with remote configuration. // Returns appropriate results indicating the synchronization status. func SyncConfig(remoteConf map[string]interface{}) map[string]interface{} { @@ -305,6 +306,11 @@ func ClusterAdd(nodeInfo map[string]interface{}) map[string]interface{} { "error": "添加集群失败"} } +type SetClusterInfo struct { + ClusterName string + Data []map[string]interface{} +} + // ClusterSetup performs the setup of a cluster using the provided cluster information. func ClusterSetup(clusterInfo map[string]interface{}) map[string]interface{} { authInfo := make(map[string]interface{}) diff --git a/models/nodes_management.go b/models/nodes_management.go index 3329b679128291764b897b6c926ade456276b5c0..7adf7a5d1ad9b81abb390fd643c43c467d0c615c 100644 --- a/models/nodes_management.go +++ b/models/nodes_management.go @@ -49,7 +49,7 @@ func getClusterName() map[string]interface{} { // getClusterInfo retrieves cluster information, including cluster nodes and their properties. // Returns the cluster information in a structured map. -func getClusterInfo() map[string]interface{} { +func GetClusterInfo() map[string]interface{} { _, currentNode := utils.RunCommand("cat /etc/hostname") currentNodeStr := strings.ReplaceAll(fmt.Sprintf("%s", currentNode), "\n", "")