Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
B
brpc
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
brpc
Commits
12e73e1d
Commit
12e73e1d
authored
Nov 28, 2019
by
jamesge
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
reuse DiscoveryRegisterParam in DiscoveryClient
parent
bc7165fb
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
44 deletions
+28
-44
discovery_naming_service.cpp
src/brpc/policy/discovery_naming_service.cpp
+27
-35
discovery_naming_service.h
src/brpc/policy/discovery_naming_service.h
+1
-9
No files found.
src/brpc/policy/discovery_naming_service.cpp
View file @
12e73e1d
...
...
@@ -166,11 +166,11 @@ int DiscoveryClient::DoRenew() const {
cntl
.
http_request
().
uri
()
=
"/discovery/renew"
;
cntl
.
http_request
().
set_content_type
(
"application/x-www-form-urlencoded"
);
butil
::
IOBufBuilder
os
;
os
<<
"appid="
<<
_appid
<<
"&hostname="
<<
_hostname
<<
"&env="
<<
_env
<<
"®ion="
<<
_region
<<
"&zone="
<<
_zone
;
os
<<
"appid="
<<
_
params
.
appid
<<
"&hostname="
<<
_
params
.
hostname
<<
"&env="
<<
_
params
.
env
<<
"®ion="
<<
_
params
.
region
<<
"&zone="
<<
_
params
.
zone
;
os
.
move_to
(
cntl
.
request_attachment
());
GetDiscoveryChannel
()
->
CallMethod
(
NULL
,
&
cntl
,
NULL
,
NULL
,
NULL
);
if
(
cntl
.
Failed
())
{
...
...
@@ -179,7 +179,7 @@ int DiscoveryClient::DoRenew() const {
}
std
::
string
error_text
;
if
(
ParseCommonResult
(
cntl
.
response_attachment
(),
&
error_text
)
!=
0
)
{
LOG
(
ERROR
)
<<
"Fail to renew "
<<
_
hostname
<<
" to "
<<
_
appid
LOG
(
ERROR
)
<<
"Fail to renew "
<<
_
params
.
hostname
<<
" to "
<<
_params
.
appid
<<
": "
<<
error_text
;
return
-
1
;
}
...
...
@@ -220,22 +220,14 @@ void* DiscoveryClient::PeriodicRenew(void* arg) {
}
int
DiscoveryClient
::
Register
(
const
DiscoveryRegisterParam
&
req
)
{
if
(
!
req
.
IsValid
())
{
return
-
1
;
}
if
(
_registered
.
load
(
butil
::
memory_order_relaxed
)
||
_registered
.
exchange
(
true
,
butil
::
memory_order_release
))
{
return
0
;
}
_appid
=
req
.
appid
;
_hostname
=
req
.
hostname
;
_addrs
=
req
.
addrs
;
_env
=
req
.
env
;
_region
=
req
.
region
;
_zone
=
req
.
zone
;
_status
=
req
.
status
;
_version
=
req
.
version
;
_metadata
=
req
.
metadata
;
if
(
!
req
.
IsValid
())
{
return
-
1
;
}
_params
=
req
;
if
(
DoRegister
()
!=
0
)
{
return
-
1
;
...
...
@@ -253,24 +245,24 @@ int DiscoveryClient::DoRegister() const {
cntl
.
http_request
().
uri
()
=
"/discovery/register"
;
cntl
.
http_request
().
set_content_type
(
"application/x-www-form-urlencoded"
);
butil
::
IOBufBuilder
os
;
os
<<
"appid="
<<
_appid
<<
"&hostname="
<<
_hostname
<<
"&addrs="
<<
_addrs
<<
"&env="
<<
_env
<<
"&zone="
<<
_zone
<<
"®ion="
<<
_region
<<
"&status="
<<
_status
<<
"&version="
<<
_version
<<
"&metadata="
<<
_metadata
;
os
<<
"appid="
<<
_
params
.
appid
<<
"&hostname="
<<
_
params
.
hostname
<<
"&addrs="
<<
_
params
.
addrs
<<
"&env="
<<
_
params
.
env
<<
"&zone="
<<
_
params
.
zone
<<
"®ion="
<<
_
params
.
region
<<
"&status="
<<
_
params
.
status
<<
"&version="
<<
_
params
.
version
<<
"&metadata="
<<
_
params
.
metadata
;
os
.
move_to
(
cntl
.
request_attachment
());
GetDiscoveryChannel
()
->
CallMethod
(
NULL
,
&
cntl
,
NULL
,
NULL
,
NULL
);
if
(
cntl
.
Failed
())
{
LOG
(
ERROR
)
<<
"Fail to register "
<<
_appid
<<
": "
<<
cntl
.
ErrorText
();
LOG
(
ERROR
)
<<
"Fail to register "
<<
_
params
.
appid
<<
": "
<<
cntl
.
ErrorText
();
return
-
1
;
}
std
::
string
error_text
;
if
(
ParseCommonResult
(
cntl
.
response_attachment
(),
&
error_text
)
!=
0
)
{
LOG
(
ERROR
)
<<
"Fail to register "
<<
_
hostname
<<
" to "
<<
_
appid
LOG
(
ERROR
)
<<
"Fail to register "
<<
_
params
.
hostname
<<
" to "
<<
_params
.
appid
<<
": "
<<
error_text
;
return
-
1
;
}
...
...
@@ -283,11 +275,11 @@ int DiscoveryClient::DoCancel() const {
cntl
.
http_request
().
uri
()
=
"/discovery/cancel"
;
cntl
.
http_request
().
set_content_type
(
"application/x-www-form-urlencoded"
);
butil
::
IOBufBuilder
os
;
os
<<
"appid="
<<
_appid
<<
"&hostname="
<<
_hostname
<<
"&env="
<<
_env
<<
"®ion="
<<
_region
<<
"&zone="
<<
_zone
;
os
<<
"appid="
<<
_
params
.
appid
<<
"&hostname="
<<
_
params
.
hostname
<<
"&env="
<<
_
params
.
env
<<
"®ion="
<<
_
params
.
region
<<
"&zone="
<<
_
params
.
zone
;
os
.
move_to
(
cntl
.
request_attachment
());
GetDiscoveryChannel
()
->
CallMethod
(
NULL
,
&
cntl
,
NULL
,
NULL
,
NULL
);
if
(
cntl
.
Failed
())
{
...
...
@@ -296,7 +288,7 @@ int DiscoveryClient::DoCancel() const {
}
std
::
string
error_text
;
if
(
ParseCommonResult
(
cntl
.
response_attachment
(),
&
error_text
)
!=
0
)
{
LOG
(
ERROR
)
<<
"Fail to cancel "
<<
_
hostname
<<
" in "
<<
_
appid
LOG
(
ERROR
)
<<
"Fail to cancel "
<<
_
params
.
hostname
<<
" in "
<<
_params
.
appid
<<
": "
<<
error_text
;
return
-
1
;
}
...
...
src/brpc/policy/discovery_naming_service.h
View file @
12e73e1d
...
...
@@ -61,15 +61,7 @@ private:
private
:
bthread_t
_th
;
butil
::
atomic
<
bool
>
_registered
;
std
::
string
_appid
;
std
::
string
_hostname
;
std
::
string
_addrs
;
std
::
string
_env
;
std
::
string
_region
;
std
::
string
_zone
;
int
_status
;
std
::
string
_version
;
std
::
string
_metadata
;
DiscoveryRegisterParam
_params
;
};
class
DiscoveryNamingService
:
public
PeriodicNamingService
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment