Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
2
22a7f0099
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Summer2022
22a7f0099
Commits
74e42986
Commit
74e42986
authored
5 years ago
by
vito.he
Browse files
Options
Downloads
Patches
Plain Diff
Mod: upper RegistryDirectory for inherit
parent
5348da4e
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
registry/directory/directory.go
+20
-20
20 additions, 20 deletions
registry/directory/directory.go
registry/directory/directory_test.go
+8
-8
8 additions, 8 deletions
registry/directory/directory_test.go
with
28 additions
and
28 deletions
registry/directory/directory.go
+
20
−
20
View file @
74e42986
...
...
@@ -43,10 +43,10 @@ import (
)
func
init
()
{
extension
.
SetDefaultRegistryDirectory
(
n
ewRegistryDirectory
)
extension
.
SetDefaultRegistryDirectory
(
N
ewRegistryDirectory
)
}
type
r
egistryDirectory
struct
{
type
R
egistryDirectory
struct
{
directory
.
BaseDirectory
cacheInvokers
[]
protocol
.
Invoker
listenerLock
sync
.
Mutex
...
...
@@ -61,12 +61,12 @@ type registryDirectory struct {
forbidden
atomic
.
Bool
}
//
n
ewRegistryDirectory ...
func
n
ewRegistryDirectory
(
url
*
common
.
URL
,
registry
registry
.
Registry
)
(
cluster
.
Directory
,
error
)
{
//
N
ewRegistryDirectory ...
func
N
ewRegistryDirectory
(
url
*
common
.
URL
,
registry
registry
.
Registry
)
(
cluster
.
Directory
,
error
)
{
if
url
.
SubURL
==
nil
{
return
nil
,
perrors
.
Errorf
(
"url is invalid, suburl can not be nil"
)
}
dir
:=
&
r
egistryDirectory
{
dir
:=
&
R
egistryDirectory
{
BaseDirectory
:
directory
.
NewBaseDirectory
(
url
),
cacheInvokers
:
[]
protocol
.
Invoker
{},
cacheInvokersMap
:
&
sync
.
Map
{},
...
...
@@ -80,18 +80,18 @@ func newRegistryDirectory(url *common.URL, registry registry.Registry) (cluster.
}
//subscribe from registry
func
(
dir
*
r
egistryDirectory
)
subscribe
(
url
*
common
.
URL
)
{
func
(
dir
*
R
egistryDirectory
)
subscribe
(
url
*
common
.
URL
)
{
dir
.
consumerConfigurationListener
.
addNotifyListener
(
dir
)
dir
.
referenceConfigurationListener
=
newReferenceConfigurationListener
(
dir
,
url
)
dir
.
registry
.
Subscribe
(
url
,
dir
)
}
func
(
dir
*
r
egistryDirectory
)
Notify
(
event
*
registry
.
ServiceEvent
)
{
func
(
dir
*
R
egistryDirectory
)
Notify
(
event
*
registry
.
ServiceEvent
)
{
go
dir
.
update
(
event
)
}
// update: subscribe service from registry, and update the cacheServices
func
(
dir
*
r
egistryDirectory
)
update
(
res
*
registry
.
ServiceEvent
)
{
func
(
dir
*
R
egistryDirectory
)
update
(
res
*
registry
.
ServiceEvent
)
{
if
res
==
nil
{
return
}
...
...
@@ -100,7 +100,7 @@ func (dir *registryDirectory) update(res *registry.ServiceEvent) {
dir
.
refreshInvokers
(
res
)
}
func
(
dir
*
r
egistryDirectory
)
refreshInvokers
(
res
*
registry
.
ServiceEvent
)
{
func
(
dir
*
R
egistryDirectory
)
refreshInvokers
(
res
*
registry
.
ServiceEvent
)
{
var
(
url
*
common
.
URL
oldInvoker
protocol
.
Invoker
=
nil
...
...
@@ -151,7 +151,7 @@ func (dir *registryDirectory) refreshInvokers(res *registry.ServiceEvent) {
}
func
(
dir
*
r
egistryDirectory
)
toGroupInvokers
()
[]
protocol
.
Invoker
{
func
(
dir
*
R
egistryDirectory
)
toGroupInvokers
()
[]
protocol
.
Invoker
{
newInvokersList
:=
[]
protocol
.
Invoker
{}
groupInvokersMap
:=
make
(
map
[
string
][]
protocol
.
Invoker
)
groupInvokersList
:=
[]
protocol
.
Invoker
{}
...
...
@@ -188,7 +188,7 @@ func (dir *registryDirectory) toGroupInvokers() []protocol.Invoker {
}
// uncacheInvoker: return abandoned Invoker,if no Invoker to be abandoned,return nil
func
(
dir
*
r
egistryDirectory
)
uncacheInvoker
(
url
*
common
.
URL
)
protocol
.
Invoker
{
func
(
dir
*
R
egistryDirectory
)
uncacheInvoker
(
url
*
common
.
URL
)
protocol
.
Invoker
{
logger
.
Debugf
(
"service will be deleted in cache invokers: invokers key is %s!"
,
url
.
Key
())
if
cacheInvoker
,
ok
:=
dir
.
cacheInvokersMap
.
Load
(
url
.
Key
());
ok
{
dir
.
cacheInvokersMap
.
Delete
(
url
.
Key
())
...
...
@@ -198,7 +198,7 @@ func (dir *registryDirectory) uncacheInvoker(url *common.URL) protocol.Invoker {
}
// cacheInvoker: return abandoned Invoker,if no Invoker to be abandoned,return nil
func
(
dir
*
r
egistryDirectory
)
cacheInvoker
(
url
*
common
.
URL
)
protocol
.
Invoker
{
func
(
dir
*
R
egistryDirectory
)
cacheInvoker
(
url
*
common
.
URL
)
protocol
.
Invoker
{
dir
.
overrideUrl
(
dir
.
GetDirectoryUrl
())
referenceUrl
:=
dir
.
GetDirectoryUrl
()
.
SubURL
...
...
@@ -234,7 +234,7 @@ func (dir *registryDirectory) cacheInvoker(url *common.URL) protocol.Invoker {
}
// list :select the protocol invokers from the directory
func
(
dir
*
r
egistryDirectory
)
List
(
invocation
protocol
.
Invocation
)
[]
protocol
.
Invoker
{
func
(
dir
*
R
egistryDirectory
)
List
(
invocation
protocol
.
Invocation
)
[]
protocol
.
Invoker
{
invokers
:=
dir
.
cacheInvokers
routerChain
:=
dir
.
RouterChain
()
...
...
@@ -244,7 +244,7 @@ func (dir *registryDirectory) List(invocation protocol.Invocation) []protocol.In
return
routerChain
.
Route
(
invokers
,
dir
.
cacheOriginUrl
,
invocation
)
}
func
(
dir
*
r
egistryDirectory
)
IsAvailable
()
bool
{
func
(
dir
*
R
egistryDirectory
)
IsAvailable
()
bool
{
if
!
dir
.
BaseDirectory
.
IsAvailable
()
{
return
dir
.
BaseDirectory
.
IsAvailable
()
}
...
...
@@ -258,7 +258,7 @@ func (dir *registryDirectory) IsAvailable() bool {
return
false
}
func
(
dir
*
r
egistryDirectory
)
Destroy
()
{
func
(
dir
*
R
egistryDirectory
)
Destroy
()
{
//TODO:unregister & unsubscribe
dir
.
BaseDirectory
.
Destroy
(
func
()
{
invokers
:=
dir
.
cacheInvokers
...
...
@@ -269,7 +269,7 @@ func (dir *registryDirectory) Destroy() {
})
}
func
(
dir
*
r
egistryDirectory
)
overrideUrl
(
targetUrl
*
common
.
URL
)
{
func
(
dir
*
R
egistryDirectory
)
overrideUrl
(
targetUrl
*
common
.
URL
)
{
doOverrideUrl
(
dir
.
configurators
,
targetUrl
)
doOverrideUrl
(
dir
.
consumerConfigurationListener
.
Configurators
(),
targetUrl
)
doOverrideUrl
(
dir
.
referenceConfigurationListener
.
Configurators
(),
targetUrl
)
...
...
@@ -283,11 +283,11 @@ func doOverrideUrl(configurators []config_center.Configurator, targetUrl *common
type
referenceConfigurationListener
struct
{
registry
.
BaseConfigurationListener
directory
*
r
egistryDirectory
directory
*
R
egistryDirectory
url
*
common
.
URL
}
func
newReferenceConfigurationListener
(
dir
*
r
egistryDirectory
,
url
*
common
.
URL
)
*
referenceConfigurationListener
{
func
newReferenceConfigurationListener
(
dir
*
R
egistryDirectory
,
url
*
common
.
URL
)
*
referenceConfigurationListener
{
listener
:=
&
referenceConfigurationListener
{
directory
:
dir
,
url
:
url
}
listener
.
InitWith
(
url
.
EncodedServiceKey
()
+
constant
.
CONFIGURATORS_SUFFIX
,
...
...
@@ -305,10 +305,10 @@ func (l *referenceConfigurationListener) Process(event *config_center.ConfigChan
type
consumerConfigurationListener
struct
{
registry
.
BaseConfigurationListener
listeners
[]
registry
.
NotifyListener
directory
*
r
egistryDirectory
directory
*
R
egistryDirectory
}
func
newConsumerConfigurationListener
(
dir
*
r
egistryDirectory
)
*
consumerConfigurationListener
{
func
newConsumerConfigurationListener
(
dir
*
R
egistryDirectory
)
*
consumerConfigurationListener
{
listener
:=
&
consumerConfigurationListener
{
directory
:
dir
}
listener
.
InitWith
(
config
.
GetConsumerConfig
()
.
ApplicationConfig
.
Name
+
constant
.
CONFIGURATORS_SUFFIX
,
...
...
This diff is collapsed.
Click to expand it.
registry/directory/directory_test.go
+
8
−
8
View file @
74e42986
...
...
@@ -66,7 +66,7 @@ func TestSubscribe(t *testing.T) {
func
TestSubscribe_InvalidUrl
(
t
*
testing
.
T
)
{
url
,
_
:=
common
.
NewURL
(
"mock://127.0.0.1:1111"
)
mockRegistry
,
_
:=
registry
.
NewMockRegistry
(
&
common
.
URL
{})
_
,
err
:=
n
ewRegistryDirectory
(
&
url
,
mockRegistry
)
_
,
err
:=
N
ewRegistryDirectory
(
&
url
,
mockRegistry
)
assert
.
Error
(
t
,
err
)
}
...
...
@@ -79,9 +79,9 @@ func TestSubscribe_Group(t *testing.T) {
suburl
.
SetParam
(
constant
.
CLUSTER_KEY
,
"mock"
)
regurl
.
SubURL
=
&
suburl
mockRegistry
,
_
:=
registry
.
NewMockRegistry
(
&
common
.
URL
{})
dir
,
_
:=
n
ewRegistryDirectory
(
&
regurl
,
mockRegistry
)
dir
,
_
:=
N
ewRegistryDirectory
(
&
regurl
,
mockRegistry
)
go
dir
.
(
*
r
egistryDirectory
)
.
subscribe
(
common
.
NewURLWithOptions
(
common
.
WithPath
(
"testservice"
)))
go
dir
.
(
*
R
egistryDirectory
)
.
subscribe
(
common
.
NewURLWithOptions
(
common
.
WithPath
(
"testservice"
)))
//for group1
urlmap
:=
url
.
Values
{}
urlmap
.
Set
(
constant
.
GROUP_KEY
,
"group1"
)
...
...
@@ -100,7 +100,7 @@ func TestSubscribe_Group(t *testing.T) {
}
time
.
Sleep
(
1e9
)
assert
.
Len
(
t
,
dir
.
(
*
r
egistryDirectory
)
.
cacheInvokers
,
2
)
assert
.
Len
(
t
,
dir
.
(
*
R
egistryDirectory
)
.
cacheInvokers
,
2
)
}
func
Test_Destroy
(
t
*
testing
.
T
)
{
...
...
@@ -172,7 +172,7 @@ Loop1:
}
func
normalRegistryDir
(
noMockEvent
...
bool
)
(
*
r
egistryDirectory
,
*
registry
.
MockRegistry
)
{
func
normalRegistryDir
(
noMockEvent
...
bool
)
(
*
R
egistryDirectory
,
*
registry
.
MockRegistry
)
{
extension
.
SetProtocol
(
protocolwrapper
.
FILTER
,
protocolwrapper
.
NewMockProtocolFilter
)
url
,
_
:=
common
.
NewURL
(
"mock://127.0.0.1:1111"
)
...
...
@@ -184,9 +184,9 @@ func normalRegistryDir(noMockEvent ...bool) (*registryDirectory, *registry.MockR
)
url
.
SubURL
=
&
suburl
mockRegistry
,
_
:=
registry
.
NewMockRegistry
(
&
common
.
URL
{})
dir
,
_
:=
n
ewRegistryDirectory
(
&
url
,
mockRegistry
)
dir
,
_
:=
N
ewRegistryDirectory
(
&
url
,
mockRegistry
)
go
dir
.
(
*
r
egistryDirectory
)
.
subscribe
(
&
suburl
)
go
dir
.
(
*
R
egistryDirectory
)
.
subscribe
(
&
suburl
)
if
len
(
noMockEvent
)
==
0
{
for
i
:=
0
;
i
<
3
;
i
++
{
mockRegistry
.
(
*
registry
.
MockRegistry
)
.
MockEvent
(
...
...
@@ -200,5 +200,5 @@ func normalRegistryDir(noMockEvent ...bool) (*registryDirectory, *registry.MockR
)
}
}
return
dir
.
(
*
r
egistryDirectory
),
mockRegistry
.
(
*
registry
.
MockRegistry
)
return
dir
.
(
*
R
egistryDirectory
),
mockRegistry
.
(
*
registry
.
MockRegistry
)
}
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment