1
|
module ForemanPipeline
|
2
|
class Job < Katello::Model
|
3
|
self.include_root_in_json = false
|
4
|
|
5
|
include Katello::Glue
|
6
|
include Glue::ElasticSearch::Job
|
7
|
include ForemanPipeline::Authorization::Job
|
8
|
include ActiveModel::Validations
|
9
|
|
10
|
belongs_to :content_view, :class_name => 'Katello::ContentView', :inverse_of => :jobs
|
11
|
belongs_to :hostgroup, :class_name => '::Hostgroup', :inverse_of => :jobs
|
12
|
belongs_to :organization
|
13
|
belongs_to :compute_resource, :class_name => '::ComputeResource', :inverse_of => :jobs
|
14
|
belongs_to :jenkins_instance, :class_name => "ForemanPipeline::JenkinsInstance"
|
15
|
belongs_to :environment, :class_name => 'Katello::KTEnvironment', :inverse_of => :jobs
|
16
|
|
17
|
has_many :job_jenkins_projects, :dependent => :destroy
|
18
|
has_many :jenkins_projects, :through => :job_jenkins_projects, :class_name => 'ForemanPipeline::JenkinsProject', :dependent => :restrict
|
19
|
|
20
|
has_many :content_view_repositories, :class_name=> 'Katello::ContentViewRepository',
|
21
|
:primary_key => :content_view_id, :foreign_key => :content_view_id
|
22
|
has_many :repositories, :through => :content_view_repositories
|
23
|
|
24
|
validates :name, :presence => true
|
25
|
validates :organization, :presence => true
|
26
|
validate :no_composite_view
|
27
|
|
28
|
def is_valid?
|
29
|
!self.attributes.values.include? nil
|
30
|
end
|
31
|
|
32
|
def target_cv_version_avail?
|
33
|
!target_cv_version.nil?
|
34
|
end
|
35
|
|
36
|
def target_cv_version
|
37
|
fail "Cannot fetch target version, no environment set" if environment.nil?
|
38
|
fail "Cannot fetch target version, no content view set" if content_view.nil?
|
39
|
self.environment.content_view_versions.where(:content_view_id => self.content_view.id).first
|
40
|
end
|
41
|
|
42
|
def init_run
|
43
|
fail "Cannnot contact Jenkins server: no Jenkins Instance set for the job: #{name}" if jenkins_instance.nil?
|
44
|
fail "Cannot log in to Jenkins server:
|
45
|
no Jenkins User set for the Jenkins Instance: #{jenkins_instancej.name}" if jenkins_instance.jenkins_user.nil?
|
46
|
jenkins_instance.create_client(jenkins_instance.jenkins_user.name, jenkins_instance.jenkins_user.token)
|
47
|
end
|
48
|
|
49
|
def version_already_promoted?
|
50
|
self.target_cv_version.environments.include?(self.environment.successor)
|
51
|
end
|
52
|
|
53
|
private
|
54
|
|
55
|
def no_composite_view
|
56
|
errors.add(:base,
|
57
|
"Cannot add content view, only non-composites allowed.") if !content_view.nil? && content_view.composite?
|
58
|
end
|
59
|
|
60
|
end
|
61
|
end
|