From 2b330a56a7c54da72cd862c86caa0ba8eb3f7228 Mon Sep 17 00:00:00 2001 From: medcl Date: Sat, 20 Feb 2021 12:26:37 +0800 Subject: [PATCH] update for cluster api --- api/init.go | 9 ++++----- api/system/cluster_config.go | 3 ++- main.go | 6 +++--- model/cluster_config.go | 20 ++++++++++---------- model/reindex.go | 2 -- search-center.yml | 5 ++--- 6 files changed, 21 insertions(+), 24 deletions(-) diff --git a/api/init.go b/api/init.go index 8c239539..0b8b4cea 100644 --- a/api/init.go +++ b/api/init.go @@ -1,14 +1,13 @@ package api import ( - "log" - "infini.sh/framework/core/api" "infini.sh/framework/core/task" "infini.sh/framework/core/ui" "infini.sh/search-center/api/index_management" - "infini.sh/search-center/config" "infini.sh/search-center/api/system" + "infini.sh/search-center/config" + log "github.com/cihub/seelog" ) func Init(cfg *config.AppConfig) { @@ -40,11 +39,11 @@ func Init(cfg *config.AppConfig) { ui.HandleUIMethod(api.GET, pathPrefix+"cluster/:cluster/version", handler.GetClusterVersion) task.RegisterScheduleTask(task.ScheduleTask{ - Description: "sync reindex task result to index infinireindex", + Description: "sync reindex task result", Task: func() { err := index_management.SyncRebuildResult(cfg.Elasticsearch) if err != nil { - log.Println(err) + log.Error(err) } }, }) diff --git a/api/system/cluster_config.go b/api/system/cluster_config.go index 3370d006..b37791b9 100644 --- a/api/system/cluster_config.go +++ b/api/system/cluster_config.go @@ -35,7 +35,8 @@ func (h *APIHandler) HandleCreateClusterAction(w http.ResponseWriter, req *http. conf.Created = time.Now() conf.Updated = conf.Created conf.ID = id - ir, err := esClient.Index(orm.GetIndexName(model.ClusterConfig{}), "", id, conf) + index:=orm.GetIndexName(model.ClusterConfig{}) + ir, err := esClient.Index(index, "", id, conf) if err != nil { resBody["error"] = err h.WriteJSON(w, resBody, http.StatusOK) diff --git a/main.go b/main.go index 00c453ca..0b75873f 100644 --- a/main.go +++ b/main.go @@ -69,9 +69,9 @@ func main() { module.Start() }, func() { - orm.RegisterSchemaWithIndexName(model.Dict{}, "infini-dict") - orm.RegisterSchemaWithIndexName(model.Reindex{}, "infini-reindex") - orm.RegisterSchemaWithIndexName(model.ClusterConfig{}, "infini-cluster") + orm.RegisterSchemaWithIndexName(model.Dict{}, "dict") + orm.RegisterSchemaWithIndexName(model.Reindex{}, "reindex") + orm.RegisterSchemaWithIndexName(model.ClusterConfig{}, "cluster") }) } diff --git a/model/cluster_config.go b/model/cluster_config.go index 93f91a90..7024eb70 100644 --- a/model/cluster_config.go +++ b/model/cluster_config.go @@ -3,14 +3,14 @@ package model import "time" type ClusterConfig struct { - ID string `json:"id" elastic_meta:"_id"` - Name string `json:"name" elastic_mapping:"name:{type:text}"` - Endpoint string `json:"endpoint" elastic_mapping:"endpoint:{type:text}"` - UserName string `json:"username" elastic_mapping:"username:{type:keyword}"` - Password string `json:"password" elastic_mapping:"password:{type:keyword}" ` - Order int `json:"order" elastic_mapping:"order:{type:integer}"` - Description string `json:"description" elastic_mapping:"description:{type:text}"` - Enabled bool `json:"enabled" elastic_mapping:"enabled:{type:boolean}"` - Created time.Time `json:"created" elastic_mapping:"created:{type:date}"` - Updated time.Time `json:"updated" elastic_mapping:"updated:{type:date}"` + ID string `json:"id" elastic_meta:"_id"` + Name string `json:"name" elastic_mapping:"name:{type:text}"` + Endpoint string `json:"endpoint" elastic_mapping:"endpoint:{type:text}"` + UserName string `json:"username" elastic_mapping:"username:{type:keyword}"` + Password string `json:"password" elastic_mapping:"password:{type:keyword}" ` + Order int `json:"order" elastic_mapping:"order:{type:integer}"` + Description string `json:"description" elastic_mapping:"description:{type:text}"` + Enabled bool `json:"enabled" elastic_mapping:"enabled:{type:boolean}"` + Created time.Time `json:"created" elastic_mapping:"created:{type:date}"` + Updated time.Time `json:"updated" elastic_mapping:"updated:{type:date}"` } diff --git a/model/reindex.go b/model/reindex.go index 9bc8c21a..6ac86cba 100644 --- a/model/reindex.go +++ b/model/reindex.go @@ -17,8 +17,6 @@ const ( ReindexStatusFailed ReindexStatus = "FAILED" ) -//const IndexReindex = ".reindex" - type Reindex struct { ID string `json:"id" elastic_meta:"_id"` Name string `json:"name" elastic_mapping:"name:{type:text}"` diff --git a/search-center.yml b/search-center.yml index 56d9dac2..5d65c849 100644 --- a/search-center.yml +++ b/search-center.yml @@ -1,8 +1,7 @@ elasticsearch: - name: default enabled: true - endpoint: https://192.168.3.98:8000 - index_prefix: + endpoint: https://192.168.3.98:9200 basic_auth: username: elastic password: ZBdkVQUUdF1Sir4X4BGB @@ -28,7 +27,7 @@ modules: enabled: true init_template: true template_name: ".infini-search-center" - index_prefix: ".infini-search-center-" + index_prefix: ".infini-search-center_" search-center: ui_path: .public