Revision 937eb715
Added by Ondřej Pražák almost 8 years ago
app/assets/javascripts/foreman_pipeline/jobs/details/job-details-environments.controller.js | ||
---|---|---|
1 | 1 |
angular.module('ForemanPipeline.jobs').controller('JobDetailsEnvironmentsController', |
2 |
['$scope', '$q', 'translate', 'Job', 'CurrentOrganization', 'Path',
|
|
3 |
function ($scope, $q, translate, Job, CurrentOrganization, Path) {
|
|
2 |
['$scope', '$q', 'translate', 'Job', 'CurrentOrganization', |
|
3 |
function ($scope, $q, translate, Job, CurrentOrganization) { |
|
4 | 4 |
|
5 | 5 |
$scope.successMessages = []; |
6 | 6 |
$scope.errorMessages = []; |
... | ... | |
10 | 10 |
}); |
11 | 11 |
|
12 | 12 |
var params = { |
13 |
id: CurrentOrganization |
|
13 |
organization_id: CurrentOrganization, |
|
14 |
id: $scope.$stateParams.jobId, |
|
15 |
all_paths: true, |
|
14 | 16 |
}; |
17 |
|
|
15 | 18 |
$scope.loading = true; |
16 | 19 |
|
17 | 20 |
$scope.chosenEnvironment = $scope.job.environment; |
18 | 21 |
|
19 |
$scope.environments = Path.allPaths(params, function () {
|
|
22 |
$scope.environments = Job.availableEnvironments(params, function () {
|
|
20 | 23 |
$scope.loading = false; |
21 | 24 |
}); |
22 | 25 |
|
app/assets/javascripts/foreman_pipeline/jobs/details/job-details-to-environments.controller.js | ||
---|---|---|
10 | 10 |
$scope.panel.loading = false; |
11 | 11 |
}); |
12 | 12 |
|
13 |
var params = { |
|
14 |
id: $scope.$stateParams.jobId, |
|
15 |
organization_id: CurrentOrganization, |
|
16 |
}; |
|
17 |
|
|
13 | 18 |
$scope.toEnvironments = $scope.job.to_environments; |
14 | 19 |
|
15 |
$scope.loading = true;
|
|
20 |
$scope.loading = true; |
|
16 | 21 |
|
17 |
$scope.paths = Job.availableToEnvironments({id: $scope.$stateParams.jobId}, function () {
|
|
22 |
$scope.paths = Job.availableEnvironments(params, function () {
|
|
18 | 23 |
$scope.loading = false; |
19 | 24 |
}); |
20 | 25 |
|
app/assets/javascripts/foreman_pipeline/jobs/jobs.factory.js | ||
---|---|---|
1 |
(function () { |
|
1 |
angular.module('ForemanPipeline.jobs').factory('Job', |
|
2 |
['BastionResource', 'CurrentOrganization', |
|
3 |
function (BastionResource, CurrentOrganization) { |
|
2 | 4 |
|
3 |
var transformPaths = function (data) { |
|
5 |
var transformPaths = function (data) {
|
|
4 | 6 |
return _.map(angular.fromJson(data)["results"], function (path) { |
5 | 7 |
return _.map(path["environments"], function (env) { |
6 | 8 |
return env; |
7 | 9 |
}); |
8 | 10 |
}) |
9 |
}; |
|
11 |
}; |
|
12 |
|
|
13 |
return BastionResource('/../foreman_pipeline/api/organizations/:organizationId/jobs/:id/:action', |
|
14 |
{id: '@id', organizationId: CurrentOrganization}, { |
|
15 |
|
|
16 |
update: {method: 'PUT'}, |
|
17 |
setContentView: {method: 'PUT', params: {action: 'set_content_view'}}, |
|
18 |
setHostgroup: {method: 'PUT', params: {action: 'set_hostgroup'}}, |
|
19 |
setJenkins: {method: 'PUT', params: {action: 'set_jenkins'}}, |
|
20 |
setResource: {method: 'PUT', params: {action: 'set_resource'}}, |
|
21 |
setEnvironment: {method: 'PUT', params: {action: 'set_environment'}}, |
|
22 |
availableResources: {method: 'GET', params: {action: 'available_resources'}, transformResponse: function (response) { |
|
23 |
return {results: angular.fromJson(response)}; |
|
24 |
}}, |
|
25 |
runJob: {method: 'GET', params: {action: 'run_job'}}, |
|
26 |
projects: {method: 'GET', transformResponse: function (response) { |
|
27 |
var job = angular.fromJson(response); |
|
28 |
return {results: job.jenkins_projects}; |
|
29 |
}}, |
|
30 |
addProjects: {method: 'PUT', params: {action: 'add_projects'}}, |
|
31 |
removeProjects: {method: 'PUT', params: {action: 'remove_projects'}}, |
|
32 |
|
|
33 |
availableEnvironments: {method: 'GET', |
|
34 |
params: {action: 'available_paths'}, |
|
35 |
isArray: true, |
|
36 |
transformResponse: function (data) { |
|
37 |
return transformPaths(data); |
|
38 |
} |
|
39 |
}, |
|
40 |
setToEnvironments: {method: 'PUT', params: {action: 'set_to_environments'}}, |
|
41 |
}); |
|
42 |
}] |
|
43 |
); |
|
44 |
|
|
45 |
angular.module('ForemanPipeline.jobs').factory('Hostgroup', |
|
46 |
['BastionResource', |
|
47 |
function (BastionResource) { |
|
48 |
|
|
49 |
return BastionResource('/../api/v2/hostgroups/:id/:action', |
|
50 |
{id: '@id'}, {}); |
|
51 |
}] |
|
52 |
); |
|
10 | 53 |
|
11 |
angular.module('ForemanPipeline.jobs').factory('Job', |
|
12 |
['BastionResource', 'CurrentOrganization', |
|
13 |
function (BastionResource, CurrentOrganization) { |
|
14 |
|
|
15 |
return BastionResource('/../foreman_pipeline/api/organizations/:organizationId/jobs/:id/:action', |
|
16 |
{id: '@id', organizationId: CurrentOrganization}, { |
|
17 |
|
|
18 |
update: {method: 'PUT'}, |
|
19 |
setContentView: {method: 'PUT', params: {action: 'set_content_view'}}, |
|
20 |
setHostgroup: {method: 'PUT', params: {action: 'set_hostgroup'}}, |
|
21 |
setJenkins: {method: 'PUT', params: {action: 'set_jenkins'}}, |
|
22 |
setResource: {method: 'PUT', params: {action: 'set_resource'}}, |
|
23 |
setEnvironment: {method: 'PUT', params: {action: 'set_environment'}}, |
|
24 |
availableResources: {method: 'GET', params: {action: 'available_resources'}, transformResponse: function (response) { |
|
25 |
return {results: angular.fromJson(response)}; |
|
26 |
}}, |
|
27 |
runJob: {method: 'GET', params: {action: 'run_job'}}, |
|
28 |
projects: {method: 'GET', transformResponse: function (response) { |
|
29 |
var job = angular.fromJson(response); |
|
30 |
return {results: job.jenkins_projects}; |
|
31 |
}}, |
|
32 |
addProjects: {method: 'PUT', params: {action: 'add_projects'}}, |
|
33 |
removeProjects: {method: 'PUT', params: {action: 'remove_projects'}}, |
|
34 |
|
|
35 |
availableToEnvironments: {method: 'GET', |
|
36 |
params: {action: 'available_paths'}, |
|
37 |
isArray: true, |
|
38 |
transformResponse: function (data) { |
|
39 |
return transformPaths(data); |
|
40 |
} |
|
41 |
}, |
|
42 |
setToEnvironments: {method: 'PUT', params: {action: 'set_to_environments'}}, |
|
43 |
}); |
|
44 |
}] |
|
45 |
); |
|
46 |
|
|
47 |
angular.module('ForemanPipeline.jobs').factory('Hostgroup', |
|
48 |
['BastionResource', |
|
49 |
function (BastionResource) { |
|
50 |
|
|
51 |
return BastionResource('/../api/v2/hostgroups/:id/:action', |
|
52 |
{id: '@id'}, {}); |
|
53 |
}] |
|
54 |
); |
|
55 |
|
|
56 |
angular.module('ForemanPipeline.jobs').factory('Path', |
|
57 |
['BastionResource', 'CurrentOrganization', |
|
58 |
function (BastionResource, CurrentOrganization) { |
|
59 |
|
|
60 |
return BastionResource('/../foreman_pipeline/api/organizations/:organizationId/paths/:action', |
|
61 |
{organizationId: CurrentOrganization}, { |
|
62 |
|
|
63 |
allPaths: {method: 'GET', |
|
64 |
params: {action: 'all_paths'}, |
|
65 |
isArray: true, |
|
66 |
transformResponse: function (data) { |
|
67 |
return transformPaths(data); |
|
68 |
} |
|
69 |
}, |
|
70 |
}); |
|
71 |
}] |
|
72 |
); |
|
73 |
})(); |
|
74 | 54 |
|
app/controllers/foreman_pipeline/api/jobs_controller.rb | ||
---|---|---|
79 | 79 |
param_group :job_id |
80 | 80 |
param :content_view_id, :number, :desc => N_("Content view id which will be set"), :required => true |
81 | 81 |
def set_content_view |
82 |
@job.content_view = Katello::ContentView.find(params[:content_view_id]) |
|
82 |
cv = Katello::ContentView.find(params[:content_view_id]) |
|
83 |
fail Katello::HttpErrors::Conflict, "Only non-composite views are accepted" if cv.composite? |
|
84 |
@job.content_view = cv |
|
83 | 85 |
@job.save! |
84 | 86 |
respond_for_show |
85 | 87 |
end |
... | ... | |
131 | 133 |
param_group :job_id |
132 | 134 |
param :path_ids, Array, :desc => N_("Identifiers of environments which are successors of job's environment") |
133 | 135 |
def set_to_environments |
136 |
fail Katello::HttpErrors::Conflict, "Job's environment must be assigned before setting 'to environments'." if @job.environment.nil? |
|
137 |
fail Katello::HttpErrors::Conflict, "Job's environment does not have any successors" if @job.environment.successors.empty? |
|
134 | 138 |
is_ok = params[:to_environment_ids].map do |new_id| |
135 | 139 |
@job.environment.successors.map(&:id).include? new_id |
136 | 140 |
end.all? |
... | ... | |
146 | 150 |
api :GET, "/organizations/:organization_id/jobs/:id/available_paths", N_("List environment paths available for a job") |
147 | 151 |
param_group :job_id |
148 | 152 |
def available_paths |
149 |
available = @job.environment.full_paths rescue [] |
|
150 |
|
|
151 |
paths = available.inject([]) do |result, path| |
|
152 |
result << { :environments => path } |
|
153 |
available = [] |
|
154 |
paths = [] |
|
155 |
if params[:all_paths] |
|
156 |
available = @organization.readable_promotion_paths |
|
157 |
paths = available.inject([]) do |result, path| |
|
158 |
result << { :environments => [@organization.library] + path } |
|
159 |
end |
|
160 |
paths = [{ :environments => [@organization.library] }] if paths.empty? |
|
161 |
else |
|
162 |
available = @job.environment.full_paths rescue [] |
|
163 |
paths = available.inject([]) do |result, path| |
|
164 |
result << { :environments => path } |
|
165 |
end |
|
166 |
paths = [{ :environments => [] }] if paths.empty? |
|
153 | 167 |
end |
154 |
paths = [{ :environments => [] }] if paths.empty? |
|
155 |
|
|
168 |
|
|
156 | 169 |
collection = { |
157 | 170 |
:results => paths, |
158 | 171 |
:total => paths.size, |
... | ... | |
174 | 187 |
def run_job |
175 | 188 |
if @job.manual_trigger |
176 | 189 |
task = async_task(::Actions::ForemanPipeline::Job::RunJobManually, @job) |
177 |
render :nothing => true
|
|
190 |
render :nothing => true |
|
178 | 191 |
else |
179 | 192 |
fail ::Katello::HttpErrors::Forbidden, "Running manually not allowed for Job: #{@job.name}. Try setting it's :manual_trigger property." |
180 | 193 |
end |
... | ... | |
216 | 229 |
if rollback[:occured] |
217 | 230 |
fail ::Katello::HttpErrors::NotFound, "Could not retrieve build params for Jenkins project: #{rollback[:project_name]}" |
218 | 231 |
else |
219 |
respond_for_show
|
|
232 |
respond_for_show |
|
220 | 233 |
end |
221 | 234 |
end |
222 | 235 |
|
app/controllers/foreman_pipeline/api/paths_controller.rb | ||
---|---|---|
1 |
module ForemanPipeline |
|
2 |
class Api::PathsController < Katello::Api::V2::ApiController |
|
3 |
respond_to :json |
|
4 |
|
|
5 |
include Api::Rendering |
|
6 |
|
|
7 |
before_filter :find_organization, :only => [:all_paths] |
|
8 |
|
|
9 |
api :GET, "/organizations/:organization_id/paths/all_paths", N_("List all environment paths in organization") |
|
10 |
param :organization_id, :number, :sdesc => N_("Organization identifier"), :required => true |
|
11 |
def all_paths |
|
12 |
env_paths = if params[:permission_type] == "promotable" |
|
13 |
@organization.promotable_promotion_paths |
|
14 |
else |
|
15 |
@organization.readable_promotion_paths |
|
16 |
end |
|
17 |
|
|
18 |
paths = env_paths.inject([]) do |result, path| |
|
19 |
result << { :environments => [@organization.library] + path } |
|
20 |
end |
|
21 |
paths = [{ :environments => [@organization.library] }] if paths.empty? |
|
22 |
|
|
23 |
collection = { |
|
24 |
:results => paths, |
|
25 |
:total => paths.size, |
|
26 |
:subtotal => paths.size |
|
27 |
} |
|
28 |
respond_for_index(:collection => collection, :template => '../jobs/available_paths') |
|
29 |
end |
|
30 |
|
|
31 |
end |
|
32 |
end |
config/routes.rb | ||
---|---|---|
46 | 46 |
api_resources :jenkins_project_params, :only => [:update] |
47 | 47 |
|
48 | 48 |
api_resources :jenkins_users, :only => [:index, :create, :destroy, :show, :update] |
49 |
|
|
50 |
api_resources :paths, :only => [] do |
|
51 |
collection do |
|
52 |
get :all_paths |
|
53 |
end |
|
54 |
end |
|
55 | 49 |
|
56 | 50 |
end |
57 | 51 |
end |
Also available in: Unified diff
loading environments simplified