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
5952c59f
Commit
5952c59f
authored
4 years ago
by
xg.gao
Browse files
Options
Downloads
Patches
Plain Diff
consul metadata report
parent
9a464273
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
metadata/report/consul/report.go
+132
-0
132 additions, 0 deletions
metadata/report/consul/report.go
metadata/report/consul/report_test.go
+18
-0
18 additions, 0 deletions
metadata/report/consul/report_test.go
metadata/report/nacos/report.go
+12
-16
12 additions, 16 deletions
metadata/report/nacos/report.go
with
162 additions
and
16 deletions
metadata/report/consul/report.go
0 → 100644
+
132
−
0
View file @
5952c59f
/*
* 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
consul
import
(
consul
"github.com/hashicorp/consul/api"
)
import
(
"github.com/apache/dubbo-go/common"
"github.com/apache/dubbo-go/common/extension"
"github.com/apache/dubbo-go/metadata/identifier"
"github.com/apache/dubbo-go/metadata/report"
"github.com/apache/dubbo-go/metadata/report/factory"
)
func
init
()
{
mf
:=
&
consulMetadataReportFactory
{}
extension
.
SetMetadataReportFactory
(
"consul"
,
func
()
factory
.
MetadataReportFactory
{
return
mf
})
}
// consulMetadataReport is the implementation of
// MetadataReport based on Consul.
type
consulMetadataReport
struct
{
client
*
consul
.
Client
}
// StoreProviderMetadata stores the metadata.
func
(
m
*
consulMetadataReport
)
StoreProviderMetadata
(
providerIdentifier
*
identifier
.
MetadataIdentifier
,
serviceDefinitions
string
)
error
{
kv
:=
&
consul
.
KVPair
{
Key
:
providerIdentifier
.
GetIdentifierKey
(),
Value
:
[]
byte
(
serviceDefinitions
)}
_
,
err
:=
m
.
client
.
KV
()
.
Put
(
kv
,
nil
)
return
err
}
// StoreConsumerMetadata stores the metadata.
func
(
m
*
consulMetadataReport
)
StoreConsumerMetadata
(
consumerMetadataIdentifier
*
identifier
.
MetadataIdentifier
,
serviceParameterString
string
)
error
{
kv
:=
&
consul
.
KVPair
{
Key
:
consumerMetadataIdentifier
.
GetIdentifierKey
(),
Value
:
[]
byte
(
serviceParameterString
)}
_
,
err
:=
m
.
client
.
KV
()
.
Put
(
kv
,
nil
)
return
err
}
// SaveServiceMetadata saves the metadata.
func
(
m
*
consulMetadataReport
)
SaveServiceMetadata
(
metadataIdentifier
*
identifier
.
ServiceMetadataIdentifier
,
url
common
.
URL
)
error
{
kv
:=
&
consul
.
KVPair
{
Key
:
metadataIdentifier
.
GetIdentifierKey
(),
Value
:
[]
byte
(
url
.
String
())}
_
,
err
:=
m
.
client
.
KV
()
.
Put
(
kv
,
nil
)
return
err
}
// RemoveServiceMetadata removes the metadata.
func
(
m
*
consulMetadataReport
)
RemoveServiceMetadata
(
metadataIdentifier
*
identifier
.
ServiceMetadataIdentifier
)
error
{
k
:=
metadataIdentifier
.
GetIdentifierKey
()
_
,
err
:=
m
.
client
.
KV
()
.
Delete
(
k
,
nil
)
return
err
}
// GetExportedURLs gets the urls.
func
(
m
*
consulMetadataReport
)
GetExportedURLs
(
metadataIdentifier
*
identifier
.
ServiceMetadataIdentifier
)
[]
string
{
k
:=
metadataIdentifier
.
GetIdentifierKey
()
kv
,
_
,
err
:=
m
.
client
.
KV
()
.
Get
(
k
,
nil
)
if
err
!=
nil
{
panic
(
err
)
}
if
kv
==
nil
{
return
[]
string
{}
}
return
[]
string
{
string
(
kv
.
Value
)}
}
// SaveSubscribedData saves the urls.
func
(
m
*
consulMetadataReport
)
SaveSubscribedData
(
subscriberMetadataIdentifier
*
identifier
.
SubscriberMetadataIdentifier
,
urlListStr
string
)
error
{
kv
:=
&
consul
.
KVPair
{
Key
:
subscriberMetadataIdentifier
.
GetIdentifierKey
(),
Value
:
[]
byte
(
urlListStr
)}
_
,
err
:=
m
.
client
.
KV
()
.
Put
(
kv
,
nil
)
return
err
}
// GetSubscribedURLs gets the urls.
func
(
m
*
consulMetadataReport
)
GetSubscribedURLs
(
subscriberMetadataIdentifier
*
identifier
.
SubscriberMetadataIdentifier
)
[]
string
{
k
:=
subscriberMetadataIdentifier
.
GetIdentifierKey
()
kv
,
_
,
err
:=
m
.
client
.
KV
()
.
Get
(
k
,
nil
)
if
err
!=
nil
{
panic
(
err
)
}
if
kv
==
nil
{
return
[]
string
{}
}
return
[]
string
{
string
(
kv
.
Value
)}
}
// GetServiceDefinition gets the service definition.
func
(
m
*
consulMetadataReport
)
GetServiceDefinition
(
metadataIdentifier
*
identifier
.
MetadataIdentifier
)
string
{
k
:=
metadataIdentifier
.
GetIdentifierKey
()
kv
,
_
,
err
:=
m
.
client
.
KV
()
.
Get
(
k
,
nil
)
if
err
!=
nil
{
panic
(
err
)
}
if
kv
==
nil
{
return
""
}
return
string
(
kv
.
Value
)
}
type
consulMetadataReportFactory
struct
{
}
func
(
m
*
consulMetadataReportFactory
)
CreateMetadataReport
(
url
*
common
.
URL
)
report
.
MetadataReport
{
config
:=
&
consul
.
Config
{
Address
:
url
.
Location
}
client
,
err
:=
consul
.
NewClient
(
config
)
if
err
!=
nil
{
panic
(
err
)
}
return
&
consulMetadataReport
{
client
:
client
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
metadata/report/consul/report_test.go
0 → 100644
+
18
−
0
View file @
5952c59f
/*
* 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
consul
This diff is collapsed.
Click to expand it.
metadata/report/nacos/report.go
+
12
−
16
View file @
5952c59f
...
...
@@ -38,19 +38,19 @@ import (
)
func
init
()
{
f
try
:=
&
nacosMetadataReportFactory
{}
m
f
:=
&
nacosMetadataReportFactory
{}
extension
.
SetMetadataReportFactory
(
"nacos"
,
func
()
factory
.
MetadataReportFactory
{
return
f
try
return
m
f
})
}
// nacosMetadataReport is the implementation of MetadataReport based Nacos
// nacosMetadataReport is the implementation
// of MetadataReport based on Nacos.
type
nacosMetadataReport
struct
{
client
config_client
.
IConfigClient
}
// StoreProviderMetadata will store the metadata
// metadata including the basic info of the server, provider info, and other user custom info
// StoreProviderMetadata stores the metadata.
func
(
n
*
nacosMetadataReport
)
StoreProviderMetadata
(
providerIdentifier
*
identifier
.
MetadataIdentifier
,
serviceDefinitions
string
)
error
{
return
n
.
storeMetadata
(
vo
.
ConfigParam
{
DataId
:
providerIdentifier
.
GetIdentifierKey
(),
...
...
@@ -59,8 +59,7 @@ func (n *nacosMetadataReport) StoreProviderMetadata(providerIdentifier *identifi
})
}
// StoreConsumerMetadata will store the metadata
// metadata including the basic info of the server, consumer info, and other user custom info
// StoreConsumerMetadata stores the metadata.
func
(
n
*
nacosMetadataReport
)
StoreConsumerMetadata
(
consumerMetadataIdentifier
*
identifier
.
MetadataIdentifier
,
serviceParameterString
string
)
error
{
return
n
.
storeMetadata
(
vo
.
ConfigParam
{
DataId
:
consumerMetadataIdentifier
.
GetIdentifierKey
(),
...
...
@@ -69,8 +68,7 @@ func (n *nacosMetadataReport) StoreConsumerMetadata(consumerMetadataIdentifier *
})
}
// SaveServiceMetadata will store the metadata
// metadata including the basic info of the server, service info, and other user custom info
// SaveServiceMetadata saves the metadata.
func
(
n
*
nacosMetadataReport
)
SaveServiceMetadata
(
metadataIdentifier
*
identifier
.
ServiceMetadataIdentifier
,
url
common
.
URL
)
error
{
return
n
.
storeMetadata
(
vo
.
ConfigParam
{
DataId
:
metadataIdentifier
.
GetIdentifierKey
(),
...
...
@@ -79,7 +77,7 @@ func (n *nacosMetadataReport) SaveServiceMetadata(metadataIdentifier *identifier
})
}
// RemoveServiceMetadata
will
remove the
service
metadata
// RemoveServiceMetadata remove
s
the metadata
.
func
(
n
*
nacosMetadataReport
)
RemoveServiceMetadata
(
metadataIdentifier
*
identifier
.
ServiceMetadataIdentifier
)
error
{
return
n
.
deleteMetadata
(
vo
.
ConfigParam
{
DataId
:
metadataIdentifier
.
GetIdentifierKey
(),
...
...
@@ -87,8 +85,7 @@ func (n *nacosMetadataReport) RemoveServiceMetadata(metadataIdentifier *identifi
})
}
// GetExportedURLs will look up the exported urls.
// if not found, an empty list will be returned.
// GetExportedURLs gets the urls.
func
(
n
*
nacosMetadataReport
)
GetExportedURLs
(
metadataIdentifier
*
identifier
.
ServiceMetadataIdentifier
)
[]
string
{
return
n
.
getConfigAsArray
(
vo
.
ConfigParam
{
DataId
:
metadataIdentifier
.
GetIdentifierKey
(),
...
...
@@ -96,7 +93,7 @@ func (n *nacosMetadataReport) GetExportedURLs(metadataIdentifier *identifier.Ser
})
}
// SaveSubscribedData
will convert the urlList to json array and then store it
// SaveSubscribedData
saves the urls.
func
(
n
*
nacosMetadataReport
)
SaveSubscribedData
(
subscriberMetadataIdentifier
*
identifier
.
SubscriberMetadataIdentifier
,
urlListStr
string
)
error
{
return
n
.
storeMetadata
(
vo
.
ConfigParam
{
DataId
:
subscriberMetadataIdentifier
.
GetIdentifierKey
(),
...
...
@@ -105,8 +102,7 @@ func (n *nacosMetadataReport) SaveSubscribedData(subscriberMetadataIdentifier *i
})
}
// GetSubscribedURLs will lookup the url
// if not found, an empty list will be returned
// GetSubscribedURLs gets the urls.
func
(
n
*
nacosMetadataReport
)
GetSubscribedURLs
(
subscriberMetadataIdentifier
*
identifier
.
SubscriberMetadataIdentifier
)
[]
string
{
return
n
.
getConfigAsArray
(
vo
.
ConfigParam
{
DataId
:
subscriberMetadataIdentifier
.
GetIdentifierKey
(),
...
...
@@ -114,7 +110,7 @@ func (n *nacosMetadataReport) GetSubscribedURLs(subscriberMetadataIdentifier *id
})
}
// GetServiceDefinition
will lookup
the service definition
// GetServiceDefinition
gets
the service definition
.
func
(
n
*
nacosMetadataReport
)
GetServiceDefinition
(
metadataIdentifier
*
identifier
.
MetadataIdentifier
)
string
{
return
n
.
getConfig
(
vo
.
ConfigParam
{
DataId
:
metadataIdentifier
.
GetIdentifierKey
(),
...
...
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