-
Notifications
You must be signed in to change notification settings - Fork 967
Ftr: condition router #294
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 99 commits
Commits
Show all changes
119 commits
Select commit
Hold shift + click to select a range
7b07c34
use router in dubbo-go
aliiohs dabfded
add GetBackupUrls method
26ca61e
use router in dubbo-go
aliiohs 3ef29b7
use router in dubbo-go
aliiohs 1faef98
use router in dubbo-go
aliiohs 8b45629
change Version file
aliiohs 50e42d0
add init router from yaml file
aliiohs dea76be
fix cycle import bug
aliiohs 84c39a3
fix
aliiohs 313171b
fix
aliiohs 10c873c
fix
aliiohs bf409d3
fix
aliiohs 0be9cf0
fix
aliiohs 16d0b99
debug log
aliiohs dcf2993
debug log
aliiohs 20ac52c
fix bug
aliiohs 44ead07
fix bug
aliiohs 92b1787
debug log
aliiohs 7034520
change router factory param
aliiohs 738321e
init ConsumerUrl when build BaseDirectory
aliiohs 3cafe33
init router only once
aliiohs a876f85
Merge branch 'aliiohs-UseRouter' into feature/addRouter
zouyx c84c1e1
add router
zouyx 52d3554
fix problems
zouyx eca2285
fix problems
zouyx 58bb83a
fix problems
zouyx 1c9c03f
fix problems
zouyx cbb4759
fix problems
zouyx e155e58
fix review problems
zouyx 5909a32
fix review problems
zouyx 085961b
fix review problems
zouyx ee8ff8d
fix review problems
zouyx 18cac91
refactor router code
zouyx b016f01
refactor router code
zouyx 6436e24
add test case
zouyx 163e9a7
refactor router code
zouyx 5ee0f0d
Merge branch 'develop' into feature/addRouter
2956fc0
remove router chain
zouyx 9b2700a
rename package
zouyx af32a05
rename package
zouyx 6d5d849
add to routers method
zouyx a4b2d66
add event update
zouyx 5a69d1c
Merge branch 'develop' into feature/addRouter
zouyx caa0df0
add router
zouyx 9b892e6
split package
zouyx 6ccf9f4
fix test case
zouyx d0035fd
add error log
zouyx a2d433b
Merge branch 'develop' into feature/addRouter
zouyx 5573269
fix review problem
zouyx 2b8699f
fix review comment
zouyx dd95421
fix review comment
zouyx 68ac99e
fix review comment
zouyx c959be6
Merge branch 'develop' into feature/addRouter
zouyx bc732b5
add router event listener
zouyx 3e71f69
add router chain
zouyx ce49840
add router chain
zouyx 3a2b75e
add router chain
zouyx 96c0902
Merge branch 'develop' into feature/addRouter
zouyx 4502c56
add test case
zouyx 625d8b0
fix test
zouyx 552d642
Merge branch 'develop' into feature/addRouter
zouyx 7068404
use before_ut.sh in travis.yml
zouyx bb91f0f
update test case
zouyx bd45b58
Update router
zouyx 2b3ac70
Merge branch 'develop' into feature/addRouter
zouyx 1971704
Merge branch 'develop' into feature/addRouter
zouyx 5b149da
format code
zouyx 948c6c5
format package
zouyx eff1a5a
format package
zouyx cd777ee
add build router chain
zouyx 4e61cdb
Merge branch 'develop' into feature/addRouter
zouyx 2be8f85
fix problems
zouyx 45256e9
fix problems
zouyx 9694d44
fix problems
zouyx cc51f5f
fix file config init invliad
zouyx 207c5a3
delete useless block
zouyx 4d73001
fix test case
zouyx 1c9a716
fix review comment
zouyx 587b9a0
fix review comment
zouyx dd802c0
fix test case
zouyx 1979db2
fix test case
zouyx 242e954
fix review problems
zouyx 1ce2cd2
fix review comment
zouyx e9e57e5
fix test case
zouyx 6054f9f
add comment
zouyx cb4ae79
fix review comment
zouyx 0bbcf48
add comment
zouyx c08374e
Merge branch 'develop' into feature/addRouter
zouyx 92679f9
Merge remote-tracking branch 'origin/feature/addRouter' into feature/…
zouyx 27cfa65
Merge branch 'develop' into feature/addRouter
zouyx c4ef90e
delete useless file
zouyx 70f4880
Merge branch 'develop' into feature/addRouter
zouyx 009f1ca
fix test case
zouyx 326e1fb
Merge branch 'develop' into feature/addRouter
zouyx 4f2731a
fix test case and add some comment
zouyx 7b13315
fix review comment
zouyx 7fab9e0
fix review comment
zouyx 53277c5
Merge branch 'develop' into feature/addRouter
zouyx a5126e1
fix review comment
zouyx fa4b5c0
delete useless file
zouyx 2f33bf0
fix review comment
zouyx dc7e5d0
fix review comment
zouyx a82ee38
fix review comment
zouyx 77c9c9e
fix test case
zouyx f419cd1
add router selection
zouyx d6c62c8
add comment and testcase
zouyx 09d7777
change init router to config.Load()
zouyx 305aa06
fix router init bug
zouyx 02498b2
add UT for app_router
zouyx f326095
Update before_ut.bat and before_ut.sh
zouyx 35223c2
add test case
zouyx 21cf354
add test case
zouyx e34203a
add test case
zouyx 124a108
add test case
zouyx 843d312
Merge branch 'develop' into feature/addRouter
zouyx fc4ed3d
add test case
zouyx 8df93da
add UT for app_router
zouyx 86e35ce
add test case
zouyx 0c7af31
split package
zouyx File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package chain | ||
|
||
import ( | ||
"sort" | ||
"sync" | ||
) | ||
|
||
import ( | ||
perrors "github.com/pkg/errors" | ||
) | ||
|
||
import ( | ||
"github.com/apache/dubbo-go/cluster/router" | ||
"github.com/apache/dubbo-go/common" | ||
"github.com/apache/dubbo-go/common/extension" | ||
"github.com/apache/dubbo-go/common/logger" | ||
"github.com/apache/dubbo-go/protocol" | ||
) | ||
|
||
// RouterChain Router chain | ||
type RouterChain struct { | ||
// Full list of addresses from registry, classified by method name. | ||
invokers []protocol.Invoker | ||
// Containing all routers, reconstruct every time 'route://' urls change. | ||
routers []router.Router | ||
// Fixed router instances: ConfigConditionRouter, TagRouter, e.g., the rule for each instance may change but the | ||
// instance will never delete or recreate. | ||
builtinRouters []router.Router | ||
|
||
mutex sync.RWMutex | ||
} | ||
|
||
// Route Loop routers in RouterChain and call Route method to determine the target invokers list. | ||
func (c RouterChain) Route(invoker []protocol.Invoker, url *common.URL, invocation protocol.Invocation) []protocol.Invoker { | ||
finalInvokers := invoker | ||
l := len(c.routers) | ||
rs := make([]router.Router, l, l) | ||
zouyx marked this conversation as resolved.
Show resolved
Hide resolved
|
||
c.mutex.RLock() | ||
copy(rs, c.routers) | ||
c.mutex.RUnlock() | ||
|
||
for _, r := range rs { | ||
finalInvokers = r.Route(finalInvokers, url, invocation) | ||
} | ||
return finalInvokers | ||
} | ||
|
||
// AddRouters Add routers to router chain | ||
// New a array add builtinRouters which is not sorted in RouterChain and routers | ||
// Sort the array | ||
// Replace router array in RouterChain | ||
func (c RouterChain) AddRouters(routers []router.Router) { | ||
newRouters := make([]router.Router, 0, len(c.builtinRouters)+len(routers)) | ||
newRouters = append(newRouters, c.builtinRouters...) | ||
newRouters = append(newRouters, routers...) | ||
sortRouter(newRouters) | ||
c.mutex.Lock() | ||
defer c.mutex.Unlock() | ||
c.routers = newRouters | ||
} | ||
|
||
// NewRouterChain Use url to init router chain | ||
// Loop routerFactories and call NewRouter method | ||
func NewRouterChain(url *common.URL) (*RouterChain, error) { | ||
routerFactories := extension.GetRouterFactories() | ||
if len(routerFactories) == 0 { | ||
return nil, perrors.Errorf("Illegal route rule!") | ||
} | ||
routers := make([]router.Router, 0, len(routerFactories)) | ||
for key, routerFactory := range routerFactories { | ||
r, err := routerFactory().NewRouter(url) | ||
if r == nil || err != nil { | ||
logger.Errorf("router chain build router fail! routerFactories key:%s error:%s", key, err.Error()) | ||
continue | ||
} | ||
routers = append(routers, r) | ||
} | ||
|
||
newRouters := make([]router.Router, len(routers)) | ||
copy(newRouters, routers) | ||
|
||
sortRouter(newRouters) | ||
|
||
chain := &RouterChain{ | ||
builtinRouters: routers, | ||
routers: newRouters, | ||
} | ||
|
||
return chain, nil | ||
} | ||
|
||
// sortRouter Sort router instance by priority with stable algorithm | ||
func sortRouter(routers []router.Router) { | ||
sort.Stable(byPriority(routers)) | ||
} | ||
|
||
// byPriority Sort by priority | ||
type byPriority []router.Router | ||
|
||
func (a byPriority) Len() int { return len(a) } | ||
func (a byPriority) Swap(i, j int) { a[i], a[j] = a[j], a[i] } | ||
func (a byPriority) Less(i, j int) bool { return a[i].Priority() < a[j].Priority() } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.