auto associate support multi cluster

This commit is contained in:
liugq 2023-07-19 10:20:20 +08:00
parent f92b448333
commit 503b201eb2
1 changed files with 102 additions and 100 deletions

View File

@ -625,7 +625,7 @@ func (h *APIHandler) associateESNode(w http.ResponseWriter, req *http.Request, p
func (h *APIHandler) autoAssociateESNode(w http.ResponseWriter, req *http.Request, ps httprouter.Params) { func (h *APIHandler) autoAssociateESNode(w http.ResponseWriter, req *http.Request, ps httprouter.Params) {
reqBody := struct { reqBody := struct {
ClusterID string `json:"cluster_id"` ClusterIDs []string `json:"cluster_ids"`
}{} }{}
err := h.DecodeJSON(req, &reqBody) err := h.DecodeJSON(req, &reqBody)
if err != nil { if err != nil {
@ -633,14 +633,6 @@ func (h *APIHandler) autoAssociateESNode(w http.ResponseWriter, req *http.Reques
h.WriteError(w, err.Error(), http.StatusInternalServerError) h.WriteError(w, err.Error(), http.StatusInternalServerError)
return return
} }
// query cluster basicauth
cfg := elastic.GetConfig(reqBody.ClusterID)
basicAuth, err := common.GetBasicAuth(cfg)
if err != nil {
log.Error(err)
h.WriteError(w, err.Error(), http.StatusInternalServerError)
return
}
// query not associated nodes info // query not associated nodes info
nodesM, err := getUnAssociateNodes() nodesM, err := getUnAssociateNodes()
if err != nil { if err != nil {
@ -662,6 +654,15 @@ func (h *APIHandler) autoAssociateESNode(w http.ResponseWriter, req *http.Reques
h.WriteError(w, err.Error(), http.StatusInternalServerError) h.WriteError(w, err.Error(), http.StatusInternalServerError)
return return
} }
for _, clusterID := range reqBody.ClusterIDs {
// query cluster basicauth
cfg := elastic.GetConfig(clusterID)
basicAuth, err := common.GetBasicAuth(cfg)
if err != nil {
log.Error(err)
h.WriteError(w, err.Error(), http.StatusInternalServerError)
return
}
taskSetting, err := getSettingsByClusterID(cfg.ID) taskSetting, err := getSettingsByClusterID(cfg.ID)
if err != nil { if err != nil {
log.Error(err) log.Error(err)
@ -766,6 +767,7 @@ func (h *APIHandler) autoAssociateESNode(w http.ResponseWriter, req *http.Reques
} }
} }
}
h.WriteAckOKJSON(w) h.WriteAckOKJSON(w)
} }
@ -985,7 +987,7 @@ func getNodesInfoFromES(agentID string) (map[int]*agent.ESNodeInfo, error) {
func getUnAssociateNodes() (map[string][]agent.ESNodeInfo, error){ func getUnAssociateNodes() (map[string][]agent.ESNodeInfo, error){
query := util.MapStr{ query := util.MapStr{
"size": 1200, "size": 3000,
"query": util.MapStr{ "query": util.MapStr{
"bool": util.MapStr{ "bool": util.MapStr{
"must_not": []util.MapStr{ "must_not": []util.MapStr{