mirror of
https://gitee.com/milvus-io/milvus.git
synced 2024-12-05 05:18:52 +08:00
dd20ab44b8
Signed-off-by: dragondriver <jiquan.long@zilliz.com>
100 lines
1.9 KiB
Go
100 lines
1.9 KiB
Go
package proxynode
|
|
|
|
import (
|
|
"encoding/json"
|
|
"io/ioutil"
|
|
"net/http"
|
|
"reflect"
|
|
"time"
|
|
|
|
"go.uber.org/zap"
|
|
|
|
"github.com/zilliztech/milvus-distributed/internal/log"
|
|
"github.com/zilliztech/milvus-distributed/internal/util/retry"
|
|
)
|
|
|
|
func GetPulsarConfig(protocol, ip, port, url string) (map[string]interface{}, error) {
|
|
var resp *http.Response
|
|
var err error
|
|
|
|
getResp := func() error {
|
|
log.Debug("proxynode util", zap.String("url", protocol+"://"+ip+":"+port+url))
|
|
resp, err = http.Get(protocol + "://" + ip + ":" + port + url)
|
|
return err
|
|
}
|
|
|
|
err = retry.Retry(10, time.Second, getResp)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer resp.Body.Close()
|
|
|
|
body, err := ioutil.ReadAll(resp.Body)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
ret := make(map[string]interface{})
|
|
err = json.Unmarshal(body, &ret)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return ret, nil
|
|
}
|
|
|
|
func SliceContain(s interface{}, item interface{}) bool {
|
|
ss := reflect.ValueOf(s)
|
|
if ss.Kind() != reflect.Slice {
|
|
panic("SliceContain expect a slice")
|
|
}
|
|
|
|
for i := 0; i < ss.Len(); i++ {
|
|
if ss.Index(i).Interface() == item {
|
|
return true
|
|
}
|
|
}
|
|
|
|
return false
|
|
}
|
|
|
|
func SliceSetEqual(s1 interface{}, s2 interface{}) bool {
|
|
ss1 := reflect.ValueOf(s1)
|
|
ss2 := reflect.ValueOf(s2)
|
|
if ss1.Kind() != reflect.Slice {
|
|
panic("expect a slice")
|
|
}
|
|
if ss2.Kind() != reflect.Slice {
|
|
panic("expect a slice")
|
|
}
|
|
if ss1.Len() != ss2.Len() {
|
|
return false
|
|
}
|
|
for i := 0; i < ss1.Len(); i++ {
|
|
if !SliceContain(s2, ss1.Index(i).Interface()) {
|
|
return false
|
|
}
|
|
}
|
|
return true
|
|
}
|
|
|
|
func SortedSliceEqual(s1 interface{}, s2 interface{}) bool {
|
|
ss1 := reflect.ValueOf(s1)
|
|
ss2 := reflect.ValueOf(s2)
|
|
if ss1.Kind() != reflect.Slice {
|
|
panic("expect a slice")
|
|
}
|
|
if ss2.Kind() != reflect.Slice {
|
|
panic("expect a slice")
|
|
}
|
|
if ss1.Len() != ss2.Len() {
|
|
return false
|
|
}
|
|
for i := 0; i < ss1.Len(); i++ {
|
|
if ss2.Index(i).Interface() != ss1.Index(i).Interface() {
|
|
return false
|
|
}
|
|
}
|
|
return true
|
|
}
|