auto associate support multi cluster
This commit is contained in:
parent
f92b448333
commit
503b201eb2
|
@ -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)
|
||||||
|
@ -685,7 +686,7 @@ func (h *APIHandler) autoAssociateESNode(w http.ResponseWriter, req *http.Reques
|
||||||
for _, node := range nodes {
|
for _, node := range nodes {
|
||||||
host := node.PublishAddress
|
host := node.PublishAddress
|
||||||
var endpoint string
|
var endpoint string
|
||||||
if strings.HasPrefix( host, "::"){
|
if strings.HasPrefix(host, "::") {
|
||||||
instURL, err := url.Parse(inst.Endpoint)
|
instURL, err := url.Parse(inst.Endpoint)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error(err)
|
log.Error(err)
|
||||||
|
@ -693,7 +694,7 @@ func (h *APIHandler) autoAssociateESNode(w http.ResponseWriter, req *http.Reques
|
||||||
}
|
}
|
||||||
host = instURL.Hostname()
|
host = instURL.Hostname()
|
||||||
endpoint = fmt.Sprintf("%s://%s:%s", node.Schema, host, node.HttpPort)
|
endpoint = fmt.Sprintf("%s://%s:%s", node.Schema, host, node.HttpPort)
|
||||||
}else{
|
} else {
|
||||||
endpoint = fmt.Sprintf("%s://%s", node.Schema, host)
|
endpoint = fmt.Sprintf("%s://%s", node.Schema, host)
|
||||||
}
|
}
|
||||||
escfg := elastic.ElasticsearchConfig{
|
escfg := elastic.ElasticsearchConfig{
|
||||||
|
@ -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{
|
||||||
|
|
Loading…
Reference in New Issue