add update agent instance api
This commit is contained in:
parent
461faa46e9
commit
536711d03f
17
console.yml
17
console.yml
|
@ -1,6 +1,11 @@
|
||||||
path.configs: "config"
|
path.configs: "config"
|
||||||
configs.auto_reload: true
|
configs.auto_reload: true
|
||||||
|
|
||||||
|
#env:
|
||||||
|
# INFINI_CONSOLE_ENDPOINT: "http://192.168.3.9:9000"
|
||||||
|
# INGEST_CLUSTER_ENDPOINT: "http://192.168.3.9:9210"
|
||||||
|
# INGEST_CLUSTER_CREDENTIAL_ID: chjkp9dath21f1ae9tq0
|
||||||
|
|
||||||
web:
|
web:
|
||||||
enabled: true
|
enabled: true
|
||||||
embedding_api: true
|
embedding_api: true
|
||||||
|
@ -64,4 +69,14 @@ badger:
|
||||||
# authorize_url: "https://github.com/login/oauth/authorize"
|
# authorize_url: "https://github.com/login/oauth/authorize"
|
||||||
# token_url: "https://github.com/login/oauth/access_token"
|
# token_url: "https://github.com/login/oauth/access_token"
|
||||||
# redirect_url: ""
|
# redirect_url: ""
|
||||||
# scopes: []
|
# scopes: []
|
||||||
|
|
||||||
|
#agent:
|
||||||
|
# setup:
|
||||||
|
# download_url: "https://release.infinilabs.com/agent/snapshot"
|
||||||
|
# version: 0.5.0_NIGHTLY-157
|
||||||
|
# ca_cert: "/opt/config/certs/ca.crt"
|
||||||
|
# ca_key: "/opt/config/certs/ca.key"
|
||||||
|
# console_endpoint: $[[env.INFINI_CONSOLE_ENDPOINT]]
|
||||||
|
# ingest_cluster_endpoint: $[[env.INGEST_CLUSTER_ENDPOINT]]
|
||||||
|
# ingest_cluster_credential_id: $[[env.INGEST_CLUSTER_CREDENTIAL_ID]]
|
|
@ -14,6 +14,7 @@ func Init() {
|
||||||
api.HandleAPIMethod(api.POST, "/agent/instance", handler.createInstance)
|
api.HandleAPIMethod(api.POST, "/agent/instance", handler.createInstance)
|
||||||
api.HandleAPIMethod(api.GET, "/agent/instance/_search", handler.RequirePermission(handler.searchInstance, enum.PermissionAgentInstanceRead))
|
api.HandleAPIMethod(api.GET, "/agent/instance/_search", handler.RequirePermission(handler.searchInstance, enum.PermissionAgentInstanceRead))
|
||||||
api.HandleAPIMethod(api.GET, "/agent/instance/:instance_id", handler.getInstance)
|
api.HandleAPIMethod(api.GET, "/agent/instance/:instance_id", handler.getInstance)
|
||||||
|
api.HandleAPIMethod(api.PUT, "/agent/instance/:instance_id", handler.updateInstance)
|
||||||
api.HandleAPIMethod(api.DELETE, "/agent/instance/:instance_id", handler.RequirePermission(handler.deleteInstance, enum.PermissionAgentInstanceWrite))
|
api.HandleAPIMethod(api.DELETE, "/agent/instance/:instance_id", handler.RequirePermission(handler.deleteInstance, enum.PermissionAgentInstanceWrite))
|
||||||
api.HandleAPIMethod(api.POST, "/agent/instance/_stats", handler.RequirePermission(handler.getInstanceStats, enum.PermissionAgentInstanceRead))
|
api.HandleAPIMethod(api.POST, "/agent/instance/_stats", handler.RequirePermission(handler.getInstanceStats, enum.PermissionAgentInstanceRead))
|
||||||
api.HandleAPIMethod(api.GET, "/agent/log/node/:node_id/files", handler.RequirePermission(handler.getLogFilesByNode, enum.PermissionAgentInstanceRead))
|
api.HandleAPIMethod(api.GET, "/agent/log/node/:node_id/files", handler.RequirePermission(handler.getLogFilesByNode, enum.PermissionAgentInstanceRead))
|
||||||
|
|
|
@ -312,6 +312,52 @@ func (h *APIHandler) getInstanceStats(w http.ResponseWriter, req *http.Request,
|
||||||
h.WriteJSON(w, result, http.StatusOK)
|
h.WriteJSON(w, result, http.StatusOK)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (h *APIHandler) updateInstance(w http.ResponseWriter, req *http.Request, ps httprouter.Params) {
|
||||||
|
id := ps.MustGetParameter("instance_id")
|
||||||
|
oldInst := agent.Instance{}
|
||||||
|
oldInst.ID = id
|
||||||
|
_, err := orm.Get(&oldInst)
|
||||||
|
if err != nil {
|
||||||
|
if err == elastic2.ErrNotFound {
|
||||||
|
h.WriteJSON(w, util.MapStr{
|
||||||
|
"_id": id,
|
||||||
|
"result": "not_found",
|
||||||
|
}, http.StatusNotFound)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
h.WriteError(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
log.Error(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
obj := agent.Instance{}
|
||||||
|
err = h.DecodeJSON(req, &obj)
|
||||||
|
if err != nil {
|
||||||
|
h.WriteError(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
log.Error(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
oldInst.Name = obj.Name
|
||||||
|
oldInst.Endpoint = obj.Endpoint
|
||||||
|
oldInst.Description = obj.Description
|
||||||
|
oldInst.Tags = obj.Tags
|
||||||
|
oldInst.BasicAuth = obj.BasicAuth
|
||||||
|
err = orm.Update(&orm.Context{
|
||||||
|
Refresh: "wait_for",
|
||||||
|
}, &oldInst)
|
||||||
|
if err != nil {
|
||||||
|
h.WriteError(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
log.Error(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
h.WriteJSON(w, util.MapStr{
|
||||||
|
"_id": obj.ID,
|
||||||
|
"result": "updated",
|
||||||
|
}, 200)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
func (h *APIHandler) searchInstance(w http.ResponseWriter, req *http.Request, ps httprouter.Params) {
|
func (h *APIHandler) searchInstance(w http.ResponseWriter, req *http.Request, ps httprouter.Params) {
|
||||||
|
|
||||||
|
|
|
@ -37,6 +37,7 @@ func ParseAgentSettings(settings []agent.Setting)(*model.ParseAgentSettingsResul
|
||||||
Enabled: true,
|
Enabled: true,
|
||||||
Name: cfg.Name,
|
Name: cfg.Name,
|
||||||
BasicAuth: cfg.BasicAuth,
|
BasicAuth: cfg.BasicAuth,
|
||||||
|
//todo get endpoint from agent node info
|
||||||
Endpoint: setting.Metadata.Labels["endpoint"].(string),
|
Endpoint: setting.Metadata.Labels["endpoint"].(string),
|
||||||
}
|
}
|
||||||
newCfg.ID = clusterID
|
newCfg.ID = clusterID
|
||||||
|
|
Loading…
Reference in New Issue