Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
12f089d9
Commit
12f089d9
authored
Feb 16, 2017
by
Douglas Barbosa Alexandre
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Only notify/update geo nodes that are enabled
[ci skip]
parent
af9e0b04
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
52 additions
and
4 deletions
+52
-4
app/services/geo/notify_nodes_service.rb
app/services/geo/notify_nodes_service.rb
+3
-0
app/workers/geo_backfill_worker.rb
app/workers/geo_backfill_worker.rb
+17
-4
lib/api/geo.rb
lib/api/geo.rb
+8
-0
spec/requests/api/geo_spec.rb
spec/requests/api/geo_spec.rb
+24
-0
No files found.
app/services/geo/notify_nodes_service.rb
View file @
12f089d9
...
...
@@ -17,8 +17,11 @@ module Geo
content
=
{
projects:
projects
}.
to_json
::
Gitlab
::
Geo
.
secondary_nodes
.
each
do
|
node
|
next
unless
node
.
enabled?
notify_url
=
node
.
send
(
notify_url_method
.
to_sym
)
success
,
message
=
notify
(
notify_url
,
content
)
unless
success
Rails
.
logger
.
error
(
"GitLab failed to notify
#{
node
.
url
}
to
#{
notify_url
}
:
#{
message
}
"
)
queue
.
store_batched_data
(
projects
)
...
...
app/workers/geo_backfill_worker.rb
View file @
12f089d9
...
...
@@ -2,6 +2,7 @@ class GeoBackfillWorker
include
Sidekiq
::
Worker
include
CronjobQueue
LEASE_TIMEOUT
=
24
.
hours
.
freeze
RUN_TIME
=
5
.
minutes
.
to_i
.
freeze
def
perform
...
...
@@ -9,6 +10,7 @@ class GeoBackfillWorker
project_ids
.
each
do
|
project_id
|
break
if
Time
.
now
-
start
>=
RUN_TIME
break
unless
node_enabled?
project
=
Project
.
find
(
project_id
)
next
if
project
.
repository_exists?
...
...
@@ -30,10 +32,8 @@ class GeoBackfillWorker
end
def
try_obtain_lease
uuid
=
Gitlab
::
ExclusiveLease
.
new
(
lease_key
,
timeout:
24
.
hours
).
try_obtain
uuid
=
Gitlab
::
ExclusiveLease
.
new
(
lease_key
,
timeout:
LEASE_TIMEOUT
)
.
try_obtain
return
unless
uuid
...
...
@@ -49,4 +49,17 @@ class GeoBackfillWorker
def
lease_key
'repository_backfill_service'
end
def
node_enabled?
# No caching of the enabled! If we cache it and an admin disables
# this node, an active GeoBackfillWorker would keep going for up
# to max run time after the node was disabled.
current_node
.
enabled?
end
def
current_node
GeoNode
.
find_by
(
host:
Gitlab
.
config
.
gitlab
.
host
,
port:
Gitlab
.
config
.
gitlab
.
port
,
relative_url_root:
Gitlab
.
config
.
gitlab
.
relative_url_root
)
end
end
lib/api/geo.rb
View file @
12f089d9
...
...
@@ -35,6 +35,7 @@ module API
# POST /geo/refresh_wikis
post
'refresh_wikis'
do
authenticated_as_admin!
require_node_to_be_enabled!
required_attributes!
[
:projects
]
::
Geo
::
ScheduleWikiRepoUpdateService
.
new
(
params
[
:projects
]).
execute
end
...
...
@@ -45,6 +46,7 @@ module API
# POST /geo/receive_events
post
'receive_events'
do
authenticate_by_gitlab_geo_token!
require_node_to_be_enabled!
required_attributes!
%w(event_name)
case
params
[
'event_name'
]
...
...
@@ -75,5 +77,11 @@ module API
end
end
end
helpers
do
def
require_node_to_be_enabled!
forbidden!
'Geo node is disabled.'
unless
Gitlab
::
Geo
.
current_node
.
enabled?
end
end
end
end
spec/requests/api/geo_spec.rb
View file @
12f089d9
...
...
@@ -9,6 +9,10 @@ describe API::Geo, api: true do
{
'X-Gitlab-Token'
=>
geo_node
.
system_hook
.
token
}
end
before
(
:each
)
do
allow
(
Gitlab
::
Geo
).
to
receive
(
:current_node
)
{
geo_node
}
end
describe
'POST /geo/receive_events authentication'
do
it
'denies access if token is not present'
do
post
api
(
'/geo/receive_events'
)
...
...
@@ -21,6 +25,26 @@ describe API::Geo, api: true do
end
end
describe
'POST /geo/refresh_wikis disabled node'
do
it
'responds with forbidden'
do
geo_node
.
enabled
=
false
post
api
(
'/geo/refresh_wikis'
,
admin
),
nil
expect
(
response
).
to
have_http_status
(
403
)
end
end
describe
'POST /geo/receive_events disabled node'
do
it
'responds with forbidden'
do
geo_node
.
enabled
=
false
post
api
(
'/geo/receive_events'
),
nil
,
geo_token_header
expect
(
response
).
to
have_http_status
(
403
)
end
end
describe
'POST /geo/receive_events key events'
do
before
(
:each
)
{
allow_any_instance_of
(
::
Geo
::
ScheduleKeyChangeService
).
to
receive
(
:execute
)
}
...
...
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