Skip to content
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

merge develop #3

Merged
merged 31 commits into from
Aug 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
2e01ed5
Ftr: add dynamic tag router
watermelo Jul 19, 2020
05d541b
update readme
fangyincheng Jul 26, 2020
71095a3
Add: add unit tests for tag router
watermelo Jul 26, 2020
fdcd408
let go_restful_server support same url and different methodType
Patrick0308 Jul 28, 2020
4ef21cb
Add: add ip address match function
watermelo Jul 29, 2020
891ec6c
Add: add listener for tag router
watermelo Jul 29, 2020
0d56ab0
Merge branch 'develop' into featrue/tagRouter
watermelo Jul 29, 2020
8580ad0
Mod: update tag router unit test
watermelo Jul 30, 2020
f2261ce
format code
Patrick0308 Jul 30, 2020
9b73313
Modify README_CN
Jul 31, 2020
55c84cd
Modify README_CN.md
Jul 31, 2020
db1e5da
Merge pull request #676 from Patrick0308/rest_methodtype
AlexStocks Aug 1, 2020
abcc4df
Merge pull request #683 from QMHTMY/master
AlexStocks Aug 1, 2020
bc46c9a
Modify README_CN
Jul 31, 2020
12680fd
Modify README_CN.md
Jul 31, 2020
70c01a5
Add: add unit test for dynamic tag
watermelo Aug 2, 2020
a31a4e2
Add: add zk jar for tag test
watermelo Aug 3, 2020
65b215a
Merge pull request #18 from apache/develop
lzp0412 Aug 3, 2020
0ef7765
unregister instance when registry destroy
lzp0412 Aug 4, 2020
7ad26fd
try to fix zk problem
wenxuwan Aug 4, 2020
53587ec
try to fix ut failed
wenxuwan Aug 5, 2020
7a88bab
change the default value to 15m
wenxuwan Aug 5, 2020
c33f4ea
change the default value to 15min
wenxuwan Aug 5, 2020
2d8224e
fix review comment
lzp0412 Aug 5, 2020
da4225e
Fix kubernetes ut
Aug 5, 2020
79ade24
FMT k8s pkg
Aug 5, 2020
9b4745f
fix comments
wenxuwan Aug 6, 2020
269714a
Merge pull request #693 from sxllwx/fix_k8s_ut
AlexStocks Aug 6, 2020
c4fbd60
Merge pull request #692 from wenxuwan/master
AlexStocks Aug 6, 2020
0b5e2f4
Merge pull request #689 from lzp0412/develop
AlexStocks Aug 6, 2020
5e377f4
Merge pull request #665 from watermelo/featrue/tagRouter
AlexStocks Aug 6, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ go test ./... -coverprofile=coverage.txt -covermode=atomic

## [User List](https://github.com/apache/dubbo-go/issues/2)

若你正在使用 [apache/dubbo-go](github.com/apache/dubbo-go) 且认为其有用或者向对其做改进,请忝列贵司信息于 [用户列表](https://github.com/apache/dubbo-go/issues/2),以便我们知晓之
若你正在使用 [apache/dubbo-go](github.com/apache/dubbo-go) 且认为其有用或者想对其做改进,请添列贵司信息于 [用户列表](https://github.com/apache/dubbo-go/issues/2),以便我们知晓

<div>
<table>
Expand Down
3 changes: 3 additions & 0 deletions before_ut.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,8 @@ cp ${zkJar} cluster/router/chain/zookeeper-4unittest/contrib/fatjar
mkdir -p cluster/router/condition/zookeeper-4unittest/contrib/fatjar
cp ${zkJar} cluster/router/condition/zookeeper-4unittest/contrib/fatjar

mkdir -p cluster/router/tag/zookeeper-4unittest/contrib/fatjar
cp ${zkJar} cluster/router/tag/zookeeper-4unittest/contrib/fatjar

mkdir -p metadata/report/zookeeper/zookeeper-4unittest/contrib/fatjar
cp ${zkJar} metadata/report/zookeeper/zookeeper-4unittest/contrib/fatjar
2 changes: 1 addition & 1 deletion cluster/router/condition/app_router_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
)

import (
_ "github.com/apache/dubbo-go/config_center/zookeeper"
"github.com/stretchr/testify/assert"
)

Expand All @@ -34,6 +33,7 @@ import (
"github.com/apache/dubbo-go/common/constant"
"github.com/apache/dubbo-go/common/extension"
"github.com/apache/dubbo-go/config_center"
_ "github.com/apache/dubbo-go/config_center/zookeeper"
"github.com/apache/dubbo-go/remoting"
"github.com/apache/dubbo-go/remoting/zookeeper"
)
Expand Down
2 changes: 1 addition & 1 deletion cluster/router/condition/listenable_router.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func newListenableRouter(url *common.URL, ruleKey string) (*AppRouter, error) {
return l, nil
}

// Process Process config change event , generate routers and set them to the listenableRouter instance
// Process Process config change event, generate routers and set them to the listenableRouter instance
func (l *listenableRouter) Process(event *config_center.ConfigChangeEvent) {
logger.Infof("Notification of condition rule, change type is:[%s] , raw rule is:[%v]", event.ConfigType, event.Value)
if remoting.EventTypeDel == event.ConfigType {
Expand Down
2 changes: 1 addition & 1 deletion cluster/router/tag/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ type FileTagRouter struct {
force bool
}

// NewFileTagRouter Create file tag router instance with content ( from config file)
// NewFileTagRouter Create file tag router instance with content (from config file)
func NewFileTagRouter(content []byte) (*FileTagRouter, error) {
fileRouter := &FileTagRouter{}
rule, err := getRule(string(content))
Expand Down
71 changes: 71 additions & 0 deletions cluster/router/tag/router_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,27 @@ import (
"github.com/apache/dubbo-go/common/yaml"
)

/**
* %YAML1.2
* ---
* force: true
* runtime: false
* enabled: true
* priority: 1
* key: demo-provider
* tags:
* - name: tag1
* addresses: [ip1, ip2]
* - name: tag2
* addresses: [ip3, ip4]
* ...
*/
// RouterRule RouterRule config read from config file or config center
type RouterRule struct {
router.BaseRouterRule `yaml:",inline""`
Tags []Tag
addressToTagNames map[string][]string
tagNameToAddresses map[string][]string
}

func getRule(rawRule string) (*RouterRule, error) {
Expand All @@ -34,5 +52,58 @@ func getRule(rawRule string) (*RouterRule, error) {
return r, err
}
r.RawRule = rawRule
r.init()
return r, nil
}

func (t *RouterRule) init() {
t.addressToTagNames = make(map[string][]string, 8)
t.tagNameToAddresses = make(map[string][]string, 8)
for _, tag := range t.Tags {
for _, address := range tag.Addresses {
t.addressToTagNames[address] = append(t.addressToTagNames[address], tag.Name)
}
t.tagNameToAddresses[tag.Name] = tag.Addresses
}
}

func (t *RouterRule) getAddresses() []string {
var result = make([]string, 0, 8*len(t.Tags))
for _, tag := range t.Tags {
result = append(result, tag.Addresses...)
}
return result
}

func (t *RouterRule) getTagNames() []string {
var result = make([]string, 0, len(t.Tags))
for _, tag := range t.Tags {
result = append(result, tag.Name)
}
return result
}

func (t *RouterRule) hasTag(tag string) bool {
for _, t := range t.Tags {
if tag == t.Name {
return true
}
}
return false
}

func (t *RouterRule) getAddressToTagNames() map[string][]string {
return t.addressToTagNames
}

func (t *RouterRule) getTagNameToAddresses() map[string][]string {
return t.tagNameToAddresses
}

func (t *RouterRule) getTags() []Tag {
return t.Tags
}

func (t *RouterRule) setTags(tags []Tag) {
t.Tags = tags
}
55 changes: 46 additions & 9 deletions cluster/router/tag/router_rule_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,56 @@ import (
)

import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/suite"
)

func TestGetRule(t *testing.T) {
type RuleTestSuite struct {
suite.Suite
rule *RouterRule
}

func (suite *RuleTestSuite) SetupTest() {
var err error
yml := `
scope: application
runtime: true
force: true
runtime: false
enabled: true
priority: 1
key: demo-provider
tags:
- name: tag1
addresses: [ip1, ip2]
- name: tag2
addresses: [ip3, ip4]
`
rule, e := getRule(yml)
assert.Nil(t, e)
assert.NotNil(t, rule)
assert.Equal(t, true, rule.Force)
assert.Equal(t, true, rule.Runtime)
assert.Equal(t, "application", rule.Scope)
suite.rule, err = getRule(yml)
suite.Nil(err)
}

func (suite *RuleTestSuite) TestGetRule() {
var err error
suite.Equal(true, suite.rule.Force)
suite.Equal(false, suite.rule.Runtime)
suite.Equal("application", suite.rule.Scope)
suite.Equal(1, suite.rule.Priority)
suite.Equal("demo-provider", suite.rule.Key)
suite.Nil(err)
}

func (suite *RuleTestSuite) TestGetTagNames() {
suite.Equal([]string{"tag1", "tag2"}, suite.rule.getTagNames())
}

func (suite *RuleTestSuite) TestGetAddresses() {
suite.Equal([]string{"ip1", "ip2", "ip3", "ip4"}, suite.rule.getAddresses())
}

func (suite *RuleTestSuite) TestHasTag() {
suite.Equal(true, suite.rule.hasTag("tag1"))
suite.Equal(false, suite.rule.hasTag("tag404"))
}

func TestRuleTestSuite(t *testing.T) {
suite.Run(t, new(RuleTestSuite))
}
39 changes: 39 additions & 0 deletions cluster/router/tag/tag.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* 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 tag

type Tag struct {
Name string
Addresses []string
}

func (t *Tag) getName() string {
return t.Name
}

func (t *Tag) setName(name string) {
t.Name = name
}

func (t *Tag) getAddresses() []string {
return t.Addresses
}

func (t *Tag) setAddresses(addresses []string) {
t.Addresses = addresses
}
Loading