diff --git a/internal/master/param_table.go b/internal/master/param_table.go index 89f3a6345e36eb767459ec3c2b330091ac1485b5..8529c765b9a70714ee72caf3cf1a25acfaece4c7 100644 --- a/internal/master/param_table.go +++ b/internal/master/param_table.go @@ -21,6 +21,7 @@ type ParamTable struct { KvRootPath string WriteNodeSegKvSubPath string PulsarAddress string + IndexBuilderAddress string // nodeID ProxyIDList []typeutil.UniqueID @@ -71,6 +72,7 @@ func (p *ParamTable) Init() { p.initKvRootPath() p.initWriteNodeSegKvSubPath() p.initPulsarAddress() + p.initIndexBuilderAddress() p.initProxyIDList() p.initWriteNodeIDList() @@ -125,6 +127,14 @@ func (p *ParamTable) initPulsarAddress() { p.PulsarAddress = addr } +func (p *ParamTable) initIndexBuilderAddress() { + ret, err := p.Load("_IndexBuilderAddress") + if err != nil { + panic(err) + } + p.IndexBuilderAddress = ret +} + func (p *ParamTable) initMetaRootPath() { rootPath, err := p.Load("etcd.rootPath") if err != nil { diff --git a/internal/master/param_table_test.go b/internal/master/param_table_test.go index 8128c5f180c0eebb787a9a0e60517ee949fe6fe5..750021666ca4b9d85455d545998de8aa65488f93 100644 --- a/internal/master/param_table_test.go +++ b/internal/master/param_table_test.go @@ -31,6 +31,11 @@ func TestParamTable_KVRootPath(t *testing.T) { assert.Equal(t, path, "by-dev/kv") } +func TestParamTable_IndexBuilderAddress(t *testing.T) { + path := Params.IndexBuilderAddress + assert.Equal(t, path, "localhost:31000") +} + func TestParamTable_TopicNum(t *testing.T) { num := Params.TopicNum fmt.Println("TopicNum:", num) diff --git a/internal/util/paramtable/paramtable.go b/internal/util/paramtable/paramtable.go index ef8d7f56f02a4eaa751f7d498397227fbce96c9a..229b47765b42b4dc6825fac39acfdca4f292bf2d 100644 --- a/internal/util/paramtable/paramtable.go +++ b/internal/util/paramtable/paramtable.go @@ -57,19 +57,40 @@ func (gp *BaseTable) Init() { if err != nil { panic(err) } + gp.tryloadFromEnv() + +} + +func (gp *BaseTable) tryloadFromEnv() { minioAddress := os.Getenv("MINIO_ADDRESS") if minioAddress == "" { - minioAddress = "localhost:9000" + minioHost, err := gp.Load("minio.address") + if err != nil { + panic(err) + } + port, err := gp.Load("minio.port") + if err != nil { + panic(err) + } + minioAddress = minioHost + ":" + port } - err = gp.Save("_MinioAddress", minioAddress) + err := gp.Save("_MinioAddress", minioAddress) if err != nil { panic(err) } etcdAddress := os.Getenv("ETCD_ADDRESS") if etcdAddress == "" { - etcdAddress = "localhost:2379" + etcdHost, err := gp.Load("etcd.address") + if err != nil { + panic(err) + } + port, err := gp.Load("etcd.port") + if err != nil { + panic(err) + } + etcdAddress = etcdHost + ":" + port } err = gp.Save("_EtcdAddress", etcdAddress) if err != nil { @@ -78,7 +99,15 @@ func (gp *BaseTable) Init() { pulsarAddress := os.Getenv("PULSAR_ADDRESS") if pulsarAddress == "" { - pulsarAddress = "pulsar://localhost:6650" + pulsarHost, err := gp.Load("pulsar.address") + if err != nil { + panic(err) + } + port, err := gp.Load("pulsar.port") + if err != nil { + panic(err) + } + pulsarAddress = "pulsar://" + pulsarHost + ":" + port } err = gp.Save("_PulsarAddress", pulsarAddress) if err != nil { @@ -87,12 +116,37 @@ func (gp *BaseTable) Init() { masterAddress := os.Getenv("MASTER_ADDRESS") if masterAddress == "" { - masterAddress = "localhost:53100" + masterHost, err := gp.Load("master.address") + if err != nil { + panic(err) + } + port, err := gp.Load("master.port") + if err != nil { + panic(err) + } + masterAddress = masterHost + ":" + port } err = gp.Save("_MasterAddress", masterAddress) if err != nil { panic(err) } + + indexBuilderAddress := os.Getenv("INDEX_BUILDER_ADDRESS") + if indexBuilderAddress == "" { + indexBuilderHost, err := gp.Load("indexBuilder.address") + if err != nil { + panic(err) + } + port, err := gp.Load("indexBuilder.port") + if err != nil { + panic(err) + } + indexBuilderAddress = indexBuilderHost + ":" + port + } + err = gp.Save("_IndexBuilderAddress", indexBuilderAddress) + if err != nil { + panic(err) + } } func (gp *BaseTable) Load(key string) (string, error) {