Class: ForemanPipeline::Api::JobsController
- Inherits:
-
Katello::Api::V2::ApiController
- Object
- Katello::Api::V2::ApiController
- ForemanPipeline::Api::JobsController
- Includes:
- Rendering, Concerns::ApiControllerExtensions
- Defined in:
- app/controllers/foreman_pipeline/api/jobs_controller.rb
Instance Method Summary collapse
- #add_projects ⇒ Object
- #available_paths ⇒ Object
- #available_resources ⇒ Object
- #create ⇒ Object
- #destroy ⇒ Object
- #index ⇒ Object
- #index_relation ⇒ Object
- #remove_projects ⇒ Object
- #run_job ⇒ Object
- #set_content_view ⇒ Object
- #set_environment ⇒ Object
- #set_hostgroup ⇒ Object
- #set_jenkins ⇒ Object
- #set_resource ⇒ Object
- #set_to_environments ⇒ Object
- #show ⇒ Object
- #update ⇒ Object
Methods included from Concerns::ApiControllerExtensions
Methods included from Rendering
Instance Method Details
#add_projects ⇒ Object
200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 |
# File 'app/controllers/foreman_pipeline/api/jobs_controller.rb', line 200 def add_projects rollback = {:occured => false} Job.transaction do projects = params[:projects].map do |p| JenkinsProject.create(:name => p, :organization_id => @organization.id) end projects_to_add = projects.delete_if { |p| @job.jenkins_projects.include? p } @job.jenkins_projects = @job.jenkins_projects + projects_to_add @job.save! projects_to_add.each do |project| project.reload task = sync_task(::Actions::ForemanPipeline::Jenkins::GetBuildParams, :job_id => @job.id, :name => project.name) unless task.output[:build_params] raise ActiveRecord::Rollback rollback[:occured] = true rollback[:project_name] = project.name end task.output[:build_params].each do |param| new_param = JenkinsProjectParam.new(:name => param[:name], :type => param[:type], :description => param[:description], :value => param[:default]) new_param.organization = @organization new_param.jenkins_project = project new_param.save! end end end if rollback[:occured] fail ::Katello::HttpErrors::NotFound, "Could not retrieve build params for Jenkins project: #{rollback[:project_name]}" else respond_for_show end end |
#available_paths ⇒ Object
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 |
# File 'app/controllers/foreman_pipeline/api/jobs_controller.rb', line 153 def available_paths available = [] paths = [] if params[:all_paths] available = @organization.readable_promotion_paths paths = available.inject([]) do |result, path| result << { :environments => [@organization.library] + path } end paths = [{ :environments => [@organization.library] }] if paths.empty? else available = @job.environment.full_paths rescue [] paths = available.inject([]) do |result, path| result << { :environments => path } end paths = [{ :environments => [] }] if paths.empty? end collection = { :results => paths, :total => paths.size, :subtotal => paths.size } respond_for_index(:collection => collection) end |
#available_resources ⇒ Object
181 182 183 184 |
# File 'app/controllers/foreman_pipeline/api/jobs_controller.rb', line 181 def available_resources @compute_resources = @job.available_compute_resources render "api/v2/compute_resources/index" end |
#create ⇒ Object
55 56 57 58 59 60 61 |
# File 'app/controllers/foreman_pipeline/api/jobs_controller.rb', line 55 def create @job = Job.new(job_params) @job.organization = @organization @job.save! respond_for_show(:resource => @job) end |
#destroy ⇒ Object
74 75 76 77 |
# File 'app/controllers/foreman_pipeline/api/jobs_controller.rb', line 74 def destroy @job.destroy respond_for_show(:resource => @job) end |
#index ⇒ Object
32 33 34 |
# File 'app/controllers/foreman_pipeline/api/jobs_controller.rb', line 32 def index respond_for_index(:collection => scoped_search(index_relation.uniq, params[:sort_by], params[:sort_order])) end |
#index_relation ⇒ Object
36 37 38 39 40 41 42 43 44 |
# File 'app/controllers/foreman_pipeline/api/jobs_controller.rb', line 36 def index_relation query = Job.readable.where(:organization_id => @organization.id) query = query.where(:name => params[:name]) if params[:name] query = query.where(:manual_trigger => params[:manual_trigger]) if params[:manual_trigger] query = query.where(:sync_trigger => params[:sync_trigger]) if params[:sync_trigger] query = query.where(:levelup_trigger => params[:levelup_trigger]) if params[:levelup_trigger] query = query.where(:promote => params[:promote]) if params[:promote] query end |
#remove_projects ⇒ Object
240 241 242 243 244 245 |
# File 'app/controllers/foreman_pipeline/api/jobs_controller.rb', line 240 def remove_projects ids = params[:project_ids] jj_projects = JobJenkinsProject.where(:jenkins_project_id => ids) jj_projects.map(&:destroy) respond_for_show end |
#run_job ⇒ Object
188 189 190 191 192 193 194 195 |
# File 'app/controllers/foreman_pipeline/api/jobs_controller.rb', line 188 def run_job if @job.manual_trigger task = async_task(::Actions::ForemanPipeline::Job::RunJobManually, @job) render :nothing => true else fail ::Katello::HttpErrors::Forbidden, "Running manually not allowed for Job: #{@job.name}. Try setting it's :manual_trigger property." end end |
#set_content_view ⇒ Object
82 83 84 85 86 87 88 |
# File 'app/controllers/foreman_pipeline/api/jobs_controller.rb', line 82 def set_content_view cv = Katello::ContentView.find(params[:content_view_id]) fail Katello::HttpErrors::Conflict, "Only non-composite views are accepted" if cv.composite? @job.content_view = cv @job.save! respond_for_show end |
#set_environment ⇒ Object
113 114 115 116 117 118 |
# File 'app/controllers/foreman_pipeline/api/jobs_controller.rb', line 113 def set_environment @job.environment = Katello::KTEnvironment.find(params[:environment_id]) @job.to_environments = [] @job.save! respond_for_show end |
#set_hostgroup ⇒ Object
93 94 95 96 97 98 |
# File 'app/controllers/foreman_pipeline/api/jobs_controller.rb', line 93 def set_hostgroup @job.hostgroup = Hostgroup.find(params[:hostgroup_id]) @job.compute_resource = nil @job.save! respond_for_show end |
#set_jenkins ⇒ Object
103 104 105 106 107 108 |
# File 'app/controllers/foreman_pipeline/api/jobs_controller.rb', line 103 def set_jenkins instance = JenkinsInstance.find(params[:jenkins_instance_id]) @job.jenkins_instance = instance @job.save! respond_for_show end |
#set_resource ⇒ Object
123 124 125 126 127 128 129 130 131 |
# File 'app/controllers/foreman_pipeline/api/jobs_controller.rb', line 123 def set_resource if @job.available_compute_resources.map(&:id).include? params[:resource_id] @job.compute_resource = ComputeResource.find(params[:resource_id]) @job.save! respond_for_show else fail Katello::HttpErrors::Conflict, "Only a Compute Resource configured for Job's Hostgroup may be set." end end |
#set_to_environments ⇒ Object
136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'app/controllers/foreman_pipeline/api/jobs_controller.rb', line 136 def set_to_environments fail Katello::HttpErrors::Conflict, "Job's environment must be assigned before setting 'to environments'." if @job.environment.nil? fail Katello::HttpErrors::Conflict, "Job's environment does not have any successors" if @job.environment.successors.empty? is_ok = params[:to_environment_ids].map do |new_id| @job.environment.successors.map(&:id).include? new_id end.all? if is_ok @job.to_environment_ids = params[:to_environment_ids] @job.save! respond_for_show else fail Katello::HttpErrors::Conflict, "Only environments that are direct successors of Job's Environment may be set as 'to environments'." end end |
#show ⇒ Object
48 49 50 |
# File 'app/controllers/foreman_pipeline/api/jobs_controller.rb', line 48 def show respond_for_show(:resource => @job) end |
#update ⇒ Object
66 67 68 69 70 |
# File 'app/controllers/foreman_pipeline/api/jobs_controller.rb', line 66 def update @job.update_attributes!(job_params) @job.save! respond_for_show(:resource => @job) end |