fetch es nodes after agent registered
This commit is contained in:
parent
cb3c975cd5
commit
5ced92f8e3
|
@ -133,6 +133,10 @@ func (h *APIHandler) createInstance(w http.ResponseWriter, req *http.Request, ps
|
|||
if err != nil {
|
||||
log.Error(err)
|
||||
}
|
||||
_, err = refreshNodesInfo(obj)
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
}
|
||||
|
||||
h.WriteCreatedOKJSON(w, obj.ID)
|
||||
|
||||
|
@ -833,7 +837,7 @@ func refreshNodesInfo(inst *agent.Instance) ([]agent.ESNodeInfo, error) {
|
|||
return nil, err
|
||||
}
|
||||
for _, node := range nodesInfo {
|
||||
oldNode := getNodeByPidOrUUID(oldNodesInfo, node.ProcessInfo.PID, node.NodeUUID)
|
||||
oldNode := getNodeByPidOrUUID(oldNodesInfo, node.ProcessInfo.PID, node.NodeUUID, node.HttpPort)
|
||||
node.AgentID = inst.ID
|
||||
if oldNode != nil {
|
||||
node.ID = oldNode.ID
|
||||
|
@ -880,7 +884,7 @@ func refreshNodesInfo(inst *agent.Instance) ([]agent.ESNodeInfo, error) {
|
|||
return resultNodes, nil
|
||||
}
|
||||
|
||||
func getNodeByPidOrUUID(nodes map[int]*agent.ESNodeInfo, pid int, uuid string) *agent.ESNodeInfo {
|
||||
func getNodeByPidOrUUID(nodes map[int]*agent.ESNodeInfo, pid int, uuid string, port string) *agent.ESNodeInfo {
|
||||
if nodes[pid] != nil {
|
||||
return nodes[pid]
|
||||
}
|
||||
|
@ -888,6 +892,10 @@ func getNodeByPidOrUUID(nodes map[int]*agent.ESNodeInfo, pid int, uuid string) *
|
|||
if node.NodeUUID != "" && node.NodeUUID == uuid {
|
||||
return node
|
||||
}
|
||||
//todo validate
|
||||
if node.HttpPort != "" && node.HttpPort == port {
|
||||
return node
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue