BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
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
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
cf996685
Unverified
Commit
cf996685
authored
May 23, 2018
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor code around scheduling cluster installations
Signed-off-by:
Dmitriy Zaporozhets
<
dmitriy.zaporozhets@gmail.com
>
parent
cf7f3606
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
22 additions
and
35 deletions
+22
-35
applications_controller.rb
app/controllers/projects/clusters/applications_controller.rb
+4
-3
schedule_installation_service.rb
...es/clusters/applications/schedule_installation_service.rb
+3
-14
schedule_installation_service_spec.rb
...usters/applications/schedule_installation_service_spec.rb
+15
-18
No files found.
app/controllers/projects/clusters/applications_controller.rb
View file @
cf996685
...
...
@@ -5,9 +5,10 @@ class Projects::Clusters::ApplicationsController < Projects::ApplicationControll
before_action
:authorize_create_cluster!
,
only:
[
:create
]
def
create
Clusters
::
Applications
::
ScheduleInstallationService
.
new
(
project
,
current_user
,
application_class:
@application_class
,
cluster:
@cluster
).
execute
application
=
@application_class
.
find_or_create_by!
(
cluster:
@cluster
)
Clusters
::
Applications
::
ScheduleInstallationService
.
new
(
project
,
current_user
).
execute
(
application
)
head
:no_content
rescue
StandardError
head
:bad_request
...
...
app/services/clusters/applications/schedule_installation_service.rb
View file @
cf996685
module
Clusters
module
Applications
class
ScheduleInstallationService
<
::
BaseService
def
execute
application_class
.
find_or_create_by!
(
cluster:
cluster
).
try
do
|
application
|
application
.
make_scheduled!
ClusterInstallAppWorker
.
perform_async
(
application
.
name
,
application
.
id
)
end
end
private
def
application_class
params
[
:application_class
]
end
def
execute
(
application
)
application
.
make_scheduled!
def
cluster
params
[
:cluster
]
ClusterInstallAppWorker
.
perform_async
(
application
.
name
,
application
.
id
)
end
end
end
...
...
spec/services/clusters/applications/schedule_installation_service_spec.rb
View file @
cf996685
...
...
@@ -2,7 +2,7 @@ require 'spec_helper'
describe
Clusters
::
Applications
::
ScheduleInstallationService
do
def
count_scheduled
application
_
class
&
.
with_status
(
:scheduled
)
&
.
count
||
0
application
&
.
class
&
.
with_status
(
:scheduled
)
&
.
count
||
0
end
shared_examples
'a failing service'
do
...
...
@@ -10,45 +10,42 @@ describe Clusters::Applications::ScheduleInstallationService do
expect
(
ClusterInstallAppWorker
).
not_to
receive
(
:perform_async
)
count_before
=
count_scheduled
expect
{
service
.
execute
}.
to
raise_error
(
StandardError
)
expect
{
service
.
execute
(
application
)
}.
to
raise_error
(
StandardError
)
expect
(
count_scheduled
).
to
eq
(
count_before
)
end
end
describe
'#execute'
do
let
(
:application_class
)
{
Clusters
::
Applications
::
Helm
}
let
(
:cluster
)
{
create
(
:cluster
,
:project
,
:provided_by_gcp
)
}
let
(
:project
)
{
cluster
.
project
}
let
(
:service
)
{
described_class
.
new
(
project
,
nil
,
cluster:
cluster
,
application_class:
application_class
)
}
let
(
:project
)
{
double
(
:project
)
}
let
(
:service
)
{
described_class
.
new
(
project
,
nil
)
}
it
'creates a new application
'
do
allow
(
ClusterInstallAppWorker
).
to
receive
(
:perform_async
)
context
'when application is installable
'
do
let
(
:application
)
{
create
(
:clusters_applications_helm
,
:installable
)
}
expect
{
service
.
execute
}.
to
change
{
application_class
.
count
}.
by
(
1
)
end
it
'make the application scheduled'
do
expect
(
ClusterInstallAppWorker
).
to
receive
(
:perform_async
).
with
(
application_class
.
application_name
,
kind_of
(
Numeric
)).
once
it
'make the application scheduled'
do
expect
(
ClusterInstallAppWorker
).
to
receive
(
:perform_async
).
with
(
application
.
name
,
kind_of
(
Numeric
)).
once
expect
{
service
.
execute
}.
to
change
{
application_class
.
with_status
(
:scheduled
).
count
}.
by
(
1
)
expect
{
service
.
execute
(
application
)
}.
to
change
{
application
.
class
.
with_status
(
:scheduled
).
count
}.
by
(
1
)
end
end
context
'when installation is already in progress'
do
let
(
:application
)
{
create
(
:clusters_applications_helm
,
:installing
)
}
let
(
:cluster
)
{
application
.
cluster
}
it_behaves_like
'a failing service'
end
context
'when application
_class
is nil'
do
let
(
:application
_class
)
{
nil
}
context
'when application is nil'
do
let
(
:application
)
{
nil
}
it_behaves_like
'a failing service'
end
context
'when application cannot be persisted'
do
let
(
:application
)
{
create
(
:clusters_applications_helm
)
}
before
do
expect
_any_instance_of
(
application_class
).
to
receive
(
:make_scheduled!
).
once
.
and_raise
(
ActiveRecord
::
RecordInvalid
)
expect
(
application
).
to
receive
(
:make_scheduled!
).
once
.
and_raise
(
ActiveRecord
::
RecordInvalid
)
end
it_behaves_like
'a failing service'
...
...
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