Skip to content

Commit

Permalink
[api] check the verifymd5 instead of the srcmd5 against jobhistory
Browse files Browse the repository at this point in the history
Also check the now fast lastfailures route for the md5sum first - saving considerable
time in repo checker
  • Loading branch information
coolo committed Jul 26, 2013
1 parent 94b0f4a commit 83f08cf
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 48 deletions.
29 changes: 14 additions & 15 deletions src/api/app/controllers/build_controller.rb
Expand Up @@ -245,31 +245,30 @@ def result
# for permission check
Project.get_by_name params[:project]

# this route is mainly for checking submissions to a target project
if params.has_key? :lastsuccess
required_parameters :package
required_parameters :package, :pathproject

outputxml = "<status>\n"
pkg = Package.get_by_project_and_name params[:project], params[:package],
use_source: false, follow_project_links: false

# might be nil
tprj = Project.find_by_name params[:pathproject]
result = pkg.buildstatus(target_project: tprj, srcmd5: params[:srcmd5])
result.each do |repo, status|
outputxml << " <repository name='#{repo}'>\n"
tprj = Project.get_by_name params[:pathproject]
bs = pkg.buildstatus(target_project: tprj, srcmd5: params[:srcmd5])
@result = []
bs.each do |repo, status|
archs = []
status.each do |arch, archstat|
outputxml << " <arch arch='#{arch}' result='#{archstat[:result]}'"
oneline = [arch, archstat[:result]]
if archstat[:missing]
missing = archstat[:missing].join(",")
outputxml << " missing='#{missing}'"
oneline << archstat[:missing].join(",")
else
oneline << nil
end
outputxml << "/> \n"
archs << oneline
end
outputxml << " </repository>\n"

@result << [repo, archs]
end
outputxml << "</status>\n"
render text: outputxml
render text: render_to_string(partial: "lastsuccess")
return
end

Expand Down
81 changes: 48 additions & 33 deletions src/api/app/models/package.rb
Expand Up @@ -1065,16 +1065,11 @@ def buildstatus(opts)
srcmd5 = opts[:srcmd5]

# check current srcmd5
cdir = Directory.hashed(:project => self.project.name,
:package => self.name,
:expand => 1)
cdir = Directory.hashed(project: self.project.name,
package: self.name,
expand: 1)
csrcmd5 = cdir['srcmd5']

if tproj
tocheck_repos = self.project.repositories_linking_project(tproj)
else
tocheck_repos = []
end
tocheck_repos = self.project.repositories_linking_project(tproj)

raise NoRepositoriesFound.new if tocheck_repos.empty?

Expand All @@ -1086,7 +1081,7 @@ def buildstatus(opts)
srep.elements('path') do |p|
if p['project'] != self.project.name
r = Repository.find_by_project_and_repo_name(p['project'], p['repository'])
r.architectures.each { |a| archs << a.name }
r.architectures.each { |a| archs << a.name.to_s }
trepo << [p['project'], p['repository']]
end
end
Expand All @@ -1101,32 +1096,52 @@ def buildstatus(opts)
next if vprojects.has_key? p
prj = Project.find_by_name(p)
next unless prj # in case of remote projects
prj.packages.select(:name).each { |n| tpackages[n.name] = p }
prj.packages.pluck(:name).each { |n| tpackages[n] = p }
vprojects[p] = 1
end

archs.each do |arch|
everbuilt = 0
eversucceeded = 0
buildcode =nil
hist = Jobhistory.find(:project => self.project.name,
:repository => srep['name'],
:package => self.name,
:arch => arch.to_s, :limit => 20)
next unless hist
hist.each_jobhist do |jh|
next if jh.srcmd5 != srcmd5
everbuilt = 1
if jh.code == 'succeeded' || jh.code == 'unchanged'
everbuilt = false
eversucceeded = false
buildcode = nil
# first we check the lastfailures. This route is fast but only has up to
# two results per package. If the md5sum does not match, we have to dig deeper
hist = Jobhistory.find_hashed(project: self.project.name,
repository: srep['name'],
package: self.name,
arch: arch,
code: 'lastfailures')
next if hist.blank?
hist.elements('jobhist') do |jh|
if jh['verifymd5'] == srcmd5
everbuilt = true
end
end

if !everbuilt
hist = Jobhistory.find_hashed(project: self.project.name,
repository: srep['name'],
package: self.name,
arch: arch,
limit: 20,
expires_in: 15.minutes)
end

# going through the job history to check if it built and if yes, succeeded
hist.elements('jobhist') do |jh|
next unless jh['verifymd5'] == srcmd5
everbuilt = true
if jh['code'] == 'succeeded' || jh['code'] == 'unchanged'
buildcode ='succeeded'
eversucceeded = 1
eversucceeded = true
break
end
end
logger.debug "arch:#{arch} md5:#{srcmd5} successed:#{eversucceeded} built:#{everbuilt}"
missingdeps=[]
if eversucceeded == 1
uri = URI("/build/#{CGI.escape(self.project.name)}/#{CGI.escape(srep['name'])}/#{CGI.escape(arch.to_s)}/_builddepinfo?package=#{CGI.escape(self.name)}&view=pkgnames")
# if
if eversucceeded
uri = URI("/build/#{CGI.escape(self.project.name)}/#{CGI.escape(srep['name'])}/#{CGI.escape(arch)}/_builddepinfo?package=#{CGI.escape(self.name)}&view=pkgnames")
begin
buildinfo = Xmlhash.parse(ActiveXML.transport.direct_http(uri))
rescue ActiveXML::Transport::Error => e
Expand All @@ -1143,22 +1158,22 @@ def buildstatus(opts)
end

# if the package does not appear in build history, check flags
if everbuilt == 0
buildflag=self.find_flag_state("build", srep['name'], arch.to_s)
logger.debug "find_flag_state #{srep['name']} #{arch.to_s} #{buildflag}"
if !everbuilt
buildflag=self.find_flag_state("build", srep['name'], arch)
logger.debug "find_flag_state #{srep['name']} #{arch} #{buildflag}"
if buildflag == 'disable'
buildcode='disabled'
end
end

if !buildcode && srcmd5 != csrcmd5 && everbuilt == 1
if !buildcode && srcmd5 != csrcmd5 && everbuilt
buildcode='failed' # has to be
end

unless buildcode
buildcode="unknown"
begin
uri = URI("/build/#{CGI.escape(self.project.name)}/_result?package=#{CGI.escape(self.name)}&repository=#{CGI.escape(srep['name'])}&arch=#{CGI.escape(arch.to_s)}")
uri = URI("/build/#{CGI.escape(self.project.name)}/_result?package=#{CGI.escape(self.name)}&repository=#{CGI.escape(srep['name'])}&arch=#{CGI.escape(arch)}")
resultlist = ActiveXML::Node.new(ActiveXML.transport.direct_http(uri))
currentcode = nil
resultlist.each_result do |r|
Expand Down Expand Up @@ -1186,8 +1201,8 @@ def buildstatus(opts)
end
end

output[srep['name']][arch.to_s] = { result: buildcode }
output[srep['name']][arch.to_s][:missing] = missingdeps.uniq if (missingdeps.size > 0 && buildcode == 'succeeded')
output[srep['name']][arch] = { result: buildcode }
output[srep['name']][arch][:missing] = missingdeps.uniq
end
end

Expand Down
13 changes: 13 additions & 0 deletions src/api/app/views/build/_lastsuccess.xml.builder
@@ -0,0 +1,13 @@
xml.status do
@result.each do |repo, archs|
xml.repository(name: repo) do
archs.each do |name, result, missing|
if missing.blank?
xml.arch(arch: name, result: result)
else
xml.arch(arch: name, result: result, missing: missing)
end
end
end
end
end

0 comments on commit 83f08cf

Please sign in to comment.