support setup with easysearch and opensearch
This commit is contained in:
parent
a6b44b63f3
commit
5d0e745012
|
@ -24,7 +24,7 @@ func bootstrapRequirementCheck() error{
|
|||
|
||||
|
||||
func checkElasticsearchRequirements() error{
|
||||
log.Trace("start to check elasticsearch requirement")
|
||||
log.Trace("start to check system cluster requirement")
|
||||
var esConfigs = []elastic.ElasticsearchConfig{}
|
||||
ok, err := env.ParseConfig("elasticsearch", &esConfigs)
|
||||
if err != nil {
|
||||
|
@ -37,7 +37,7 @@ func checkElasticsearchRequirements() error{
|
|||
elasticsearchID:=global.Lookup(elastic.GlobalSystemElasticsearchID)
|
||||
|
||||
if elasticsearchID == nil||elasticsearchID=="" {
|
||||
return fmt.Errorf("elasticsearch config in web section can not be empty")
|
||||
return fmt.Errorf("cluster config in web section can not be empty")
|
||||
}
|
||||
|
||||
esID:=elasticsearchID.(string)
|
||||
|
@ -50,7 +50,7 @@ func checkElasticsearchRequirements() error{
|
|||
}
|
||||
|
||||
if targetEsConfig == nil {
|
||||
return fmt.Errorf("elasticsearch config %s was not found", esID)
|
||||
return fmt.Errorf("cluster config %s was not found", esID)
|
||||
}
|
||||
var req = util.NewGetRequest(targetEsConfig.Endpoint, nil)
|
||||
if targetEsConfig.BasicAuth != nil {
|
||||
|
@ -59,23 +59,30 @@ func checkElasticsearchRequirements() error{
|
|||
|
||||
result, err := util.ExecuteRequest(req)
|
||||
if err != nil {
|
||||
return fmt.Errorf("check elasticsearch requirement error: %v", err)
|
||||
return fmt.Errorf("check system cluster requirement error: %v", err)
|
||||
}
|
||||
|
||||
if result==nil||result.Body==nil||len(result.Body)==0{
|
||||
return fmt.Errorf("failed to retrive elasticsearch version info")
|
||||
return fmt.Errorf("failed to retrive cluster version info")
|
||||
}
|
||||
|
||||
|
||||
versionNumber, err := jsonparser.GetString(result.Body, "version", "number")
|
||||
if err != nil {
|
||||
return fmt.Errorf("check elasticsearch requirement error: %v, got response: %s", err, string(result.Body))
|
||||
return fmt.Errorf("check system cluster requirement error: %v, got response: %s", err, string(result.Body))
|
||||
}
|
||||
distribution, _ := jsonparser.GetString(result.Body, "version", "distribution")
|
||||
if distribution == "easysearch" || distribution == "opensearch" {
|
||||
return nil
|
||||
} else if distribution != "" {
|
||||
return fmt.Errorf("unkonw cluster distribution: %v", distribution)
|
||||
}
|
||||
cr, err := util.VersionCompare(versionNumber, "7.3")
|
||||
if err !=nil {
|
||||
return fmt.Errorf("check elasticsearch requirement error: %v", err)
|
||||
return fmt.Errorf("check system cluster requirement error: %v", err)
|
||||
}
|
||||
if cr == -1 {
|
||||
return fmt.Errorf("elasticsearch cluster version of store data required to be version 7.3 and above, but got %s", versionNumber)
|
||||
return fmt.Errorf("system cluster version with distribution elasticsearch required to be version 7.3 and above, but got %s", versionNumber)
|
||||
}
|
||||
return nil
|
||||
}
|
|
@ -20,6 +20,7 @@ import (
|
|||
"infini.sh/framework/core/pipeline"
|
||||
"infini.sh/framework/core/util"
|
||||
elastic2 "infini.sh/framework/modules/elastic"
|
||||
"infini.sh/framework/modules/elastic/adapter"
|
||||
elastic1 "infini.sh/framework/modules/elastic/common"
|
||||
elastic3 "infini.sh/framework/modules/elastic/api"
|
||||
"infini.sh/framework/modules/security"
|
||||
|
@ -174,23 +175,28 @@ func (module *Module) validate(w http.ResponseWriter, r *http.Request, ps httpro
|
|||
}
|
||||
|
||||
//validate version
|
||||
version := client.GetVersion()
|
||||
if version != "" {
|
||||
verInfo, err := adapter.ClusterVersion(elastic.GetMetadata(cfg.ID))
|
||||
if verInfo.Version.Distribution == "" {
|
||||
if verInfo.Version.Number != "" {
|
||||
ver := &util.Version{}
|
||||
ver, err = util.ParseSemantic(version)
|
||||
ver, err = util.ParseSemantic(verInfo.Version.Number)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if ver.Major() >= 7 {
|
||||
if ver.Major() == 7 && ver.Minor() < 3 {
|
||||
errType = VersionTooOld
|
||||
panic(errors.Errorf("elasticsearch version(%v) should greater than v7.3", version))
|
||||
panic(errors.Errorf("elasticsearch version(%v) should greater than v7.3", verInfo.Version.Number))
|
||||
}
|
||||
} else {
|
||||
errType = VersionTooOld
|
||||
panic(errors.Errorf("elasticsearch version(%v) should greater than v7.3", version))
|
||||
panic(errors.Errorf("elasticsearch version(%v) should greater than v7.3", verInfo.Version.Number))
|
||||
}
|
||||
}
|
||||
}else if verInfo.Version.Distribution != "easysearch" && verInfo.Version.Distribution != "opensearch" {
|
||||
errType = VersionTooOld
|
||||
panic(errors.Errorf("unsupport distribution (%v)", verInfo.Version.Distribution))
|
||||
}
|
||||
cfg1 = elastic1.ORMConfig{}
|
||||
exist, err := env.ParseConfig("elastic.orm", &cfg1)
|
||||
if exist && err != nil {
|
||||
|
@ -295,7 +301,9 @@ func (module *Module) initTempClient(r *http.Request) (error, elastic.API,SetupR
|
|||
if health != nil {
|
||||
cfg.RawName = health.Name
|
||||
}
|
||||
cfg.Version=client.GetVersion()
|
||||
ver := client.GetVersion()
|
||||
cfg.Version = ver.Number
|
||||
cfg.Distribution = ver.Distribution
|
||||
|
||||
return err, client,request
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue