2021-03-09 16:18:58 +08:00
|
|
|
package proxynode
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"io/ioutil"
|
|
|
|
"net/http"
|
2021-03-13 09:57:22 +08:00
|
|
|
"reflect"
|
2021-03-09 16:18:58 +08:00
|
|
|
"time"
|
|
|
|
|
2021-03-12 19:47:37 +08:00
|
|
|
"go.uber.org/zap"
|
|
|
|
|
|
|
|
"github.com/zilliztech/milvus-distributed/internal/log"
|
2021-03-09 16:18:58 +08:00
|
|
|
"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 {
|
2021-03-12 19:47:37 +08:00
|
|
|
log.Debug("proxynode util", zap.String("url", protocol+"://"+ip+":"+port+url))
|
2021-03-09 16:18:58 +08:00
|
|
|
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
|
|
|
|
}
|
2021-03-13 09:57:22 +08:00
|
|
|
|
|
|
|
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
|
|
|
|
}
|