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
2f246b9e
Commit
2f246b9e
authored
Apr 19, 2016
by
Gabriel Mazetto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Geo: repository update changed to use push event from system hook
parent
f619d34f
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
61 additions
and
95 deletions
+61
-95
app/services/geo/enqueue_project_update_service.rb
app/services/geo/enqueue_project_update_service.rb
+0
-14
app/services/geo/notify_nodes_service.rb
app/services/geo/notify_nodes_service.rb
+0
-2
app/services/geo/schedule_repo_update_service.rb
app/services/geo/schedule_repo_update_service.rb
+5
-6
app/workers/post_receive.rb
app/workers/post_receive.rb
+0
-3
lib/api/geo.rb
lib/api/geo.rb
+6
-11
lib/gitlab/geo.rb
lib/gitlab/geo.rb
+0
-4
lib/gitlab/middleware/readonly_geo.rb
lib/gitlab/middleware/readonly_geo.rb
+1
-1
spec/requests/api/geo_spec.rb
spec/requests/api/geo_spec.rb
+49
-23
spec/services/geo/enqueue_project_update_service_spec.rb
spec/services/geo/enqueue_project_update_service_spec.rb
+0
-31
No files found.
app/services/geo/enqueue_project_update_service.rb
deleted
100644 → 0
View file @
f619d34f
module
Geo
class
EnqueueProjectUpdateService
attr_reader
:project
def
initialize
(
project
)
@queue
=
Gitlab
::
Geo
::
UpdateQueue
.
new
(
'updated_projects'
)
@project
=
project
end
def
execute
@queue
.
store
({
id:
@project
.
id
,
clone_url:
@project
.
url_to_repo
})
end
end
end
app/services/geo/notify_nodes_service.rb
View file @
2f246b9e
...
...
@@ -2,12 +2,10 @@ module Geo
class
NotifyNodesService
<
BaseNotify
def
initialize
@proj_queue
=
Gitlab
::
Geo
::
UpdateQueue
.
new
(
'updated_projects'
)
@wiki_queue
=
Gitlab
::
Geo
::
UpdateQueue
.
new
(
'updated_wikis'
)
end
def
execute
process
(
@proj_queue
,
:notify_projects_url
)
process
(
@wiki_queue
,
:notify_wikis_url
)
end
...
...
app/services/geo/schedule_repo_update_service.rb
View file @
2f246b9e
module
Geo
class
ScheduleRepoUpdateService
attr_reader
:
projects
attr_reader
:
id
,
:clone_url
def
initialize
(
projects
)
@projects
=
projects
def
initialize
(
params
)
@id
=
params
[
:project_id
]
@clone_url
=
params
[
:project
][
:git_ssh_url
]
end
def
execute
@projects
.
each
do
|
project
|
GeoRepositoryUpdateWorker
.
perform_async
(
project
[
'id'
],
project
[
'clone_url'
])
end
GeoRepositoryUpdateWorker
.
perform_async
(
@id
,
@clone_url
)
end
end
end
app/workers/post_receive.rb
View file @
2f246b9e
...
...
@@ -23,9 +23,6 @@ class PostReceive
# Triggers repository update on secondary nodes when Geo is enabled
Gitlab
::
Geo
.
notify_wiki_update
(
post_received
.
project
)
if
Gitlab
::
Geo
.
enabled?
elsif
post_received
.
regular_project?
# Triggers repository update on secondary nodes when Geo is enabled
Gitlab
::
Geo
.
notify_project_update
(
post_received
.
project
)
if
Gitlab
::
Geo
.
enabled?
process_project_changes
(
post_received
)
else
log
(
"Triggered hook for unidentifiable repository type with full path
\"
#{
repo_path
}
\"
"
)
...
...
lib/api/geo.rb
View file @
2f246b9e
module
API
class
Geo
<
Grape
::
API
resource
:geo
do
# Enqueue a batch of IDs of modified projects to have their
# repositories updated
#
# Example request:
# POST /geo/refresh_projects
post
'refresh_projects'
do
authenticated_as_admin!
required_attributes!
[
:projects
]
::
Geo
::
ScheduleRepoUpdateService
.
new
(
params
[
:projects
]).
execute
end
# Enqueue a batch of IDs of wiki's projects to have their
# wiki repositories updated
#
...
...
@@ -35,6 +24,12 @@ module API
when
'key_create'
,
'key_destroy'
required_attributes!
%w(key id)
::
Geo
::
ScheduleKeyChangeService
.
new
(
params
).
execute
when
'push'
required_attributes!
%w(event_name project_id project)
::
Geo
::
ScheduleRepoUpdateService
.
new
(
params
).
execute
when
'tag_push'
required_attributes!
%w(event_name project_id project)
::
Geo
::
ScheduleWikiRepoUpdateService
.
new
(
params
).
execute
end
end
end
...
...
lib/gitlab/geo.rb
View file @
2f246b9e
...
...
@@ -34,10 +34,6 @@ module Gitlab
GeoNode
.
where
(
host:
host
,
port:
port
).
exists?
end
def
self
.
notify_project_update
(
project
)
::
Geo
::
EnqueueProjectUpdateService
.
new
(
project
).
execute
end
def
self
.
notify_wiki_update
(
project
)
::
Geo
::
EnqueueWikiUpdateService
.
new
(
project
).
execute
end
...
...
lib/gitlab/middleware/readonly_geo.rb
View file @
2f246b9e
...
...
@@ -2,7 +2,7 @@ module Gitlab
module
Middleware
class
ReadonlyGeo
DISALLOWED_METHODS
=
%w(POST PATCH PUT DELETE)
WHITELISTED
=
%w(api/v3/internal api/v3/geo/refresh_
projects api/v3/geo/refresh_wikis api/v3/geo/refresh_key
api/v3/geo/receive_events)
WHITELISTED
=
%w(api/v3/internal api/v3/geo/refresh_
wikis
api/v3/geo/receive_events)
APPLICATION_JSON
=
'application/json'
def
initialize
(
app
)
...
...
spec/requests/api/geo_spec.rb
View file @
2f246b9e
...
...
@@ -5,30 +5,28 @@ describe API::API, api: true do
let
(
:admin
)
{
create
(
:admin
)
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:geo_node
)
{
build
(
:geo_node
)
}
let
(
:geo_token_header
)
do
{
'X-Gitlab-Token'
=>
geo_node
.
system_hook
.
token
}
end
describe
'POST /geo/refresh_projects'
do
before
(
:each
)
{
allow_any_instance_of
(
::
Geo
::
ScheduleRepoUpdateService
).
to
receive
(
:execute
)
}
before
(
:each
)
do
allow
(
Gitlab
::
Geo
).
to
receive
(
:current_node
)
{
geo_node
}
end
it
'starts refresh process if admin and correct params'
do
post
api
(
'/geo/refresh_projects'
,
admin
),
projects:
[
'1'
,
'2'
,
'3'
]
expect
(
response
.
status
).
to
eq
201
describe
'POST /geo/receive_events authentication'
do
it
'denies access if token is not present'
do
post
api
(
'/geo/receive_events'
)
expect
(
response
.
status
).
to
eq
401
end
it
'denies access if
not admin
'
do
post
api
(
'/geo/re
fresh_projects'
,
user
)
expect
(
response
.
status
).
to
eq
40
3
it
'denies access if
token is invalid
'
do
post
api
(
'/geo/re
ceive_events'
),
nil
,
{
'X-Gitlab-Token'
=>
'nothing'
}
expect
(
response
.
status
).
to
eq
40
1
end
end
describe
'POST /geo/receive_events'
do
before
(
:each
)
do
allow_any_instance_of
(
::
Geo
::
ScheduleKeyChangeService
).
to
receive
(
:execute
)
allow
(
Gitlab
::
Geo
).
to
receive
(
:current_node
)
{
geo_node
}
end
let
(
:geo_token_header
)
do
{
'X-Gitlab-Token'
=>
geo_node
.
system_hook
.
token
}
end
describe
'POST /geo/receive_events key events'
do
before
(
:each
)
{
allow_any_instance_of
(
::
Geo
::
ScheduleKeyChangeService
).
to
receive
(
:execute
)
}
let
(
:key_create_payload
)
do
{
...
...
@@ -61,15 +59,43 @@ describe API::API, api: true do
post
api
(
'/geo/receive_events'
),
key_destroy_payload
,
geo_token_header
expect
(
response
.
status
).
to
eq
201
end
end
it
'denies access if token is not present'
do
post
api
(
'/geo/receive_events'
)
expect
(
response
.
status
).
to
eq
401
describe
'POST /geo/receive_events push events'
do
before
(
:each
)
{
allow_any_instance_of
(
::
Geo
::
ScheduleRepoUpdateService
).
to
receive
(
:execute
)
}
let
(
:push_payload
)
do
{
'event_name'
=>
'push'
,
'project_id'
=>
1
,
'project'
=>
{
'git_ssh_url'
=>
'git@example.com:mike/diaspora.git'
}
}
end
it
'denies access if token is invalid'
do
post
api
(
'/geo/receive_events'
),
nil
,
{
'X-Gitlab-Token'
=>
'nothing'
}
expect
(
response
.
status
).
to
eq
401
it
'starts refresh process if admin and correct params'
do
post
api
(
'/geo/receive_events'
),
push_payload
,
geo_token_header
expect
(
response
.
status
).
to
eq
201
end
end
describe
'POST /geo/receive_events push_tag events'
do
before
(
:each
)
{
allow_any_instance_of
(
::
Geo
::
ScheduleWikiRepoUpdateService
).
to
receive
(
:execute
)
}
let
(
:tag_push_payload
)
do
{
'event_name'
=>
'tag_push'
,
'project_id'
=>
1
,
'project'
=>
{
'git_ssh_url'
=>
'git@example.com:mike/diaspora.git'
}
}
end
it
'starts refresh process if admin and correct params'
do
post
api
(
'/geo/receive_events'
),
tag_push_payload
,
geo_token_header
expect
(
response
.
status
).
to
eq
201
end
end
end
spec/services/geo/enqueue_project_update_service_spec.rb
deleted
100644 → 0
View file @
f619d34f
describe
Geo
::
EnqueueProjectUpdateService
,
services:
true
do
subject
{
Geo
::
EnqueueProjectUpdateService
.
new
(
project
)
}
let
(
:project
)
{
double
(
:project
)
}
let
(
:fake_url
)
{
'git@localhost:repo/path.git'
}
let
(
:fake_id
)
{
999
}
let
(
:queue
)
{
subject
.
instance_variable_get
(
:@queue
)
}
before
(
:each
)
do
queue
.
empty!
expect
(
project
).
to
receive
(
:url_to_repo
)
{
fake_url
}
expect
(
project
).
to
receive
(
:id
)
{
fake_id
}
end
describe
'#execute'
do
let
(
:stored_data
)
{
queue
.
first
}
before
(
:each
)
{
subject
.
execute
}
it
'persists id and clone_url to redis queue'
do
expect
(
stored_data
).
to
have_key
(
'id'
)
expect
(
stored_data
).
to
have_key
(
'clone_url'
)
end
it
'persisted id is equal to original'
do
expect
(
stored_data
[
'id'
]).
to
eq
(
fake_id
)
end
it
'persisted clone_url is equal to original'
do
expect
(
stored_data
[
'clone_url'
]).
to
eq
(
fake_url
)
end
end
end
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