Skip to content
Snippets Groups Projects
Commit 0dfe4ca7 authored by LaurenceLiZhixin's avatar LaurenceLiZhixin
Browse files

fix: fix refer

parent 00f79535
No related branches found
No related tags found
No related merge requests found
...@@ -76,30 +76,10 @@ func (c *RouterChain) GetNotifyChan() chan struct{} { ...@@ -76,30 +76,10 @@ func (c *RouterChain) GetNotifyChan() chan struct{} {
// Route Loop routers in RouterChain and call Route method to determine the target invokers list. // Route Loop routers in RouterChain and call Route method to determine the target invokers list.
func (c *RouterChain) Route(url *common.URL, invocation protocol.Invocation) []protocol.Invoker { func (c *RouterChain) Route(url *common.URL, invocation protocol.Invocation) []protocol.Invoker {
//cache := c.loadCache()
//if cache == nil {
// c.mutex.RLock()
// defer c.mutex.RUnlock()
// return c.invokers
//}
finalInvokers := make([]protocol.Invoker, 0) finalInvokers := make([]protocol.Invoker, 0)
for _, r := range c.copyRouters() { for _, r := range c.copyRouters() {
finalInvokers = r.Route(c.invokers, url, invocation) finalInvokers = r.Route(c.invokers, url, invocation)
} }
//
//bitmap := cache.bitmap
//for _, r := range c.copyRouters() {
// bitmap = r.Route(bitmap, cache, url, invocation)
//}
//
//indexes := bitmap.ToArray()
//finalInvokers := make([]protocol.Invoker, len(indexes))
//for i, index := range indexes {
// finalInvokers[i] = cache.invokers[index]
//}
return finalInvokers return finalInvokers
} }
...@@ -234,15 +214,6 @@ func NewRouterChain(url *common.URL) (*RouterChain, error) { ...@@ -234,15 +214,6 @@ func NewRouterChain(url *common.URL) (*RouterChain, error) {
} }
routers := make([]router.PriorityRouter, 0, len(routerFactories)) routers := make([]router.PriorityRouter, 0, len(routerFactories))
// to delete
//for key, routerFactory := range fileRouterFactories {
// r, err := routerFactory.NewFileRouter(config.GetUniformRouterConfigByte(), chain.notify)
// 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)
//}
for key, routerFactory := range routerFactories { for key, routerFactory := range routerFactories {
if virtualServiceConfigByte == nil || destinationRuleConfigByte == nil { if virtualServiceConfigByte == nil || destinationRuleConfigByte == nil {
...@@ -250,7 +221,7 @@ func NewRouterChain(url *common.URL) (*RouterChain, error) { ...@@ -250,7 +221,7 @@ func NewRouterChain(url *common.URL) (*RouterChain, error) {
} }
r, err := routerFactory().NewPriorityRouter(virtualServiceConfigByte, destinationRuleConfigByte, chain.notify) r, err := routerFactory().NewPriorityRouter(virtualServiceConfigByte, destinationRuleConfigByte, chain.notify)
if r == nil || err != nil { if r == nil || err != nil {
logger.Errorf("router chain build router fail! routerFactories key:%s error:%s", key, err.Error()) logger.Errorf("router chain build router fail! routerFactories key:%s error:%vv", key, err)
continue continue
} }
routers = append(routers, r) routers = append(routers, r)
......
...@@ -30,7 +30,6 @@ import ( ...@@ -30,7 +30,6 @@ import (
import ( import (
"github.com/apache/dubbo-go/cluster/router" "github.com/apache/dubbo-go/cluster/router"
"github.com/apache/dubbo-go/cluster/router/condition"
"github.com/apache/dubbo-go/common" "github.com/apache/dubbo-go/common"
"github.com/apache/dubbo-go/common/config" "github.com/apache/dubbo-go/common/config"
"github.com/apache/dubbo-go/common/constant" "github.com/apache/dubbo-go/common/constant"
...@@ -91,20 +90,6 @@ conditions: ...@@ -91,20 +90,6 @@ conditions:
chain, err := NewRouterChain(getRouteUrl(applicationKey)) chain, err := NewRouterChain(getRouteUrl(applicationKey))
assert.Nil(t, err) assert.Nil(t, err)
assert.Equal(t, 1, len(chain.routers)) assert.Equal(t, 1, len(chain.routers))
appRouter := chain.routers[0].(*condition.AppRouter)
assert.NotNil(t, appRouter)
assert.NotNil(t, appRouter.RouterRule())
rule := appRouter.RouterRule()
assert.Equal(t, "application", rule.Scope)
assert.True(t, rule.Force)
assert.True(t, rule.Enabled)
assert.True(t, rule.Valid)
assert.Equal(t, testyml, rule.RawRule)
assert.Equal(t, false, rule.Runtime)
assert.Equal(t, false, rule.Dynamic)
assert.Equal(t, "mock-app", rule.Key)
} }
func TestNewRouterChainURLNil(t *testing.T) { func TestNewRouterChainURLNil(t *testing.T) {
...@@ -153,7 +138,7 @@ conditions: ...@@ -153,7 +138,7 @@ conditions:
for range notify { for range notify {
} }
}() }()
r, err := factory.NewPriorityRouter(url, notify) r, err := factory.NewPriorityRouter([]byte{}, []byte{}, notify)
assert.Nil(t, err) assert.Nil(t, err)
assert.NotNil(t, r) assert.NotNil(t, r)
......
...@@ -151,7 +151,6 @@ func TestNewProviderConfig(t *testing.T) { ...@@ -151,7 +151,6 @@ func TestNewProviderConfig(t *testing.T) {
WithProviderServices("UserProvider", serviceConfig), WithProviderServices("UserProvider", serviceConfig),
WithProviderProtocol("dubbo", "dubbo", "20000"), WithProviderProtocol("dubbo", "dubbo", "20000"),
WithProviderRegistry("demoConsul", defaultConsulRegistry), WithProviderRegistry("demoConsul", defaultConsulRegistry),
WithProviderRegistry("demoNacos", defaultNacosRegistry),
) )
assert.NotNil(t, testProviderConfig.Services) assert.NotNil(t, testProviderConfig.Services)
...@@ -160,16 +159,9 @@ func TestNewProviderConfig(t *testing.T) { ...@@ -160,16 +159,9 @@ func TestNewProviderConfig(t *testing.T) {
assert.Equal(t, v, serviceConfig) assert.Equal(t, v, serviceConfig)
} }
assert.NotNil(t, testProviderConfig.Registries) assert.NotNil(t, testProviderConfig.Registries)
i := 0
for k, v := range testProviderConfig.Registries { for k, v := range testProviderConfig.Registries {
if i == 0 { assert.Equal(t, k, "demoConsul")
assert.Equal(t, k, "demoConsul") assert.Equal(t, v, defaultConsulRegistry)
assert.Equal(t, v, defaultConsulRegistry)
i++
} else {
assert.Equal(t, k, "demoNacos")
assert.Equal(t, v, defaultNacosRegistry)
}
} }
assert.NotNil(t, testProviderConfig.Protocols) assert.NotNil(t, testProviderConfig.Protocols)
......
...@@ -308,11 +308,6 @@ func selectMetadataServiceExportedURL() *common.URL { ...@@ -308,11 +308,6 @@ func selectMetadataServiceExportedURL() *common.URL {
} }
func initRouter() { func initRouter() {
//if confRouterFile != "" {
// if err := RouterInit(confRouterFile); err != nil {
// log.Printf("[routerConfig init] %#v", err)
// }
//}
if uniformDestRuleConfigPath != "" && uniformVirturlServiceConfigPath != "" { if uniformDestRuleConfigPath != "" && uniformVirturlServiceConfigPath != "" {
if err := RouterInit(uniformVirturlServiceConfigPath, uniformDestRuleConfigPath); err != nil { if err := RouterInit(uniformVirturlServiceConfigPath, uniformDestRuleConfigPath); err != nil {
log.Printf("[routerConfig init] %#v", err) log.Printf("[routerConfig init] %#v", err)
......
...@@ -40,26 +40,17 @@ type LocalRouterRules struct { ...@@ -40,26 +40,17 @@ type LocalRouterRules struct {
// RouterInit Set config file to init router config // RouterInit Set config file to init router config
func RouterInit(vsConfigPath, drConfigPath string) error { func RouterInit(vsConfigPath, drConfigPath string) error {
vsBytes, err := yaml.LoadYMLConfig(vsConfigPath) vsBytes, err := yaml.LoadYMLConfig(vsConfigPath)
if err != nil {
return err
}
drBytes, err := yaml.LoadYMLConfig(drConfigPath) drBytes, err := yaml.LoadYMLConfig(drConfigPath)
if err != nil {
return err
}
chain.SetVSAndDRConfigByte(vsBytes, drBytes) chain.SetVSAndDRConfigByte(vsBytes, drBytes)
return err return nil
} }
//func initRouterConfig(content []byte, factories map[string]router.FilePriorityRouterFactory) error {
// logger.Warnf("get fileRouterFactories len{%+v})", len(factories))
//
// for k, factory := range factories {
// r, e := factory.NewFileRouter(content)
// if e == nil {
// url := r.URL()
// routerURLSet.Add(url)
// return nil
// }
// logger.Warnf("router config type %s create fail {%v}\n", k, e)
// }
// return perrors.Errorf("no file router exists for parse %s , implement router.FIleRouterFactory please.", confRouterFile)
//}
// GetRouterURLSet exposes the routerURLSet // GetRouterURLSet exposes the routerURLSet
func GetRouterURLSet() *gxset.HashSet { func GetRouterURLSet() *gxset.HashSet {
return routerURLSet return routerURLSet
......
...@@ -23,17 +23,12 @@ import ( ...@@ -23,17 +23,12 @@ import (
) )
import ( import (
"github.com/dubbogo/gost/container/set"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )
import ( const testVirtualServiceYML = "testdata/router_config_virtual_service.yml"
_ "github.com/apache/dubbo-go/cluster/router/condition" const testDestinationRuleYML = "testdata/router_config_dest_rule.yml"
) const errorTestDestinationRuleYML = "testdata/router_config_destination_rule_error.yml"
const testYML = "testdata/router_config.yml"
const testMultiRouterYML = "testdata/router_multi_config.yml"
const errorTestYML = "testdata/router_config_error.yml"
func TestString(t *testing.T) { func TestString(t *testing.T) {
...@@ -56,19 +51,9 @@ func TestString(t *testing.T) { ...@@ -56,19 +51,9 @@ func TestString(t *testing.T) {
} }
func TestRouterInit(t *testing.T) { func TestRouterInit(t *testing.T) {
errPro := RouterInit(errorTestYML) err := RouterInit(testVirtualServiceYML, testDestinationRuleYML)
assert.Error(t, errPro) assert.NoError(t, err)
assert.Equal(t, 0, routerURLSet.Size())
errPro = RouterInit(testYML)
assert.NoError(t, errPro)
assert.Equal(t, 1, routerURLSet.Size())
routerURLSet = gxset.NewSet()
errPro = RouterInit(testMultiRouterYML)
assert.NoError(t, errPro)
assert.Equal(t, 2, routerURLSet.Size()) err = RouterInit(testVirtualServiceYML, errorTestDestinationRuleYML)
assert.Error(t, err)
} }
# dubbo router yaml configure file
routerRules:
- scope: application
key: mock-app
priority: 1
force: true
conditions :
- "a => b"
- "c => d"
\ No newline at end of file
apiVersion: service.dubbo.apache.org/v1alpha1
kind: DestinationRule
metadata:
name: demo-route
spec:
host: demo
subsets:
- name: v1
labels:
sigma.ali/mg: v1-host
generic: false
- name: v2
labels:
generic: false
- name: v3
labels:
sigma.ali/mg: v3-host
\ No newline at end of file
# dubbo router yaml configure file
routerRules:
- priority: 1
force: true
noConditions :
- "a => b"
- "c => d"
\ No newline at end of file
apiVersion: service.dubbo.apache.org/v1alpha1
kind: VirtualService
metadata:
name: demo-route
spec:
hosts:
- demo # 统一定义为应用名
dubbo:
- service:
- exact: com.taobao.hsf.demoService:1.0.0
- exact: com.taobao.hsf.demoService:2.0.0
routedetail:
- name: sayHello-String-method-route
match:
- method:
name_match:
exact: "sayHello"
# argp:
# - string
route:
- destination:
host: demo
subset: v1
fallback:
destination:
host: demo
subset: v2
fallback:
destination:
host: demo
subset: v3
- name: sayHello-method-route
match:
- method:
name_match:
exact: "s-method"
route:
- destination:
host: demo
subset: v2
fallback:
destination:
host: demo
subset: v3
- name: some-method-route
match:
- method:
name_match:
exact: "some-method"
route:
- destination:
host: demo
subset: v4
# - name: interface-route
# route:
# - destination:
# host: demo
# subset: v3
- name: final
match:
- method:
name_match:
exact: "GetUser"
route:
- destination:
host: demo
subset: v1
fallback:
destination:
host: demo
subset: v2
fallback:
destination:
host: demo
subset: v3
- destination:
host: demo
subset: v3
fallback:
destination:
host: demo
subset: v2
fallback:
destination:
host: demo
subset: v1
- service:
- exact: com.taobao.hsf.demoService:1.0.0
- exact: org.apache.dubbo.UserProvider
routedetail:
- name: sayHello-String-method-route
match:
- method:
name_match:
exact: "sayHello"
# argp:
# - string
route:
- destination:
host: demo
subset: v1
fallback:
destination:
host: demo
subset: v2
fallback:
destination:
host: demo
subset: v3
- name: sayHello-method-route
match:
- method:
name_match:
exact: "s-method"
route:
- destination:
host: demo
subset: v2
fallback:
destination:
host: demo
subset: v3
- name: some-method-route
match:
- method:
name_match:
exact: "some-method"
route:
- destination:
host: demo
subset: v4
# - name: interface-route
# route:
# - destination:
# host: demo
# subset: v3
- name: final
match:
- method:
name_match:
exact: "GetUser"
route:
- destination:
host: demo
subset: v1
fallback:
destination:
host: demo
subset: v2
fallback:
destination:
host: demo
subset: v3
- destination:
host: demo
subset: v3
fallback:
destination:
host: demo
subset: v2
fallback:
destination:
host: demo
subset: v1
\ No newline at end of file
# dubbo router yaml configure file
routerRules:
- scope: application
key: mock-app
priority: 1
force: true
conditions :
- "a => b"
- "c => d"
- scope: application
key: mock-app2
priority: 1
force: true
conditions :
- "a => b"
- "c => d"
\ No newline at end of file
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment