Skip to content

Commit

Permalink
fix: fix lint bug
Browse files Browse the repository at this point in the history
  • Loading branch information
LaurenceLiZhixin committed Apr 5, 2021
1 parent a1550a8 commit 9651ec2
Show file tree
Hide file tree
Showing 86 changed files with 174 additions and 174 deletions.
18 changes: 9 additions & 9 deletions cluster/cluster_impl/base_cluster_invoker.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ func newBaseClusterInvoker(directory cluster.Directory) baseClusterInvoker {
}
}

func (invoker *baseClusterInvoker) GetUrl() *common.URL {
return invoker.directory.GetUrl()
func (invoker *baseClusterInvoker) GetURL() *common.URL {
return invoker.directory.GetURL()
}

func (invoker *baseClusterInvoker) Destroy() {
Expand All @@ -75,7 +75,7 @@ func (invoker *baseClusterInvoker) checkInvokers(invokers []protocol.Invoker, in
ip := common.GetLocalIp()
return perrors.Errorf("Failed to invoke the method %v. No provider available for the service %v from "+
"registry %v on the consumer %v using the dubbo version %v .Please check if the providers have been started and registered.",
invocation.MethodName(), invoker.directory.GetUrl().SubURL.Key(), invoker.directory.GetUrl().String(), ip, constant.Version)
invocation.MethodName(), invoker.directory.GetURL().SubURL.Key(), invoker.directory.GetURL().String(), ip, constant.Version)
}
return nil
}
Expand All @@ -85,7 +85,7 @@ func (invoker *baseClusterInvoker) checkWhetherDestroyed() error {
if invoker.destroyed.Load() {
ip := common.GetLocalIp()
return perrors.Errorf("Rpc cluster invoker for %v on consumer %v use dubbo version %v is now destroyed! can not invoke any more. ",
invoker.directory.GetUrl().Service(), ip, constant.Version)
invoker.directory.GetURL().Service(), ip, constant.Version)
}
return nil
}
Expand All @@ -96,7 +96,7 @@ func (invoker *baseClusterInvoker) doSelect(lb cluster.LoadBalance, invocation p
return selectedInvoker
}

url := invokers[0].GetUrl()
url := invokers[0].GetURL()
sticky := url.GetParamBool(constant.STICKY_KEY, false)
// Get the service method sticky config if have
sticky = url.GetMethodParamBool(invocation.MethodName(), constant.STICKY_KEY, sticky)
Expand Down Expand Up @@ -128,7 +128,7 @@ func (invoker *baseClusterInvoker) doSelectInvoker(lb cluster.LoadBalance, invoc
return invokers[0]
}
protocol.SetInvokerUnhealthyStatus(invokers[0])
logger.Errorf("the invokers of %s is nil. ", invokers[0].GetUrl().ServiceKey())
logger.Errorf("the invokers of %s is nil. ", invokers[0].GetURL().ServiceKey())
return nil
}

Expand All @@ -151,7 +151,7 @@ func (invoker *baseClusterInvoker) doSelectInvoker(lb cluster.LoadBalance, invoc
}
if !reselectedInvoker.IsAvailable() {
logger.Infof("the invoker of %s is not available, maybe some network error happened or the server is shutdown.",
invoker.GetUrl().Ip)
invoker.GetURL().Ip)
protocol.SetInvokerUnhealthyStatus(reselectedInvoker)
otherInvokers = getOtherInvokers(otherInvokers, reselectedInvoker)
continue
Expand All @@ -161,7 +161,7 @@ func (invoker *baseClusterInvoker) doSelectInvoker(lb cluster.LoadBalance, invoc
} else {
return selectedInvoker
}
logger.Errorf("all %d invokers is unavailable for %s.", len(invokers), selectedInvoker.GetUrl().String())
logger.Errorf("all %d invokers is unavailable for %s.", len(invokers), selectedInvoker.GetURL().String())
return nil
}

Expand Down Expand Up @@ -189,7 +189,7 @@ func isInvoked(selectedInvoker protocol.Invoker, invoked []protocol.Invoker) boo
}

func getLoadBalance(invoker protocol.Invoker, invocation protocol.Invocation) cluster.LoadBalance {
url := invoker.GetUrl()
url := invoker.GetURL()

methodName := invocation.MethodName()
// Get the service loadbalance config
Expand Down
10 changes: 5 additions & 5 deletions cluster/cluster_impl/failback_cluster_invoker.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,14 @@ func newFailbackClusterInvoker(directory cluster.Directory) protocol.Invoker {
invoker := &failbackClusterInvoker{
baseClusterInvoker: newBaseClusterInvoker(directory),
}
retriesConfig := invoker.GetUrl().GetParam(constant.RETRIES_KEY, constant.DEFAULT_FAILBACK_TIMES)
retriesConfig := invoker.GetURL().GetParam(constant.RETRIES_KEY, constant.DEFAULT_FAILBACK_TIMES)
retries, err := strconv.Atoi(retriesConfig)
if err != nil || retries < 0 {
logger.Error("Your retries config is invalid,pls do a check. And will use the default fail back times configuration instead.")
retries = constant.DEFAULT_FAILBACK_TIMES_INT
}

failbackTasksConfig := invoker.GetUrl().GetParamInt(constant.FAIL_BACK_TASKS_KEY, constant.DEFAULT_FAILBACK_TASKS)
failbackTasksConfig := invoker.GetURL().GetParamInt(constant.FAIL_BACK_TASKS_KEY, constant.DEFAULT_FAILBACK_TASKS)
if failbackTasksConfig <= 0 {
failbackTasksConfig = constant.DEFAULT_FAILBACK_TASKS
}
Expand Down Expand Up @@ -114,7 +114,7 @@ func (invoker *failbackClusterInvoker) process(ctx context.Context) {

func (invoker *failbackClusterInvoker) checkRetry(retryTask *retryTimerTask, err error) {
logger.Errorf("Failed retry to invoke the method %v in the service %v, wait again. The exception: %v.\n",
retryTask.invocation.MethodName(), invoker.GetUrl().Service(), err.Error())
retryTask.invocation.MethodName(), invoker.GetURL().Service(), err.Error())
retryTask.retries++
retryTask.lastT = time.Now()
if retryTask.retries > invoker.maxRetries {
Expand All @@ -133,12 +133,12 @@ func (invoker *failbackClusterInvoker) Invoke(ctx context.Context, invocation pr
invokers := invoker.directory.List(invocation)
if err := invoker.checkInvokers(invokers, invocation); err != nil {
logger.Errorf("Failed to invoke the method %v in the service %v, wait for retry in background. Ignored exception: %v.\n",
invocation.MethodName(), invoker.GetUrl().Service(), err)
invocation.MethodName(), invoker.GetURL().Service(), err)
return &protocol.RPCResult{}
}

// Get the service loadbalance config
url := invokers[0].GetUrl()
url := invokers[0].GetURL()
lb := url.GetParam(constant.LOADBALANCE_KEY, constant.DEFAULT_LOADBALANCE)
// Get the service method loadbalance config if have
methodName := invocation.MethodName()
Expand Down
8 changes: 4 additions & 4 deletions cluster/cluster_impl/failover_cluster_invoker.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,14 @@ func (invoker *failoverClusterInvoker) Invoke(ctx context.Context, invocation pr
// DO INVOKE
result = ivk.Invoke(ctx, invocation)
if result.Error() != nil {
providers = append(providers, ivk.GetUrl().Key())
providers = append(providers, ivk.GetURL().Key())
continue
}
return result
}
ip := common.GetLocalIp()
invokerSvc := invoker.GetUrl().Service()
invokerUrl := invoker.directory.GetUrl()
invokerSvc := invoker.GetURL().Service()
invokerUrl := invoker.directory.GetURL()
if ivk == nil {
logger.Errorf("Failed to invoke the method %s of the service %s .No provider is available.", methodName, invokerSvc)
return &protocol.RPCResult{
Expand All @@ -114,7 +114,7 @@ func getRetries(invokers []protocol.Invoker, methodName string) int {
return constant.DEFAULT_RETRIES_INT
}

url := invokers[0].GetUrl()
url := invokers[0].GetURL()
// get reties
retriesConfig := url.GetParam(constant.RETRIES_KEY, constant.DEFAULT_RETRIES)
// Get the service method loadbalance config if have
Expand Down
4 changes: 2 additions & 2 deletions cluster/cluster_impl/failover_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func NewMockInvoker(url *common.URL, successCount int) *MockInvoker {
}

// nolint
func (bi *MockInvoker) GetUrl() *common.URL {
func (bi *MockInvoker) GetURL() *common.URL {
return bi.url
}

Expand Down Expand Up @@ -103,7 +103,7 @@ func (bi *MockInvoker) Invoke(c context.Context, invocation protocol.Invocation)

// nolint
func (bi *MockInvoker) Destroy() {
logger.Infof("Destroy invoker: %v", bi.GetUrl().String())
logger.Infof("Destroy invoker: %v", bi.GetURL().String())
bi.destroyed = true
bi.available = false
}
Expand Down
2 changes: 1 addition & 1 deletion cluster/cluster_impl/failsafe_cluster_invoker.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func (invoker *failsafeClusterInvoker) Invoke(ctx context.Context, invocation pr
return &protocol.RPCResult{}
}

url := invokers[0].GetUrl()
url := invokers[0].GetURL()
methodName := invocation.MethodName()
// Get the service loadbalance config
lb := url.GetParam(constant.LOADBALANCE_KEY, constant.DEFAULT_LOADBALANCE)
Expand Down
4 changes: 2 additions & 2 deletions cluster/cluster_impl/forking_cluster_invoker.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ func (invoker *forkingClusterInvoker) Invoke(ctx context.Context, invocation pro
}

var selected []protocol.Invoker
forks := invoker.GetUrl().GetParamByIntValue(constant.FORKS_KEY, constant.DEFAULT_FORKS)
timeouts := invoker.GetUrl().GetParamInt(constant.TIMEOUT_KEY, constant.DEFAULT_TIMEOUT)
forks := invoker.GetURL().GetParamByIntValue(constant.FORKS_KEY, constant.DEFAULT_FORKS)
timeouts := invoker.GetURL().GetParamInt(constant.TIMEOUT_KEY, constant.DEFAULT_TIMEOUT)
if forks < 0 || forks > len(invokers) {
selected = invokers
} else {
Expand Down
2 changes: 1 addition & 1 deletion cluster/cluster_impl/mock_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@ func NewMockCluster() cluster.Cluster {

// nolint
func (cluster *mockCluster) Join(directory cluster.Directory) protocol.Invoker {
return protocol.NewBaseInvoker(directory.GetUrl())
return protocol.NewBaseInvoker(directory.GetURL())
}
4 changes: 2 additions & 2 deletions cluster/cluster_impl/zone_aware_cluster_invoker.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func (invoker *zoneAwareClusterInvoker) DoInvoke(ctx context.Context, invocation
return &protocol.RPCResult{
Err: fmt.Errorf("no registry instance in zone or "+
"no available providers in the registry, zone: %v, "+
" registries: %v", zone, invoker.GetUrl()),
" registries: %v", zone, invoker.GetURL()),
}
}
}
Expand Down Expand Up @@ -128,5 +128,5 @@ func (invoker *zoneAwareClusterInvoker) AfterInvoker(ctx context.Context, invoca
}

func matchParam(target, key, def string, invoker protocol.Invoker) bool {
return target == invoker.GetUrl().GetParam(key, def)
return target == invoker.GetURL().GetParam(key, def)
}
14 changes: 7 additions & 7 deletions cluster/directory/base_directory.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ func (dir *BaseDirectory) SetRouterChain(routerChain router.Chain) {
dir.routerChain = routerChain
}

// GetUrl Get URL
func (dir *BaseDirectory) GetUrl() *common.URL {
// GetURL Get URL
func (dir *BaseDirectory) GetURL() *common.URL {
return dir.url
}

Expand All @@ -74,13 +74,13 @@ func (dir *BaseDirectory) GetDirectoryUrl() *common.URL {

func (dir *BaseDirectory) isProperRouter(url *common.URL) bool {
app := url.GetParam(constant.APPLICATION_KEY, "")
dirApp := dir.GetUrl().GetParam(constant.APPLICATION_KEY, "")
if len(dirApp) == 0 && dir.GetUrl().SubURL != nil {
dirApp = dir.GetUrl().SubURL.GetParam(constant.APPLICATION_KEY, "")
dirApp := dir.GetURL().GetParam(constant.APPLICATION_KEY, "")
if len(dirApp) == 0 && dir.GetURL().SubURL != nil {
dirApp = dir.GetURL().SubURL.GetParam(constant.APPLICATION_KEY, "")
}
serviceKey := dir.GetUrl().ServiceKey()
serviceKey := dir.GetURL().ServiceKey()
if len(serviceKey) == 0 {
serviceKey = dir.GetUrl().SubURL.ServiceKey()
serviceKey = dir.GetURL().SubURL.ServiceKey()
}
if len(app) > 0 && app == dirApp {
return true
Expand Down
2 changes: 1 addition & 1 deletion cluster/directory/base_directory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ var (

func TestNewBaseDirectory(t *testing.T) {
dir := NewBaseDirectory(url)
assert.Equal(t, url, dir.GetUrl())
assert.Equal(t, url, dir.GetURL())
assert.Equal(t, url, dir.GetDirectoryUrl())
}

Expand Down
6 changes: 3 additions & 3 deletions cluster/directory/static_directory.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func NewStaticDirectory(invokers []protocol.Invoker) *staticDirectory {
var url *common.URL

if len(invokers) > 0 {
url = invokers[0].GetUrl()
url = invokers[0].GetURL()
}
dir := &staticDirectory{
BaseDirectory: NewBaseDirectory(url),
Expand Down Expand Up @@ -71,7 +71,7 @@ func (dir *staticDirectory) List(invocation protocol.Invocation) []protocol.Invo
if routerChain == nil {
return invokers
}
dirUrl := dir.GetUrl()
dirUrl := dir.GetURL()
return routerChain.Route(dirUrl, invocation)
}

Expand All @@ -90,7 +90,7 @@ func (dir *staticDirectory) BuildRouterChain(invokers []protocol.Invoker) error
if len(invokers) == 0 {
return perrors.Errorf("invokers == null")
}
url := invokers[0].GetUrl()
url := invokers[0].GetURL()
routerChain, e := chain.NewRouterChain(url)
if e != nil {
return e
Expand Down
6 changes: 3 additions & 3 deletions cluster/loadbalance/consistent_hash.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func NewConsistentHashLoadBalance() cluster.LoadBalance {
// Select gets invoker based on load balancing strategy
func (lb *ConsistentHashLoadBalance) Select(invokers []protocol.Invoker, invocation protocol.Invocation) protocol.Invoker {
methodName := invocation.MethodName()
key := invokers[0].GetUrl().ServiceKey() + "." + methodName
key := invokers[0].GetURL().ServiceKey() + "." + methodName

// hash the invokers
bs := make([]byte, 0)
Expand Down Expand Up @@ -105,7 +105,7 @@ func newConsistentHashSelector(invokers []protocol.Invoker, methodName string,
selector := &ConsistentHashSelector{}
selector.virtualInvokers = make(map[uint32]protocol.Invoker)
selector.hashCode = hashCode
url := invokers[0].GetUrl()
url := invokers[0].GetURL()
selector.replicaNum = url.GetMethodParamIntValue(methodName, HashNodes, 160)
indices := re.Split(url.GetMethodParam(methodName, HashArguments, "0"), -1)
for _, index := range indices {
Expand All @@ -116,7 +116,7 @@ func newConsistentHashSelector(invokers []protocol.Invoker, methodName string,
selector.argumentIndex = append(selector.argumentIndex, i)
}
for _, invoker := range invokers {
u := invoker.GetUrl()
u := invoker.GetURL()
address := u.Ip + ":" + u.Port
for i := 0; i < selector.replicaNum/4; i++ {
digest := md5.Sum([]byte(address + strconv.Itoa(i)))
Expand Down
6 changes: 3 additions & 3 deletions cluster/loadbalance/consistent_hash_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func (s *consistentHashSelectorSuite) TestSelectForKey() {
s.selector.virtualInvokers[9999945] = protocol.NewBaseInvoker(url2)
s.selector.keys = []uint32{99874, 9999945}
result := s.selector.selectForKey(9999944)
s.Equal(result.GetUrl().String(), url8081Short+"?")
s.Equal(result.GetURL().String(), url8081Short+"?")
}

func TestConsistentHashLoadBalanceSuite(t *testing.T) {
Expand Down Expand Up @@ -114,9 +114,9 @@ func (s *consistentHashLoadBalanceSuite) SetupTest() {
func (s *consistentHashLoadBalanceSuite) TestSelect() {
args := []interface{}{"name", "password", "age"}
invoker := s.lb.Select(s.invokers, invocation.NewRPCInvocation("echo", args, nil))
s.Equal(invoker.GetUrl().Location, fmt.Sprintf("%s:%d", ip, port8080))
s.Equal(invoker.GetURL().Location, fmt.Sprintf("%s:%d", ip, port8080))

args = []interface{}{"ok", "abc"}
invoker = s.lb.Select(s.invokers, invocation.NewRPCInvocation("echo", args, nil))
s.Equal(invoker.GetUrl().Location, fmt.Sprintf("%s:%d", ip, port8082))
s.Equal(invoker.GetURL().Location, fmt.Sprintf("%s:%d", ip, port8082))
}
2 changes: 1 addition & 1 deletion cluster/loadbalance/least_active.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func (lb *leastActiveLoadBalance) Select(invokers []protocol.Invoker, invocation
for i := 0; i < count; i++ {
invoker := invokers[i]
// Active number
active := protocol.GetMethodStatus(invoker.GetUrl(), invocation.MethodName()).GetActive()
active := protocol.GetMethodStatus(invoker.GetURL(), invocation.MethodName()).GetActive()
// current weight (maybe in warmUp)
weight := GetWeight(invoker, invocation)
// There are smaller active services
Expand Down
8 changes: 4 additions & 4 deletions cluster/loadbalance/least_active_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func TestLeastActiveSelect(t *testing.T) {
url, _ := common.NewURL(fmt.Sprintf("dubbo://%s:%d/org.apache.demo.HelloService", constant.LOCAL_HOST_VALUE, constant.DEFAULT_PORT))
invokers = append(invokers, protocol.NewBaseInvoker(url))
i := loadBalance.Select(invokers, &invocation.RPCInvocation{})
assert.True(t, i.GetUrl().URLEqual(url))
assert.True(t, i.GetURL().URLEqual(url))

for i := 1; i < 10; i++ {
url, _ := common.NewURL(fmt.Sprintf("dubbo://192.168.1.%v:20000/org.apache.demo.HelloService", i))
Expand All @@ -61,7 +61,7 @@ func TestLeastActiveByWeight(t *testing.T) {
}

inv := invocation.NewRPCInvocationWithOptions(invocation.WithMethodName("test"))
protocol.BeginCount(invokers[2].GetUrl(), inv.MethodName())
protocol.BeginCount(invokers[2].GetURL(), inv.MethodName())

loop = 10000

Expand All @@ -72,9 +72,9 @@ func TestLeastActiveByWeight(t *testing.T) {

for i := 1; i <= loop; i++ {
invoker := loadBalance.Select(invokers, inv)
if invoker.GetUrl().Protocol == "test1" {
if invoker.GetURL().Protocol == "test1" {
firstCount++
} else if invoker.GetUrl().Protocol == "test2" {
} else if invoker.GetURL().Protocol == "test2" {
secondCount++
}
}
Expand Down
6 changes: 3 additions & 3 deletions cluster/loadbalance/random_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func TestRandomlbSelect(t *testing.T) {
url, _ := common.NewURL(fmt.Sprintf(tmpUrlFormat, 0))
invokers = append(invokers, protocol.NewBaseInvoker(url))
i := randomlb.Select(invokers, &invocation.RPCInvocation{})
assert.True(t, i.GetUrl().URLEqual(url))
assert.True(t, i.GetURL().URLEqual(url))

for i := 1; i < 10; i++ {
url, _ := common.NewURL(fmt.Sprintf(tmpUrlFormat, i))
Expand Down Expand Up @@ -78,7 +78,7 @@ func TestRandomlbSelectWeight(t *testing.T) {
var selected float64
for i := 0; i < 10000; i++ {
s := randomlb.Select(invokers, ivc)
if s.GetUrl().Ip == tmpIp {
if s.GetURL().Ip == tmpIp {
selected++
}
selectedInvoker = append(selectedInvoker, s)
Expand Down Expand Up @@ -110,7 +110,7 @@ func TestRandomlbSelectWarmup(t *testing.T) {
var selected float64
for i := 0; i < 10000; i++ {
s := randomlb.Select(invokers, ivc)
if s.GetUrl().Ip == tmpIp {
if s.GetURL().Ip == tmpIp {
selected++
}
selectedInvoker = append(selectedInvoker, s)
Expand Down
Loading

0 comments on commit 9651ec2

Please sign in to comment.